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/browser/password_manager_url_collecti
on_experiment.h" | 38 #include "components/password_manager/core/browser/password_manager_url_collecti
on_experiment.h" |
39 #include "components/password_manager/core/common/password_manager_switches.h" | 39 #include "components/password_manager/core/common/password_manager_switches.h" |
40 #include "content/public/browser/navigation_entry.h" | 40 #include "content/public/browser/navigation_entry.h" |
41 #include "content/public/browser/render_view_host.h" | 41 #include "content/public/browser/render_view_host.h" |
42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
43 #include "google_apis/gaia/gaia_urls.h" | 43 #include "google_apis/gaia/gaia_urls.h" |
44 #include "net/base/url_util.h" | 44 #include "net/base/url_util.h" |
45 #include "third_party/re2/re2/re2.h" | 45 #include "third_party/re2/re2/re2.h" |
46 | 46 |
47 #if defined(OS_ANDROID) | 47 #if defined(OS_ANDROID) |
48 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" | 48 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" |
49 #endif | 49 #endif |
50 | 50 |
| 51 using password_manager::ContentPasswordManagerDriverFactory; |
51 using password_manager::PasswordManagerInternalsService; | 52 using password_manager::PasswordManagerInternalsService; |
52 using password_manager::PasswordManagerInternalsServiceFactory; | 53 using password_manager::PasswordManagerInternalsServiceFactory; |
53 | 54 |
54 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
55 | 56 |
56 // Shorten the name to spare line breaks. The code provides enough context | 57 // Shorten the name to spare line breaks. The code provides enough context |
57 // already. | 58 // already. |
58 typedef autofill::SavePasswordProgressLogger Logger; | 59 typedef autofill::SavePasswordProgressLogger Logger; |
59 | 60 |
60 // static | 61 // static |
61 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( | 62 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( |
62 content::WebContents* contents, | 63 content::WebContents* contents, |
63 autofill::AutofillClient* autofill_client) { | 64 autofill::AutofillClient* autofill_client) { |
64 if (FromWebContents(contents)) | 65 if (FromWebContents(contents)) |
65 return; | 66 return; |
66 | 67 |
67 contents->SetUserData( | 68 contents->SetUserData( |
68 UserDataKey(), | 69 UserDataKey(), |
69 new ChromePasswordManagerClient(contents, autofill_client)); | 70 new ChromePasswordManagerClient(contents, autofill_client)); |
70 } | 71 } |
71 | 72 |
72 ChromePasswordManagerClient::ChromePasswordManagerClient( | 73 ChromePasswordManagerClient::ChromePasswordManagerClient( |
73 content::WebContents* web_contents, | 74 content::WebContents* web_contents, |
74 autofill::AutofillClient* autofill_client) | 75 autofill::AutofillClient* autofill_client) |
75 : content::WebContentsObserver(web_contents), | 76 : content::WebContentsObserver(web_contents), |
76 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 77 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
77 driver_(web_contents, this, autofill_client), | 78 password_manager_(this), |
| 79 driver_factory_(nullptr), |
78 credential_manager_dispatcher_(web_contents, this), | 80 credential_manager_dispatcher_(web_contents, this), |
79 observer_(NULL), | 81 observer_(nullptr), |
80 can_use_log_router_(false), | 82 can_use_log_router_(false), |
81 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), | 83 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), |
82 sync_credential_was_filtered_(false) { | 84 sync_credential_was_filtered_(false) { |
| 85 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
| 86 autofill_client); |
| 87 driver_factory_ = |
| 88 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
| 89 |
83 PasswordManagerInternalsService* service = | 90 PasswordManagerInternalsService* service = |
84 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 91 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
85 if (service) | 92 if (service) |
86 can_use_log_router_ = service->RegisterClient(this); | 93 can_use_log_router_ = service->RegisterClient(this); |
87 SetUpAutofillSyncState(); | 94 SetUpAutofillSyncState(); |
88 } | 95 } |
89 | 96 |
90 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 97 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
91 PasswordManagerInternalsService* service = | 98 PasswordManagerInternalsService* service = |
92 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 99 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 255 |
249 password_manager::PasswordStore* | 256 password_manager::PasswordStore* |
250 ChromePasswordManagerClient::GetPasswordStore() { | 257 ChromePasswordManagerClient::GetPasswordStore() { |
251 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord | 258 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord |
252 // itself when it shouldn't access the PasswordStore. | 259 // itself when it shouldn't access the PasswordStore. |
253 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? | 260 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? |
254 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) | 261 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) |
255 .get(); | 262 .get(); |
256 } | 263 } |
257 | 264 |
258 password_manager::PasswordManagerDriver* | |
259 ChromePasswordManagerClient::GetDriver() { | |
260 return &driver_; | |
261 } | |
262 | |
263 base::FieldTrial::Probability | 265 base::FieldTrial::Probability |
264 ChromePasswordManagerClient::GetProbabilityForExperiment( | 266 ChromePasswordManagerClient::GetProbabilityForExperiment( |
265 const std::string& experiment_name) { | 267 const std::string& experiment_name) { |
266 base::FieldTrial::Probability enabled_probability = 0; | 268 base::FieldTrial::Probability enabled_probability = 0; |
267 if (experiment_name == | 269 if (experiment_name == |
268 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { | 270 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { |
269 switch (chrome::VersionInfo::GetChannel()) { | 271 switch (chrome::VersionInfo::GetChannel()) { |
270 case chrome::VersionInfo::CHANNEL_DEV: | 272 case chrome::VersionInfo::CHANNEL_DEV: |
271 case chrome::VersionInfo::CHANNEL_BETA: | 273 case chrome::VersionInfo::CHANNEL_BETA: |
272 enabled_probability = 50; | 274 enabled_probability = 50; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 int http_status_code = entry->GetHttpStatusCode(); | 338 int http_status_code = entry->GetHttpStatusCode(); |
337 | 339 |
338 if (logger) | 340 if (logger) |
339 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); | 341 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
340 | 342 |
341 if (http_status_code >= 400 && http_status_code < 600) | 343 if (http_status_code >= 400 && http_status_code < 600) |
342 return true; | 344 return true; |
343 return false; | 345 return false; |
344 } | 346 } |
345 | 347 |
346 // static | 348 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() { |
347 password_manager::PasswordGenerationManager* | 349 content::NavigationEntry* entry = |
348 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | 350 web_contents()->GetController().GetLastCommittedEntry(); |
349 content::WebContents* contents) { | 351 if (!entry) |
350 ChromePasswordManagerClient* client = | 352 return false; |
351 ChromePasswordManagerClient::FromWebContents(contents); | 353 |
352 if (!client) | 354 return net::IsCertStatusError(entry->GetSSL().cert_status); |
353 return NULL; | |
354 return client->GetDriver()->GetPasswordGenerationManager(); | |
355 } | 355 } |
356 | 356 |
357 // static | 357 bool ChromePasswordManagerClient::IsOffTheRecord() { |
| 358 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 359 } |
| 360 |
358 password_manager::PasswordManager* | 361 password_manager::PasswordManager* |
359 ChromePasswordManagerClient::GetManagerFromWebContents( | 362 ChromePasswordManagerClient::GetPasswordManager() { |
360 content::WebContents* contents) { | 363 return &password_manager_; |
361 ChromePasswordManagerClient* client = | |
362 ChromePasswordManagerClient::FromWebContents(contents); | |
363 if (!client) | |
364 return NULL; | |
365 return client->GetDriver()->GetPasswordManager(); | |
366 } | 364 } |
367 | 365 |
368 void ChromePasswordManagerClient::SetTestObserver( | 366 void ChromePasswordManagerClient::SetTestObserver( |
369 autofill::PasswordGenerationPopupObserver* observer) { | 367 autofill::PasswordGenerationPopupObserver* observer) { |
370 observer_ = observer; | 368 observer_ = observer; |
371 } | 369 } |
372 | 370 |
373 bool ChromePasswordManagerClient::OnMessageReceived( | 371 bool ChromePasswordManagerClient::OnMessageReceived( |
374 const IPC::Message& message) { | 372 const IPC::Message& message, |
| 373 content::RenderFrameHost* render_frame_host) { |
375 bool handled = true; | 374 bool handled = true; |
376 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 375 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ChromePasswordManagerClient, message, |
| 376 render_frame_host) |
377 // Autofill messages: | 377 // Autofill messages: |
378 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | 378 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, |
379 ShowPasswordGenerationPopup) | 379 ShowPasswordGenerationPopup) |
380 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 380 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
381 ShowPasswordEditingPopup) | 381 ShowPasswordEditingPopup) |
| 382 IPC_END_MESSAGE_MAP() |
| 383 |
| 384 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
382 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 385 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
383 HidePasswordGenerationPopup) | 386 HidePasswordGenerationPopup) |
384 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | 387 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, |
385 NotifyRendererOfLoggingAvailability) | 388 NotifyRendererOfLoggingAvailability) |
386 | |
387 // Default: | 389 // Default: |
388 IPC_MESSAGE_UNHANDLED(handled = false) | 390 IPC_MESSAGE_UNHANDLED(handled = false) |
389 IPC_END_MESSAGE_MAP() | 391 IPC_END_MESSAGE_MAP() |
| 392 |
390 return handled; | 393 return handled; |
391 } | 394 } |
392 | 395 |
393 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 396 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
394 const gfx::RectF& bounds) { | 397 const gfx::RectF& bounds) { |
395 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 398 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
396 return bounds + client_area.OffsetFromOrigin(); | 399 return bounds + client_area.OffsetFromOrigin(); |
397 } | 400 } |
398 | 401 |
399 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 402 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
| 403 content::RenderFrameHost* render_frame_host, |
400 const gfx::RectF& bounds, | 404 const gfx::RectF& bounds, |
401 int max_length, | 405 int max_length, |
402 const autofill::PasswordForm& form) { | 406 const autofill::PasswordForm& form) { |
403 // TODO(gcasto): Validate data in PasswordForm. | 407 // TODO(gcasto): Validate data in PasswordForm. |
404 | 408 |
405 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 409 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
406 | 410 |
407 popup_controller_ = | 411 popup_controller_ = |
408 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 412 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
409 popup_controller_, | 413 popup_controller_, element_bounds_in_screen_space, form, max_length, |
410 element_bounds_in_screen_space, | 414 &password_manager_, |
411 form, | 415 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
412 max_length, | 416 web_contents(), web_contents()->GetNativeView()); |
413 driver_.GetPasswordManager(), | |
414 observer_, | |
415 web_contents(), | |
416 web_contents()->GetNativeView()); | |
417 popup_controller_->Show(true /* display_password */); | 417 popup_controller_->Show(true /* display_password */); |
418 } | 418 } |
419 | 419 |
420 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 420 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
| 421 content::RenderFrameHost* render_frame_host, |
421 const gfx::RectF& bounds, | 422 const gfx::RectF& bounds, |
422 const autofill::PasswordForm& form) { | 423 const autofill::PasswordForm& form) { |
423 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 424 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
424 popup_controller_ = | 425 popup_controller_ = |
425 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 426 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
426 popup_controller_, | 427 popup_controller_, element_bounds_in_screen_space, form, |
427 element_bounds_in_screen_space, | |
428 form, | |
429 0, // Unspecified max length. | 428 0, // Unspecified max length. |
430 driver_.GetPasswordManager(), | 429 &password_manager_, |
431 observer_, | 430 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
432 web_contents(), | 431 web_contents(), web_contents()->GetNativeView()); |
433 web_contents()->GetNativeView()); | |
434 popup_controller_->Show(false /* display_password */); | 432 popup_controller_->Show(false /* display_password */); |
435 } | 433 } |
436 | 434 |
437 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 435 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
438 if (!web_contents()) | 436 if (!web_contents()) |
439 return; | 437 return; |
440 | 438 |
441 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 439 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
442 web_contents()->GetRenderViewHost()->GetRoutingID(), | 440 web_contents()->GetRenderViewHost()->GetRoutingID(), |
443 can_use_log_router_)); | 441 can_use_log_router_)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 540 |
543 if (group_name == "DisallowSyncCredentialsForReauth") { | 541 if (group_name == "DisallowSyncCredentialsForReauth") { |
544 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | 542 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
545 } else if (group_name == "DisallowSyncCredentials") { | 543 } else if (group_name == "DisallowSyncCredentials") { |
546 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 544 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
547 } else { | 545 } else { |
548 // Allow by default. | 546 // Allow by default. |
549 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 547 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
550 } | 548 } |
551 } | 549 } |
OLD | NEW |