| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 231 |
| 225 password_manager::PasswordStore* | 232 password_manager::PasswordStore* |
| 226 ChromePasswordManagerClient::GetPasswordStore() { | 233 ChromePasswordManagerClient::GetPasswordStore() { |
| 227 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord | 234 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord |
| 228 // itself when it shouldn't access the PasswordStore. | 235 // itself when it shouldn't access the PasswordStore. |
| 229 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? | 236 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? |
| 230 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) | 237 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) |
| 231 .get(); | 238 .get(); |
| 232 } | 239 } |
| 233 | 240 |
| 234 password_manager::PasswordManagerDriver* | |
| 235 ChromePasswordManagerClient::GetDriver() { | |
| 236 return &driver_; | |
| 237 } | |
| 238 | |
| 239 base::FieldTrial::Probability | 241 base::FieldTrial::Probability |
| 240 ChromePasswordManagerClient::GetProbabilityForExperiment( | 242 ChromePasswordManagerClient::GetProbabilityForExperiment( |
| 241 const std::string& experiment_name) { | 243 const std::string& experiment_name) { |
| 242 base::FieldTrial::Probability enabled_probability = 0; | 244 base::FieldTrial::Probability enabled_probability = 0; |
| 243 if (experiment_name == | 245 if (experiment_name == |
| 244 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { | 246 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { |
| 245 switch (chrome::VersionInfo::GetChannel()) { | 247 switch (chrome::VersionInfo::GetChannel()) { |
| 246 case chrome::VersionInfo::CHANNEL_DEV: | 248 case chrome::VersionInfo::CHANNEL_DEV: |
| 247 case chrome::VersionInfo::CHANNEL_BETA: | 249 case chrome::VersionInfo::CHANNEL_BETA: |
| 248 enabled_probability = 50; | 250 enabled_probability = 50; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 int http_status_code = entry->GetHttpStatusCode(); | 314 int http_status_code = entry->GetHttpStatusCode(); |
| 313 | 315 |
| 314 if (logger) | 316 if (logger) |
| 315 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); | 317 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
| 316 | 318 |
| 317 if (http_status_code >= 400 && http_status_code < 600) | 319 if (http_status_code >= 400 && http_status_code < 600) |
| 318 return true; | 320 return true; |
| 319 return false; | 321 return false; |
| 320 } | 322 } |
| 321 | 323 |
| 322 // static | 324 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() { |
| 323 password_manager::PasswordGenerationManager* | 325 content::NavigationEntry* entry = |
| 324 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | 326 web_contents()->GetController().GetLastCommittedEntry(); |
| 325 content::WebContents* contents) { | 327 if (!entry) |
| 326 ChromePasswordManagerClient* client = | 328 return false; |
| 327 ChromePasswordManagerClient::FromWebContents(contents); | 329 |
| 328 if (!client) | 330 return net::IsCertStatusError(entry->GetSSL().cert_status); |
| 329 return NULL; | |
| 330 return client->GetDriver()->GetPasswordGenerationManager(); | |
| 331 } | 331 } |
| 332 | 332 |
| 333 // static | 333 bool ChromePasswordManagerClient::IsOffTheRecord() { |
| 334 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 335 } |
| 336 |
| 334 password_manager::PasswordManager* | 337 password_manager::PasswordManager* |
| 335 ChromePasswordManagerClient::GetManagerFromWebContents( | 338 ChromePasswordManagerClient::GetPasswordManager() { |
| 336 content::WebContents* contents) { | 339 return &password_manager_; |
| 337 ChromePasswordManagerClient* client = | |
| 338 ChromePasswordManagerClient::FromWebContents(contents); | |
| 339 if (!client) | |
| 340 return NULL; | |
| 341 return client->GetDriver()->GetPasswordManager(); | |
| 342 } | 340 } |
| 343 | 341 |
| 344 void ChromePasswordManagerClient::SetTestObserver( | 342 void ChromePasswordManagerClient::SetTestObserver( |
| 345 autofill::PasswordGenerationPopupObserver* observer) { | 343 autofill::PasswordGenerationPopupObserver* observer) { |
| 346 observer_ = observer; | 344 observer_ = observer; |
| 347 } | 345 } |
| 348 | 346 |
| 349 bool ChromePasswordManagerClient::OnMessageReceived( | 347 bool ChromePasswordManagerClient::OnMessageReceived( |
| 350 const IPC::Message& message) { | 348 const IPC::Message& message, |
| 349 content::RenderFrameHost* render_frame_host) { |
| 351 bool handled = true; | 350 bool handled = true; |
| 352 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 351 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ChromePasswordManagerClient, message, |
| 352 render_frame_host) |
| 353 // Autofill messages: | 353 // Autofill messages: |
| 354 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | 354 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, |
| 355 ShowPasswordGenerationPopup) | 355 ShowPasswordGenerationPopup) |
| 356 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 356 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
| 357 ShowPasswordEditingPopup) | 357 ShowPasswordEditingPopup) |
| 358 IPC_END_MESSAGE_MAP() |
| 359 |
| 360 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
| 358 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 361 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
| 359 HidePasswordGenerationPopup) | 362 HidePasswordGenerationPopup) |
| 360 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | 363 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, |
| 361 NotifyRendererOfLoggingAvailability) | 364 NotifyRendererOfLoggingAvailability) |
| 362 | |
| 363 // Default: | 365 // Default: |
| 364 IPC_MESSAGE_UNHANDLED(handled = false) | 366 IPC_MESSAGE_UNHANDLED(handled = false) |
| 365 IPC_END_MESSAGE_MAP() | 367 IPC_END_MESSAGE_MAP() |
| 368 |
| 366 return handled; | 369 return handled; |
| 367 } | 370 } |
| 368 | 371 |
| 369 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 372 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
| 370 const gfx::RectF& bounds) { | 373 const gfx::RectF& bounds) { |
| 371 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 374 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
| 372 return bounds + client_area.OffsetFromOrigin(); | 375 return bounds + client_area.OffsetFromOrigin(); |
| 373 } | 376 } |
| 374 | 377 |
| 375 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 378 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
| 379 content::RenderFrameHost* render_frame_host, |
| 376 const gfx::RectF& bounds, | 380 const gfx::RectF& bounds, |
| 377 int max_length, | 381 int max_length, |
| 378 const autofill::PasswordForm& form) { | 382 const autofill::PasswordForm& form) { |
| 379 // TODO(gcasto): Validate data in PasswordForm. | 383 // TODO(gcasto): Validate data in PasswordForm. |
| 380 | 384 |
| 381 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 385 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 382 | 386 |
| 383 popup_controller_ = | 387 popup_controller_ = |
| 384 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 388 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 385 popup_controller_, | 389 popup_controller_, element_bounds_in_screen_space, form, max_length, |
| 386 element_bounds_in_screen_space, | 390 &password_manager_, |
| 387 form, | 391 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
| 388 max_length, | 392 web_contents(), web_contents()->GetNativeView()); |
| 389 driver_.GetPasswordManager(), | |
| 390 observer_, | |
| 391 web_contents(), | |
| 392 web_contents()->GetNativeView()); | |
| 393 popup_controller_->Show(true /* display_password */); | 393 popup_controller_->Show(true /* display_password */); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 396 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
| 397 content::RenderFrameHost* render_frame_host, |
| 397 const gfx::RectF& bounds, | 398 const gfx::RectF& bounds, |
| 398 const autofill::PasswordForm& form) { | 399 const autofill::PasswordForm& form) { |
| 399 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 400 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 400 popup_controller_ = | 401 popup_controller_ = |
| 401 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 402 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 402 popup_controller_, | 403 popup_controller_, element_bounds_in_screen_space, form, |
| 403 element_bounds_in_screen_space, | |
| 404 form, | |
| 405 0, // Unspecified max length. | 404 0, // Unspecified max length. |
| 406 driver_.GetPasswordManager(), | 405 &password_manager_, |
| 407 observer_, | 406 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
| 408 web_contents(), | 407 web_contents(), web_contents()->GetNativeView()); |
| 409 web_contents()->GetNativeView()); | |
| 410 popup_controller_->Show(false /* display_password */); | 408 popup_controller_->Show(false /* display_password */); |
| 411 } | 409 } |
| 412 | 410 |
| 413 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 411 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
| 414 if (!web_contents()) | 412 if (!web_contents()) |
| 415 return; | 413 return; |
| 416 | 414 |
| 417 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 415 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
| 418 web_contents()->GetRenderViewHost()->GetRoutingID(), | 416 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 419 can_use_log_router_)); | 417 can_use_log_router_)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 516 |
| 519 if (group_name == "DisallowSyncCredentialsForReauth") { | 517 if (group_name == "DisallowSyncCredentialsForReauth") { |
| 520 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | 518 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
| 521 } else if (group_name == "DisallowSyncCredentials") { | 519 } else if (group_name == "DisallowSyncCredentials") { |
| 522 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 520 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
| 523 } else { | 521 } else { |
| 524 // Allow by default. | 522 // Allow by default. |
| 525 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 523 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
| 526 } | 524 } |
| 527 } | 525 } |
| OLD | NEW |