Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / passwords / manage_passwords_bubble_ui_controller.h
blob83e7c12bbe5612c4fa9859d8ba469b21a70d3127
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_UI_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_UI_CONTROLLER_H_
8 #include "chrome/browser/password_manager/password_form_manager.h"
9 #include "content/public/browser/navigation_details.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
13 namespace content {
14 class WebContents;
17 // Per-tab class to control the Omnibox password icon and bubble.
18 class ManagePasswordsBubbleUIController
19 : public content::WebContentsObserver,
20 public content::WebContentsUserData<ManagePasswordsBubbleUIController> {
21 public:
22 virtual ~ManagePasswordsBubbleUIController();
24 // Called when the user submits a form containing login information, so we
25 // can handle later requests to save or blacklist that login information.
26 // This stores the provided object in form_manager_ and triggers the UI to
27 // prompt the user about whether they would like to save the password.
28 void OnPasswordSubmitted(PasswordFormManager* form_manager);
30 // Called when a form is autofilled with login information, so we can manage
31 // password credentials for the current site which are stored in
32 // |password_form_map|. This stores a copy of |password_form_map| and shows
33 // the manage password icon.
34 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map);
36 // TODO(npentrel) This ought to be changed. Best matches should be newly
37 // made when opening the ManagePasswordsBubble because there may have been
38 // changes to the best matches via the settings page. At the moment this also
39 // fails if one deletes a password when they are autofilled, as it still shows
40 // up after logging in and saving a password.
41 void RemoveFromBestMatches(autofill::PasswordForm password_form);
43 void SavePassword();
45 // Called when the bubble is opened after the icon gets displayed. We change
46 // the state to know that we do not need to pop up the bubble again.
47 void OnBubbleShown();
49 bool manage_passwords_icon_to_be_shown() const {
50 return manage_passwords_icon_to_be_shown_;
53 bool password_to_be_saved() const {
54 return password_to_be_saved_;
57 bool manage_passwords_bubble_needs_showing() const {
58 return manage_passwords_bubble_needs_showing_;
61 void unset_manage_passwords_bubble_needs_showing() {
62 manage_passwords_bubble_needs_showing_ = false;
65 void unset_password_to_be_saved() {
66 password_to_be_saved_ = false;
69 const autofill::PasswordForm pending_credentials() const {
70 return form_manager_->pending_credentials();
73 const autofill::PasswordFormMap best_matches() const {
74 return password_form_map_;
77 bool password_submitted() const {
78 return password_submitted_;
81 void set_password_submitted(bool password_submitted) {
82 password_submitted_ = password_submitted;
85 private:
86 friend class content::WebContentsUserData<ManagePasswordsBubbleUIController>;
88 explicit ManagePasswordsBubbleUIController(
89 content::WebContents* web_contents);
91 // Called when a passwordform is autofilled, when a new passwordform is
92 // submitted, or when a navigation occurs to update the visibility of the
93 // manage passwords icon and bubble.
94 void UpdateBubbleAndIconVisibility();
96 // content::WebContentsObserver:
97 virtual void DidNavigateMainFrame(
98 const content::LoadCommittedDetails& details,
99 const content::FrameNavigateParams& params) OVERRIDE;
101 // Set by OnPasswordSubmitted() when the user submits a form containing login
102 // information. If the user responds to a subsequent "Do you want to save
103 // this password?" prompt, we ask this object to save or blacklist the
104 // associated login information in Chrome's password store.
105 scoped_ptr<PasswordFormManager> form_manager_;
107 // All previously stored credentials for a specific site. Set by
108 // OnPasswordSubmitted() or OnPasswordAutofilled().
109 autofill::PasswordFormMap password_form_map_;
111 bool manage_passwords_icon_to_be_shown_;
112 bool password_to_be_saved_;
113 bool manage_passwords_bubble_needs_showing_;
114 // Stores whether a new password has been submitted, if so we have
115 // |pending_credentials|.
116 bool password_submitted_;
118 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleUIController);
121 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_UI_CONTROLLER_H_