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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 #endif | 57 #endif |
| 58 | 58 |
| 59 #if defined(OS_ANDROID) | 59 #if defined(OS_ANDROID) |
| 60 #include "chrome/browser/android/tab_android.h" | 60 #include "chrome/browser/android/tab_android.h" |
| 61 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg ate_android.h" | 61 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg ate_android.h" |
| 62 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" | 62 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" |
| 63 #endif | 63 #endif |
| 64 | 64 |
| 65 using password_manager::ContentPasswordManagerDriverFactory; | 65 using password_manager::ContentPasswordManagerDriverFactory; |
| 66 using password_manager::PasswordManagerInternalsService; | 66 using password_manager::PasswordManagerInternalsService; |
| 67 using password_manager::PasswordManagerInternalsServiceFactory; | |
| 68 | 67 |
| 69 // Shorten the name to spare line breaks. The code provides enough context | 68 // Shorten the name to spare line breaks. The code provides enough context |
| 70 // already. | 69 // already. |
| 71 typedef autofill::SavePasswordProgressLogger Logger; | 70 typedef autofill::SavePasswordProgressLogger Logger; |
| 72 | 71 |
| 73 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 72 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
| 74 | 73 |
| 75 namespace { | 74 namespace { |
| 76 | 75 |
| 77 const sync_driver::SyncService* GetSyncService(Profile* profile) { | 76 const sync_driver::SyncService* GetSyncService(Profile* profile) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 128 |
| 130 ChromePasswordManagerClient::ChromePasswordManagerClient( | 129 ChromePasswordManagerClient::ChromePasswordManagerClient( |
| 131 content::WebContents* web_contents, | 130 content::WebContents* web_contents, |
| 132 autofill::AutofillClient* autofill_client) | 131 autofill::AutofillClient* autofill_client) |
| 133 : content::WebContentsObserver(web_contents), | 132 : content::WebContentsObserver(web_contents), |
| 134 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 133 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 135 password_manager_(this), | 134 password_manager_(this), |
| 136 driver_factory_(nullptr), | 135 driver_factory_(nullptr), |
| 137 credential_manager_dispatcher_(web_contents, this), | 136 credential_manager_dispatcher_(web_contents, this), |
| 138 observer_(nullptr), | 137 observer_(nullptr), |
| 139 can_use_log_router_(false), | |
| 140 credentials_filter_(this, | 138 credentials_filter_(this, |
| 141 base::Bind(&GetSyncService, profile_), | 139 base::Bind(&GetSyncService, profile_), |
| 142 base::Bind(&GetSigninManager, profile_)) { | 140 base::Bind(&GetSigninManager, profile_)) { |
| 143 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 141 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
| 144 autofill_client); | 142 autofill_client); |
| 145 driver_factory_ = | 143 driver_factory_ = |
| 146 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 144 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
| 147 | 145 |
| 148 PasswordManagerInternalsService* service = | |
| 149 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | |
| 150 if (service) | |
| 151 can_use_log_router_ = service->RegisterClient(this); | |
| 152 saving_and_filling_passwords_enabled_.Init( | 146 saving_and_filling_passwords_enabled_.Init( |
| 153 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); | 147 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); |
| 154 ReportMetrics(*saving_and_filling_passwords_enabled_, this, profile_); | 148 ReportMetrics(*saving_and_filling_passwords_enabled_, this, profile_); |
| 149 NotifyDriversAboutLoggingAvailability(password_manager_.IsLoggingActive()); | |
| 155 } | 150 } |
| 156 | 151 |
| 157 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 152 ChromePasswordManagerClient::~ChromePasswordManagerClient() {} |
| 158 PasswordManagerInternalsService* service = | |
| 159 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | |
| 160 if (service) | |
| 161 service->UnregisterClient(this); | |
|
vasilii
2015/11/12 16:27:34
How is it related to the changes?
vabr (Chromium)
2015/11/12 21:55:43
The client no longer registers with the service=Lo
| |
| 162 } | |
| 163 | 153 |
| 164 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 154 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
| 165 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 155 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 166 password_manager::switches::kEnableAutomaticPasswordSaving) && | 156 password_manager::switches::kEnableAutomaticPasswordSaving) && |
| 167 chrome::GetChannel() == version_info::Channel::UNKNOWN; | 157 chrome::GetChannel() == version_info::Channel::UNKNOWN; |
| 168 } | 158 } |
| 169 | 159 |
| 170 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() | 160 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() |
| 171 const { | 161 const { |
| 172 DCHECK(web_contents()); | 162 DCHECK(web_contents()); |
| 173 content::NavigationEntry* entry = | 163 content::NavigationEntry* entry = |
| 174 web_contents()->GetController().GetLastCommittedEntry(); | 164 web_contents()->GetController().GetLastCommittedEntry(); |
| 175 bool is_enabled = false; | 165 bool is_enabled = false; |
| 176 if (!entry) { | 166 if (!entry) { |
| 177 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 167 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
| 178 is_enabled = true; | 168 is_enabled = true; |
| 179 } else if (EnabledForSyncSignin()) { | 169 } else if (EnabledForSyncSignin()) { |
| 180 is_enabled = true; | 170 is_enabled = true; |
| 181 } else { | 171 } else { |
| 182 // Do not fill nor save password when a user is signing in for sync. This | 172 // Do not fill nor save password when a user is signing in for sync. This |
| 183 // is because users need to remember their password if they are syncing as | 173 // is because users need to remember their password if they are syncing as |
| 184 // this is effectively their master password. | 174 // this is effectively their master password. |
| 185 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | 175 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
| 186 } | 176 } |
| 187 if (IsLoggingActive()) { | 177 if (password_manager_.IsLoggingActive()) { |
| 188 password_manager::BrowserSavePasswordProgressLogger logger(this); | 178 password_manager::BrowserSavePasswordProgressLogger logger( |
| 179 GetPasswordManager()); | |
| 189 logger.LogBoolean( | 180 logger.LogBoolean( |
| 190 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, | 181 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, |
| 191 is_enabled); | 182 is_enabled); |
| 192 } | 183 } |
| 193 return is_enabled; | 184 return is_enabled; |
| 194 } | 185 } |
| 195 | 186 |
| 196 bool ChromePasswordManagerClient::IsSavingAndFillingEnabledForCurrentPage() | 187 bool ChromePasswordManagerClient::IsSavingAndFillingEnabledForCurrentPage() |
| 197 const { | 188 const { |
| 198 // TODO(melandory): remove saving_and_filling_passwords_enabled_ check from | 189 // TODO(melandory): remove saving_and_filling_passwords_enabled_ check from |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); | 306 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 316 } | 307 } |
| 317 | 308 |
| 318 password_manager::PasswordSyncState | 309 password_manager::PasswordSyncState |
| 319 ChromePasswordManagerClient::GetPasswordSyncState() const { | 310 ChromePasswordManagerClient::GetPasswordSyncState() const { |
| 320 const ProfileSyncService* sync_service = | 311 const ProfileSyncService* sync_service = |
| 321 ProfileSyncServiceFactory::GetForProfile(profile_); | 312 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 322 return password_manager_util::GetPasswordSyncState(sync_service); | 313 return password_manager_util::GetPasswordSyncState(sync_service); |
| 323 } | 314 } |
| 324 | 315 |
| 325 void ChromePasswordManagerClient::OnLogRouterAvailabilityChanged( | |
| 326 bool router_can_be_used) { | |
| 327 if (can_use_log_router_ == router_can_be_used) | |
| 328 return; | |
| 329 can_use_log_router_ = router_can_be_used; | |
| 330 | |
| 331 NotifyRendererOfLoggingAvailability(); | |
| 332 } | |
| 333 | |
| 334 void ChromePasswordManagerClient::LogSavePasswordProgress( | |
| 335 const std::string& text) const { | |
| 336 if (!IsLoggingActive()) | |
| 337 return; | |
| 338 PasswordManagerInternalsService* service = | |
| 339 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | |
| 340 if (service) | |
| 341 service->ProcessLog(text); | |
| 342 } | |
| 343 | |
| 344 bool ChromePasswordManagerClient::IsLoggingActive() const { | |
| 345 // WebUI tabs do not need to log password saving progress. In particular, the | |
| 346 // internals page itself should not send any logs. | |
| 347 return can_use_log_router_ && !web_contents()->GetWebUI(); | |
| 348 } | |
| 349 | |
| 350 bool ChromePasswordManagerClient::WasLastNavigationHTTPError() const { | 316 bool ChromePasswordManagerClient::WasLastNavigationHTTPError() const { |
| 351 DCHECK(web_contents()); | 317 DCHECK(web_contents()); |
| 352 | 318 |
| 353 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; | 319 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; |
| 354 if (IsLoggingActive()) { | 320 if (password_manager_.IsLoggingActive()) { |
| 355 logger.reset(new password_manager::BrowserSavePasswordProgressLogger(this)); | 321 logger.reset(new password_manager::BrowserSavePasswordProgressLogger( |
| 322 GetPasswordManager())); | |
| 356 logger->LogMessage( | 323 logger->LogMessage( |
| 357 Logger::STRING_WAS_LAST_NAVIGATION_HTTP_ERROR_METHOD); | 324 Logger::STRING_WAS_LAST_NAVIGATION_HTTP_ERROR_METHOD); |
| 358 } | 325 } |
| 359 | 326 |
| 360 content::NavigationEntry* entry = | 327 content::NavigationEntry* entry = |
| 361 web_contents()->GetController().GetVisibleEntry(); | 328 web_contents()->GetController().GetVisibleEntry(); |
| 362 if (!entry) | 329 if (!entry) |
| 363 return false; | 330 return false; |
| 364 int http_status_code = entry->GetHttpStatusCode(); | 331 int http_status_code = entry->GetHttpStatusCode(); |
| 365 | 332 |
| 366 if (logger) | 333 if (logger) |
| 367 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); | 334 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
| 368 | 335 |
| 369 if (http_status_code >= 400 && http_status_code < 600) | 336 if (http_status_code >= 400 && http_status_code < 600) |
| 370 return true; | 337 return true; |
| 371 return false; | 338 return false; |
| 372 } | 339 } |
| 373 | 340 |
| 374 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { | 341 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { |
| 375 content::NavigationEntry* entry = | 342 content::NavigationEntry* entry = |
| 376 web_contents()->GetController().GetLastCommittedEntry(); | 343 web_contents()->GetController().GetLastCommittedEntry(); |
| 377 bool ssl_errors = true; | 344 bool ssl_errors = true; |
| 378 if (!entry) { | 345 if (!entry) { |
| 379 ssl_errors = false; | 346 ssl_errors = false; |
| 380 } else { | 347 } else { |
| 381 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); | 348 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); |
| 382 } | 349 } |
| 383 if (IsLoggingActive()) { | 350 if (password_manager_.IsLoggingActive()) { |
| 384 password_manager::BrowserSavePasswordProgressLogger logger(this); | 351 password_manager::BrowserSavePasswordProgressLogger logger( |
| 352 GetPasswordManager()); | |
| 385 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); | 353 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); |
| 386 } | 354 } |
| 387 return ssl_errors; | 355 return ssl_errors; |
| 388 } | 356 } |
| 389 | 357 |
| 390 bool ChromePasswordManagerClient::IsOffTheRecord() const { | 358 bool ChromePasswordManagerClient::IsOffTheRecord() const { |
| 391 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 359 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 392 } | 360 } |
| 393 | 361 |
| 394 const password_manager::PasswordManager* | 362 const password_manager::PasswordManager* |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 422 ShowPasswordGenerationPopup) | 390 ShowPasswordGenerationPopup) |
| 423 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 391 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
| 424 ShowPasswordEditingPopup) | 392 ShowPasswordEditingPopup) |
| 425 IPC_END_MESSAGE_MAP() | 393 IPC_END_MESSAGE_MAP() |
| 426 | 394 |
| 427 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 395 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
| 428 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 396 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
| 429 HidePasswordGenerationPopup) | 397 HidePasswordGenerationPopup) |
| 430 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, | 398 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, |
| 431 GenerationAvailableForForm) | 399 GenerationAvailableForForm) |
| 432 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | |
| 433 NotifyRendererOfLoggingAvailability) | |
| 434 // Default: | 400 // Default: |
| 435 IPC_MESSAGE_UNHANDLED(handled = false) | 401 IPC_MESSAGE_UNHANDLED(handled = false) |
| 436 IPC_END_MESSAGE_MAP() | 402 IPC_END_MESSAGE_MAP() |
| 437 | 403 |
| 438 return handled; | 404 return handled; |
| 439 } | 405 } |
| 440 | 406 |
| 441 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 407 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
| 442 const gfx::RectF& bounds) { | 408 const gfx::RectF& bounds) { |
| 443 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 409 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 driver_factory_->GetDriverForFrame(render_frame_host), observer_, | 441 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
| 476 web_contents(), web_contents()->GetNativeView()); | 442 web_contents(), web_contents()->GetNativeView()); |
| 477 popup_controller_->Show(false /* display_password */); | 443 popup_controller_->Show(false /* display_password */); |
| 478 } | 444 } |
| 479 | 445 |
| 480 void ChromePasswordManagerClient::GenerationAvailableForForm( | 446 void ChromePasswordManagerClient::GenerationAvailableForForm( |
| 481 const autofill::PasswordForm& form) { | 447 const autofill::PasswordForm& form) { |
| 482 password_manager_.GenerationAvailableForForm(form); | 448 password_manager_.GenerationAvailableForForm(form); |
| 483 } | 449 } |
| 484 | 450 |
| 485 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | |
| 486 if (!web_contents()) | |
| 487 return; | |
| 488 | |
| 489 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | |
| 490 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
| 491 can_use_log_router_)); | |
| 492 } | |
| 493 | |
| 494 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { | 451 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
| 495 #if defined(OS_ANDROID) | 452 #if defined(OS_ANDROID) |
| 496 return false; | 453 return false; |
| 497 #elif defined(OS_MACOSX) | 454 #elif defined(OS_MACOSX) |
| 498 // Query the group first for correct UMA reporting. | 455 // Query the group first for correct UMA reporting. |
| 499 std::string group_name = | 456 std::string group_name = |
| 500 base::FieldTrialList::FindFullName("PasswordManagerUI"); | 457 base::FieldTrialList::FindFullName("PasswordManagerUI"); |
| 501 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 458 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 502 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | 459 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) |
| 503 return false; | 460 return false; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 if (!entry) | 505 if (!entry) |
| 549 return GURL::EmptyGURL(); | 506 return GURL::EmptyGURL(); |
| 550 | 507 |
| 551 return entry->GetURL(); | 508 return entry->GetURL(); |
| 552 } | 509 } |
| 553 | 510 |
| 554 const password_manager::CredentialsFilter* | 511 const password_manager::CredentialsFilter* |
| 555 ChromePasswordManagerClient::GetStoreResultFilter() const { | 512 ChromePasswordManagerClient::GetStoreResultFilter() const { |
| 556 return &credentials_filter_; | 513 return &credentials_filter_; |
| 557 } | 514 } |
| 515 | |
| 516 password_manager::LogRouter* ChromePasswordManagerClient::GetLogRouter() const { | |
| 517 if (web_contents()->GetWebUI()) | |
| 518 return nullptr; | |
| 519 return password_manager::PasswordManagerInternalsServiceFactory:: | |
| 520 GetForBrowserContext(profile_); | |
| 521 } | |
| 522 | |
| 523 void ChromePasswordManagerClient::NotifyDriversAboutLoggingAvailability( | |
| 524 bool is_available) { | |
| 525 driver_factory_->NotifyDriversAboutLoggingAvailability(is_available); | |
| 526 } | |
| OLD | NEW |