OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/timer/elapsed_timer.h" | 10 #include "base/timer/elapsed_timer.h" |
11 #include "components/autofill/core/common/password_form.h" | 11 #include "components/autofill/core/common/password_form.h" |
12 #include "components/password_manager/core/browser/password_form_manager.h" | 12 #include "components/password_manager/core/browser/password_form_manager.h" |
13 #include "components/password_manager/core/browser/password_store.h" | 13 #include "components/password_manager/core/browser/password_store.h" |
14 #include "components/password_manager/core/browser/password_store_change.h" | 14 #include "components/password_manager/core/browser/password_store_change.h" |
15 #include "components/password_manager/core/common/password_manager_ui.h" | 15 #include "components/password_manager/core/common/password_manager_ui.h" |
16 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
18 #include "content/public/browser/web_contents_user_data.h" | 18 #include "content/public/browser/web_contents_user_data.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class WebContents; | 21 class WebContents; |
22 } | 22 } |
23 | 23 |
24 namespace password_manager { | |
25 struct CredentialInfo; | |
26 } | |
27 | |
28 class ManagePasswordsBubbleModel; | |
24 class ManagePasswordsIcon; | 29 class ManagePasswordsIcon; |
25 | 30 |
26 // Per-tab class to control the Omnibox password icon and bubble. | 31 // Per-tab class to control the Omnibox password icon and bubble. |
27 class ManagePasswordsUIController | 32 class ManagePasswordsUIController |
28 : public content::WebContentsObserver, | 33 : public content::WebContentsObserver, |
29 public content::WebContentsUserData<ManagePasswordsUIController>, | 34 public content::WebContentsUserData<ManagePasswordsUIController>, |
30 public password_manager::PasswordStore::Observer { | 35 public password_manager::PasswordStore::Observer { |
31 public: | 36 public: |
32 ~ManagePasswordsUIController() override; | 37 ~ManagePasswordsUIController() override; |
33 | 38 |
34 // Called when the user submits a form containing login information, so we | 39 // Called when the user submits a form containing login information, so we |
35 // can handle later requests to save or blacklist that login information. | 40 // can handle later requests to save or blacklist that login information. |
36 // This stores the provided object in form_manager_ and triggers the UI to | 41 // This stores the provided object in form_manager_ and triggers the UI to |
37 // prompt the user about whether they would like to save the password. | 42 // prompt the user about whether they would like to save the password. |
38 void OnPasswordSubmitted( | 43 void OnPasswordSubmitted( |
39 scoped_ptr<password_manager::PasswordFormManager> form_manager); | 44 scoped_ptr<password_manager::PasswordFormManager> form_manager); |
40 | 45 |
46 // Called when the site asks user to choose from credentials. This triggers | |
47 // the UI to prompt the user. |credentials| shouldn't be empty. | |
48 bool OnChooseCredentials( | |
49 ScopedVector<autofill::PasswordForm> credentials, | |
50 base::Callback<void(const password_manager::CredentialInfo&)> callback); | |
51 | |
41 // Called when the password will be saved automatically, but we still wish to | 52 // Called when the password will be saved automatically, but we still wish to |
42 // visually inform the user that the save has occured. | 53 // visually inform the user that the save has occured. |
43 void OnAutomaticPasswordSave( | 54 void OnAutomaticPasswordSave( |
44 scoped_ptr<password_manager::PasswordFormManager> form_manager); | 55 scoped_ptr<password_manager::PasswordFormManager> form_manager); |
45 | 56 |
46 // Called when a form is autofilled with login information, so we can manage | 57 // Called when a form is autofilled with login information, so we can manage |
47 // password credentials for the current site which are stored in | 58 // password credentials for the current site which are stored in |
48 // |password_form_map|. This stores a copy of |password_form_map| and shows | 59 // |password_form_map|. This stores a copy of |password_form_map| and shows |
49 // the manage password icon. | 60 // the manage password icon. |
50 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map); | 61 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map); |
51 | 62 |
52 // Called when a form is _not_ autofilled due to user blacklisting. This | 63 // Called when a form is _not_ autofilled due to user blacklisting. This |
53 // stores a copy of |password_form_map| so that we can offer the user the | 64 // stores a copy of |password_form_map| so that we can offer the user the |
54 // ability to reenable the manager for this form. | 65 // ability to reenable the manager for this form. |
55 void OnBlacklistBlockedAutofill( | 66 void OnBlacklistBlockedAutofill( |
56 const autofill::PasswordFormMap& password_form_map); | 67 const autofill::PasswordFormMap& password_form_map); |
57 | 68 |
58 // PasswordStore::Observer implementation. | 69 // PasswordStore::Observer implementation. |
59 void OnLoginsChanged( | 70 void OnLoginsChanged( |
60 const password_manager::PasswordStoreChangeList& changes) override; | 71 const password_manager::PasswordStoreChangeList& changes) override; |
61 | 72 |
62 // Called from the model when the user chooses to save a password; passes the | 73 // Called from the model when the user chooses to save a password; passes the |
63 // action off to the FormManager. The controller MUST be in a pending state, | 74 // action off to the FormManager. The controller MUST be in a pending state, |
64 // and WILL be in MANAGE_STATE after this method executes. | 75 // and WILL be in MANAGE_STATE after this method executes. |
65 virtual void SavePassword(); | 76 virtual void SavePassword(); |
66 | 77 |
78 // Called from the model when the user chooses a credential. | |
79 // The controller MUST be in a pending credentials state. | |
80 virtual void ChooseCredential(bool was_chosen, | |
81 const autofill::PasswordForm& form); | |
82 | |
67 // Called from the model when the user chooses to never save passwords; passes | 83 // Called from the model when the user chooses to never save passwords; passes |
68 // the action off to the FormManager. The controller MUST be in a pending | 84 // the action off to the FormManager. The controller MUST be in a pending |
69 // state, and WILL be in BLACKLIST_STATE after this method executes. | 85 // state, and WILL be in BLACKLIST_STATE after this method executes. |
70 virtual void NeverSavePassword(); | 86 virtual void NeverSavePassword(); |
71 | 87 |
72 // Called from the model when the user chooses to unblacklist the site. The | 88 // Called from the model when the user chooses to unblacklist the site. The |
73 // controller MUST be in BLACKLIST_STATE, and WILL be in MANAGE_STATE after | 89 // controller MUST be in BLACKLIST_STATE, and WILL be in MANAGE_STATE after |
74 // this method executes. | 90 // this method executes. |
75 virtual void UnblacklistSite(); | 91 virtual void UnblacklistSite(); |
76 | 92 |
77 // Open a new tab, pointing to the password manager settings page. | 93 // Open a new tab, pointing to the password manager settings page. |
78 virtual void NavigateToPasswordManagerSettingsPage(); | 94 virtual void NavigateToPasswordManagerSettingsPage(); |
79 | 95 |
80 virtual const autofill::PasswordForm& PendingCredentials() const; | 96 virtual const autofill::PasswordForm& PendingPassword() const; |
81 | 97 |
82 // Set the state of the Omnibox icon, and possibly show the associated bubble | 98 // Set the state of the Omnibox icon, and possibly show the associated bubble |
83 // without user interaction. | 99 // without user interaction. |
84 virtual void UpdateIconAndBubbleState(ManagePasswordsIcon* icon); | 100 virtual void UpdateIconAndBubbleState(ManagePasswordsIcon* icon); |
85 | 101 |
102 // Called from the model when the bubble is displayed. | |
103 void OnBubbleShown(); | |
104 | |
86 password_manager::ui::State state() const { return state_; } | 105 password_manager::ui::State state() const { return state_; } |
87 | 106 |
88 // True if a password is sitting around, waiting for a user to decide whether | 107 // True if a password is sitting around, waiting for a user to decide whether |
89 // or not to save it. | 108 // or not to save it. |
90 bool PasswordPendingUserDecision() const; | 109 bool PasswordPendingUserDecision() const; |
91 | 110 |
92 const autofill::ConstPasswordFormMap& best_matches() const { | 111 const autofill::ConstPasswordFormMap& best_matches() const { |
93 return password_form_map_; | 112 return password_form_map_; |
94 } | 113 } |
95 | 114 |
96 const GURL& origin() const { return origin_; } | 115 const GURL& origin() const { return origin_; } |
97 | 116 |
98 protected: | 117 protected: |
99 explicit ManagePasswordsUIController( | 118 explicit ManagePasswordsUIController( |
100 content::WebContents* web_contents); | 119 content::WebContents* web_contents); |
101 | 120 |
102 // The pieces of saving and blacklisting passwords that interact with | 121 // The pieces of saving and blacklisting passwords that interact with |
103 // FormManager, split off into internal functions for testing/mocking. | 122 // FormManager, split off into internal functions for testing/mocking. |
104 virtual void SavePasswordInternal(); | 123 virtual void SavePasswordInternal(); |
105 virtual void NeverSavePasswordInternal(); | 124 virtual void NeverSavePasswordInternal(); |
106 | 125 |
126 // Called when a passwordform is autofilled, when a new passwordform is | |
127 // submitted, or when a navigation occurs to update the visibility of the | |
128 // manage passwords icon and bubble. | |
129 virtual void UpdateBubbleAndIconVisibility(); | |
130 | |
107 // content::WebContentsObserver: | 131 // content::WebContentsObserver: |
108 void DidNavigateMainFrame( | 132 void DidNavigateMainFrame( |
109 const content::LoadCommittedDetails& details, | 133 const content::LoadCommittedDetails& details, |
110 const content::FrameNavigateParams& params) override; | 134 const content::FrameNavigateParams& params) override; |
111 void WasHidden() override; | 135 void WasHidden() override; |
112 | 136 |
113 // We create copies of PasswordForm objects that come in with unclear lifetime | 137 // We create copies of PasswordForm objects that come in with unclear lifetime |
114 // and store them in this vector as well as in |password_form_map_| to ensure | 138 // and store them in this vector as well as in |password_form_map_| to ensure |
115 // that we destroy them correctly. If |new_password_forms_| gets cleared then | 139 // that we destroy them correctly. If |new_password_forms_| gets cleared then |
116 // |password_form_map_| is to be cleared too. | 140 // |password_form_map_| is to be cleared too. |
117 ScopedVector<autofill::PasswordForm> new_password_forms_; | 141 ScopedVector<autofill::PasswordForm> new_password_forms_; |
118 | 142 |
119 // All previously stored credentials for a specific site. | 143 // All previously stored credentials for a specific site. |
120 // Protected, not private, so we can mess with the value in | 144 // Protected, not private, so we can mess with the value in |
121 // ManagePasswordsUIControllerMock. | 145 // ManagePasswordsUIControllerMock. |
122 autofill::ConstPasswordFormMap password_form_map_; | 146 autofill::ConstPasswordFormMap password_form_map_; |
123 | 147 |
124 // The current state of the password manager. Protected so we can manipulate | 148 // The current state of the password manager. Protected so we can manipulate |
125 // the value in tests. | 149 // the value in tests. |
126 password_manager::ui::State state_; | 150 password_manager::ui::State state_; |
127 | 151 |
128 // Used to measure the amount of time on a page; if it's less than some | 152 // Used to measure the amount of time on a page; if it's less than some |
129 // reasonable limit, then don't close the bubble upon navigation. We create | 153 // reasonable limit, then don't close the bubble upon navigation. We create |
130 // (and destroy) the timer in DidNavigateMainFrame. | 154 // (and destroy) the timer in DidNavigateMainFrame. |
131 scoped_ptr<base::ElapsedTimer> timer_; | 155 scoped_ptr<base::ElapsedTimer> timer_; |
132 | 156 |
133 private: | 157 private: |
134 friend class content::WebContentsUserData<ManagePasswordsUIController>; | 158 friend class content::WebContentsUserData<ManagePasswordsUIController>; |
159 friend void InitPasswordsModelFromController( | |
Mike West
2014/11/20 08:19:32
Why `friend`?
vasilii
2014/11/20 15:08:06
We steal ScopedVector<autofill::PasswordForm> from
| |
160 ManagePasswordsUIController* controller, | |
161 ManagePasswordsBubbleModel* model); | |
135 | 162 |
136 // Shows the password bubble without user interaction. The controller MUST | 163 // Shows the password bubble without user interaction. The controller MUST |
137 // be in PENDING_PASSWORD_AND_BUBBLE_STATE. | 164 // be in PENDING_PASSWORD_AND_BUBBLE_STATE. |
138 void ShowBubbleWithoutUserInteraction(); | 165 void ShowBubbleWithoutUserInteraction(); |
139 | 166 |
140 // Called when a passwordform is autofilled, when a new passwordform is | |
141 // submitted, or when a navigation occurs to update the visibility of the | |
142 // manage passwords icon and bubble. | |
143 void UpdateBubbleAndIconVisibility(); | |
144 | |
145 // content::WebContentsObserver: | 167 // content::WebContentsObserver: |
146 void WebContentsDestroyed() override; | 168 void WebContentsDestroyed() override; |
147 | 169 |
148 // Set by OnPasswordSubmitted() when the user submits a form containing login | 170 // Set by OnPasswordSubmitted() when the user submits a form containing login |
149 // information. If the user responds to a subsequent "Do you want to save | 171 // information. If the user responds to a subsequent "Do you want to save |
150 // this password?" prompt, we ask this object to save or blacklist the | 172 // this password?" prompt, we ask this object to save or blacklist the |
151 // associated login information in Chrome's password store. | 173 // associated login information in Chrome's password store. |
152 scoped_ptr<password_manager::PasswordFormManager> form_manager_; | 174 scoped_ptr<password_manager::PasswordFormManager> form_manager_; |
153 | 175 |
154 // Stores whether autofill was blocked due to a user's decision to blacklist | 176 // A callback to be invoked when user selects a credential. |
155 // the current site ("Never save passwords for this site"). | 177 base::Callback<void(const password_manager::CredentialInfo&)> |
156 bool autofill_blocked_; | 178 credentials_callback_; |
Mike West
2014/11/20 08:19:32
This was unused? Weird.
vasilii
2014/11/20 15:08:05
Yes.
| |
179 | |
180 // Contains true is the bubble's appeared during the last call to | |
181 // UpdateBubbleAndIconVisibility(). | |
182 bool bubble_shown_; | |
157 | 183 |
158 // The origin of the form we're currently dealing with; we'll use this to | 184 // The origin of the form we're currently dealing with; we'll use this to |
159 // determine which PasswordStore changes we should care about when updating | 185 // determine which PasswordStore changes we should care about when updating |
160 // |password_form_map_|. | 186 // |password_form_map_|. |
161 GURL origin_; | 187 GURL origin_; |
162 | 188 |
163 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController); | 189 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController); |
164 }; | 190 }; |
165 | 191 |
166 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ | 192 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ |
OLD | NEW |