| 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); | |
| 57 | |
| 58 // Shorten the name to spare line breaks. The code provides enough context | 58 // Shorten the name to spare line breaks. The code provides enough context |
| 59 // already. | 59 // already. |
| 60 typedef autofill::SavePasswordProgressLogger Logger; | 60 typedef autofill::SavePasswordProgressLogger Logger; |
| 61 | 61 |
| 62 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
| 63 |
| 64 namespace { |
| 65 // This routine is called when PasswordManagerClient is constructed. |
| 66 // Currently we report metrics only once at startup. We require |
| 67 // that this is only ever called from a single thread in order to |
| 68 // avoid needing to lock (a static boolean flag is then sufficient to |
| 69 // guarantee running only once). |
| 70 void ReportMetrics(bool password_manager_enabled, |
| 71 password_manager::PasswordManagerClient* client) { |
| 72 static base::PlatformThreadId initial_thread_id = |
| 73 base::PlatformThread::CurrentId(); |
| 74 DCHECK_EQ(base::PlatformThread::CurrentId(), initial_thread_id); |
| 75 |
| 76 static bool ran_once = false; |
| 77 if (ran_once) |
| 78 return; |
| 79 ran_once = true; |
| 80 |
| 81 password_manager::PasswordStore* store = client->GetPasswordStore(); |
| 82 // May be null in tests. |
| 83 if (store) { |
| 84 store->ReportMetrics(client->GetSyncUsername(), |
| 85 client->IsPasswordSyncEnabled( |
| 86 password_manager::ONLY_CUSTOM_PASSPHRASE)); |
| 87 } |
| 88 UMA_HISTOGRAM_BOOLEAN("PasswordManager.Enabled", password_manager_enabled); |
| 89 } |
| 90 |
| 91 } // namespace |
| 92 |
| 62 // static | 93 // static |
| 63 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( | 94 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( |
| 64 content::WebContents* contents, | 95 content::WebContents* contents, |
| 65 autofill::AutofillClient* autofill_client) { | 96 autofill::AutofillClient* autofill_client) { |
| 66 if (FromWebContents(contents)) | 97 if (FromWebContents(contents)) |
| 67 return; | 98 return; |
| 68 | 99 |
| 69 contents->SetUserData( | 100 contents->SetUserData( |
| 70 UserDataKey(), | 101 UserDataKey(), |
| 71 new ChromePasswordManagerClient(contents, autofill_client)); | 102 new ChromePasswordManagerClient(contents, autofill_client)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 86 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 117 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
| 87 autofill_client); | 118 autofill_client); |
| 88 driver_factory_ = | 119 driver_factory_ = |
| 89 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 120 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
| 90 | 121 |
| 91 PasswordManagerInternalsService* service = | 122 PasswordManagerInternalsService* service = |
| 92 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 123 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 93 if (service) | 124 if (service) |
| 94 can_use_log_router_ = service->RegisterClient(this); | 125 can_use_log_router_ = service->RegisterClient(this); |
| 95 SetUpAutofillSyncState(); | 126 SetUpAutofillSyncState(); |
| 127 saving_passwords_enabled_.Init( |
| 128 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); |
| 129 ReportMetrics(*saving_passwords_enabled_, this); |
| 96 } | 130 } |
| 97 | 131 |
| 98 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 132 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
| 99 PasswordManagerInternalsService* service = | 133 PasswordManagerInternalsService* service = |
| 100 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 134 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 101 if (service) | 135 if (service) |
| 102 service->UnregisterClient(this); | 136 service->UnregisterClient(this); |
| 103 } | 137 } |
| 104 | 138 |
| 105 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 139 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
| 106 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 140 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 107 password_manager::switches::kEnableAutomaticPasswordSaving) && | 141 password_manager::switches::kEnableAutomaticPasswordSaving) && |
| 108 chrome::VersionInfo::GetChannel() == | 142 chrome::VersionInfo::GetChannel() == |
| 109 chrome::VersionInfo::CHANNEL_UNKNOWN; | 143 chrome::VersionInfo::CHANNEL_UNKNOWN; |
| 110 } | 144 } |
| 111 | 145 |
| 112 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() | 146 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() |
| 113 const { | 147 const { |
| 114 DCHECK(web_contents()); | 148 DCHECK(web_contents()); |
| 115 content::NavigationEntry* entry = | 149 content::NavigationEntry* entry = |
| 116 web_contents()->GetController().GetLastCommittedEntry(); | 150 web_contents()->GetController().GetLastCommittedEntry(); |
| 151 bool is_enabled = false; |
| 117 if (!entry) { | 152 if (!entry) { |
| 118 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 153 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
| 119 return true; | 154 is_enabled = true; |
| 155 } else if (IsURLPasswordWebsiteReauth(entry->GetURL())) { |
| 156 // Disable the password manager for online password management. |
| 157 is_enabled = false; |
| 158 } else if (EnabledForSyncSignin()) { |
| 159 is_enabled = true; |
| 160 } else { |
| 161 // Do not fill nor save password when a user is signing in for sync. This |
| 162 // is because users need to remember their password if they are syncing as |
| 163 // this is effectively their master password. |
| 164 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
| 120 } | 165 } |
| 166 if (IsLoggingActive()) { |
| 167 password_manager::BrowserSavePasswordProgressLogger logger(this); |
| 168 logger.LogBoolean( |
| 169 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, |
| 170 is_enabled); |
| 171 } |
| 172 return is_enabled; |
| 173 } |
| 121 | 174 |
| 122 // Disable the password manager for online password management. | 175 bool ChromePasswordManagerClient::IsSavingEnabledForCurrentPage() const { |
| 123 if (IsURLPasswordWebsiteReauth(entry->GetURL())) | 176 return *saving_passwords_enabled_ && !IsOffTheRecord() && |
| 124 return false; | 177 !DidLastPageLoadEncounterSSLErrors() && |
| 125 | 178 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 } | 179 } |
| 134 | 180 |
| 135 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( | 181 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( |
| 136 const autofill::PasswordForm& form) { | 182 const autofill::PasswordForm& form) { |
| 137 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), | 183 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), |
| 138 form.signon_realm)) | 184 form.signon_realm)) |
| 139 return false; | 185 return false; |
| 140 | 186 |
| 141 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) { | 187 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) { |
| 142 sync_credential_was_filtered_ = true; | 188 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); | 368 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
| 323 | 369 |
| 324 if (http_status_code >= 400 && http_status_code < 600) | 370 if (http_status_code >= 400 && http_status_code < 600) |
| 325 return true; | 371 return true; |
| 326 return false; | 372 return false; |
| 327 } | 373 } |
| 328 | 374 |
| 329 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { | 375 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { |
| 330 content::NavigationEntry* entry = | 376 content::NavigationEntry* entry = |
| 331 web_contents()->GetController().GetLastCommittedEntry(); | 377 web_contents()->GetController().GetLastCommittedEntry(); |
| 332 if (!entry) | 378 bool ssl_errors = true; |
| 333 return false; | 379 if (!entry) { |
| 334 | 380 ssl_errors = false; |
| 335 return net::IsCertStatusError(entry->GetSSL().cert_status); | 381 } else { |
| 382 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); |
| 383 } |
| 384 if (IsLoggingActive()) { |
| 385 password_manager::BrowserSavePasswordProgressLogger logger(this); |
| 386 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); |
| 387 } |
| 388 return ssl_errors; |
| 336 } | 389 } |
| 337 | 390 |
| 338 bool ChromePasswordManagerClient::IsOffTheRecord() const { | 391 bool ChromePasswordManagerClient::IsOffTheRecord() const { |
| 339 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 392 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 340 } | 393 } |
| 341 | 394 |
| 342 password_manager::PasswordManager* | 395 password_manager::PasswordManager* |
| 343 ChromePasswordManagerClient::GetPasswordManager() { | 396 ChromePasswordManagerClient::GetPasswordManager() { |
| 344 return &password_manager_; | 397 return &password_manager_; |
| 345 } | 398 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 588 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
| 536 } else { | 589 } else { |
| 537 // Allow by default. | 590 // Allow by default. |
| 538 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 591 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
| 539 } | 592 } |
| 540 } | 593 } |
| 541 | 594 |
| 542 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { | 595 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { |
| 543 return web_contents()->GetVisibleURL(); | 596 return web_contents()->GetVisibleURL(); |
| 544 } | 597 } |
| OLD | NEW |