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 #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 "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/prefs/pref_service.h" | |
| 11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 14 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 14 #include "chrome/browser/password_manager/password_manager_util.h" | 15 #include "chrome/browser/password_manager/password_manager_util.h" |
| 15 #include "chrome/browser/password_manager/password_store_factory.h" | 16 #include "chrome/browser/password_manager/password_store_factory.h" |
| 16 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 17 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
| 17 #include "chrome/browser/password_manager/sync_metrics.h" | 18 #include "chrome/browser/password_manager/sync_metrics.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/sync/profile_sync_service.h" | 20 #include "chrome/browser/sync/profile_sync_service.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 21 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 21 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " | 22 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " |
| 22 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 23 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/chrome_version_info.h" | 25 #include "chrome/common/chrome_version_info.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "components/autofill/content/browser/content_autofill_driver.h" | 27 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 27 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 28 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
| 28 #include "components/autofill/content/common/autofill_messages.h" | 29 #include "components/autofill/content/common/autofill_messages.h" |
| 29 #include "components/autofill/core/browser/password_generator.h" | 30 #include "components/autofill/core/browser/password_generator.h" |
| 30 #include "components/autofill/core/common/password_form.h" | 31 #include "components/autofill/core/common/password_form.h" |
| 31 #include "components/password_manager/content/browser/content_password_manager_d river.h" | 32 #include "components/password_manager/content/browser/content_password_manager_d river.h" |
| 32 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" | 33 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" |
| 33 #include "components/password_manager/content/common/credential_manager_messages .h" | 34 #include "components/password_manager/content/common/credential_manager_messages .h" |
| 34 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" | 35 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" |
| 35 #include "components/password_manager/core/browser/log_receiver.h" | 36 #include "components/password_manager/core/browser/log_receiver.h" |
| 36 #include "components/password_manager/core/browser/password_form_manager.h" | 37 #include "components/password_manager/core/browser/password_form_manager.h" |
| 37 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" | 38 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" |
| 38 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 39 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
| 39 #include "components/password_manager/core/common/credential_manager_types.h" | 40 #include "components/password_manager/core/common/credential_manager_types.h" |
| 41 #include "components/password_manager/core/common/password_manager_pref_names.h" | |
| 40 #include "components/password_manager/core/common/password_manager_switches.h" | 42 #include "components/password_manager/core/common/password_manager_switches.h" |
| 41 #include "content/public/browser/navigation_entry.h" | 43 #include "content/public/browser/navigation_entry.h" |
| 42 #include "content/public/browser/render_view_host.h" | 44 #include "content/public/browser/render_view_host.h" |
| 43 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 44 #include "google_apis/gaia/gaia_urls.h" | 46 #include "google_apis/gaia/gaia_urls.h" |
| 45 #include "net/base/url_util.h" | 47 #include "net/base/url_util.h" |
| 46 #include "third_party/re2/re2/re2.h" | 48 #include "third_party/re2/re2/re2.h" |
| 47 | 49 |
| 48 #if defined(OS_ANDROID) | 50 #if defined(OS_ANDROID) |
| 49 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg ate_android.h" | 51 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg ate_android.h" |
| 50 #endif | 52 #endif |
| 51 | 53 |
| 52 using password_manager::ContentPasswordManagerDriverFactory; | 54 using password_manager::ContentPasswordManagerDriverFactory; |
| 53 using password_manager::PasswordManagerInternalsService; | 55 using password_manager::PasswordManagerInternalsService; |
| 54 using password_manager::PasswordManagerInternalsServiceFactory; | 56 using password_manager::PasswordManagerInternalsServiceFactory; |
| 55 | 57 |
| 56 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 58 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
| 57 | 59 |
| 60 namespace { | |
| 61 // This routine is called when PasswordManagersClient is constructed. | |
|
vabr (Chromium)
2015/04/07 13:53:14
typo: Managers -> Manager
melandory
2015/04/07 14:28:52
Done.
| |
| 62 // | |
| 63 // Currently we report metrics only once at startup. We require | |
| 64 // that this is only ever called from a single thread in order to | |
| 65 // avoid needing to lock (a static boolean flag is then sufficient to | |
| 66 // guarantee running only once). | |
| 67 void ReportMetrics(bool password_manager_enabled, | |
| 68 password_manager::PasswordManagerClient* client) { | |
| 69 static base::PlatformThreadId initial_thread_id = | |
| 70 base::PlatformThread::CurrentId(); | |
| 71 DCHECK(initial_thread_id == base::PlatformThread::CurrentId()); | |
|
vabr (Chromium)
2015/04/07 13:53:14
nit: Use
DCHECK_EQ(base::PlatformThread::CurrentId
melandory
2015/04/07 14:28:52
Done.
| |
| 72 | |
| 73 static bool ran_once = false; | |
| 74 if (ran_once) | |
| 75 return; | |
| 76 ran_once = true; | |
| 77 | |
| 78 password_manager::PasswordStore* store = client->GetPasswordStore(); | |
| 79 // May be null in tests. | |
| 80 if (store) { | |
| 81 store->ReportMetrics(client->GetSyncUsername(), | |
| 82 client->IsPasswordSyncEnabled( | |
| 83 password_manager::ONLY_CUSTOM_PASSPHRASE)); | |
| 84 } | |
| 85 UMA_HISTOGRAM_BOOLEAN("PasswordManager.Enabled", password_manager_enabled); | |
| 86 } | |
| 87 | |
| 58 // Shorten the name to spare line breaks. The code provides enough context | 88 // Shorten the name to spare line breaks. The code provides enough context |
| 59 // already. | 89 // already. |
| 60 typedef autofill::SavePasswordProgressLogger Logger; | 90 typedef autofill::SavePasswordProgressLogger Logger; |
|
vabr (Chromium)
2015/04/07 13:53:14
I believe this should go above the namespace. Idea
melandory
2015/04/07 14:28:52
Done.
| |
| 61 | 91 |
| 92 } // namespace | |
| 93 | |
| 62 // static | 94 // static |
| 63 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( | 95 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( |
| 64 content::WebContents* contents, | 96 content::WebContents* contents, |
| 65 autofill::AutofillClient* autofill_client) { | 97 autofill::AutofillClient* autofill_client) { |
| 66 if (FromWebContents(contents)) | 98 if (FromWebContents(contents)) |
| 67 return; | 99 return; |
| 68 | 100 |
| 69 contents->SetUserData( | 101 contents->SetUserData( |
| 70 UserDataKey(), | 102 UserDataKey(), |
| 71 new ChromePasswordManagerClient(contents, autofill_client)); | 103 new ChromePasswordManagerClient(contents, autofill_client)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 86 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 118 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
| 87 autofill_client); | 119 autofill_client); |
| 88 driver_factory_ = | 120 driver_factory_ = |
| 89 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 121 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
| 90 | 122 |
| 91 PasswordManagerInternalsService* service = | 123 PasswordManagerInternalsService* service = |
| 92 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 124 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 93 if (service) | 125 if (service) |
| 94 can_use_log_router_ = service->RegisterClient(this); | 126 can_use_log_router_ = service->RegisterClient(this); |
| 95 SetUpAutofillSyncState(); | 127 SetUpAutofillSyncState(); |
| 128 saving_passwords_enabled_.Init( | |
| 129 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); | |
| 130 ReportMetrics(*saving_passwords_enabled_, this); | |
| 96 } | 131 } |
| 97 | 132 |
| 98 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 133 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
| 99 PasswordManagerInternalsService* service = | 134 PasswordManagerInternalsService* service = |
| 100 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 135 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 101 if (service) | 136 if (service) |
| 102 service->UnregisterClient(this); | 137 service->UnregisterClient(this); |
| 103 } | 138 } |
| 104 | 139 |
| 105 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 140 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
| 106 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 141 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 107 password_manager::switches::kEnableAutomaticPasswordSaving) && | 142 password_manager::switches::kEnableAutomaticPasswordSaving) && |
| 108 chrome::VersionInfo::GetChannel() == | 143 chrome::VersionInfo::GetChannel() == |
| 109 chrome::VersionInfo::CHANNEL_UNKNOWN; | 144 chrome::VersionInfo::CHANNEL_UNKNOWN; |
| 110 } | 145 } |
| 111 | 146 |
| 112 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() | 147 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() |
| 113 const { | 148 const { |
| 114 DCHECK(web_contents()); | 149 DCHECK(web_contents()); |
| 115 content::NavigationEntry* entry = | 150 content::NavigationEntry* entry = |
| 116 web_contents()->GetController().GetLastCommittedEntry(); | 151 web_contents()->GetController().GetLastCommittedEntry(); |
| 152 bool is_enabled = false; | |
| 117 if (!entry) { | 153 if (!entry) { |
| 118 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 154 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
| 119 return true; | 155 is_enabled = true; |
| 156 } else if (IsURLPasswordWebsiteReauth(entry->GetURL())) { | |
| 157 // Disable the password manager for online password management. | |
| 158 is_enabled = false; | |
| 159 } else if (EnabledForSyncSignin()) { | |
| 160 is_enabled = true; | |
| 161 } else { | |
| 162 // Do not fill nor save password when a user is signing in for sync. This | |
| 163 // is because users need to remember their password if they are syncing as | |
| 164 // this is effectively their master password. | |
| 165 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | |
| 120 } | 166 } |
| 167 if (IsLoggingActive()) { | |
| 168 password_manager::BrowserSavePasswordProgressLogger logger(this); | |
| 169 logger.LogBoolean( | |
| 170 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, | |
| 171 is_enabled); | |
| 172 } | |
| 173 return is_enabled; | |
| 174 } | |
| 121 | 175 |
| 122 // Disable the password manager for online password management. | 176 bool ChromePasswordManagerClient::IsSavingEnabledForCurrentPage() const { |
| 123 if (IsURLPasswordWebsiteReauth(entry->GetURL())) | 177 return *saving_passwords_enabled_ && !IsOffTheRecord() && |
| 124 return false; | 178 !DidLastPageLoadEncounterSSLErrors() && |
| 125 | 179 IsPasswordManagementEnabledForCurrentPage(); |
| 126 if (EnabledForSyncSignin()) | |
| 127 return true; | |
| 128 | |
| 129 // Do not fill nor save password when a user is signing in for sync. This | |
| 130 // is because users need to remember their password if they are syncing as | |
| 131 // this is effectively their master password. | |
| 132 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | |
| 133 } | 180 } |
| 134 | 181 |
| 135 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( | 182 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( |
| 136 const autofill::PasswordForm& form) { | 183 const autofill::PasswordForm& form) { |
| 137 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), | 184 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), |
| 138 form.signon_realm)) | 185 form.signon_realm)) |
| 139 return false; | 186 return false; |
| 140 | 187 |
| 141 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) { | 188 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) { |
| 142 sync_credential_was_filtered_ = true; | 189 sync_credential_was_filtered_ = true; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); | 369 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
| 323 | 370 |
| 324 if (http_status_code >= 400 && http_status_code < 600) | 371 if (http_status_code >= 400 && http_status_code < 600) |
| 325 return true; | 372 return true; |
| 326 return false; | 373 return false; |
| 327 } | 374 } |
| 328 | 375 |
| 329 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { | 376 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { |
| 330 content::NavigationEntry* entry = | 377 content::NavigationEntry* entry = |
| 331 web_contents()->GetController().GetLastCommittedEntry(); | 378 web_contents()->GetController().GetLastCommittedEntry(); |
| 332 if (!entry) | 379 bool ssl_errors = true; |
| 333 return false; | 380 if (!entry) { |
| 334 | 381 ssl_errors = false; |
| 335 return net::IsCertStatusError(entry->GetSSL().cert_status); | 382 } else { |
| 383 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); | |
| 384 } | |
| 385 if (IsLoggingActive()) { | |
| 386 password_manager::BrowserSavePasswordProgressLogger logger(this); | |
| 387 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); | |
| 388 } | |
| 389 return ssl_errors; | |
| 336 } | 390 } |
| 337 | 391 |
| 338 bool ChromePasswordManagerClient::IsOffTheRecord() const { | 392 bool ChromePasswordManagerClient::IsOffTheRecord() const { |
| 339 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 393 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 340 } | 394 } |
| 341 | 395 |
| 342 password_manager::PasswordManager* | 396 password_manager::PasswordManager* |
| 343 ChromePasswordManagerClient::GetPasswordManager() { | 397 ChromePasswordManagerClient::GetPasswordManager() { |
| 344 return &password_manager_; | 398 return &password_manager_; |
| 345 } | 399 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 589 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
| 536 } else { | 590 } else { |
| 537 // Allow by default. | 591 // Allow by default. |
| 538 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 592 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
| 539 } | 593 } |
| 540 } | 594 } |
| 541 | 595 |
| 542 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { | 596 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { |
| 543 return web_contents()->GetVisibleURL(); | 597 return web_contents()->GetVisibleURL(); |
| 544 } | 598 } |
| OLD | NEW |