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