Index: chrome/browser/password_manager/chrome_password_manager_client.cc |
diff --git a/chrome/browser/password_manager/chrome_password_manager_client.cc b/chrome/browser/password_manager/chrome_password_manager_client.cc |
index df029aee357b8dec1ca6818c1e06058f092054f7..f6097f5e9bdee1780fbcadf65c8a0970c79afdd2 100644 |
--- a/chrome/browser/password_manager/chrome_password_manager_client.cc |
+++ b/chrome/browser/password_manager/chrome_password_manager_client.cc |
@@ -8,6 +8,7 @@ |
#include "base/command_line.h" |
#include "base/memory/singleton.h" |
#include "base/metrics/histogram.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/password_manager/password_manager_util.h" |
#include "chrome/browser/password_manager/password_store_factory.h" |
#include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
@@ -33,6 +34,8 @@ |
#include "content/public/browser/navigation_entry.h" |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/web_contents.h" |
+#include "google_apis/gaia/gaia_urls.h" |
+#include "net/base/url_util.h" |
#if defined(OS_ANDROID) |
#include "chrome/browser/android/password_authentication_manager.h" |
@@ -41,6 +44,8 @@ |
using password_manager::PasswordManagerInternalsService; |
using password_manager::PasswordManagerInternalsServiceFactory; |
+namespace pm_switches = password_manager::switches; |
Ilya Sherman
2014/08/13 20:48:14
nit: Please don't use acronyms or abbreviations wh
Garrett Casto
2014/08/13 23:12:54
Changed to switches. I don't normally do this, but
|
+ |
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
// static |
@@ -63,11 +68,13 @@ ChromePasswordManagerClient::ChromePasswordManagerClient( |
driver_(web_contents, this, autofill_client), |
observer_(NULL), |
weak_factory_(this), |
- can_use_log_router_(false) { |
+ can_use_log_router_(false), |
+ autofill_sync_state_(ALLOW_SYNC_CREDENTIALS) { |
PasswordManagerInternalsService* service = |
PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
if (service) |
can_use_log_router_ = service->RegisterClient(this); |
+ SetUpAutofillSyncState(); |
} |
ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
@@ -79,7 +86,7 @@ ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
return CommandLine::ForCurrentProcess()->HasSwitch( |
- password_manager::switches::kEnableAutomaticPasswordSaving) && |
+ pm_switches::kEnableAutomaticPasswordSaving) && |
chrome::VersionInfo::GetChannel() == |
chrome::VersionInfo::CHANNEL_UNKNOWN; |
} |
@@ -102,6 +109,22 @@ bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() |
return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
} |
+bool ChromePasswordManagerClient::ShouldFilterAutofillResult( |
+ const autofill::PasswordForm& form) const { |
+ if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), |
+ form.signon_realm)) |
+ return false; |
+ |
+ if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) |
+ return true; |
+ |
+ if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH && |
+ LastLoadWasTransactionalReauthPage()) |
+ return true; |
+ |
+ return false; |
+} |
+ |
bool ChromePasswordManagerClient::IsSyncAccountCredential( |
const std::string& username, const std::string& origin) const { |
return password_manager_sync_metrics::IsSyncAccountCredential( |
@@ -353,6 +376,24 @@ void ChromePasswordManagerClient::CommitFillPasswordForm( |
driver_.FillPasswordForm(*data); |
} |
+bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const { |
+ DCHECK(web_contents()); |
+ content::NavigationEntry* entry = |
+ web_contents()->GetController().GetLastCommittedEntry(); |
+ if (!entry) |
+ return false; |
+ |
+ if (entry->GetURL().GetOrigin() != |
+ GaiaUrls::GetInstance()->gaia_url().GetOrigin()) |
+ return false; |
+ |
+ // "rart" is the transactional reauth paramter. |
+ std::string ignored_value; |
+ return net::GetValueForKeyInQuery(entry->GetURL(), |
+ "rart", |
+ &ignored_value); |
+} |
+ |
bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
#if !defined(USE_AURA) |
return false; |
@@ -374,11 +415,11 @@ bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
bool ChromePasswordManagerClient::EnabledForSyncSignin() { |
CommandLine* command_line = CommandLine::ForCurrentProcess(); |
if (command_line->HasSwitch( |
- password_manager::switches::kDisableManagerForSyncSignin)) |
+ pm_switches::kDisableManagerForSyncSignin)) |
return false; |
if (command_line->HasSwitch( |
- password_manager::switches::kEnableManagerForSyncSignin)) |
+ pm_switches::kEnableManagerForSyncSignin)) |
return true; |
// Default is enabled. |
@@ -386,3 +427,34 @@ bool ChromePasswordManagerClient::EnabledForSyncSignin() { |
base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); |
return group_name != "Disabled"; |
} |
+ |
+void ChromePasswordManagerClient::SetUpAutofillSyncState() { |
+ std::string group_name = |
+ base::FieldTrialList::FindFullName("AutofillSyncCredential"); |
+ |
+ CommandLine* command_line = CommandLine::ForCurrentProcess(); |
+ if (command_line->HasSwitch( |
+ pm_switches::kAllowAutofillSyncCredential)) { |
+ autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
+ return; |
+ } |
+ if (command_line->HasSwitch( |
+ pm_switches::kDisallowAutofillSyncCredentialForReauth)) { |
+ autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
+ return; |
+ } |
+ if (command_line->HasSwitch( |
+ pm_switches::kDisallowAutofillSyncCredential)) { |
+ autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
+ return; |
+ } |
+ |
+ if (group_name == "DisallowSyncCredentialsForReauth") { |
+ autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
+ } else if (group_name == "DisallowSyncCredentials") { |
+ autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
+ } else { |
+ // Allow by default. |
+ autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
+ } |
+} |