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 "content/public/browser/navigation_entry.h" | 44 #include "content/public/browser/navigation_entry.h" |
44 #include "content/public/browser/render_view_host.h" | 45 #include "content/public/browser/render_view_host.h" |
45 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
46 #include "google_apis/gaia/gaia_urls.h" | 47 #include "google_apis/gaia/gaia_urls.h" |
47 #include "net/base/url_util.h" | 48 #include "net/base/url_util.h" |
48 #include "third_party/re2/re2/re2.h" | 49 #include "third_party/re2/re2/re2.h" |
49 | 50 |
50 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
51 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" | 52 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" |
52 #endif | 53 #endif |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 105 |
105 ChromePasswordManagerClient::ChromePasswordManagerClient( | 106 ChromePasswordManagerClient::ChromePasswordManagerClient( |
106 content::WebContents* web_contents, | 107 content::WebContents* web_contents, |
107 autofill::AutofillClient* autofill_client) | 108 autofill::AutofillClient* autofill_client) |
108 : content::WebContentsObserver(web_contents), | 109 : content::WebContentsObserver(web_contents), |
109 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 110 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
110 password_manager_(this), | 111 password_manager_(this), |
111 driver_factory_(nullptr), | 112 driver_factory_(nullptr), |
112 credential_manager_dispatcher_(web_contents, this), | 113 credential_manager_dispatcher_(web_contents, this), |
113 observer_(nullptr), | 114 observer_(nullptr), |
114 can_use_log_router_(false), | 115 can_use_log_router_(false) { |
115 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), | |
116 sync_credential_was_filtered_(false) { | |
117 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 116 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
118 autofill_client); | 117 autofill_client); |
119 driver_factory_ = | 118 driver_factory_ = |
120 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 119 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
121 | 120 |
122 PasswordManagerInternalsService* service = | 121 PasswordManagerInternalsService* service = |
123 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 122 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
124 if (service) | 123 if (service) |
125 can_use_log_router_ = service->RegisterClient(this); | 124 can_use_log_router_ = service->RegisterClient(this); |
126 SetUpAutofillSyncState(); | |
127 saving_passwords_enabled_.Init( | 125 saving_passwords_enabled_.Init( |
128 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); | 126 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); |
129 ReportMetrics(*saving_passwords_enabled_, this); | 127 ReportMetrics(*saving_passwords_enabled_, this); |
130 } | 128 } |
131 | 129 |
132 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 130 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
133 PasswordManagerInternalsService* service = | 131 PasswordManagerInternalsService* service = |
134 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 132 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
135 if (service) | 133 if (service) |
136 service->UnregisterClient(this); | 134 service->UnregisterClient(this); |
(...skipping 34 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::PromptUserToSavePassword( | 190 bool ChromePasswordManagerClient::PromptUserToSavePassword( |
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 // Save password infobar and the password bubble prompts in case of | 193 // Save password infobar and the password bubble prompts in case of |
222 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). | 194 // "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://). |
223 if (!BrowsingDataHelper::IsWebScheme( | 195 if (!BrowsingDataHelper::IsWebScheme( |
224 web_contents()->GetLastCommittedURL().scheme())) { | 196 web_contents()->GetLastCommittedURL().scheme())) { |
225 return false; | 197 return false; |
226 } | 198 } |
227 | 199 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 446 |
475 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 447 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
476 if (!web_contents()) | 448 if (!web_contents()) |
477 return; | 449 return; |
478 | 450 |
479 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 451 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
480 web_contents()->GetRenderViewHost()->GetRoutingID(), | 452 web_contents()->GetRenderViewHost()->GetRoutingID(), |
481 can_use_log_router_)); | 453 can_use_log_router_)); |
482 } | 454 } |
483 | 455 |
484 bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const { | |
485 DCHECK(web_contents()); | |
486 content::NavigationEntry* entry = | |
487 web_contents()->GetController().GetLastCommittedEntry(); | |
488 if (!entry) | |
489 return false; | |
490 | |
491 if (entry->GetURL().GetOrigin() != | |
492 GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | |
493 return false; | |
494 | |
495 // "rart" is the transactional reauth paramter. | |
496 std::string ignored_value; | |
497 return net::GetValueForKeyInQuery(entry->GetURL(), | |
498 "rart", | |
499 &ignored_value); | |
500 } | |
501 | |
502 bool ChromePasswordManagerClient::IsURLPasswordWebsiteReauth( | 456 bool ChromePasswordManagerClient::IsURLPasswordWebsiteReauth( |
503 const GURL& url) const { | 457 const GURL& url) const { |
504 if (url.GetOrigin() != GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | 458 if (url.GetOrigin() != GaiaUrls::GetInstance()->gaia_url().GetOrigin()) |
505 return false; | 459 return false; |
506 | 460 |
507 // "rart" param signals this page is for transactional reauth. | 461 // "rart" param signals this page is for transactional reauth. |
508 std::string param_value; | 462 std::string param_value; |
509 if (!net::GetValueForKeyInQuery(url, "rart", ¶m_value)) | 463 if (!net::GetValueForKeyInQuery(url, "rart", ¶m_value)) |
510 return false; | 464 return false; |
511 | 465 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (command_line->HasSwitch( | 503 if (command_line->HasSwitch( |
550 password_manager::switches::kEnableManagerForSyncSignin)) | 504 password_manager::switches::kEnableManagerForSyncSignin)) |
551 return true; | 505 return true; |
552 | 506 |
553 // Default is enabled. | 507 // Default is enabled. |
554 std::string group_name = | 508 std::string group_name = |
555 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); | 509 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); |
556 return group_name != "Disabled"; | 510 return group_name != "Disabled"; |
557 } | 511 } |
558 | 512 |
559 void ChromePasswordManagerClient::SetUpAutofillSyncState() { | |
560 std::string group_name = | |
561 base::FieldTrialList::FindFullName("AutofillSyncCredential"); | |
562 | |
563 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
564 if (command_line->HasSwitch( | |
565 password_manager::switches::kAllowAutofillSyncCredential)) { | |
566 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
567 return; | |
568 } | |
569 if (command_line->HasSwitch( | |
570 password_manager::switches:: | |
571 kDisallowAutofillSyncCredentialForReauth)) { | |
572 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
573 return; | |
574 } | |
575 if (command_line->HasSwitch( | |
576 password_manager::switches::kDisallowAutofillSyncCredential)) { | |
577 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
578 return; | |
579 } | |
580 | |
581 if (group_name == "DisallowSyncCredentialsForReauth") { | |
582 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
583 } else if (group_name == "DisallowSyncCredentials") { | |
584 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
585 } else { | |
586 // Allow by default. | |
587 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
588 } | |
589 } | |
590 | |
591 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { | 513 const GURL& ChromePasswordManagerClient::GetMainFrameURL() const { |
592 return web_contents()->GetVisibleURL(); | 514 return web_contents()->GetVisibleURL(); |
593 } | 515 } |
| 516 |
| 517 const GURL& ChromePasswordManagerClient::GetLastCommittedEntryURL() const { |
| 518 DCHECK(web_contents()); |
| 519 content::NavigationEntry* entry = |
| 520 web_contents()->GetController().GetLastCommittedEntry(); |
| 521 if (!entry) |
| 522 return GURL::EmptyGURL(); |
| 523 |
| 524 return entry->GetURL(); |
| 525 } |
| 526 |
| 527 scoped_ptr<password_manager::StoreResultFilter> |
| 528 ChromePasswordManagerClient::CreateStoreResultFilter() const { |
| 529 return make_scoped_ptr(new password_manager::SyncStoreResultFilter(this)); |
| 530 } |
OLD | NEW |