Chromium Code Reviews| 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/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/timer/elapsed_timer.h" | 9 #include "base/timer/elapsed_timer.h" |
| 10 #include "chrome/browser/ui/passwords/manage_passwords_state.h" | |
| 10 #include "components/autofill/core/common/password_form.h" | 11 #include "components/autofill/core/common/password_form.h" |
| 11 #include "components/password_manager/core/browser/password_store.h" | 12 #include "components/password_manager/core/browser/password_store.h" |
| 12 #include "components/password_manager/core/common/password_manager_ui.h" | 13 #include "components/password_manager/core/common/password_manager_ui.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 class WebContents; | 18 class WebContents; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace password_manager { | 21 namespace password_manager { |
| 21 enum class CredentialType : unsigned int; | 22 enum class CredentialType : unsigned int; |
| 22 struct CredentialInfo; | 23 struct CredentialInfo; |
| 23 class PasswordFormManager; | 24 class PasswordFormManager; |
| 24 } | 25 } |
| 25 | 26 |
| 26 class ManagePasswordsIcon; | 27 class ManagePasswordsIcon; |
| 27 | 28 |
| 28 // Per-tab class to control the Omnibox password icon and bubble. | 29 // Per-tab class to control the Omnibox password icon and bubble. |
| 29 class ManagePasswordsUIController | 30 class ManagePasswordsUIController |
| 30 : public content::WebContentsObserver, | 31 : public content::WebContentsObserver, |
| 31 public content::WebContentsUserData<ManagePasswordsUIController>, | 32 public content::WebContentsUserData<ManagePasswordsUIController>, |
| 32 public password_manager::PasswordStore::Observer { | 33 public password_manager::PasswordStore::Observer { |
| 33 public: | 34 public: |
| 34 ~ManagePasswordsUIController() override; | 35 ~ManagePasswordsUIController() override; |
| 35 | 36 |
| 36 // Called when the user submits a form containing login information, so we | 37 // Called when the user submits a form containing login information, so we |
| 37 // can handle later requests to save or blacklist that login information. | 38 // can handle later requests to save or blacklist that login information. |
| 38 // This stores the provided object in form_manager_ and triggers the UI to | 39 // This stores the provided object and triggers the UI to prompt the user |
| 39 // prompt the user about whether they would like to save the password. | 40 // about whether they would like to save the password. |
| 40 void OnPasswordSubmitted( | 41 void OnPasswordSubmitted( |
| 41 scoped_ptr<password_manager::PasswordFormManager> form_manager); | 42 scoped_ptr<password_manager::PasswordFormManager> form_manager); |
| 42 | 43 |
| 43 // Called when the site asks user to choose from credentials. This triggers | 44 // Called when the site asks user to choose from credentials. This triggers |
| 44 // the UI to prompt the user. |local_credentials| and |federated_credentials| | 45 // the UI to prompt the user. |local_credentials| and |federated_credentials| |
| 45 // shouldn't both be empty. | 46 // shouldn't both be empty. |
| 46 bool OnChooseCredentials( | 47 bool OnChooseCredentials( |
| 47 ScopedVector<autofill::PasswordForm> local_credentials, | 48 ScopedVector<autofill::PasswordForm> local_credentials, |
| 48 ScopedVector<autofill::PasswordForm> federated_credentials, | 49 ScopedVector<autofill::PasswordForm> federated_credentials, |
| 49 const GURL& origin, | 50 const GURL& origin, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 // Set the state of the Omnibox icon, and possibly show the associated bubble | 104 // Set the state of the Omnibox icon, and possibly show the associated bubble |
| 104 // without user interaction. | 105 // without user interaction. |
| 105 virtual void UpdateIconAndBubbleState(ManagePasswordsIcon* icon); | 106 virtual void UpdateIconAndBubbleState(ManagePasswordsIcon* icon); |
| 106 | 107 |
| 107 // Called from the model when the bubble is displayed. | 108 // Called from the model when the bubble is displayed. |
| 108 void OnBubbleShown(); | 109 void OnBubbleShown(); |
| 109 | 110 |
| 110 // Called from the model when the bubble is hidden. | 111 // Called from the model when the bubble is hidden. |
| 111 void OnBubbleHidden(); | 112 void OnBubbleHidden(); |
| 112 | 113 |
| 113 password_manager::ui::State state() const { return state_; } | 114 password_manager::ui::State state() const { return passwords_data_.state(); } |
| 114 | |
| 115 ScopedVector<autofill::PasswordForm>& federated_credentials_forms() { | |
| 116 return federated_credentials_forms_; | |
| 117 } | |
| 118 | |
| 119 ScopedVector<autofill::PasswordForm>& local_credentials_forms() { | |
| 120 return local_credentials_forms_; | |
| 121 } | |
| 122 | 115 |
| 123 // True if a password is sitting around, waiting for a user to decide whether | 116 // True if a password is sitting around, waiting for a user to decide whether |
| 124 // or not to save it. | 117 // or not to save it. |
| 125 bool PasswordPendingUserDecision() const; | 118 bool PasswordPendingUserDecision() const { |
| 126 | 119 return state() == password_manager::ui::PENDING_PASSWORD_STATE; |
| 127 const autofill::ConstPasswordFormMap& best_matches() const { | |
| 128 return password_form_map_; | |
| 129 } | 120 } |
| 130 | 121 |
| 131 const GURL& origin() const { return origin_; } | 122 const GURL& origin() const { return passwords_data_.origin(); } |
| 132 | 123 |
| 133 bool IsAutomaticallyOpeningBubble() const { return should_pop_up_bubble_; } | 124 bool IsAutomaticallyOpeningBubble() const { return should_pop_up_bubble_; } |
| 134 | 125 |
| 126 // Current local forms. | |
| 127 const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const { | |
| 128 return passwords_data_.GetCurrentForms(); | |
| 129 } | |
| 130 | |
| 131 // Current federated forms. | |
| 132 const std::vector<const autofill::PasswordForm*>& GetFederatedForms() const { | |
| 133 return passwords_data_.federated_credentials_forms(); | |
| 134 } | |
| 135 | |
| 135 protected: | 136 protected: |
| 136 explicit ManagePasswordsUIController( | 137 explicit ManagePasswordsUIController( |
| 137 content::WebContents* web_contents); | 138 content::WebContents* web_contents); |
| 138 | 139 |
| 139 // The pieces of saving and blacklisting passwords that interact with | 140 // The pieces of saving and blacklisting passwords that interact with |
| 140 // FormManager, split off into internal functions for testing/mocking. | 141 // FormManager, split off into internal functions for testing/mocking. |
| 141 virtual void SavePasswordInternal(); | 142 virtual void SavePasswordInternal(); |
| 142 virtual void NeverSavePasswordInternal(); | 143 virtual void NeverSavePasswordInternal(); |
| 143 | 144 |
| 144 // Called when a passwordform is autofilled, when a new passwordform is | 145 // Called when a passwordform is autofilled, when a new PasswordForm is |
|
vabr (Chromium)
2015/03/17 09:25:58
nit: One more all-lowercase "passwordform" still l
vasilii
2015/03/17 10:49:48
Done.
| |
| 145 // submitted, or when a navigation occurs to update the visibility of the | 146 // submitted, or when a navigation occurs to update the visibility of the |
| 146 // manage passwords icon and bubble. | 147 // manage passwords icon and bubble. |
| 147 virtual void UpdateBubbleAndIconVisibility(); | 148 virtual void UpdateBubbleAndIconVisibility(); |
| 148 | 149 |
| 149 // Returns the time elapsed since |timer_| was initialized, | 150 // Returns the time elapsed since |timer_| was initialized, |
| 150 // or base::TimeDelta::Max() if |timer_| was not initialized. | 151 // or base::TimeDelta::Max() if |timer_| was not initialized. |
| 151 virtual base::TimeDelta Elapsed() const; | 152 virtual base::TimeDelta Elapsed() const; |
| 152 | 153 |
| 153 // content::WebContentsObserver: | 154 // content::WebContentsObserver: |
| 154 void DidNavigateMainFrame( | 155 void DidNavigateMainFrame( |
| 155 const content::LoadCommittedDetails& details, | 156 const content::LoadCommittedDetails& details, |
| 156 const content::FrameNavigateParams& params) override; | 157 const content::FrameNavigateParams& params) override; |
| 157 void WasHidden() override; | 158 void WasHidden() override; |
| 158 | 159 |
| 159 // Sets |state_|. Protected so we can manipulate the value in tests. | |
| 160 void SetState(password_manager::ui::State state); | |
| 161 | |
| 162 // All previously stored credentials for a specific site. | |
| 163 // Protected, not private, so we can mess with the value in | |
| 164 // ManagePasswordsUIControllerMock. | |
| 165 autofill::ConstPasswordFormMap password_form_map_; | |
| 166 | |
| 167 private: | 160 private: |
| 168 friend class content::WebContentsUserData<ManagePasswordsUIController>; | 161 friend class content::WebContentsUserData<ManagePasswordsUIController>; |
| 169 | 162 |
| 170 // Shows the password bubble without user interaction. | 163 // Shows the password bubble without user interaction. |
| 171 void ShowBubbleWithoutUserInteraction(); | 164 void ShowBubbleWithoutUserInteraction(); |
| 172 | 165 |
| 173 // content::WebContentsObserver: | 166 // content::WebContentsObserver: |
| 174 void WebContentsDestroyed() override; | 167 void WebContentsDestroyed() override; |
| 175 | 168 |
| 176 // Saves the parameters and clean the previous forms. | |
| 177 void SaveForms(ScopedVector<autofill::PasswordForm> local_forms, | |
| 178 ScopedVector<autofill::PasswordForm> federated_forms); | |
| 179 | |
| 180 // Shows infobar which allows user to choose credentials. Placing this | 169 // Shows infobar which allows user to choose credentials. Placing this |
| 181 // code to separate method allows mocking. | 170 // code to separate method allows mocking. |
| 182 virtual void UpdateAndroidAccountChooserInfoBarVisibility(); | 171 virtual void UpdateAndroidAccountChooserInfoBarVisibility(); |
| 183 | 172 |
| 184 // The current state of the password manager UI. | 173 // The wrapper around current state and data. |
| 185 password_manager::ui::State state_; | 174 ManagePasswordsState passwords_data_; |
|
vabr (Chromium)
2015/03/17 09:25:57
optional nit: Personally I would prefer the name t
vasilii
2015/03/17 10:49:48
But then there is a confusion with state() which u
vabr (Chromium)
2015/03/17 11:55:13
Fair enough. Then we should probably rename Manage
| |
| 186 | 175 |
| 187 // Used to measure the amount of time on a page; if it's less than some | 176 // Used to measure the amount of time on a page; if it's less than some |
| 188 // reasonable limit, then don't close the bubble upon navigation. We create | 177 // reasonable limit, then don't close the bubble upon navigation. We create |
| 189 // (and destroy) the timer in DidNavigateMainFrame. | 178 // (and destroy) the timer in DidNavigateMainFrame. |
| 190 scoped_ptr<base::ElapsedTimer> timer_; | 179 scoped_ptr<base::ElapsedTimer> timer_; |
| 191 | 180 |
| 192 // TODO(vasilii): remove these data variables, use ManagePasswordsState. | |
| 193 | |
| 194 // Set by OnPasswordSubmitted() when the user submits a form containing login | |
| 195 // information. If the user responds to a subsequent "Do you want to save | |
| 196 // this password?" prompt, we ask this object to save or blacklist the | |
| 197 // associated login information in Chrome's password store. | |
| 198 scoped_ptr<password_manager::PasswordFormManager> form_manager_; | |
| 199 | |
| 200 // We create copies of PasswordForm objects that come in with unclear lifetime | |
| 201 // and store them in this vector as well as in |password_form_map_| to ensure | |
| 202 // that we destroy them correctly. If |new_password_forms_| gets cleared then | |
| 203 // |password_form_map_| is to be cleared too. | |
| 204 ScopedVector<autofill::PasswordForm> new_password_forms_; | |
| 205 | |
| 206 // Federated credentials. Stores federated credentials which will be shown | |
| 207 // when Credential Management API was used. | |
| 208 ScopedVector<autofill::PasswordForm> federated_credentials_forms_; | |
| 209 | |
| 210 // Local credentials. Stores local credentials which will be shown | |
| 211 // when Credential Management API was used. | |
| 212 ScopedVector<autofill::PasswordForm> local_credentials_forms_; | |
| 213 | |
| 214 // A callback to be invoked when user selects a credential. | |
| 215 base::Callback<void(const password_manager::CredentialInfo&)> | |
| 216 credentials_callback_; | |
| 217 | |
| 218 // Contains true if the bubble is to be popped up in the next call to | 181 // Contains true if the bubble is to be popped up in the next call to |
| 219 // UpdateBubbleAndIconVisibility(). | 182 // UpdateBubbleAndIconVisibility(). |
| 220 bool should_pop_up_bubble_; | 183 bool should_pop_up_bubble_; |
| 221 | 184 |
| 222 // The origin of the form we're currently dealing with; we'll use this to | |
| 223 // determine which PasswordStore changes we should care about when updating | |
| 224 // |password_form_map_|. | |
| 225 GURL origin_; | |
| 226 | |
| 227 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController); | 185 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController); |
| 228 }; | 186 }; |
| 229 | 187 |
| 230 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ | 188 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ |
| OLD | NEW |