| 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/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 13 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 14 #include "chrome/browser/password_manager/password_manager_util.h" | 14 #include "chrome/browser/password_manager/password_manager_util.h" |
| 15 #include "chrome/browser/password_manager/password_store_factory.h" | 15 #include "chrome/browser/password_manager/password_store_factory.h" |
| 16 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 16 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
| 17 #include "chrome/browser/password_manager/sync_metrics.h" | 17 #include "chrome/browser/password_manager/sync_metrics.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/sync/profile_sync_service.h" | 19 #include "chrome/browser/sync/profile_sync_service.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 21 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" | 21 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" |
| 22 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 22 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
| 25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "components/autofill/content/common/autofill_messages.h" | 26 #include "components/autofill/content/common/autofill_messages.h" |
| 27 #include "components/autofill/core/browser/password_generator.h" | 27 #include "components/autofill/core/browser/password_generator.h" |
| 28 #include "components/autofill/core/common/password_form.h" | 28 #include "components/autofill/core/common/password_form.h" |
| 29 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
| 29 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" | 30 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" |
| 30 #include "components/password_manager/content/common/credential_manager_messages
.h" | 31 #include "components/password_manager/content/common/credential_manager_messages
.h" |
| 31 #include "components/password_manager/content/common/credential_manager_types.h" | 32 #include "components/password_manager/content/common/credential_manager_types.h" |
| 32 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 33 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
| 33 #include "components/password_manager/core/browser/log_receiver.h" | 34 #include "components/password_manager/core/browser/log_receiver.h" |
| 34 #include "components/password_manager/core/browser/password_form_manager.h" | 35 #include "components/password_manager/core/browser/password_form_manager.h" |
| 35 #include "components/password_manager/core/browser/password_manager.h" | |
| 36 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" | 36 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
| 37 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 37 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
| 38 #include "components/password_manager/core/common/password_manager_switches.h" | 38 #include "components/password_manager/core/common/password_manager_switches.h" |
| 39 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
| 40 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
| 41 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 42 #include "google_apis/gaia/gaia_urls.h" | 42 #include "google_apis/gaia/gaia_urls.h" |
| 43 #include "net/base/url_util.h" | 43 #include "net/base/url_util.h" |
| 44 #include "third_party/re2/re2/re2.h" | 44 #include "third_party/re2/re2/re2.h" |
| 45 | 45 |
| 46 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
| 47 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" | 47 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 using password_manager::ContentPasswordManagerDriverFactory; |
| 50 using password_manager::PasswordManagerInternalsService; | 51 using password_manager::PasswordManagerInternalsService; |
| 51 using password_manager::PasswordManagerInternalsServiceFactory; | 52 using password_manager::PasswordManagerInternalsServiceFactory; |
| 52 | 53 |
| 53 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 54 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
| 54 | 55 |
| 55 // Shorten the name to spare line breaks. The code provides enough context | 56 // Shorten the name to spare line breaks. The code provides enough context |
| 56 // already. | 57 // already. |
| 57 typedef autofill::SavePasswordProgressLogger Logger; | 58 typedef autofill::SavePasswordProgressLogger Logger; |
| 58 | 59 |
| 59 // static | 60 // static |
| 60 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( | 61 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( |
| 61 content::WebContents* contents, | 62 content::WebContents* contents, |
| 62 autofill::AutofillClient* autofill_client) { | 63 autofill::AutofillClient* autofill_client) { |
| 63 if (FromWebContents(contents)) | 64 if (FromWebContents(contents)) |
| 64 return; | 65 return; |
| 65 | 66 |
| 66 contents->SetUserData( | 67 contents->SetUserData( |
| 67 UserDataKey(), | 68 UserDataKey(), |
| 68 new ChromePasswordManagerClient(contents, autofill_client)); | 69 new ChromePasswordManagerClient(contents, autofill_client)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 ChromePasswordManagerClient::ChromePasswordManagerClient( | 72 ChromePasswordManagerClient::ChromePasswordManagerClient( |
| 72 content::WebContents* web_contents, | 73 content::WebContents* web_contents, |
| 73 autofill::AutofillClient* autofill_client) | 74 autofill::AutofillClient* autofill_client) |
| 74 : content::WebContentsObserver(web_contents), | 75 : content::WebContentsObserver(web_contents), |
| 75 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 76 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 76 driver_(web_contents, this, autofill_client), | 77 password_manager_(this), |
| 78 driver_factory_(nullptr), |
| 77 credential_manager_dispatcher_(web_contents, this), | 79 credential_manager_dispatcher_(web_contents, this), |
| 78 observer_(NULL), | 80 observer_(nullptr), |
| 79 can_use_log_router_(false), | 81 can_use_log_router_(false), |
| 80 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), | 82 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), |
| 81 sync_credential_was_filtered_(false) { | 83 sync_credential_was_filtered_(false) { |
| 84 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
| 85 autofill_client); |
| 86 driver_factory_ = |
| 87 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
| 88 |
| 82 PasswordManagerInternalsService* service = | 89 PasswordManagerInternalsService* service = |
| 83 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 90 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 84 if (service) | 91 if (service) |
| 85 can_use_log_router_ = service->RegisterClient(this); | 92 can_use_log_router_ = service->RegisterClient(this); |
| 86 SetUpAutofillSyncState(); | 93 SetUpAutofillSyncState(); |
| 87 } | 94 } |
| 88 | 95 |
| 89 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 96 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
| 90 PasswordManagerInternalsService* service = | 97 PasswordManagerInternalsService* service = |
| 91 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 98 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 243 |
| 237 password_manager::PasswordStore* | 244 password_manager::PasswordStore* |
| 238 ChromePasswordManagerClient::GetPasswordStore() { | 245 ChromePasswordManagerClient::GetPasswordStore() { |
| 239 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord | 246 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord |
| 240 // itself when it shouldn't access the PasswordStore. | 247 // itself when it shouldn't access the PasswordStore. |
| 241 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? | 248 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? |
| 242 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) | 249 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) |
| 243 .get(); | 250 .get(); |
| 244 } | 251 } |
| 245 | 252 |
| 246 password_manager::PasswordManagerDriver* | |
| 247 ChromePasswordManagerClient::GetDriver() { | |
| 248 return &driver_; | |
| 249 } | |
| 250 | |
| 251 base::FieldTrial::Probability | 253 base::FieldTrial::Probability |
| 252 ChromePasswordManagerClient::GetProbabilityForExperiment( | 254 ChromePasswordManagerClient::GetProbabilityForExperiment( |
| 253 const std::string& experiment_name) { | 255 const std::string& experiment_name) { |
| 254 base::FieldTrial::Probability enabled_probability = 0; | 256 base::FieldTrial::Probability enabled_probability = 0; |
| 255 if (experiment_name == | 257 if (experiment_name == |
| 256 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { | 258 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { |
| 257 switch (chrome::VersionInfo::GetChannel()) { | 259 switch (chrome::VersionInfo::GetChannel()) { |
| 258 case chrome::VersionInfo::CHANNEL_DEV: | 260 case chrome::VersionInfo::CHANNEL_DEV: |
| 259 case chrome::VersionInfo::CHANNEL_BETA: | 261 case chrome::VersionInfo::CHANNEL_BETA: |
| 260 enabled_probability = 50; | 262 enabled_probability = 50; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 int http_status_code = entry->GetHttpStatusCode(); | 326 int http_status_code = entry->GetHttpStatusCode(); |
| 325 | 327 |
| 326 if (logger) | 328 if (logger) |
| 327 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); | 329 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
| 328 | 330 |
| 329 if (http_status_code >= 400 && http_status_code < 600) | 331 if (http_status_code >= 400 && http_status_code < 600) |
| 330 return true; | 332 return true; |
| 331 return false; | 333 return false; |
| 332 } | 334 } |
| 333 | 335 |
| 334 // static | 336 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() { |
| 335 password_manager::PasswordGenerationManager* | 337 content::NavigationEntry* entry = |
| 336 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | 338 web_contents()->GetController().GetLastCommittedEntry(); |
| 337 content::WebContents* contents) { | 339 if (!entry) |
| 338 ChromePasswordManagerClient* client = | 340 return false; |
| 339 ChromePasswordManagerClient::FromWebContents(contents); | 341 |
| 340 if (!client) | 342 return net::IsCertStatusError(entry->GetSSL().cert_status); |
| 341 return NULL; | |
| 342 return client->GetDriver()->GetPasswordGenerationManager(); | |
| 343 } | 343 } |
| 344 | 344 |
| 345 // static | 345 bool ChromePasswordManagerClient::IsOffTheRecord() { |
| 346 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 347 } |
| 348 |
| 346 password_manager::PasswordManager* | 349 password_manager::PasswordManager* |
| 347 ChromePasswordManagerClient::GetManagerFromWebContents( | 350 ChromePasswordManagerClient::GetPasswordManager() { |
| 348 content::WebContents* contents) { | 351 return &password_manager_; |
| 349 ChromePasswordManagerClient* client = | |
| 350 ChromePasswordManagerClient::FromWebContents(contents); | |
| 351 if (!client) | |
| 352 return NULL; | |
| 353 return client->GetDriver()->GetPasswordManager(); | |
| 354 } | 352 } |
| 355 | 353 |
| 356 void ChromePasswordManagerClient::SetTestObserver( | 354 void ChromePasswordManagerClient::SetTestObserver( |
| 357 autofill::PasswordGenerationPopupObserver* observer) { | 355 autofill::PasswordGenerationPopupObserver* observer) { |
| 358 observer_ = observer; | 356 observer_ = observer; |
| 359 } | 357 } |
| 360 | 358 |
| 361 bool ChromePasswordManagerClient::OnMessageReceived( | 359 bool ChromePasswordManagerClient::OnMessageReceived( |
| 362 const IPC::Message& message) { | 360 const IPC::Message& message, |
| 361 content::RenderFrameHost* render_frame_host) { |
| 363 bool handled = true; | 362 bool handled = true; |
| 364 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 363 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ChromePasswordManagerClient, message, |
| 364 render_frame_host) |
| 365 // Autofill messages: | 365 // Autofill messages: |
| 366 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | 366 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, |
| 367 ShowPasswordGenerationPopup) | 367 ShowPasswordGenerationPopup) |
| 368 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 368 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
| 369 ShowPasswordEditingPopup) | 369 ShowPasswordEditingPopup) |
| 370 IPC_END_MESSAGE_MAP() |
| 371 |
| 372 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
| 370 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 373 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
| 371 HidePasswordGenerationPopup) | 374 HidePasswordGenerationPopup) |
| 372 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | 375 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, |
| 373 NotifyRendererOfLoggingAvailability) | 376 NotifyRendererOfLoggingAvailability) |
| 374 | |
| 375 // Default: | 377 // Default: |
| 376 IPC_MESSAGE_UNHANDLED(handled = false) | 378 IPC_MESSAGE_UNHANDLED(handled = false) |
| 377 IPC_END_MESSAGE_MAP() | 379 IPC_END_MESSAGE_MAP() |
| 380 |
| 378 return handled; | 381 return handled; |
| 379 } | 382 } |
| 380 | 383 |
| 381 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 384 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
| 382 const gfx::RectF& bounds) { | 385 const gfx::RectF& bounds) { |
| 383 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 386 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
| 384 return bounds + client_area.OffsetFromOrigin(); | 387 return bounds + client_area.OffsetFromOrigin(); |
| 385 } | 388 } |
| 386 | 389 |
| 387 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 390 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
| 391 content::RenderFrameHost* render_frame_host, |
| 388 const gfx::RectF& bounds, | 392 const gfx::RectF& bounds, |
| 389 int max_length, | 393 int max_length, |
| 390 const autofill::PasswordForm& form) { | 394 const autofill::PasswordForm& form) { |
| 391 // TODO(gcasto): Validate data in PasswordForm. | 395 // TODO(gcasto): Validate data in PasswordForm. |
| 392 | 396 |
| 393 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 397 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 394 | 398 |
| 395 popup_controller_ = | 399 popup_controller_ = |
| 396 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 400 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 397 popup_controller_, | 401 popup_controller_, element_bounds_in_screen_space, form, max_length, |
| 398 element_bounds_in_screen_space, | 402 &password_manager_, |
| 399 form, | 403 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
| 400 max_length, | 404 web_contents(), web_contents()->GetNativeView()); |
| 401 driver_.GetPasswordManager(), | |
| 402 observer_, | |
| 403 web_contents(), | |
| 404 web_contents()->GetNativeView()); | |
| 405 popup_controller_->Show(true /* display_password */); | 405 popup_controller_->Show(true /* display_password */); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 408 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
| 409 content::RenderFrameHost* render_frame_host, |
| 409 const gfx::RectF& bounds, | 410 const gfx::RectF& bounds, |
| 410 const autofill::PasswordForm& form) { | 411 const autofill::PasswordForm& form) { |
| 411 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 412 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 412 popup_controller_ = | 413 popup_controller_ = |
| 413 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 414 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 414 popup_controller_, | 415 popup_controller_, element_bounds_in_screen_space, form, |
| 415 element_bounds_in_screen_space, | |
| 416 form, | |
| 417 0, // Unspecified max length. | 416 0, // Unspecified max length. |
| 418 driver_.GetPasswordManager(), | 417 &password_manager_, |
| 419 observer_, | 418 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
| 420 web_contents(), | 419 web_contents(), web_contents()->GetNativeView()); |
| 421 web_contents()->GetNativeView()); | |
| 422 popup_controller_->Show(false /* display_password */); | 420 popup_controller_->Show(false /* display_password */); |
| 423 } | 421 } |
| 424 | 422 |
| 425 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 423 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
| 426 if (!web_contents()) | 424 if (!web_contents()) |
| 427 return; | 425 return; |
| 428 | 426 |
| 429 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 427 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
| 430 web_contents()->GetRenderViewHost()->GetRoutingID(), | 428 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 431 can_use_log_router_)); | 429 can_use_log_router_)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 528 |
| 531 if (group_name == "DisallowSyncCredentialsForReauth") { | 529 if (group_name == "DisallowSyncCredentialsForReauth") { |
| 532 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | 530 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
| 533 } else if (group_name == "DisallowSyncCredentials") { | 531 } else if (group_name == "DisallowSyncCredentials") { |
| 534 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 532 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
| 535 } else { | 533 } else { |
| 536 // Allow by default. | 534 // Allow by default. |
| 537 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 535 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
| 538 } | 536 } |
| 539 } | 537 } |
| OLD | NEW |