| 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/log_receiver.h" | 33 #include "components/password_manager/core/browser/log_receiver.h" |
| 33 #include "components/password_manager/core/browser/password_form_manager.h" | 34 #include "components/password_manager/core/browser/password_form_manager.h" |
| 34 #include "components/password_manager/core/browser/password_manager.h" | |
| 35 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" | 35 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
| 36 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 36 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
| 37 #include "components/password_manager/core/common/password_manager_switches.h" | 37 #include "components/password_manager/core/common/password_manager_switches.h" |
| 38 #include "content/public/browser/navigation_entry.h" | 38 #include "content/public/browser/navigation_entry.h" |
| 39 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "google_apis/gaia/gaia_urls.h" | 41 #include "google_apis/gaia/gaia_urls.h" |
| 42 #include "net/base/url_util.h" | 42 #include "net/base/url_util.h" |
| 43 #include "third_party/re2/re2/re2.h" | 43 #include "third_party/re2/re2/re2.h" |
| 44 | 44 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 61 contents->SetUserData( | 61 contents->SetUserData( |
| 62 UserDataKey(), | 62 UserDataKey(), |
| 63 new ChromePasswordManagerClient(contents, autofill_client)); | 63 new ChromePasswordManagerClient(contents, autofill_client)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 ChromePasswordManagerClient::ChromePasswordManagerClient( | 66 ChromePasswordManagerClient::ChromePasswordManagerClient( |
| 67 content::WebContents* web_contents, | 67 content::WebContents* web_contents, |
| 68 autofill::AutofillClient* autofill_client) | 68 autofill::AutofillClient* autofill_client) |
| 69 : content::WebContentsObserver(web_contents), | 69 : content::WebContentsObserver(web_contents), |
| 70 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 70 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 71 driver_(web_contents, this, autofill_client), | 71 password_manager_(this), |
| 72 driver_factory_(web_contents, this, autofill_client), |
| 72 credential_manager_dispatcher_(web_contents, this), | 73 credential_manager_dispatcher_(web_contents, this), |
| 73 observer_(NULL), | 74 observer_(NULL), |
| 74 can_use_log_router_(false), | 75 can_use_log_router_(false), |
| 75 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), | 76 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), |
| 76 sync_credential_was_filtered_(false) { | 77 sync_credential_was_filtered_(false), |
| 78 render_frame_host_source_(NULL) { |
| 77 PasswordManagerInternalsService* service = | 79 PasswordManagerInternalsService* service = |
| 78 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 80 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 79 if (service) | 81 if (service) |
| 80 can_use_log_router_ = service->RegisterClient(this); | 82 can_use_log_router_ = service->RegisterClient(this); |
| 81 SetUpAutofillSyncState(); | 83 SetUpAutofillSyncState(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 86 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
| 85 PasswordManagerInternalsService* service = | 87 PasswordManagerInternalsService* service = |
| 86 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 88 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 ChromePasswordManagerClient::GetPasswordStore() { | 223 ChromePasswordManagerClient::GetPasswordStore() { |
| 222 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord | 224 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord |
| 223 // itself when it shouldn't access the PasswordStore. | 225 // itself when it shouldn't access the PasswordStore. |
| 224 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? | 226 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? |
| 225 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) | 227 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) |
| 226 .get(); | 228 .get(); |
| 227 } | 229 } |
| 228 | 230 |
| 229 password_manager::PasswordManagerDriver* | 231 password_manager::PasswordManagerDriver* |
| 230 ChromePasswordManagerClient::GetDriver() { | 232 ChromePasswordManagerClient::GetDriver() { |
| 231 return &driver_; | 233 return driver_factory_.GetDriverForFrame(web_contents()->GetMainFrame()); |
| 232 } | 234 } |
| 233 | 235 |
| 234 base::FieldTrial::Probability | 236 base::FieldTrial::Probability |
| 235 ChromePasswordManagerClient::GetProbabilityForExperiment( | 237 ChromePasswordManagerClient::GetProbabilityForExperiment( |
| 236 const std::string& experiment_name) { | 238 const std::string& experiment_name) { |
| 237 base::FieldTrial::Probability enabled_probability = 0; | 239 base::FieldTrial::Probability enabled_probability = 0; |
| 238 if (experiment_name == | 240 if (experiment_name == |
| 239 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { | 241 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { |
| 240 switch (chrome::VersionInfo::GetChannel()) { | 242 switch (chrome::VersionInfo::GetChannel()) { |
| 241 case chrome::VersionInfo::CHANNEL_DEV: | 243 case chrome::VersionInfo::CHANNEL_DEV: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (service) | 285 if (service) |
| 284 service->ProcessLog(text); | 286 service->ProcessLog(text); |
| 285 } | 287 } |
| 286 | 288 |
| 287 bool ChromePasswordManagerClient::IsLoggingActive() const { | 289 bool ChromePasswordManagerClient::IsLoggingActive() const { |
| 288 // WebUI tabs do not need to log password saving progress. In particular, the | 290 // WebUI tabs do not need to log password saving progress. In particular, the |
| 289 // internals page itself should not send any logs. | 291 // internals page itself should not send any logs. |
| 290 return can_use_log_router_ && !web_contents()->GetWebUI(); | 292 return can_use_log_router_ && !web_contents()->GetWebUI(); |
| 291 } | 293 } |
| 292 | 294 |
| 293 // static | 295 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() { |
| 294 password_manager::PasswordGenerationManager* | 296 content::NavigationEntry* entry = |
| 295 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | 297 web_contents()->GetController().GetLastCommittedEntry(); |
| 296 content::WebContents* contents) { | 298 if (!entry) |
| 297 ChromePasswordManagerClient* client = | 299 return false; |
| 298 ChromePasswordManagerClient::FromWebContents(contents); | 300 |
| 299 if (!client) | 301 return net::IsCertStatusError(entry->GetSSL().cert_status); |
| 300 return NULL; | |
| 301 return client->GetDriver()->GetPasswordGenerationManager(); | |
| 302 } | 302 } |
| 303 | 303 |
| 304 // static | 304 bool ChromePasswordManagerClient::IsOffTheRecord() { |
| 305 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 306 } |
| 307 |
| 305 password_manager::PasswordManager* | 308 password_manager::PasswordManager* |
| 306 ChromePasswordManagerClient::GetManagerFromWebContents( | 309 ChromePasswordManagerClient::GetPasswordManager() { |
| 307 content::WebContents* contents) { | 310 return &password_manager_; |
| 308 ChromePasswordManagerClient* client = | |
| 309 ChromePasswordManagerClient::FromWebContents(contents); | |
| 310 if (!client) | |
| 311 return NULL; | |
| 312 return client->GetDriver()->GetPasswordManager(); | |
| 313 } | 311 } |
| 314 | 312 |
| 315 void ChromePasswordManagerClient::SetTestObserver( | 313 void ChromePasswordManagerClient::SetTestObserver( |
| 316 autofill::PasswordGenerationPopupObserver* observer) { | 314 autofill::PasswordGenerationPopupObserver* observer) { |
| 317 observer_ = observer; | 315 observer_ = observer; |
| 318 } | 316 } |
| 319 | 317 |
| 320 bool ChromePasswordManagerClient::OnMessageReceived( | 318 bool ChromePasswordManagerClient::OnMessageReceived( |
| 321 const IPC::Message& message) { | 319 const IPC::Message& message, |
| 320 content::RenderFrameHost* render_frame_host) { |
| 321 render_frame_host_source_ = render_frame_host; |
| 322 |
| 322 bool handled = true; | 323 bool handled = true; |
| 323 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 324 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
| 324 // Autofill messages: | 325 // Autofill messages: |
| 325 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | 326 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, |
| 326 ShowPasswordGenerationPopup) | 327 ShowPasswordGenerationPopup) |
| 327 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 328 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
| 328 ShowPasswordEditingPopup) | 329 ShowPasswordEditingPopup) |
| 329 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 330 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
| 330 HidePasswordGenerationPopup) | 331 HidePasswordGenerationPopup) |
| 331 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | 332 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, |
| 332 NotifyRendererOfLoggingAvailability) | 333 NotifyRendererOfLoggingAvailability) |
| 333 | 334 |
| 334 // Default: | 335 // Default: |
| 335 IPC_MESSAGE_UNHANDLED(handled = false) | 336 IPC_MESSAGE_UNHANDLED(handled = false) |
| 336 IPC_END_MESSAGE_MAP() | 337 IPC_END_MESSAGE_MAP() |
| 338 |
| 339 render_frame_host_source_ = NULL; |
| 337 return handled; | 340 return handled; |
| 338 } | 341 } |
| 339 | 342 |
| 340 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 343 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
| 341 const gfx::RectF& bounds) { | 344 const gfx::RectF& bounds) { |
| 342 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 345 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
| 343 return bounds + client_area.OffsetFromOrigin(); | 346 return bounds + client_area.OffsetFromOrigin(); |
| 344 } | 347 } |
| 345 | 348 |
| 346 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 349 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
| 347 const gfx::RectF& bounds, | 350 const gfx::RectF& bounds, |
| 348 int max_length, | 351 int max_length, |
| 349 const autofill::PasswordForm& form) { | 352 const autofill::PasswordForm& form) { |
| 350 // TODO(gcasto): Validate data in PasswordForm. | 353 // TODO(gcasto): Validate data in PasswordForm. |
| 351 | 354 |
| 352 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 355 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 353 | 356 |
| 354 popup_controller_ = | 357 popup_controller_ = |
| 355 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 358 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 356 popup_controller_, | 359 popup_controller_, element_bounds_in_screen_space, form, max_length, |
| 357 element_bounds_in_screen_space, | 360 &password_manager_, |
| 358 form, | 361 driver_factory_.GetDriverForFrame(render_frame_host_source_), |
| 359 max_length, | 362 observer_, web_contents(), web_contents()->GetNativeView()); |
| 360 driver_.GetPasswordManager(), | |
| 361 observer_, | |
| 362 web_contents(), | |
| 363 web_contents()->GetNativeView()); | |
| 364 popup_controller_->Show(true /* display_password */); | 363 popup_controller_->Show(true /* display_password */); |
| 365 } | 364 } |
| 366 | 365 |
| 367 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 366 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
| 368 const gfx::RectF& bounds, | 367 const gfx::RectF& bounds, |
| 369 const autofill::PasswordForm& form) { | 368 const autofill::PasswordForm& form) { |
| 370 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 369 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 371 popup_controller_ = | 370 popup_controller_ = |
| 372 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 371 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 373 popup_controller_, | 372 popup_controller_, element_bounds_in_screen_space, form, |
| 374 element_bounds_in_screen_space, | |
| 375 form, | |
| 376 0, // Unspecified max length. | 373 0, // Unspecified max length. |
| 377 driver_.GetPasswordManager(), | 374 &password_manager_, |
| 378 observer_, | 375 driver_factory_.GetDriverForFrame(render_frame_host_source_), |
| 379 web_contents(), | 376 observer_, web_contents(), web_contents()->GetNativeView()); |
| 380 web_contents()->GetNativeView()); | |
| 381 popup_controller_->Show(false /* display_password */); | 377 popup_controller_->Show(false /* display_password */); |
| 382 } | 378 } |
| 383 | 379 |
| 384 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 380 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
| 385 if (!web_contents()) | 381 if (!web_contents()) |
| 386 return; | 382 return; |
| 387 | 383 |
| 388 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 384 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
| 389 web_contents()->GetRenderViewHost()->GetRoutingID(), | 385 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 390 can_use_log_router_)); | 386 can_use_log_router_)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 485 |
| 490 if (group_name == "DisallowSyncCredentialsForReauth") { | 486 if (group_name == "DisallowSyncCredentialsForReauth") { |
| 491 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | 487 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
| 492 } else if (group_name == "DisallowSyncCredentials") { | 488 } else if (group_name == "DisallowSyncCredentials") { |
| 493 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 489 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
| 494 } else { | 490 } else { |
| 495 // Allow by default. | 491 // Allow by default. |
| 496 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 492 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
| 497 } | 493 } |
| 498 } | 494 } |
| OLD | NEW |