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_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" | |
14 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" | 15 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" |
15 #include "components/password_manager/content/browser/credential_manager_impl.h" | 16 #include "components/password_manager/content/browser/credential_manager_impl.h" |
16 #include "components/password_manager/core/browser/password_manager.h" | 17 #include "components/password_manager/core/browser/password_manager.h" |
17 #include "components/password_manager/core/browser/password_manager_client.h" | 18 #include "components/password_manager/core/browser/password_manager_client.h" |
18 #include "components/password_manager/sync/browser/sync_credentials_filter.h" | 19 #include "components/password_manager/sync/browser/sync_credentials_filter.h" |
19 #include "components/prefs/pref_member.h" | 20 #include "components/prefs/pref_member.h" |
21 #include "content/public/browser/web_contents_binding_set.h" | |
20 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
21 #include "content/public/browser/web_contents_user_data.h" | 23 #include "content/public/browser/web_contents_user_data.h" |
22 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
23 | 25 |
24 class Profile; | 26 class Profile; |
25 | 27 |
26 namespace autofill { | 28 namespace autofill { |
27 class PasswordGenerationPopupObserver; | 29 class PasswordGenerationPopupObserver; |
28 class PasswordGenerationPopupControllerImpl; | 30 class PasswordGenerationPopupControllerImpl; |
29 } | 31 } |
30 | 32 |
31 namespace content { | 33 namespace content { |
32 class WebContents; | 34 class WebContents; |
33 } | 35 } |
34 | 36 |
35 namespace password_manager { | 37 namespace password_manager { |
36 struct CredentialInfo; | 38 struct CredentialInfo; |
37 class PasswordGenerationManager; | 39 class PasswordGenerationManager; |
38 class PasswordManagerDriver; | 40 class PasswordManagerDriver; |
39 } | 41 } |
40 | 42 |
41 // ChromePasswordManagerClient implements the PasswordManagerClient interface. | 43 // ChromePasswordManagerClient implements the PasswordManagerClient interface. |
42 class ChromePasswordManagerClient | 44 class ChromePasswordManagerClient |
43 : public password_manager::PasswordManagerClient, | 45 : public password_manager::PasswordManagerClient, |
44 public content::WebContentsObserver, | 46 public content::WebContentsObserver, |
45 public content::WebContentsUserData<ChromePasswordManagerClient> { | 47 public content::WebContentsUserData<ChromePasswordManagerClient>, |
48 public autofill::mojom::PasswordManagerClient { | |
46 public: | 49 public: |
47 ~ChromePasswordManagerClient() override; | 50 ~ChromePasswordManagerClient() override; |
48 | 51 |
49 // PasswordManagerClient implementation. | 52 // PasswordManagerClient implementation. |
50 bool IsAutomaticPasswordSavingEnabled() const override; | 53 bool IsAutomaticPasswordSavingEnabled() const override; |
51 bool IsSavingAndFillingEnabledForCurrentPage() const override; | 54 bool IsSavingAndFillingEnabledForCurrentPage() const override; |
52 bool IsFillingEnabledForCurrentPage() const override; | 55 bool IsFillingEnabledForCurrentPage() const override; |
53 bool PromptUserToSaveOrUpdatePassword( | 56 bool PromptUserToSaveOrUpdatePassword( |
54 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, | 57 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, |
55 password_manager::CredentialSourceType type, | 58 password_manager::CredentialSourceType type, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 const password_manager::PasswordManager* GetPasswordManager() const override; | 90 const password_manager::PasswordManager* GetPasswordManager() const override; |
88 autofill::AutofillManager* GetAutofillManagerForMainFrame() override; | 91 autofill::AutofillManager* GetAutofillManagerForMainFrame() override; |
89 const GURL& GetMainFrameURL() const override; | 92 const GURL& GetMainFrameURL() const override; |
90 bool IsUpdatePasswordUIEnabled() const override; | 93 bool IsUpdatePasswordUIEnabled() const override; |
91 const GURL& GetLastCommittedEntryURL() const override; | 94 const GURL& GetLastCommittedEntryURL() const override; |
92 void AnnotateNavigationEntry(bool has_password_field) override; | 95 void AnnotateNavigationEntry(bool has_password_field) override; |
93 const password_manager::CredentialsFilter* GetStoreResultFilter() | 96 const password_manager::CredentialsFilter* GetStoreResultFilter() |
94 const override; | 97 const override; |
95 const password_manager::LogManager* GetLogManager() const override; | 98 const password_manager::LogManager* GetLogManager() const override; |
96 | 99 |
100 // autofill::mojom::PasswordManagerClient overrides. | |
101 // Causes the password generation UI to be shown for the specified form. | |
vabr (Chromium)
2016/09/27 15:06:11
nit: Please move these comments to interface Passw
leonhsl(Using Gerrit)
2016/09/28 02:40:39
Done. Moved these comments to interface definition
| |
102 // The popup will be anchored at |bounds|. The generated password | |
103 // will be no longer than |max_length|. |generation_element| should contain a | |
104 // name of a password field at which generation popup is attached. | |
105 // |is_manually_triggered| informs whether it is automatically or manually | |
106 // triggered generation. | |
107 void ShowPasswordGenerationPopup(const gfx::RectF& bounds, | |
108 int max_length, | |
109 const base::string16& generation_element, | |
110 bool is_manually_triggered, | |
111 const autofill::PasswordForm& form) override; | |
112 // Causes the password editing UI to be shown anchored at |bounds|. | |
113 void ShowPasswordEditingPopup(const gfx::RectF& bounds, | |
114 const autofill::PasswordForm& form) override; | |
115 // Notify the PasswordManager that generation is available for |form|. Used | |
116 // for UMA stats. | |
117 void GenerationAvailableForForm(const autofill::PasswordForm& form) override; | |
97 // Hides any visible generation UI. | 118 // Hides any visible generation UI. |
98 void HidePasswordGenerationPopup(); | 119 void HidePasswordGenerationPopup() override; |
99 | 120 |
100 static void CreateForWebContentsWithAutofillClient( | 121 static void CreateForWebContentsWithAutofillClient( |
101 content::WebContents* contents, | 122 content::WebContents* contents, |
102 autofill::AutofillClient* autofill_client); | 123 autofill::AutofillClient* autofill_client); |
103 | 124 |
104 // Observer for PasswordGenerationPopup events. Used for testing. | 125 // Observer for PasswordGenerationPopup events. Used for testing. |
105 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer); | 126 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer); |
106 | 127 |
107 static void BindCredentialManager( | 128 static void BindCredentialManager( |
108 content::RenderFrameHost* render_frame_host, | 129 content::RenderFrameHost* render_frame_host, |
109 password_manager::mojom::CredentialManagerRequest request); | 130 password_manager::mojom::CredentialManagerRequest request); |
110 | 131 |
111 protected: | 132 protected: |
112 // Callable for tests. | 133 // Callable for tests. |
113 ChromePasswordManagerClient(content::WebContents* web_contents, | 134 ChromePasswordManagerClient(content::WebContents* web_contents, |
114 autofill::AutofillClient* autofill_client); | 135 autofill::AutofillClient* autofill_client); |
115 | 136 |
116 private: | 137 private: |
117 friend class content::WebContentsUserData<ChromePasswordManagerClient>; | 138 friend class content::WebContentsUserData<ChromePasswordManagerClient>; |
118 | 139 |
119 // content::WebContentsObserver overrides. | 140 // content::WebContentsObserver overrides. |
120 bool OnMessageReceived(const IPC::Message& message, | |
121 content::RenderFrameHost* render_frame_host) override; | |
122 void DidStartNavigation( | 141 void DidStartNavigation( |
123 content::NavigationHandle* navigation_handle) override; | 142 content::NavigationHandle* navigation_handle) override; |
124 | 143 |
125 // Given |bounds| in the renderers coordinate system, return the same bounds | 144 // Given |bounds| in the renderers coordinate system, return the same bounds |
126 // in the screens coordinate system. | 145 // in the screens coordinate system. |
127 gfx::RectF GetBoundsInScreenSpace(const gfx::RectF& bounds); | 146 gfx::RectF GetBoundsInScreenSpace(const gfx::RectF& bounds); |
128 | 147 |
129 // Checks if the current page fulfils the conditions for the password manager | 148 // Checks if the current page fulfils the conditions for the password manager |
130 // to be active on it, for example Sync credentials are not saved or auto | 149 // to be active on it, for example Sync credentials are not saved or auto |
131 // filled. | 150 // filled. |
132 bool IsPasswordManagementEnabledForCurrentPage() const; | 151 bool IsPasswordManagementEnabledForCurrentPage() const; |
133 | 152 |
134 // Causes the password generation UI to be shown for the specified form. | |
135 // The popup will be anchored at |element_bounds|. The generated password | |
136 // will be no longer than |max_length|. |generation_element| should contain a | |
137 // name of a password field at which generation popup is attached. | |
138 // |is_manually_triggered| informs whether it is automatically or manually | |
139 // triggered generation. | |
140 void ShowPasswordGenerationPopup(content::RenderFrameHost* render_frame_host, | |
141 const gfx::RectF& bounds, | |
142 int max_length, | |
143 const base::string16& generation_element, | |
144 bool is_manually_triggered, | |
145 const autofill::PasswordForm& form); | |
146 | |
147 // Causes the password editing UI to be shown anchored at |element_bounds|. | |
148 void ShowPasswordEditingPopup(content::RenderFrameHost* render_frame_host, | |
149 const gfx::RectF& bounds, | |
150 const autofill::PasswordForm& form); | |
151 | |
152 // Shows the dialog where the user can accept or decline the global autosignin | 153 // Shows the dialog where the user can accept or decline the global autosignin |
153 // setting as a first run experience. The dialog won't appear in Incognito or | 154 // setting as a first run experience. The dialog won't appear in Incognito or |
154 // when the autosign-in is off. | 155 // when the autosign-in is off. |
155 void PromptUserToEnableAutosigninIfNecessary(); | 156 void PromptUserToEnableAutosigninIfNecessary(); |
156 | 157 |
157 // Notify the PasswordManager that generation is available for |form|. Used | |
158 // for UMA stats. | |
159 void GenerationAvailableForForm(const autofill::PasswordForm& form); | |
160 | |
161 // Called as a response to PromptUserToChooseCredentials. nullptr in |form| | 158 // Called as a response to PromptUserToChooseCredentials. nullptr in |form| |
162 // means that nothing was chosen. |one_local_credential| is true if there was | 159 // means that nothing was chosen. |one_local_credential| is true if there was |
163 // just one local credential to be chosen from. | 160 // just one local credential to be chosen from. |
164 void OnCredentialsChosen(const CredentialsCallback& callback, | 161 void OnCredentialsChosen(const CredentialsCallback& callback, |
165 bool one_local_credential, | 162 bool one_local_credential, |
166 const autofill::PasswordForm* form); | 163 const autofill::PasswordForm* form); |
167 | 164 |
168 // Returns true if this profile has metrics reporting and active sync | 165 // Returns true if this profile has metrics reporting and active sync |
169 // without custom sync passphrase. | 166 // without custom sync passphrase. |
170 static bool ShouldAnnotateNavigationEntries(Profile* profile); | 167 static bool ShouldAnnotateNavigationEntries(Profile* profile); |
171 | 168 |
172 Profile* const profile_; | 169 Profile* const profile_; |
173 | 170 |
174 password_manager::PasswordManager password_manager_; | 171 password_manager::PasswordManager password_manager_; |
175 | 172 |
176 password_manager::ContentPasswordManagerDriverFactory* driver_factory_; | 173 password_manager::ContentPasswordManagerDriverFactory* driver_factory_; |
177 | 174 |
178 // As a mojo service, will be registered into service registry | 175 // As a mojo service, will be registered into service registry |
179 // of the main frame host by ChromeContentBrowserClient | 176 // of the main frame host by ChromeContentBrowserClient |
180 // once main frame host was created. | 177 // once main frame host was created. |
181 password_manager::CredentialManagerImpl credential_manager_impl_; | 178 password_manager::CredentialManagerImpl credential_manager_impl_; |
182 | 179 |
180 content::WebContentsFrameBindingSet<autofill::mojom::PasswordManagerClient> | |
181 password_manager_client_bindings_; | |
182 | |
183 // Observer for password generation popup. | 183 // Observer for password generation popup. |
184 autofill::PasswordGenerationPopupObserver* observer_; | 184 autofill::PasswordGenerationPopupObserver* observer_; |
185 | 185 |
186 // Controls the popup | 186 // Controls the popup |
187 base::WeakPtr< | 187 base::WeakPtr< |
188 autofill::PasswordGenerationPopupControllerImpl> popup_controller_; | 188 autofill::PasswordGenerationPopupControllerImpl> popup_controller_; |
189 | 189 |
190 // Set to false to disable password saving (will no longer ask if you | 190 // Set to false to disable password saving (will no longer ask if you |
191 // want to save passwords and also won't fill the passwords). | 191 // want to save passwords and also won't fill the passwords). |
192 BooleanPrefMember saving_and_filling_passwords_enabled_; | 192 BooleanPrefMember saving_and_filling_passwords_enabled_; |
193 | 193 |
194 const password_manager::SyncCredentialsFilter credentials_filter_; | 194 const password_manager::SyncCredentialsFilter credentials_filter_; |
195 | 195 |
196 std::unique_ptr<password_manager::LogManager> log_manager_; | 196 std::unique_ptr<password_manager::LogManager> log_manager_; |
197 | 197 |
198 // Set during 'NotifyUserCouldBeAutoSignedIn' in order to store the | 198 // Set during 'NotifyUserCouldBeAutoSignedIn' in order to store the |
199 // form for potential use during 'NotifySuccessfulLoginWithExistingPassword'. | 199 // form for potential use during 'NotifySuccessfulLoginWithExistingPassword'. |
200 std::unique_ptr<autofill::PasswordForm> possible_auto_sign_in_; | 200 std::unique_ptr<autofill::PasswordForm> possible_auto_sign_in_; |
201 | 201 |
202 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient); | 202 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient); |
203 }; | 203 }; |
204 | 204 |
205 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_ | 205 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_ |
OLD | NEW |