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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "components/password_manager/content/common/credential_manager_messages
.h" | 33 #include "components/password_manager/content/common/credential_manager_messages
.h" |
34 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 34 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
35 #include "components/password_manager/core/browser/log_receiver.h" | 35 #include "components/password_manager/core/browser/log_receiver.h" |
36 #include "components/password_manager/core/browser/password_form_manager.h" | 36 #include "components/password_manager/core/browser/password_form_manager.h" |
37 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" | 37 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
38 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 38 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
39 #include "components/password_manager/core/browser/password_manager_util.h" | 39 #include "components/password_manager/core/browser/password_manager_util.h" |
40 #include "components/password_manager/core/common/credential_manager_types.h" | 40 #include "components/password_manager/core/common/credential_manager_types.h" |
41 #include "components/password_manager/core/common/password_manager_pref_names.h" | 41 #include "components/password_manager/core/common/password_manager_pref_names.h" |
42 #include "components/password_manager/core/common/password_manager_switches.h" | 42 #include "components/password_manager/core/common/password_manager_switches.h" |
| 43 #include "components/password_manager/sync/browser/sync_store_result_filter.h" |
43 #include "components/version_info/version_info.h" | 44 #include "components/version_info/version_info.h" |
44 #include "content/public/browser/navigation_entry.h" | 45 #include "content/public/browser/navigation_entry.h" |
45 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
46 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
47 #include "google_apis/gaia/gaia_urls.h" | 48 #include "google_apis/gaia/gaia_urls.h" |
48 #include "net/base/url_util.h" | 49 #include "net/base/url_util.h" |
49 #include "third_party/re2/re2/re2.h" | 50 #include "third_party/re2/re2/re2.h" |
50 | 51 |
51 #if defined(OS_ANDROID) | 52 #if defined(OS_ANDROID) |
52 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" | 53 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 106 |
106 ChromePasswordManagerClient::ChromePasswordManagerClient( | 107 ChromePasswordManagerClient::ChromePasswordManagerClient( |
107 content::WebContents* web_contents, | 108 content::WebContents* web_contents, |
108 autofill::AutofillClient* autofill_client) | 109 autofill::AutofillClient* autofill_client) |
109 : content::WebContentsObserver(web_contents), | 110 : content::WebContentsObserver(web_contents), |
110 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 111 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
111 password_manager_(this), | 112 password_manager_(this), |
112 driver_factory_(nullptr), | 113 driver_factory_(nullptr), |
113 credential_manager_dispatcher_(web_contents, this), | 114 credential_manager_dispatcher_(web_contents, this), |
114 observer_(nullptr), | 115 observer_(nullptr), |
115 can_use_log_router_(false), | 116 can_use_log_router_(false) { |
116 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), | |
117 sync_credential_was_filtered_(false) { | |
118 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 117 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
119 autofill_client); | 118 autofill_client); |
120 driver_factory_ = | 119 driver_factory_ = |
121 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 120 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
122 | 121 |
123 PasswordManagerInternalsService* service = | 122 PasswordManagerInternalsService* service = |
124 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 123 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
125 if (service) | 124 if (service) |
126 can_use_log_router_ = service->RegisterClient(this); | 125 can_use_log_router_ = service->RegisterClient(this); |
127 SetUpAutofillSyncState(); | |
128 saving_passwords_enabled_.Init( | 126 saving_passwords_enabled_.Init( |
129 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); | 127 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); |
130 ReportMetrics(*saving_passwords_enabled_, this); | 128 ReportMetrics(*saving_passwords_enabled_, this); |
131 } | 129 } |
132 | 130 |
133 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 131 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
134 PasswordManagerInternalsService* service = | 132 PasswordManagerInternalsService* service = |
135 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 133 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
136 if (service) | 134 if (service) |
137 service->UnregisterClient(this); | 135 service->UnregisterClient(this); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 169 } |
172 return is_enabled; | 170 return is_enabled; |
173 } | 171 } |
174 | 172 |
175 bool ChromePasswordManagerClient::IsSavingEnabledForCurrentPage() const { | 173 bool ChromePasswordManagerClient::IsSavingEnabledForCurrentPage() const { |
176 return *saving_passwords_enabled_ && !IsOffTheRecord() && | 174 return *saving_passwords_enabled_ && !IsOffTheRecord() && |
177 !DidLastPageLoadEncounterSSLErrors() && | 175 !DidLastPageLoadEncounterSSLErrors() && |
178 IsPasswordManagementEnabledForCurrentPage(); | 176 IsPasswordManagementEnabledForCurrentPage(); |
179 } | 177 } |
180 | 178 |
181 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( | |
182 const autofill::PasswordForm& form) { | |
183 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), | |
184 form.signon_realm)) | |
185 return false; | |
186 | |
187 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) { | |
188 sync_credential_was_filtered_ = true; | |
189 return true; | |
190 } | |
191 | |
192 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH && | |
193 LastLoadWasTransactionalReauthPage()) { | |
194 sync_credential_was_filtered_ = true; | |
195 return true; | |
196 } | |
197 | |
198 return false; | |
199 } | |
200 | |
201 std::string ChromePasswordManagerClient::GetSyncUsername() const { | 179 std::string ChromePasswordManagerClient::GetSyncUsername() const { |
202 return password_manager_sync_metrics::GetSyncUsername(profile_); | 180 return password_manager_sync_metrics::GetSyncUsername(profile_); |
203 } | 181 } |
204 | 182 |
205 bool ChromePasswordManagerClient::IsSyncAccountCredential( | 183 bool ChromePasswordManagerClient::IsSyncAccountCredential( |
206 const std::string& username, | 184 const std::string& username, |
207 const std::string& realm) const { | 185 const std::string& realm) const { |
208 return password_manager_sync_metrics::IsSyncAccountCredential( | 186 return password_manager_sync_metrics::IsSyncAccountCredential( |
209 profile_, username, realm); | 187 profile_, username, realm); |
210 } | 188 } |
211 | 189 |
212 void ChromePasswordManagerClient::AutofillResultsComputed() { | |
213 UMA_HISTOGRAM_BOOLEAN("PasswordManager.SyncCredentialFiltered", | |
214 sync_credential_was_filtered_); | |
215 sync_credential_was_filtered_ = false; | |
216 } | |
217 | |
218 bool ChromePasswordManagerClient::PromptUserToSaveOrUpdatePassword( | 190 bool ChromePasswordManagerClient::PromptUserToSaveOrUpdatePassword( |
219 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 191 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
220 password_manager::CredentialSourceType type, | 192 password_manager::CredentialSourceType type, |
221 bool update_password) { | 193 bool update_password) { |
222 // Save password infobar and the password bubble prompts in case of | 194 // Save password infobar and the password bubble prompts in case of |
223 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). | 195 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). |
224 if (!BrowsingDataHelper::IsWebScheme( | 196 if (!BrowsingDataHelper::IsWebScheme( |
225 web_contents()->GetLastCommittedURL().scheme())) { | 197 web_contents()->GetLastCommittedURL().scheme())) { |
226 return false; | 198 return false; |
227 } | 199 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 452 |
481 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 453 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
482 if (!web_contents()) | 454 if (!web_contents()) |
483 return; | 455 return; |
484 | 456 |
485 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 457 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
486 web_contents()->GetRenderViewHost()->GetRoutingID(), | 458 web_contents()->GetRenderViewHost()->GetRoutingID(), |
487 can_use_log_router_)); | 459 can_use_log_router_)); |
488 } | 460 } |
489 | 461 |
490 bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const { | |
491 DCHECK(web_contents()); | |
492 content::NavigationEntry* entry = | |
493 web_contents()->GetController().GetLastCommittedEntry(); | |
494 if (!entry) | |
495 return false; | |
496 | |
497 if (entry->GetURL().GetOrigin() != | |
498 GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | |
499 return false; | |
500 | |
501 // "rart" is the transactional reauth paramter. | |
502 std::string ignored_value; | |
503 return net::GetValueForKeyInQuery(entry->GetURL(), | |
504 "rart", | |
505 &ignored_value); | |
506 } | |
507 | |
508 bool ChromePasswordManagerClient::IsURLPasswordWebsiteReauth( | 462 bool ChromePasswordManagerClient::IsURLPasswordWebsiteReauth( |
509 const GURL& url) const { | 463 const GURL& url) const { |
510 if (url.GetOrigin() != GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | 464 if (url.GetOrigin() != GaiaUrls::GetInstance()->gaia_url().GetOrigin()) |
511 return false; | 465 return false; |
512 | 466 |
513 // "rart" param signals this page is for transactional reauth. | 467 // "rart" param signals this page is for transactional reauth. |
514 std::string param_value; | 468 std::string param_value; |
515 if (!net::GetValueForKeyInQuery(url, "rart", ¶m_value)) | 469 if (!net::GetValueForKeyInQuery(url, "rart", ¶m_value)) |
516 return false; | 470 return false; |
517 | 471 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 if (command_line->HasSwitch( | 519 if (command_line->HasSwitch( |
566 password_manager::switches::kEnableManagerForSyncSignin)) | 520 password_manager::switches::kEnableManagerForSyncSignin)) |
567 return true; | 521 return true; |
568 | 522 |
569 // Default is enabled. | 523 // Default is enabled. |
570 std::string group_name = | 524 std::string group_name = |
571 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); | 525 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); |
572 return group_name != "Disabled"; | 526 return group_name != "Disabled"; |
573 } | 527 } |
574 | 528 |
575 void ChromePasswordManagerClient::SetUpAutofillSyncState() { | |
576 std::string group_name = | |
577 base::FieldTrialList::FindFullName("AutofillSyncCredential"); | |
578 | |
579 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
580 if (command_line->HasSwitch( | |
581 password_manager::switches::kAllowAutofillSyncCredential)) { | |
582 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
583 return; | |
584 } | |
585 if (command_line->HasSwitch( | |
586 password_manager::switches:: | |
587 kDisallowAutofillSyncCredentialForReauth)) { | |
588 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
589 return; | |
590 } | |
591 if (command_line->HasSwitch( | |
592 password_manager::switches::kDisallowAutofillSyncCredential)) { | |
593 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
594 return; | |
595 } | |
596 | |
597 if (group_name == "DisallowSyncCredentialsForReauth") { | |
598 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
599 } else if (group_name == "DisallowSyncCredentials") { | |
600 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
601 } else { | |
602 // Allow by default. | |
603 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
604 } | |
605 } | |
606 | |
607 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { | 529 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { |
608 return web_contents()->GetVisibleURL(); | 530 return web_contents()->GetVisibleURL(); |
609 } | 531 } |
| 532 |
| 533 const GURL& ChromePasswordManagerClient::GetLastCommittedEntryURL() const { |
| 534 DCHECK(web_contents()); |
| 535 content::NavigationEntry* entry = |
| 536 web_contents()->GetController().GetLastCommittedEntry(); |
| 537 if (!entry) |
| 538 return GURL::EmptyGURL(); |
| 539 |
| 540 return entry->GetURL(); |
| 541 } |
| 542 |
| 543 scoped_ptr<password_manager::StoreResultFilter> |
| 544 ChromePasswordManagerClient::CreateStoreResultFilter() const { |
| 545 return make_scoped_ptr(new password_manager::SyncStoreResultFilter(this)); |
| 546 } |
OLD | NEW |