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 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
19 #include "chrome/browser/password_manager/password_store_factory.h" | 19 #include "chrome/browser/password_manager/password_store_factory.h" |
20 #include "chrome/browser/prerender/prerender_contents.h" | 20 #include "chrome/browser/prerender/prerender_contents.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
23 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
24 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" | 24 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" |
25 #include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h" | 25 #include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h" |
26 #include "chrome/common/channel_info.h" | 26 #include "chrome/common/channel_info.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/features.h" | |
29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
30 #include "components/autofill/content/browser/content_autofill_driver.h" | 29 #include "components/autofill/content/browser/content_autofill_driver.h" |
31 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 30 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
32 #include "components/autofill/core/browser/password_generator.h" | 31 #include "components/autofill/core/browser/password_generator.h" |
33 #include "components/autofill/core/common/password_form.h" | 32 #include "components/autofill/core/common/password_form.h" |
34 #include "components/browser_sync/profile_sync_service.h" | 33 #include "components/browser_sync/profile_sync_service.h" |
35 #include "components/password_manager/content/browser/content_password_manager_d
river.h" | 34 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
36 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" | 35 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" |
37 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 36 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
38 #include "components/password_manager/core/browser/log_manager.h" | 37 #include "components/password_manager/core/browser/log_manager.h" |
(...skipping 13 matching lines...) Expand all Loading... |
52 #include "components/signin/core/browser/signin_manager.h" | 51 #include "components/signin/core/browser/signin_manager.h" |
53 #include "components/version_info/version_info.h" | 52 #include "components/version_info/version_info.h" |
54 #include "content/public/browser/navigation_entry.h" | 53 #include "content/public/browser/navigation_entry.h" |
55 #include "content/public/browser/render_view_host.h" | 54 #include "content/public/browser/render_view_host.h" |
56 #include "content/public/browser/ssl_status.h" | 55 #include "content/public/browser/ssl_status.h" |
57 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
58 #include "google_apis/gaia/gaia_urls.h" | 57 #include "google_apis/gaia/gaia_urls.h" |
59 #include "net/base/url_util.h" | 58 #include "net/base/url_util.h" |
60 #include "third_party/re2/src/re2/re2.h" | 59 #include "third_party/re2/src/re2/re2.h" |
61 | 60 |
62 #if BUILDFLAG(ANDROID_JAVA_UI) | 61 #if defined(OS_ANDROID) |
63 #include "chrome/browser/android/tab_android.h" | 62 #include "chrome/browser/android/tab_android.h" |
64 #include "chrome/browser/password_manager/account_chooser_dialog_android.h" | 63 #include "chrome/browser/password_manager/account_chooser_dialog_android.h" |
65 #include "chrome/browser/password_manager/auto_signin_first_run_dialog_android.h
" | 64 #include "chrome/browser/password_manager/auto_signin_first_run_dialog_android.h
" |
66 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" | 65 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" |
67 #include "chrome/browser/password_manager/save_password_infobar_delegate_android
.h" | 66 #include "chrome/browser/password_manager/save_password_infobar_delegate_android
.h" |
68 #include "chrome/browser/password_manager/update_password_infobar_delegate_andro
id.h" | 67 #include "chrome/browser/password_manager/update_password_infobar_delegate_andro
id.h" |
69 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" | 68 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" |
70 #endif | 69 #endif |
71 | 70 |
72 using password_manager::ContentPasswordManagerDriverFactory; | 71 using password_manager::ContentPasswordManagerDriverFactory; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, | 229 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, |
231 password_manager::CredentialSourceType type, | 230 password_manager::CredentialSourceType type, |
232 bool update_password) { | 231 bool update_password) { |
233 // Save password infobar and the password bubble prompts in case of | 232 // Save password infobar and the password bubble prompts in case of |
234 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). | 233 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). |
235 if (!BrowsingDataHelper::IsWebScheme( | 234 if (!BrowsingDataHelper::IsWebScheme( |
236 web_contents()->GetLastCommittedURL().scheme())) { | 235 web_contents()->GetLastCommittedURL().scheme())) { |
237 return false; | 236 return false; |
238 } | 237 } |
239 | 238 |
240 #if !BUILDFLAG(ANDROID_JAVA_UI) | 239 #if !defined(OS_ANDROID) |
241 PasswordsClientUIDelegate* manage_passwords_ui_controller = | 240 PasswordsClientUIDelegate* manage_passwords_ui_controller = |
242 PasswordsClientUIDelegateFromWebContents(web_contents()); | 241 PasswordsClientUIDelegateFromWebContents(web_contents()); |
243 if (update_password) { | 242 if (update_password) { |
244 manage_passwords_ui_controller->OnUpdatePasswordSubmitted( | 243 manage_passwords_ui_controller->OnUpdatePasswordSubmitted( |
245 std::move(form_to_save)); | 244 std::move(form_to_save)); |
246 } else { | 245 } else { |
247 manage_passwords_ui_controller->OnPasswordSubmitted( | 246 manage_passwords_ui_controller->OnPasswordSubmitted( |
248 std::move(form_to_save)); | 247 std::move(form_to_save)); |
249 } | 248 } |
250 #else | 249 #else |
251 if (form_to_save->IsBlacklisted()) | 250 if (form_to_save->IsBlacklisted()) |
252 return false; | 251 return false; |
253 | 252 |
254 if (update_password) { | 253 if (update_password) { |
255 UpdatePasswordInfoBarDelegate::Create(web_contents(), | 254 UpdatePasswordInfoBarDelegate::Create(web_contents(), |
256 std::move(form_to_save)); | 255 std::move(form_to_save)); |
257 return true; | 256 return true; |
258 } | 257 } |
259 SavePasswordInfoBarDelegate::Create(web_contents(), | 258 SavePasswordInfoBarDelegate::Create(web_contents(), |
260 std::move(form_to_save)); | 259 std::move(form_to_save)); |
261 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | 260 #endif // !defined(OS_ANDROID) |
262 return true; | 261 return true; |
263 } | 262 } |
264 | 263 |
265 bool ChromePasswordManagerClient::PromptUserToChooseCredentials( | 264 bool ChromePasswordManagerClient::PromptUserToChooseCredentials( |
266 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, | 265 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, |
267 const GURL& origin, | 266 const GURL& origin, |
268 const CredentialsCallback& callback) { | 267 const CredentialsCallback& callback) { |
269 // Set up an intercept callback if the prompt is zero-clickable (e.g. just one | 268 // Set up an intercept callback if the prompt is zero-clickable (e.g. just one |
270 // form provided). | 269 // form provided). |
271 CredentialsCallback intercept = | 270 CredentialsCallback intercept = |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 driver->GeneratePassword(); | 309 driver->GeneratePassword(); |
311 } | 310 } |
312 | 311 |
313 void ChromePasswordManagerClient::NotifyUserAutoSignin( | 312 void ChromePasswordManagerClient::NotifyUserAutoSignin( |
314 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, | 313 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, |
315 const GURL& origin) { | 314 const GURL& origin) { |
316 DCHECK(!local_forms.empty()); | 315 DCHECK(!local_forms.empty()); |
317 // If a site gets back a credential some navigations are likely to occur. They | 316 // If a site gets back a credential some navigations are likely to occur. They |
318 // shouldn't trigger the autofill password manager. | 317 // shouldn't trigger the autofill password manager. |
319 password_manager_.DropFormManagers(); | 318 password_manager_.DropFormManagers(); |
320 #if BUILDFLAG(ANDROID_JAVA_UI) | 319 #if defined(OS_ANDROID) |
321 ShowAutoSigninPrompt(web_contents(), local_forms[0]->username_value); | 320 ShowAutoSigninPrompt(web_contents(), local_forms[0]->username_value); |
322 #else | 321 #else |
323 PasswordsClientUIDelegateFromWebContents(web_contents()) | 322 PasswordsClientUIDelegateFromWebContents(web_contents()) |
324 ->OnAutoSignin(std::move(local_forms), origin); | 323 ->OnAutoSignin(std::move(local_forms), origin); |
325 #endif | 324 #endif |
326 } | 325 } |
327 | 326 |
328 void ChromePasswordManagerClient::NotifyUserCouldBeAutoSignedIn( | 327 void ChromePasswordManagerClient::NotifyUserCouldBeAutoSignedIn( |
329 std::unique_ptr<autofill::PasswordForm> form) { | 328 std::unique_ptr<autofill::PasswordForm> form) { |
330 possible_auto_sign_in_ = std::move(form); | 329 possible_auto_sign_in_ = std::move(form); |
(...skipping 13 matching lines...) Expand all Loading... |
344 } | 343 } |
345 | 344 |
346 void ChromePasswordManagerClient::NotifyStorePasswordCalled() { | 345 void ChromePasswordManagerClient::NotifyStorePasswordCalled() { |
347 // If a site stores a credential the autofill password manager shouldn't kick | 346 // If a site stores a credential the autofill password manager shouldn't kick |
348 // in. | 347 // in. |
349 password_manager_.DropFormManagers(); | 348 password_manager_.DropFormManagers(); |
350 } | 349 } |
351 | 350 |
352 void ChromePasswordManagerClient::AutomaticPasswordSave( | 351 void ChromePasswordManagerClient::AutomaticPasswordSave( |
353 std::unique_ptr<password_manager::PasswordFormManager> saved_form) { | 352 std::unique_ptr<password_manager::PasswordFormManager> saved_form) { |
354 #if BUILDFLAG(ANDROID_JAVA_UI) | 353 #if defined(OS_ANDROID) |
355 GeneratedPasswordSavedInfoBarDelegateAndroid::Create(web_contents()); | 354 GeneratedPasswordSavedInfoBarDelegateAndroid::Create(web_contents()); |
356 #else | 355 #else |
357 PasswordsClientUIDelegate* manage_passwords_ui_controller = | 356 PasswordsClientUIDelegate* manage_passwords_ui_controller = |
358 PasswordsClientUIDelegateFromWebContents(web_contents()); | 357 PasswordsClientUIDelegateFromWebContents(web_contents()); |
359 manage_passwords_ui_controller->OnAutomaticPasswordSave( | 358 manage_passwords_ui_controller->OnAutomaticPasswordSave( |
360 std::move(saved_form)); | 359 std::move(saved_form)); |
361 #endif | 360 #endif |
362 } | 361 } |
363 | 362 |
364 void ChromePasswordManagerClient::PasswordWasAutofilled( | 363 void ChromePasswordManagerClient::PasswordWasAutofilled( |
365 const std::map<base::string16, const autofill::PasswordForm*>& best_matches, | 364 const std::map<base::string16, const autofill::PasswordForm*>& best_matches, |
366 const GURL& origin, | 365 const GURL& origin, |
367 const std::vector<const autofill::PasswordForm*>* federated_matches) const { | 366 const std::vector<const autofill::PasswordForm*>* federated_matches) const { |
368 #if !BUILDFLAG(ANDROID_JAVA_UI) | 367 #if !defined(OS_ANDROID) |
369 PasswordsClientUIDelegate* manage_passwords_ui_controller = | 368 PasswordsClientUIDelegate* manage_passwords_ui_controller = |
370 PasswordsClientUIDelegateFromWebContents(web_contents()); | 369 PasswordsClientUIDelegateFromWebContents(web_contents()); |
371 manage_passwords_ui_controller->OnPasswordAutofilled(best_matches, origin, | 370 manage_passwords_ui_controller->OnPasswordAutofilled(best_matches, origin, |
372 federated_matches); | 371 federated_matches); |
373 #endif | 372 #endif |
374 } | 373 } |
375 | 374 |
376 void ChromePasswordManagerClient::HidePasswordGenerationPopup() { | 375 void ChromePasswordManagerClient::HidePasswordGenerationPopup() { |
377 if (popup_controller_) | 376 if (popup_controller_) |
378 popup_controller_->HideAndDestroy(); | 377 popup_controller_->HideAndDestroy(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } | 536 } |
538 | 537 |
539 void ChromePasswordManagerClient::PromptUserToEnableAutosigninIfNecessary() { | 538 void ChromePasswordManagerClient::PromptUserToEnableAutosigninIfNecessary() { |
540 if (!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 539 if (!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
541 GetPrefs()) || | 540 GetPrefs()) || |
542 !GetPrefs()->GetBoolean( | 541 !GetPrefs()->GetBoolean( |
543 password_manager::prefs::kCredentialsEnableAutosignin) || | 542 password_manager::prefs::kCredentialsEnableAutosignin) || |
544 IsOffTheRecord()) | 543 IsOffTheRecord()) |
545 return; | 544 return; |
546 | 545 |
547 #if BUILDFLAG(ANDROID_JAVA_UI) | 546 #if defined(OS_ANDROID) |
548 // Dialog is deleted by the Java counterpart after user interacts with it. | 547 // Dialog is deleted by the Java counterpart after user interacts with it. |
549 AutoSigninFirstRunDialogAndroid* auto_signin_first_run_dialog = | 548 AutoSigninFirstRunDialogAndroid* auto_signin_first_run_dialog = |
550 new AutoSigninFirstRunDialogAndroid(web_contents()); | 549 new AutoSigninFirstRunDialogAndroid(web_contents()); |
551 auto_signin_first_run_dialog->ShowDialog(); | 550 auto_signin_first_run_dialog->ShowDialog(); |
552 #else | 551 #else |
553 PasswordsClientUIDelegateFromWebContents(web_contents()) | 552 PasswordsClientUIDelegateFromWebContents(web_contents()) |
554 ->OnPromptEnableAutoSignin(); | 553 ->OnPromptEnableAutoSignin(); |
555 #endif | 554 #endif |
556 } | 555 } |
557 | 556 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 ChromePasswordManagerClient::FromWebContents(web_contents); | 635 ChromePasswordManagerClient::FromWebContents(web_contents); |
637 | 636 |
638 // Try to bind to the driver, but if driver is not available for this render | 637 // Try to bind to the driver, but if driver is not available for this render |
639 // frame host, the request will be just dropped. This will cause the message | 638 // frame host, the request will be just dropped. This will cause the message |
640 // pipe to be closed, which will raise a connection error on the peer side. | 639 // pipe to be closed, which will raise a connection error on the peer side. |
641 if (!instance) | 640 if (!instance) |
642 return; | 641 return; |
643 | 642 |
644 instance->credential_manager_impl_.BindRequest(std::move(request)); | 643 instance->credential_manager_impl_.BindRequest(std::move(request)); |
645 } | 644 } |
OLD | NEW |