1 // Copyright 2014 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_UI_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_
8 #include "components/password_manager/core/browser/password_form_manager.h"
9 #include "components/password_manager/core/browser/password_store.h"
10 #include "components/password_manager/core/browser/password_store_change.h"
11 #include "components/password_manager/core/common/password_manager_ui.h"
12 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
20 class ManagePasswordsIcon;
22 // Per-tab class to control the Omnibox password icon and bubble.
23 class ManagePasswordsUIController
24 : public content::WebContentsObserver,
25 public content::WebContentsUserData<ManagePasswordsUIController>,
26 public password_manager::PasswordStore::Observer {
28 virtual ~ManagePasswordsUIController();
30 // Called when the user submits a form containing login information, so we
31 // can handle later requests to save or blacklist that login information.
32 // This stores the provided object in form_manager_ and triggers the UI to
33 // prompt the user about whether they would like to save the password.
34 void OnPasswordSubmitted(password_manager::PasswordFormManager* form_manager);
36 // Called when a form is autofilled with login information, so we can manage
37 // password credentials for the current site which are stored in
38 // |password_form_map|. This stores a copy of |password_form_map| and shows
39 // the manage password icon.
40 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map);
42 // Called when a form is _not_ autofilled due to user blacklisting. This
43 // stores a copy of |password_form_map| so that we can offer the user the
44 // ability to reenable the manager for this form.
45 void OnBlacklistBlockedAutofill(
46 const autofill::PasswordFormMap& password_form_map);
48 // PasswordStore::Observer implementation.
49 virtual void OnLoginsChanged(
50 const password_manager::PasswordStoreChangeList& changes) OVERRIDE;
52 // Called from the model when the user chooses to save a password; passes the
53 // action off to the FormManager. The controller MUST be in a pending state,
54 // and WILL be in MANAGE_STATE after this method executes.
55 virtual void SavePassword();
57 // Called from the model when the user chooses to never save passwords; passes
58 // the action off to the FormManager. The controller MUST be in a pending
59 // state, and WILL be in BLACKLIST_STATE after this method executes.
60 virtual void NeverSavePassword();
62 // Called from the model when the user chooses to unblacklist the site. The
63 // controller MUST be in BLACKLIST_STATE, and WILL be in MANAGE_STATE after
64 // this method executes.
65 virtual void UnblacklistSite();
67 // Open a new tab, pointing to the password manager settings page.
68 virtual void NavigateToPasswordManagerSettingsPage();
70 virtual const autofill::PasswordForm& PendingCredentials() const;
72 // Set the state of the Omnibox icon, and possibly show the associated bubble
73 // without user interaction.
74 virtual void UpdateIconAndBubbleState(ManagePasswordsIcon* icon);
76 password_manager::ui::State state() const { return state_; }
78 // True if a password is sitting around, waiting for a user to decide whether
80 bool PasswordPendingUserDecision() const;
82 const autofill::PasswordFormMap best_matches() const {
83 return password_form_map_;
86 const GURL& origin() const { return origin_; }
89 explicit ManagePasswordsUIController(
90 content::WebContents* web_contents);
92 // All previously stored credentials for a specific site. Set by
93 // OnPasswordSubmitted(), OnPasswordAutofilled(), or
94 // OnBlacklistBlockedAutofill(). Protected, not private, so we can mess with
95 // the value in ManagePasswordsUIControllerMock.
96 autofill::PasswordFormMap password_form_map_;
98 // The current state of the password manager. Protected so we can manipulate
99 // the value in tests.
100 password_manager::ui::State state_;
103 friend class content::WebContentsUserData<ManagePasswordsUIController>;
105 // Shows the password bubble without user interaction. The controller MUST
106 // be in PENDING_PASSWORD_AND_BUBBLE_STATE.
107 void ShowBubbleWithoutUserInteraction();
109 // Called when a passwordform is autofilled, when a new passwordform is
110 // submitted, or when a navigation occurs to update the visibility of the
111 // manage passwords icon and bubble.
112 void UpdateBubbleAndIconVisibility();
114 // content::WebContentsObserver:
115 virtual void DidNavigateMainFrame(
116 const content::LoadCommittedDetails& details,
117 const content::FrameNavigateParams& params) OVERRIDE;
118 virtual void WebContentsDestroyed() OVERRIDE;
120 // Set by OnPasswordSubmitted() when the user submits a form containing login
121 // information. If the user responds to a subsequent "Do you want to save
122 // this password?" prompt, we ask this object to save or blacklist the
123 // associated login information in Chrome's password store.
124 scoped_ptr<password_manager::PasswordFormManager> form_manager_;
126 // Stores whether autofill was blocked due to a user's decision to blacklist
127 // the current site ("Never save passwords for this site").
128 bool autofill_blocked_;
130 // The origin of the form we're currently dealing with; we'll use this to
131 // determine which PasswordStore changes we should care about when updating
132 // |password_form_map_|.
135 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController);
138 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_