Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/password_manager/chrome_password_manager_client.cc

Issue 451853003: [Password Manager] Setup experiment to restrict autofilling of sync credential (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unittest fix Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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),
71 sync_credential_was_filtered_(false) {
67 PasswordManagerInternalsService* service = 72 PasswordManagerInternalsService* service =
68 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); 73 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_);
69 if (service) 74 if (service)
70 can_use_log_router_ = service->RegisterClient(this); 75 can_use_log_router_ = service->RegisterClient(this);
76 SetUpAutofillSyncState();
71 } 77 }
72 78
73 ChromePasswordManagerClient::~ChromePasswordManagerClient() { 79 ChromePasswordManagerClient::~ChromePasswordManagerClient() {
74 PasswordManagerInternalsService* service = 80 PasswordManagerInternalsService* service =
75 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); 81 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_);
76 if (service) 82 if (service)
77 service->UnregisterClient(this); 83 service->UnregisterClient(this);
78 } 84 }
79 85
80 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { 86 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const {
81 return CommandLine::ForCurrentProcess()->HasSwitch( 87 return CommandLine::ForCurrentProcess()->HasSwitch(
82 password_manager::switches::kEnableAutomaticPasswordSaving) && 88 password_manager::switches::kEnableAutomaticPasswordSaving) &&
83 chrome::VersionInfo::GetChannel() == 89 chrome::VersionInfo::GetChannel() ==
84 chrome::VersionInfo::CHANNEL_UNKNOWN; 90 chrome::VersionInfo::CHANNEL_UNKNOWN;
85 } 91 }
86 92
87 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() 93 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage()
88 const { 94 const {
89 if (EnabledForSyncSignin()) 95 if (EnabledForSyncSignin())
90 return true; 96 return true;
91 97
92 DCHECK(web_contents()); 98 DCHECK(web_contents());
93 content::NavigationEntry* entry = 99 content::NavigationEntry* entry =
94 web_contents()->GetController().GetLastCommittedEntry(); 100 web_contents()->GetController().GetLastCommittedEntry();
95 if (!entry) { 101 if (!entry) {
96 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. 102 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here.
97 return true; 103 return true;
98 } 104 }
99 // Do not fill nor save password when a user is signing in for sync. This 105 // 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 106 // is because users need to remember their password if they are syncing as
101 // this is effectively their master password. 107 // this is effectively their master password.
102 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; 108 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost;
103 } 109 }
104 110
111 bool ChromePasswordManagerClient::ShouldFilterAutofillResult(
112 const autofill::PasswordForm& form) {
113 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value),
114 form.signon_realm))
115 return false;
116
117 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) {
118 sync_credential_was_filtered_ = true;
119 return true;
120 }
121
122 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH &&
123 LastLoadWasTransactionalReauthPage()) {
124 sync_credential_was_filtered_ = true;
125 return true;
126 }
127
128 return false;
129 }
130
105 bool ChromePasswordManagerClient::IsSyncAccountCredential( 131 bool ChromePasswordManagerClient::IsSyncAccountCredential(
106 const std::string& username, const std::string& origin) const { 132 const std::string& username, const std::string& origin) const {
107 return password_manager_sync_metrics::IsSyncAccountCredential( 133 return password_manager_sync_metrics::IsSyncAccountCredential(
108 profile_, username, origin); 134 profile_, username, origin);
109 } 135 }
110 136
137 void ChromePasswordManagerClient::AutofillResultsComputed() {
138 UMA_HISTOGRAM_BOOLEAN("PasswordManager.SyncCredentialFiltered",
139 sync_credential_was_filtered_);
140 sync_credential_was_filtered_ = false;
141 }
142
111 void ChromePasswordManagerClient::PromptUserToSavePassword( 143 void ChromePasswordManagerClient::PromptUserToSavePassword(
112 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { 144 scoped_ptr<password_manager::PasswordFormManager> form_to_save) {
113 if (IsTheHotNewBubbleUIEnabled()) { 145 if (IsTheHotNewBubbleUIEnabled()) {
114 ManagePasswordsUIController* manage_passwords_ui_controller = 146 ManagePasswordsUIController* manage_passwords_ui_controller =
115 ManagePasswordsUIController::FromWebContents(web_contents()); 147 ManagePasswordsUIController::FromWebContents(web_contents());
116 manage_passwords_ui_controller->OnPasswordSubmitted(form_to_save.Pass()); 148 manage_passwords_ui_controller->OnPasswordSubmitted(form_to_save.Pass());
117 } else { 149 } else {
118 std::string uma_histogram_suffix( 150 std::string uma_histogram_suffix(
119 password_manager::metrics_util::GroupIdToString( 151 password_manager::metrics_util::GroupIdToString(
120 password_manager::metrics_util::MonitoredDomainGroupId( 152 password_manager::metrics_util::MonitoredDomainGroupId(
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( 378 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState(
347 web_contents()->GetRenderViewHost()->GetRoutingID(), 379 web_contents()->GetRenderViewHost()->GetRoutingID(),
348 can_use_log_router_)); 380 can_use_log_router_));
349 } 381 }
350 382
351 void ChromePasswordManagerClient::CommitFillPasswordForm( 383 void ChromePasswordManagerClient::CommitFillPasswordForm(
352 autofill::PasswordFormFillData* data) { 384 autofill::PasswordFormFillData* data) {
353 driver_.FillPasswordForm(*data); 385 driver_.FillPasswordForm(*data);
354 } 386 }
355 387
388 bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const {
389 DCHECK(web_contents());
390 content::NavigationEntry* entry =
391 web_contents()->GetController().GetLastCommittedEntry();
392 if (!entry)
393 return false;
394
395 if (entry->GetURL().GetOrigin() !=
396 GaiaUrls::GetInstance()->gaia_url().GetOrigin())
397 return false;
398
399 // "rart" is the transactional reauth paramter.
400 std::string ignored_value;
401 return net::GetValueForKeyInQuery(entry->GetURL(),
402 "rart",
403 &ignored_value);
404 }
405
356 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { 406 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() {
357 #if !defined(USE_AURA) 407 #if !defined(USE_AURA)
358 return false; 408 return false;
359 #endif 409 #endif
360 CommandLine* command_line = CommandLine::ForCurrentProcess(); 410 CommandLine* command_line = CommandLine::ForCurrentProcess();
361 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) 411 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble))
362 return false; 412 return false;
363 413
364 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) 414 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble))
365 return true; 415 return true;
(...skipping 13 matching lines...) Expand all
379 429
380 if (command_line->HasSwitch( 430 if (command_line->HasSwitch(
381 password_manager::switches::kEnableManagerForSyncSignin)) 431 password_manager::switches::kEnableManagerForSyncSignin))
382 return true; 432 return true;
383 433
384 // Default is enabled. 434 // Default is enabled.
385 std::string group_name = 435 std::string group_name =
386 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); 436 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin");
387 return group_name != "Disabled"; 437 return group_name != "Disabled";
388 } 438 }
439
440 void ChromePasswordManagerClient::SetUpAutofillSyncState() {
441 std::string group_name =
442 base::FieldTrialList::FindFullName("AutofillSyncCredential");
443
444 CommandLine* command_line = CommandLine::ForCurrentProcess();
445 if (command_line->HasSwitch(
446 password_manager::switches::kAllowAutofillSyncCredential)) {
447 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS;
448 return;
449 }
450 if (command_line->HasSwitch(
451 password_manager::switches::
452 kDisallowAutofillSyncCredentialForReauth)) {
453 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH;
454 return;
455 }
456 if (command_line->HasSwitch(
457 password_manager::switches::kDisallowAutofillSyncCredential)) {
458 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS;
459 return;
460 }
461
462 if (group_name == "DisallowSyncCredentialsForReauth") {
463 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH;
464 } else if (group_name == "DisallowSyncCredentials") {
465 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS;
466 } else {
467 // Allow by default.
468 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS;
469 }
470 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698