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 "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_(nullptr), |
| 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_(nullptr) { | |
| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 | 221 |
| 220 password_manager::PasswordStore* | 222 password_manager::PasswordStore* |
| 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* | |
| 230 ChromePasswordManagerClient::GetDriver() { | |
| 231 return &driver_; | |
| 232 } | |
| 233 | |
| 234 base::FieldTrial::Probability | 231 base::FieldTrial::Probability |
| 235 ChromePasswordManagerClient::GetProbabilityForExperiment( | 232 ChromePasswordManagerClient::GetProbabilityForExperiment( |
| 236 const std::string& experiment_name) { | 233 const std::string& experiment_name) { |
| 237 base::FieldTrial::Probability enabled_probability = 0; | 234 base::FieldTrial::Probability enabled_probability = 0; |
| 238 if (experiment_name == | 235 if (experiment_name == |
| 239 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { | 236 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { |
| 240 switch (chrome::VersionInfo::GetChannel()) { | 237 switch (chrome::VersionInfo::GetChannel()) { |
| 241 case chrome::VersionInfo::CHANNEL_DEV: | 238 case chrome::VersionInfo::CHANNEL_DEV: |
| 242 case chrome::VersionInfo::CHANNEL_BETA: | 239 case chrome::VersionInfo::CHANNEL_BETA: |
| 243 enabled_probability = 50; | 240 enabled_probability = 50; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 if (service) | 280 if (service) |
| 284 service->ProcessLog(text); | 281 service->ProcessLog(text); |
| 285 } | 282 } |
| 286 | 283 |
| 287 bool ChromePasswordManagerClient::IsLoggingActive() const { | 284 bool ChromePasswordManagerClient::IsLoggingActive() const { |
| 288 // WebUI tabs do not need to log password saving progress. In particular, the | 285 // WebUI tabs do not need to log password saving progress. In particular, the |
| 289 // internals page itself should not send any logs. | 286 // internals page itself should not send any logs. |
| 290 return can_use_log_router_ && !web_contents()->GetWebUI(); | 287 return can_use_log_router_ && !web_contents()->GetWebUI(); |
| 291 } | 288 } |
| 292 | 289 |
| 293 // static | 290 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() { |
| 294 password_manager::PasswordGenerationManager* | 291 content::NavigationEntry* entry = |
| 295 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | 292 web_contents()->GetController().GetLastCommittedEntry(); |
| 296 content::WebContents* contents) { | 293 if (!entry) |
| 297 ChromePasswordManagerClient* client = | 294 return false; |
| 298 ChromePasswordManagerClient::FromWebContents(contents); | 295 |
| 299 if (!client) | 296 return net::IsCertStatusError(entry->GetSSL().cert_status); |
| 300 return NULL; | |
| 301 return client->GetDriver()->GetPasswordGenerationManager(); | |
| 302 } | 297 } |
| 303 | 298 |
| 304 // static | 299 bool ChromePasswordManagerClient::IsOffTheRecord() { |
| 300 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | |
| 301 } | |
| 302 | |
| 305 password_manager::PasswordManager* | 303 password_manager::PasswordManager* |
| 306 ChromePasswordManagerClient::GetManagerFromWebContents( | 304 ChromePasswordManagerClient::GetPasswordManager() { |
| 307 content::WebContents* contents) { | 305 return &password_manager_; |
| 308 ChromePasswordManagerClient* client = | |
| 309 ChromePasswordManagerClient::FromWebContents(contents); | |
| 310 if (!client) | |
| 311 return NULL; | |
| 312 return client->GetDriver()->GetPasswordManager(); | |
| 313 } | 306 } |
| 314 | 307 |
| 315 void ChromePasswordManagerClient::SetTestObserver( | 308 void ChromePasswordManagerClient::SetTestObserver( |
| 316 autofill::PasswordGenerationPopupObserver* observer) { | 309 autofill::PasswordGenerationPopupObserver* observer) { |
| 317 observer_ = observer; | 310 observer_ = observer; |
| 318 } | 311 } |
| 319 | 312 |
| 320 bool ChromePasswordManagerClient::OnMessageReceived( | 313 bool ChromePasswordManagerClient::OnMessageReceived( |
| 321 const IPC::Message& message) { | 314 const IPC::Message& message, |
| 315 content::RenderFrameHost* render_frame_host) { | |
| 316 render_frame_host_source_ = render_frame_host; | |
| 317 | |
| 322 bool handled = true; | 318 bool handled = true; |
| 323 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 319 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
|
jam
2014/11/17 23:13:21
use IPC_BEGIN_MESSAGE_MAP_WITH_PARAM instead, and
Evan Stade
2014/11/18 00:39:05
Done. Any problem with using two message maps in a
jam
2014/11/18 17:33:51
why are you using two instead of just one? i reali
Evan Stade
2014/11/18 19:39:29
A couple of the message handling functions are cal
jam
2014/11/19 17:43:27
I see, I didn't realize they're called from elsewh
Evan Stade
2014/11/19 22:20:04
Done.
| |
| 324 // Autofill messages: | 320 // Autofill messages: |
| 325 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | 321 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, |
| 326 ShowPasswordGenerationPopup) | 322 ShowPasswordGenerationPopup) |
| 327 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 323 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
| 328 ShowPasswordEditingPopup) | 324 ShowPasswordEditingPopup) |
| 329 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 325 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
| 330 HidePasswordGenerationPopup) | 326 HidePasswordGenerationPopup) |
| 331 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | 327 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, |
| 332 NotifyRendererOfLoggingAvailability) | 328 NotifyRendererOfLoggingAvailability) |
| 333 | 329 |
| 334 // Default: | 330 // Default: |
| 335 IPC_MESSAGE_UNHANDLED(handled = false) | 331 IPC_MESSAGE_UNHANDLED(handled = false) |
| 336 IPC_END_MESSAGE_MAP() | 332 IPC_END_MESSAGE_MAP() |
| 333 | |
| 334 render_frame_host_source_ = nullptr; | |
| 337 return handled; | 335 return handled; |
| 338 } | 336 } |
| 339 | 337 |
| 340 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 338 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
| 341 const gfx::RectF& bounds) { | 339 const gfx::RectF& bounds) { |
| 342 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 340 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
| 343 return bounds + client_area.OffsetFromOrigin(); | 341 return bounds + client_area.OffsetFromOrigin(); |
| 344 } | 342 } |
| 345 | 343 |
| 346 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 344 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
| 347 const gfx::RectF& bounds, | 345 const gfx::RectF& bounds, |
| 348 int max_length, | 346 int max_length, |
| 349 const autofill::PasswordForm& form) { | 347 const autofill::PasswordForm& form) { |
| 350 // TODO(gcasto): Validate data in PasswordForm. | 348 // TODO(gcasto): Validate data in PasswordForm. |
| 351 | 349 |
| 352 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 350 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 353 | 351 |
| 354 popup_controller_ = | 352 popup_controller_ = |
| 355 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 353 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 356 popup_controller_, | 354 popup_controller_, element_bounds_in_screen_space, form, max_length, |
| 357 element_bounds_in_screen_space, | 355 &password_manager_, |
| 358 form, | 356 driver_factory_.GetDriverForFrame(render_frame_host_source_), |
| 359 max_length, | 357 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 */); | 358 popup_controller_->Show(true /* display_password */); |
| 365 } | 359 } |
| 366 | 360 |
| 367 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 361 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
| 368 const gfx::RectF& bounds, | 362 const gfx::RectF& bounds, |
| 369 const autofill::PasswordForm& form) { | 363 const autofill::PasswordForm& form) { |
| 370 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 364 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 371 popup_controller_ = | 365 popup_controller_ = |
| 372 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 366 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 373 popup_controller_, | 367 popup_controller_, element_bounds_in_screen_space, form, |
| 374 element_bounds_in_screen_space, | |
| 375 form, | |
| 376 0, // Unspecified max length. | 368 0, // Unspecified max length. |
| 377 driver_.GetPasswordManager(), | 369 &password_manager_, |
| 378 observer_, | 370 driver_factory_.GetDriverForFrame(render_frame_host_source_), |
| 379 web_contents(), | 371 observer_, web_contents(), web_contents()->GetNativeView()); |
| 380 web_contents()->GetNativeView()); | |
| 381 popup_controller_->Show(false /* display_password */); | 372 popup_controller_->Show(false /* display_password */); |
| 382 } | 373 } |
| 383 | 374 |
| 384 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 375 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
| 385 if (!web_contents()) | 376 if (!web_contents()) |
| 386 return; | 377 return; |
| 387 | 378 |
| 388 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 379 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
| 389 web_contents()->GetRenderViewHost()->GetRoutingID(), | 380 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 390 can_use_log_router_)); | 381 can_use_log_router_)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 | 480 |
| 490 if (group_name == "DisallowSyncCredentialsForReauth") { | 481 if (group_name == "DisallowSyncCredentialsForReauth") { |
| 491 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | 482 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
| 492 } else if (group_name == "DisallowSyncCredentials") { | 483 } else if (group_name == "DisallowSyncCredentials") { |
| 493 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 484 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
| 494 } else { | 485 } else { |
| 495 // Allow by default. | 486 // Allow by default. |
| 496 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 487 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
| 497 } | 488 } |
| 498 } | 489 } |
| OLD | NEW |