| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "components/prefs/pref_service.h" | 49 #include "components/prefs/pref_service.h" |
| 50 #include "components/signin/core/browser/signin_manager.h" | 50 #include "components/signin/core/browser/signin_manager.h" |
| 51 #include "components/version_info/version_info.h" | 51 #include "components/version_info/version_info.h" |
| 52 #include "content/public/browser/navigation_entry.h" | 52 #include "content/public/browser/navigation_entry.h" |
| 53 #include "content/public/browser/render_view_host.h" | 53 #include "content/public/browser/render_view_host.h" |
| 54 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
| 55 #include "google_apis/gaia/gaia_urls.h" | 55 #include "google_apis/gaia/gaia_urls.h" |
| 56 #include "net/base/url_util.h" | 56 #include "net/base/url_util.h" |
| 57 #include "third_party/re2/src/re2/re2.h" | 57 #include "third_party/re2/src/re2/re2.h" |
| 58 | 58 |
| 59 #if defined(OS_MACOSX) || BUILDFLAG(ANDROID_JAVA_UI) | |
| 60 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | |
| 61 #endif | |
| 62 | |
| 63 #if BUILDFLAG(ANDROID_JAVA_UI) | 59 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 64 #include "chrome/browser/android/tab_android.h" | 60 #include "chrome/browser/android/tab_android.h" |
| 65 #include "chrome/browser/password_manager/account_chooser_dialog_android.h" | 61 #include "chrome/browser/password_manager/account_chooser_dialog_android.h" |
| 66 #include "chrome/browser/password_manager/auto_signin_first_run_dialog_android.h
" | 62 #include "chrome/browser/password_manager/auto_signin_first_run_dialog_android.h
" |
| 67 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" | 63 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" |
| 64 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
| 68 #include "chrome/browser/password_manager/update_password_infobar_delegate.h" | 65 #include "chrome/browser/password_manager/update_password_infobar_delegate.h" |
| 69 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" | 66 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" |
| 70 #endif | 67 #endif |
| 71 | 68 |
| 72 using password_manager::ContentPasswordManagerDriverFactory; | 69 using password_manager::ContentPasswordManagerDriverFactory; |
| 73 using password_manager::PasswordManagerInternalsService; | 70 using password_manager::PasswordManagerInternalsService; |
| 74 | 71 |
| 75 // Shorten the name to spare line breaks. The code provides enough context | 72 // Shorten the name to spare line breaks. The code provides enough context |
| 76 // already. | 73 // already. |
| 77 typedef autofill::SavePasswordProgressLogger Logger; | 74 typedef autofill::SavePasswordProgressLogger Logger; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, | 212 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, |
| 216 password_manager::CredentialSourceType type, | 213 password_manager::CredentialSourceType type, |
| 217 bool update_password) { | 214 bool update_password) { |
| 218 // Save password infobar and the password bubble prompts in case of | 215 // Save password infobar and the password bubble prompts in case of |
| 219 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). | 216 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). |
| 220 if (!BrowsingDataHelper::IsWebScheme( | 217 if (!BrowsingDataHelper::IsWebScheme( |
| 221 web_contents()->GetLastCommittedURL().scheme())) { | 218 web_contents()->GetLastCommittedURL().scheme())) { |
| 222 return false; | 219 return false; |
| 223 } | 220 } |
| 224 | 221 |
| 225 if (IsTheHotNewBubbleUIEnabled()) { | |
| 226 #if !BUILDFLAG(ANDROID_JAVA_UI) | 222 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 227 PasswordsClientUIDelegate* manage_passwords_ui_controller = | 223 PasswordsClientUIDelegate* manage_passwords_ui_controller = |
| 228 PasswordsClientUIDelegateFromWebContents(web_contents()); | 224 PasswordsClientUIDelegateFromWebContents(web_contents()); |
| 229 if (update_password && IsUpdatePasswordUIEnabled()) { | 225 if (update_password) { |
| 230 manage_passwords_ui_controller->OnUpdatePasswordSubmitted( | 226 manage_passwords_ui_controller->OnUpdatePasswordSubmitted( |
| 231 std::move(form_to_save)); | 227 std::move(form_to_save)); |
| 232 } else { | |
| 233 manage_passwords_ui_controller->OnPasswordSubmitted( | |
| 234 std::move(form_to_save)); | |
| 235 } | |
| 236 #endif | |
| 237 } else { | 228 } else { |
| 238 #if defined(OS_MACOSX) || BUILDFLAG(ANDROID_JAVA_UI) | 229 manage_passwords_ui_controller->OnPasswordSubmitted( |
| 239 if (form_to_save->IsBlacklisted()) | 230 std::move(form_to_save)); |
| 240 return false; | 231 } |
| 241 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 242 if (update_password && IsUpdatePasswordUIEnabled()) { | |
| 243 UpdatePasswordInfoBarDelegate::Create(web_contents(), | |
| 244 std::move(form_to_save)); | |
| 245 return true; | |
| 246 } | |
| 247 #endif | |
| 248 SavePasswordInfoBarDelegate::Create(web_contents(), | |
| 249 std::move(form_to_save)); | |
| 250 #else | 232 #else |
| 251 NOTREACHED() << "Aura platforms should always use the bubble"; | 233 if (form_to_save->IsBlacklisted()) |
| 252 #endif | 234 return false; |
| 235 |
| 236 if (update_password && IsUpdatePasswordUIEnabled()) { |
| 237 UpdatePasswordInfoBarDelegate::Create(web_contents(), |
| 238 std::move(form_to_save)); |
| 239 return true; |
| 253 } | 240 } |
| 241 SavePasswordInfoBarDelegate::Create(web_contents(), |
| 242 std::move(form_to_save)); |
| 243 #endif // !BUILDFLAG(ANDROID_JAVA_UI) |
| 254 return true; | 244 return true; |
| 255 } | 245 } |
| 256 | 246 |
| 257 bool ChromePasswordManagerClient::PromptUserToChooseCredentials( | 247 bool ChromePasswordManagerClient::PromptUserToChooseCredentials( |
| 258 ScopedVector<autofill::PasswordForm> local_forms, | 248 ScopedVector<autofill::PasswordForm> local_forms, |
| 259 ScopedVector<autofill::PasswordForm> federated_forms, | 249 ScopedVector<autofill::PasswordForm> federated_forms, |
| 260 const GURL& origin, | 250 const GURL& origin, |
| 261 const CredentialsCallback& callback) { | 251 const CredentialsCallback& callback) { |
| 262 // Set up an intercept callback if the prompt is zero-clickable (e.g. just one | 252 // Set up an intercept callback if the prompt is zero-clickable (e.g. just one |
| 263 // form provided). | 253 // form provided). |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // If a site stores a credential the autofill password manager shouldn't kick | 332 // If a site stores a credential the autofill password manager shouldn't kick |
| 343 // in. | 333 // in. |
| 344 password_manager_.DropFormManagers(); | 334 password_manager_.DropFormManagers(); |
| 345 } | 335 } |
| 346 | 336 |
| 347 void ChromePasswordManagerClient::AutomaticPasswordSave( | 337 void ChromePasswordManagerClient::AutomaticPasswordSave( |
| 348 std::unique_ptr<password_manager::PasswordFormManager> saved_form) { | 338 std::unique_ptr<password_manager::PasswordFormManager> saved_form) { |
| 349 #if BUILDFLAG(ANDROID_JAVA_UI) | 339 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 350 GeneratedPasswordSavedInfoBarDelegateAndroid::Create(web_contents()); | 340 GeneratedPasswordSavedInfoBarDelegateAndroid::Create(web_contents()); |
| 351 #else | 341 #else |
| 352 if (IsTheHotNewBubbleUIEnabled()) { | 342 PasswordsClientUIDelegate* manage_passwords_ui_controller = |
| 353 PasswordsClientUIDelegate* manage_passwords_ui_controller = | 343 PasswordsClientUIDelegateFromWebContents(web_contents()); |
| 354 PasswordsClientUIDelegateFromWebContents(web_contents()); | 344 manage_passwords_ui_controller->OnAutomaticPasswordSave( |
| 355 manage_passwords_ui_controller->OnAutomaticPasswordSave( | 345 std::move(saved_form)); |
| 356 std::move(saved_form)); | |
| 357 } | |
| 358 #endif | 346 #endif |
| 359 } | 347 } |
| 360 | 348 |
| 361 void ChromePasswordManagerClient::PasswordWasAutofilled( | 349 void ChromePasswordManagerClient::PasswordWasAutofilled( |
| 362 const autofill::PasswordFormMap& best_matches, | 350 const autofill::PasswordFormMap& best_matches, |
| 363 const GURL& origin, | 351 const GURL& origin, |
| 364 const std::vector<std::unique_ptr<autofill::PasswordForm>>* | 352 const std::vector<std::unique_ptr<autofill::PasswordForm>>* |
| 365 federated_matches) const { | 353 federated_matches) const { |
| 366 #if !BUILDFLAG(ANDROID_JAVA_UI) | 354 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 367 PasswordsClientUIDelegate* manage_passwords_ui_controller = | 355 PasswordsClientUIDelegate* manage_passwords_ui_controller = |
| 368 PasswordsClientUIDelegateFromWebContents(web_contents()); | 356 PasswordsClientUIDelegateFromWebContents(web_contents()); |
| 369 if (manage_passwords_ui_controller && IsTheHotNewBubbleUIEnabled()) | 357 manage_passwords_ui_controller->OnPasswordAutofilled(best_matches, origin, |
| 370 manage_passwords_ui_controller->OnPasswordAutofilled(best_matches, origin, | 358 federated_matches); |
| 371 federated_matches); | |
| 372 #endif | 359 #endif |
| 373 } | 360 } |
| 374 | 361 |
| 375 void ChromePasswordManagerClient::HidePasswordGenerationPopup() { | 362 void ChromePasswordManagerClient::HidePasswordGenerationPopup() { |
| 376 if (popup_controller_) | 363 if (popup_controller_) |
| 377 popup_controller_->HideAndDestroy(); | 364 popup_controller_->HideAndDestroy(); |
| 378 } | 365 } |
| 379 | 366 |
| 380 PrefService* ChromePasswordManagerClient::GetPrefs() { | 367 PrefService* ChromePasswordManagerClient::GetPrefs() { |
| 381 return profile_->GetPrefs(); | 368 return profile_->GetPrefs(); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 PasswordsClientUIDelegateFromWebContents(web_contents()) | 542 PasswordsClientUIDelegateFromWebContents(web_contents()) |
| 556 ->OnPromptEnableAutoSignin(); | 543 ->OnPromptEnableAutoSignin(); |
| 557 #endif | 544 #endif |
| 558 } | 545 } |
| 559 | 546 |
| 560 void ChromePasswordManagerClient::GenerationAvailableForForm( | 547 void ChromePasswordManagerClient::GenerationAvailableForForm( |
| 561 const autofill::PasswordForm& form) { | 548 const autofill::PasswordForm& form) { |
| 562 password_manager_.GenerationAvailableForForm(form); | 549 password_manager_.GenerationAvailableForForm(form); |
| 563 } | 550 } |
| 564 | 551 |
| 565 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { | |
| 566 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 567 return false; | |
| 568 #elif defined(OS_MACOSX) | |
| 569 // Query the group first for correct UMA reporting. | |
| 570 std::string group_name = | |
| 571 base::FieldTrialList::FindFullName("PasswordManagerUI"); | |
| 572 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 573 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | |
| 574 return false; | |
| 575 | |
| 576 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) | |
| 577 return true; | |
| 578 | |
| 579 // The bubble should be the default case that runs on the bots. | |
| 580 return group_name != "Infobar"; | |
| 581 #else | |
| 582 // All other platforms use Aura, and therefore always show the bubble. | |
| 583 return true; | |
| 584 #endif | |
| 585 } | |
| 586 | |
| 587 bool ChromePasswordManagerClient::IsUpdatePasswordUIEnabled() const { | 552 bool ChromePasswordManagerClient::IsUpdatePasswordUIEnabled() const { |
| 588 #if BUILDFLAG(ANDROID_JAVA_UI) | 553 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 589 return base::FeatureList::IsEnabled( | 554 return base::FeatureList::IsEnabled( |
| 590 password_manager::features::kEnablePasswordChangeSupport); | 555 password_manager::features::kEnablePasswordChangeSupport); |
| 591 #else | 556 #else |
| 592 return IsTheHotNewBubbleUIEnabled(); | 557 return true; |
| 593 #endif | 558 #endif |
| 594 } | 559 } |
| 595 | 560 |
| 596 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { | 561 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { |
| 597 return web_contents()->GetVisibleURL(); | 562 return web_contents()->GetVisibleURL(); |
| 598 } | 563 } |
| 599 | 564 |
| 600 const GURL& ChromePasswordManagerClient::GetLastCommittedEntryURL() const { | 565 const GURL& ChromePasswordManagerClient::GetLastCommittedEntryURL() const { |
| 601 DCHECK(web_contents()); | 566 DCHECK(web_contents()); |
| 602 content::NavigationEntry* entry = | 567 content::NavigationEntry* entry = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 623 password_manager::mojom::CredentialManagerRequest request) { | 588 password_manager::mojom::CredentialManagerRequest request) { |
| 624 content::WebContents* web_contents = | 589 content::WebContents* web_contents = |
| 625 content::WebContents::FromRenderFrameHost(render_frame_host); | 590 content::WebContents::FromRenderFrameHost(render_frame_host); |
| 626 DCHECK(web_contents); | 591 DCHECK(web_contents); |
| 627 | 592 |
| 628 ChromePasswordManagerClient* instance = | 593 ChromePasswordManagerClient* instance = |
| 629 ChromePasswordManagerClient::FromWebContents(web_contents); | 594 ChromePasswordManagerClient::FromWebContents(web_contents); |
| 630 DCHECK(instance); | 595 DCHECK(instance); |
| 631 instance->credential_manager_impl_.BindRequest(std::move(request)); | 596 instance->credential_manager_impl_.BindRequest(std::move(request)); |
| 632 } | 597 } |
| OLD | NEW |