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/utf_string_conversions.h" | |
11 #include "chrome/browser/password_manager/password_manager_util.h" | 12 #include "chrome/browser/password_manager/password_manager_util.h" |
12 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
13 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 14 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
14 #include "chrome/browser/password_manager/sync_metrics.h" | 15 #include "chrome/browser/password_manager/sync_metrics.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
18 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " | 19 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " |
19 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 20 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
23 #include "components/autofill/content/common/autofill_messages.h" | 24 #include "components/autofill/content/common/autofill_messages.h" |
24 #include "components/autofill/core/browser/password_generator.h" | 25 #include "components/autofill/core/browser/password_generator.h" |
25 #include "components/autofill/core/common/password_form.h" | 26 #include "components/autofill/core/common/password_form.h" |
26 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" | 27 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" |
27 #include "components/password_manager/core/browser/log_receiver.h" | 28 #include "components/password_manager/core/browser/log_receiver.h" |
28 #include "components/password_manager/core/browser/password_form_manager.h" | 29 #include "components/password_manager/core/browser/password_form_manager.h" |
29 #include "components/password_manager/core/browser/password_manager.h" | 30 #include "components/password_manager/core/browser/password_manager.h" |
30 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" | 31 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" |
31 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 32 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
32 #include "components/password_manager/core/common/password_manager_switches.h" | 33 #include "components/password_manager/core/common/password_manager_switches.h" |
33 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "google_apis/gaia/gaia_urls.h" | |
38 #include "net/base/url_util.h" | |
36 | 39 |
37 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
38 #include "chrome/browser/android/password_authentication_manager.h" | 41 #include "chrome/browser/android/password_authentication_manager.h" |
39 #endif // OS_ANDROID | 42 #endif // OS_ANDROID |
40 | 43 |
41 using password_manager::PasswordManagerInternalsService; | 44 using password_manager::PasswordManagerInternalsService; |
42 using password_manager::PasswordManagerInternalsServiceFactory; | 45 using password_manager::PasswordManagerInternalsServiceFactory; |
43 | 46 |
44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 47 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
45 | 48 |
(...skipping 10 matching lines...) Expand all Loading... | |
56 } | 59 } |
57 | 60 |
58 ChromePasswordManagerClient::ChromePasswordManagerClient( | 61 ChromePasswordManagerClient::ChromePasswordManagerClient( |
59 content::WebContents* web_contents, | 62 content::WebContents* web_contents, |
60 autofill::AutofillClient* autofill_client) | 63 autofill::AutofillClient* autofill_client) |
61 : content::WebContentsObserver(web_contents), | 64 : content::WebContentsObserver(web_contents), |
62 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 65 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
63 driver_(web_contents, this, autofill_client), | 66 driver_(web_contents, this, autofill_client), |
64 observer_(NULL), | 67 observer_(NULL), |
65 weak_factory_(this), | 68 weak_factory_(this), |
66 can_use_log_router_(false) { | 69 can_use_log_router_(false), |
70 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS) { | |
67 PasswordManagerInternalsService* service = | 71 PasswordManagerInternalsService* service = |
68 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 72 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
69 if (service) | 73 if (service) |
70 can_use_log_router_ = service->RegisterClient(this); | 74 can_use_log_router_ = service->RegisterClient(this); |
75 SetUpAutofillSyncState(); | |
71 } | 76 } |
72 | 77 |
73 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 78 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
74 PasswordManagerInternalsService* service = | 79 PasswordManagerInternalsService* service = |
75 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 80 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
76 if (service) | 81 if (service) |
77 service->UnregisterClient(this); | 82 service->UnregisterClient(this); |
78 } | 83 } |
79 | 84 |
80 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 85 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
81 return CommandLine::ForCurrentProcess()->HasSwitch( | 86 return CommandLine::ForCurrentProcess()->HasSwitch( |
82 password_manager::switches::kEnableAutomaticPasswordSaving) && | 87 password_manager::switches::kEnableAutomaticPasswordSaving) && |
83 chrome::VersionInfo::GetChannel() == | 88 chrome::VersionInfo::GetChannel() == |
84 chrome::VersionInfo::CHANNEL_UNKNOWN; | 89 chrome::VersionInfo::CHANNEL_UNKNOWN; |
85 } | 90 } |
86 | 91 |
87 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() | 92 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() |
88 const { | 93 const { |
89 if (EnabledForSyncSignin()) | 94 if (EnabledForSyncSignin()) |
90 return true; | 95 return true; |
91 | 96 |
92 DCHECK(web_contents()); | 97 DCHECK(web_contents()); |
93 content::NavigationEntry* entry = | 98 content::NavigationEntry* entry = |
94 web_contents()->GetController().GetLastCommittedEntry(); | 99 web_contents()->GetController().GetLastCommittedEntry(); |
95 if (!entry) { | 100 if (!entry) { |
96 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 101 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
97 return true; | 102 return true; |
98 } | 103 } |
99 // Do not fill nor save password when a user is signing in for sync. This | 104 // Do not fill nor save password when a user is signing in for sync. This |
100 // is because users need to remember their password if they are syncing as | 105 // is because users need to remember their password if they are syncing as |
101 // this is effectively their master password. | 106 // this is effectively their master password. |
102 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | 107 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
103 } | 108 } |
104 | 109 |
110 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( | |
111 const autofill::PasswordForm& form) { | |
112 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), | |
113 form.signon_realm)) | |
114 return false; | |
115 | |
116 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) { | |
117 sync_credential_filtered_ = true; | |
Ilya Sherman
2014/08/14 07:38:14
You should initialize this variable in the constru
Garrett Casto
2014/08/14 19:48:43
Done.
| |
118 return true; | |
119 } | |
120 | |
121 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH && | |
122 LastLoadWasTransactionalReauthPage()) { | |
123 sync_credential_filtered_ = true; | |
124 return true; | |
125 } | |
126 | |
127 return false; | |
128 } | |
129 | |
105 bool ChromePasswordManagerClient::IsSyncAccountCredential( | 130 bool ChromePasswordManagerClient::IsSyncAccountCredential( |
106 const std::string& username, const std::string& origin) const { | 131 const std::string& username, const std::string& origin) const { |
107 return password_manager_sync_metrics::IsSyncAccountCredential( | 132 return password_manager_sync_metrics::IsSyncAccountCredential( |
108 profile_, username, origin); | 133 profile_, username, origin); |
109 } | 134 } |
110 | 135 |
136 void ChromePasswordManagerClient::AutofillResultsComputed() { | |
137 UMA_HISTOGRAM_BOOLEAN("PasswordManager.SyncCredentialFiltered", | |
138 sync_credential_filtered_); | |
139 sync_credential_filtered_ = false; | |
140 } | |
141 | |
111 void ChromePasswordManagerClient::PromptUserToSavePassword( | 142 void ChromePasswordManagerClient::PromptUserToSavePassword( |
112 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { | 143 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { |
113 if (IsTheHotNewBubbleUIEnabled()) { | 144 if (IsTheHotNewBubbleUIEnabled()) { |
114 ManagePasswordsUIController* manage_passwords_ui_controller = | 145 ManagePasswordsUIController* manage_passwords_ui_controller = |
115 ManagePasswordsUIController::FromWebContents(web_contents()); | 146 ManagePasswordsUIController::FromWebContents(web_contents()); |
116 manage_passwords_ui_controller->OnPasswordSubmitted(form_to_save.Pass()); | 147 manage_passwords_ui_controller->OnPasswordSubmitted(form_to_save.Pass()); |
117 } else { | 148 } else { |
118 std::string uma_histogram_suffix( | 149 std::string uma_histogram_suffix( |
119 password_manager::metrics_util::GroupIdToString( | 150 password_manager::metrics_util::GroupIdToString( |
120 password_manager::metrics_util::MonitoredDomainGroupId( | 151 password_manager::metrics_util::MonitoredDomainGroupId( |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 377 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
347 web_contents()->GetRenderViewHost()->GetRoutingID(), | 378 web_contents()->GetRenderViewHost()->GetRoutingID(), |
348 can_use_log_router_)); | 379 can_use_log_router_)); |
349 } | 380 } |
350 | 381 |
351 void ChromePasswordManagerClient::CommitFillPasswordForm( | 382 void ChromePasswordManagerClient::CommitFillPasswordForm( |
352 autofill::PasswordFormFillData* data) { | 383 autofill::PasswordFormFillData* data) { |
353 driver_.FillPasswordForm(*data); | 384 driver_.FillPasswordForm(*data); |
354 } | 385 } |
355 | 386 |
387 bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const { | |
388 DCHECK(web_contents()); | |
389 content::NavigationEntry* entry = | |
390 web_contents()->GetController().GetLastCommittedEntry(); | |
391 if (!entry) | |
392 return false; | |
393 | |
394 if (entry->GetURL().GetOrigin() != | |
395 GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | |
396 return false; | |
397 | |
398 // "rart" is the transactional reauth paramter. | |
399 std::string ignored_value; | |
400 return net::GetValueForKeyInQuery(entry->GetURL(), | |
401 "rart", | |
402 &ignored_value); | |
403 } | |
404 | |
356 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { | 405 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
357 #if !defined(USE_AURA) | 406 #if !defined(USE_AURA) |
358 return false; | 407 return false; |
359 #endif | 408 #endif |
360 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 409 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
361 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | 410 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) |
362 return false; | 411 return false; |
363 | 412 |
364 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) | 413 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) |
365 return true; | 414 return true; |
(...skipping 13 matching lines...) Expand all Loading... | |
379 | 428 |
380 if (command_line->HasSwitch( | 429 if (command_line->HasSwitch( |
381 password_manager::switches::kEnableManagerForSyncSignin)) | 430 password_manager::switches::kEnableManagerForSyncSignin)) |
382 return true; | 431 return true; |
383 | 432 |
384 // Default is enabled. | 433 // Default is enabled. |
385 std::string group_name = | 434 std::string group_name = |
386 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); | 435 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); |
387 return group_name != "Disabled"; | 436 return group_name != "Disabled"; |
388 } | 437 } |
438 | |
439 void ChromePasswordManagerClient::SetUpAutofillSyncState() { | |
440 std::string group_name = | |
441 base::FieldTrialList::FindFullName("AutofillSyncCredential"); | |
442 | |
443 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
444 if (command_line->HasSwitch( | |
445 password_manager::switches::kAllowAutofillSyncCredential)) { | |
446 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
447 return; | |
448 } | |
449 if (command_line->HasSwitch( | |
450 password_manager::switches:: | |
451 kDisallowAutofillSyncCredentialForReauth)) { | |
452 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
453 return; | |
454 } | |
455 if (command_line->HasSwitch( | |
456 password_manager::switches::kDisallowAutofillSyncCredential)) { | |
457 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
458 return; | |
459 } | |
460 | |
461 if (group_name == "DisallowSyncCredentialsForReauth") { | |
462 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
463 } else if (group_name == "DisallowSyncCredentials") { | |
464 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
465 } else { | |
466 // Allow by default. | |
467 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
468 } | |
469 } | |
OLD | NEW |