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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/timer/elapsed_timer.h" | 11 #include "base/timer/elapsed_timer.h" |
12 #include "chrome/browser/ui/passwords/manage_passwords_state.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_state.h" |
| 13 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" |
13 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
14 #include "components/password_manager/core/browser/password_store.h" | 15 #include "components/password_manager/core/browser/password_store.h" |
15 #include "components/password_manager/core/common/password_manager_ui.h" | |
16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
17 #include "content/public/browser/web_contents_user_data.h" | 17 #include "content/public/browser/web_contents_user_data.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 class WebContents; | 20 class WebContents; |
21 } | 21 } |
22 | 22 |
23 namespace password_manager { | 23 namespace password_manager { |
24 enum class CredentialType; | 24 enum class CredentialType; |
25 struct CredentialInfo; | 25 struct CredentialInfo; |
26 struct InteractionsStats; | 26 struct InteractionsStats; |
27 class PasswordFormManager; | 27 class PasswordFormManager; |
28 } | 28 } |
29 | 29 |
30 class ManagePasswordsIconView; | 30 class ManagePasswordsIconView; |
31 | 31 |
32 // Per-tab class to control the Omnibox password icon and bubble. | 32 // Per-tab class to control the Omnibox password icon and bubble. |
33 class ManagePasswordsUIController | 33 class ManagePasswordsUIController |
34 : public content::WebContentsObserver, | 34 : public content::WebContentsObserver, |
35 public content::WebContentsUserData<ManagePasswordsUIController>, | 35 public content::WebContentsUserData<ManagePasswordsUIController>, |
36 public password_manager::PasswordStore::Observer { | 36 public password_manager::PasswordStore::Observer, |
| 37 public PasswordsModelDelegate { |
37 public: | 38 public: |
38 ~ManagePasswordsUIController() override; | 39 ~ManagePasswordsUIController() override; |
39 | 40 |
40 // Called when the user submits a form containing login information, so we | 41 // Called when the user submits a form containing login information, so we |
41 // can handle later requests to save or blacklist that login information. | 42 // can handle later requests to save or blacklist that login information. |
42 // This stores the provided object and triggers the UI to prompt the user | 43 // This stores the provided object and triggers the UI to prompt the user |
43 // about whether they would like to save the password. | 44 // about whether they would like to save the password. |
44 void OnPasswordSubmitted( | 45 void OnPasswordSubmitted( |
45 scoped_ptr<password_manager::PasswordFormManager> form_manager); | 46 scoped_ptr<password_manager::PasswordFormManager> form_manager); |
46 | 47 |
(...skipping 26 matching lines...) Expand all Loading... |
73 // password credentials for the current site which are stored in | 74 // password credentials for the current site which are stored in |
74 // |password_form_map|. This stores a copy of |password_form_map| and shows | 75 // |password_form_map|. This stores a copy of |password_form_map| and shows |
75 // the manage password icon. | 76 // the manage password icon. |
76 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map, | 77 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map, |
77 const GURL& origin); | 78 const GURL& origin); |
78 | 79 |
79 // PasswordStore::Observer implementation. | 80 // PasswordStore::Observer implementation. |
80 void OnLoginsChanged( | 81 void OnLoginsChanged( |
81 const password_manager::PasswordStoreChangeList& changes) override; | 82 const password_manager::PasswordStoreChangeList& changes) override; |
82 | 83 |
83 // Called from the model when the user chooses to save a password; passes the | |
84 // action to the |form_manager|. The controller must be in a pending state, | |
85 // and will be in MANAGE_STATE after this method executes. | |
86 virtual void SavePassword(); | |
87 | |
88 // Called from the model when the user chooses to update a password; passes | |
89 // the action to the |form_manager|. The controller must be in a pending | |
90 // state, and will be in MANAGE_STATE after this method executes. | |
91 virtual void UpdatePassword(const autofill::PasswordForm& password_form); | |
92 | |
93 // Called from the model when the user chooses a credential. | |
94 // The controller MUST be in a pending credentials state. | |
95 virtual void ChooseCredential( | |
96 const autofill::PasswordForm& form, | |
97 password_manager::CredentialType credential_type); | |
98 | |
99 // Called from the model when the user chooses to never save passwords; passes | |
100 // the action off to the FormManager. The controller must be in a pending | |
101 // state, and will state in this state. | |
102 virtual void NeverSavePassword(); | |
103 | |
104 // Open a new tab, pointing to the password manager settings page. | |
105 virtual void NavigateToPasswordManagerSettingsPage(); | |
106 | |
107 // Two different ways to open a new tab pointing to passwords.google.com. | |
108 // TODO(crbug.com/548259) eliminate one of them. | |
109 virtual void NavigateToExternalPasswordManager(); | |
110 virtual void NavigateToSmartLockPage(); | |
111 | |
112 // Open a new tab, pointing to the Smart Lock help article. | |
113 virtual void NavigateToSmartLockHelpPage(); | |
114 | |
115 virtual const autofill::PasswordForm& PendingPassword() const; | |
116 | |
117 #if !defined(OS_ANDROID) | 84 #if !defined(OS_ANDROID) |
118 // Set the state of the Omnibox icon, and possibly show the associated bubble | 85 // Set the state of the Omnibox icon, and possibly show the associated bubble |
119 // without user interaction. | 86 // without user interaction. |
120 virtual void UpdateIconAndBubbleState(ManagePasswordsIconView* icon); | 87 virtual void UpdateIconAndBubbleState(ManagePasswordsIconView* icon); |
121 #endif | 88 #endif |
122 | 89 |
123 // Called from the model when the bubble is displayed. | |
124 void OnBubbleShown(); | |
125 | |
126 // Called from the model when the bubble is hidden. | |
127 virtual void OnBubbleHidden(); | |
128 | |
129 // Called when the user chose not to update password. | |
130 void OnNopeUpdateClicked(); | |
131 | |
132 // Called when the user didn't interact with Update UI. | |
133 void OnNoInteractionOnUpdate(); | |
134 | |
135 virtual password_manager::ui::State state() const; | |
136 | |
137 // True if a password is sitting around, waiting for a user to decide whether | |
138 // or not to save it. | |
139 // TODO(vasilii): remove. | |
140 bool PasswordPendingUserDecision() const { | |
141 return state() == password_manager::ui::PENDING_PASSWORD_STATE; | |
142 } | |
143 | |
144 const GURL& origin() const { return passwords_data_.origin(); } | |
145 | |
146 bool IsAutomaticallyOpeningBubble() const { return should_pop_up_bubble_; } | 90 bool IsAutomaticallyOpeningBubble() const { return should_pop_up_bubble_; } |
147 | 91 |
148 // Current local forms. | 92 // PasswordsModelDelegate: |
149 const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const { | 93 const GURL& GetOrigin() const override; |
150 return passwords_data_.GetCurrentForms(); | 94 password_manager::ui::State GetState() const override; |
151 } | 95 const autofill::PasswordForm& GetPendingPassword() const override; |
152 | 96 bool IsPasswordOverridden() const override; |
153 // Current federated forms. | 97 const std::vector<const autofill::PasswordForm*>& GetCurrentForms() |
154 const std::vector<const autofill::PasswordForm*>& GetFederatedForms() const { | 98 const override; |
155 return passwords_data_.federated_credentials_forms(); | 99 const std::vector<const autofill::PasswordForm*>& GetFederatedForms() |
156 } | 100 const override; |
157 | 101 password_manager::InteractionsStats* GetCurrentInteractionStats() const |
158 // True if the password for previously stored account was overridden, i.e. in | 102 override; |
159 // newly submitted form the password is different from stored one. | 103 void OnBubbleShown() override; |
160 bool PasswordOverridden() const; | 104 void OnBubbleHidden() override; |
161 | 105 void OnNoInteractionOnUpdate() override; |
162 // For PENDING_PASSWORD_STATE state returns the current statistics for | 106 void OnNopeUpdateClicked() override; |
163 // the pending username. | 107 void NeverSavePassword() override; |
164 virtual password_manager::InteractionsStats* GetCurrentInteractionStats() | 108 void SavePassword() override; |
165 const; | 109 void UpdatePassword(const autofill::PasswordForm& password_form) override; |
| 110 void ChooseCredential( |
| 111 const autofill::PasswordForm& form, |
| 112 password_manager::CredentialType credential_type) override; |
| 113 // Two different ways to open a new tab pointing to passwords.google.com. |
| 114 // TODO(crbug.com/548259) eliminate one of them. |
| 115 void NavigateToExternalPasswordManager() override; |
| 116 void NavigateToSmartLockPage() override; |
| 117 void NavigateToSmartLockHelpPage() override; |
| 118 void NavigateToPasswordManagerSettingsPage() override; |
166 | 119 |
167 protected: | 120 protected: |
168 explicit ManagePasswordsUIController( | 121 explicit ManagePasswordsUIController( |
169 content::WebContents* web_contents); | 122 content::WebContents* web_contents); |
170 | 123 |
171 // The pieces of saving and blacklisting passwords that interact with | 124 // The pieces of saving and blacklisting passwords that interact with |
172 // FormManager, split off into internal functions for testing/mocking. | 125 // FormManager, split off into internal functions for testing/mocking. |
173 virtual void SavePasswordInternal(); | 126 virtual void SavePasswordInternal(); |
174 virtual void UpdatePasswordInternal( | 127 virtual void UpdatePasswordInternal( |
175 const autofill::PasswordForm& password_form); | 128 const autofill::PasswordForm& password_form); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 scoped_ptr<base::ElapsedTimer> timer_; | 170 scoped_ptr<base::ElapsedTimer> timer_; |
218 | 171 |
219 // Contains true if the bubble is to be popped up in the next call to | 172 // Contains true if the bubble is to be popped up in the next call to |
220 // UpdateBubbleAndIconVisibility(). | 173 // UpdateBubbleAndIconVisibility(). |
221 bool should_pop_up_bubble_; | 174 bool should_pop_up_bubble_; |
222 | 175 |
223 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController); | 176 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController); |
224 }; | 177 }; |
225 | 178 |
226 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ | 179 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_ |
OLD | NEW |