Commit cbcd16e9 authored by vasilii's avatar vasilii Committed by Commit bot

Add a global setting for "Auto sign-in".

The setting is used for Credential Manager API.

BUG=400674

Review URL: https://codereview.chromium.org/890943002

Cr-Commit-Position: refs/heads/master@{#314118}
parent 72474e08
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/testing_pref_service.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -15,6 +17,7 @@ ...@@ -15,6 +17,7 @@
#include "components/password_manager/core/browser/stub_password_manager_client.h" #include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "components/password_manager/core/browser/stub_password_manager_driver.h" #include "components/password_manager/core/browser/stub_password_manager_driver.h"
#include "components/password_manager/core/browser/test_password_store.h" #include "components/password_manager/core/browser/test_password_store.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
...@@ -36,14 +39,18 @@ class TestPasswordManagerClient ...@@ -36,14 +39,18 @@ class TestPasswordManagerClient
: did_prompt_user_to_save_(false), : did_prompt_user_to_save_(false),
did_prompt_user_to_choose_(false), did_prompt_user_to_choose_(false),
is_off_the_record_(false), is_off_the_record_(false),
is_zero_click_enabled_(true), store_(store) {
store_(store) {} prefs_.registry()->RegisterBooleanPref(
password_manager::prefs::kPasswordManagerAutoSignin, true);
}
~TestPasswordManagerClient() override {} ~TestPasswordManagerClient() override {}
password_manager::PasswordStore* GetPasswordStore() override { password_manager::PasswordStore* GetPasswordStore() override {
return store_; return store_;
} }
PrefService* GetPrefs() override { return &prefs_; }
bool PromptUserToSavePassword( bool PromptUserToSavePassword(
scoped_ptr<password_manager::PasswordFormManager> manager) override { scoped_ptr<password_manager::PasswordFormManager> manager) override {
did_prompt_user_to_save_ = true; did_prompt_user_to_save_ = true;
...@@ -76,7 +83,6 @@ class TestPasswordManagerClient ...@@ -76,7 +83,6 @@ class TestPasswordManagerClient
} }
bool IsOffTheRecord() override { return is_off_the_record_; } bool IsOffTheRecord() override { return is_off_the_record_; }
bool IsZeroClickEnabled() override { return is_zero_click_enabled_; }
bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; }
bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; }
...@@ -90,14 +96,15 @@ class TestPasswordManagerClient ...@@ -90,14 +96,15 @@ class TestPasswordManagerClient
} }
void set_zero_click_enabled(bool zero_click_enabled) { void set_zero_click_enabled(bool zero_click_enabled) {
is_zero_click_enabled_ = zero_click_enabled; prefs_.SetBoolean(password_manager::prefs::kPasswordManagerAutoSignin,
zero_click_enabled);
} }
private: private:
TestingPrefServiceSimple prefs_;
bool did_prompt_user_to_save_; bool did_prompt_user_to_save_;
bool did_prompt_user_to_choose_; bool did_prompt_user_to_choose_;
bool is_off_the_record_; bool is_off_the_record_;
bool is_zero_click_enabled_;
password_manager::PasswordStore* store_; password_manager::PasswordStore* store_;
scoped_ptr<password_manager::PasswordFormManager> manager_; scoped_ptr<password_manager::PasswordFormManager> manager_;
}; };
...@@ -191,9 +198,9 @@ class CredentialManagerDispatcherTest ...@@ -191,9 +198,9 @@ class CredentialManagerDispatcherTest
autofill::PasswordForm form2_; autofill::PasswordForm form2_;
autofill::PasswordForm cross_origin_form_; autofill::PasswordForm cross_origin_form_;
scoped_refptr<TestPasswordStore> store_; scoped_refptr<TestPasswordStore> store_;
scoped_ptr<CredentialManagerDispatcher> dispatcher_;
scoped_ptr<TestPasswordManagerClient> client_; scoped_ptr<TestPasswordManagerClient> client_;
StubPasswordManagerDriver stub_driver_; StubPasswordManagerDriver stub_driver_;
scoped_ptr<CredentialManagerDispatcher> dispatcher_;
}; };
TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/password_manager/content/common/credential_manager_types.h" #include "components/password_manager/content/common/credential_manager_types.h"
#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_client.h"
#include "components/password_manager/core/browser/password_store.h" #include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
...@@ -43,6 +44,8 @@ CredentialManagerDispatcher::CredentialManagerDispatcher( ...@@ -43,6 +44,8 @@ CredentialManagerDispatcher::CredentialManagerDispatcher(
PasswordManagerClient* client) PasswordManagerClient* client)
: WebContentsObserver(web_contents), client_(client) { : WebContentsObserver(web_contents), client_(client) {
DCHECK(web_contents); DCHECK(web_contents);
auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin,
client_->GetPrefs());
} }
CredentialManagerDispatcher::~CredentialManagerDispatcher() { CredentialManagerDispatcher::~CredentialManagerDispatcher() {
...@@ -203,7 +206,7 @@ bool CredentialManagerDispatcher::IsSavingEnabledForCurrentPage() const { ...@@ -203,7 +206,7 @@ bool CredentialManagerDispatcher::IsSavingEnabledForCurrentPage() const {
} }
bool CredentialManagerDispatcher::IsZeroClickAllowed() const { bool CredentialManagerDispatcher::IsZeroClickAllowed() const {
return !client_->IsOffTheRecord() && client_->IsZeroClickEnabled(); return *auto_signin_enabled_ && !client_->IsOffTheRecord();
} }
base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() { base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/prefs/pref_member.h"
#include "components/password_manager/core/browser/password_store_consumer.h" #include "components/password_manager/core/browser/password_store_consumer.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
...@@ -86,6 +87,9 @@ class CredentialManagerDispatcher : public content::WebContentsObserver, ...@@ -86,6 +87,9 @@ class CredentialManagerDispatcher : public content::WebContentsObserver,
PasswordManagerClient* client_; PasswordManagerClient* client_;
scoped_ptr<CredentialManagerPasswordFormManager> form_manager_; scoped_ptr<CredentialManagerPasswordFormManager> form_manager_;
// Set to false to disable automatic signing in.
BooleanPrefMember auto_signin_enabled_;
// When 'OnRequestCredential' is called, it in turn calls out to the // When 'OnRequestCredential' is called, it in turn calls out to the
// PasswordStore; we store request details here in order to properly // PasswordStore; we store request details here in order to properly
// respond to the request once the PasswordStore gives us data. // respond to the request once the PasswordStore gives us data.
......
...@@ -120,8 +120,10 @@ void PasswordManager::RegisterProfilePrefs( ...@@ -120,8 +120,10 @@ void PasswordManager::RegisterProfilePrefs(
true, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref( registry->RegisterBooleanPref(
prefs::kPasswordManagerAllowShowPasswords, prefs::kPasswordManagerAutoSignin, true,
true, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterBooleanPref(
prefs::kPasswordManagerAllowShowPasswords, true,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterListPref(prefs::kPasswordManagerGroupsForDomains, registry->RegisterListPref(prefs::kPasswordManagerGroupsForDomains,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
......
...@@ -71,10 +71,6 @@ bool PasswordManagerClient::IsOffTheRecord() { ...@@ -71,10 +71,6 @@ bool PasswordManagerClient::IsOffTheRecord() {
return false; return false;
} }
bool PasswordManagerClient::IsZeroClickEnabled() {
return true;
}
PasswordManager* PasswordManagerClient::GetPasswordManager() { PasswordManager* PasswordManagerClient::GetPasswordManager() {
return nullptr; return nullptr;
} }
......
...@@ -163,9 +163,6 @@ class PasswordManagerClient { ...@@ -163,9 +163,6 @@ class PasswordManagerClient {
// Returns the main frame URL. // Returns the main frame URL.
virtual const GURL& GetMainFrameURL(); virtual const GURL& GetMainFrameURL();
// Whether or not "zero-click" sign-in is enabled.
virtual bool IsZeroClickEnabled();
private: private:
DISALLOW_COPY_AND_ASSIGN(PasswordManagerClient); DISALLOW_COPY_AND_ASSIGN(PasswordManagerClient);
}; };
......
...@@ -24,6 +24,8 @@ const char kOsPasswordLastChanged[] = ...@@ -24,6 +24,8 @@ const char kOsPasswordLastChanged[] =
const char kPasswordManagerAllowShowPasswords[] = const char kPasswordManagerAllowShowPasswords[] =
"profile.password_manager_allow_show_passwords"; "profile.password_manager_allow_show_passwords";
const char kPasswordManagerAutoSignin[] =
"profile.password_manager_auto_signin";
const char kPasswordManagerSavingEnabled[] = "profile.password_manager_enabled"; const char kPasswordManagerSavingEnabled[] = "profile.password_manager_enabled";
const char kPasswordManagerGroupsForDomains[] = const char kPasswordManagerGroupsForDomains[] =
"profile.password_manager_groups_for_domains"; "profile.password_manager_groups_for_domains";
......
...@@ -39,6 +39,10 @@ extern const char kOsPasswordLastChanged[]; ...@@ -39,6 +39,10 @@ extern const char kOsPasswordLastChanged[];
// in clear text. // in clear text.
extern const char kPasswordManagerAllowShowPasswords[]; extern const char kPasswordManagerAllowShowPasswords[];
// Boolean controlling whether the password manager allows automatic signing in
// through Credential Manager API.
extern const char kPasswordManagerAutoSignin[];
// Boolean that is true if password saving is on (will record new // Boolean that is true if password saving is on (will record new
// passwords and fill in known passwords). When it is false, it doesn't // passwords and fill in known passwords). When it is false, it doesn't
// ask if you want to save passwords but will continue to fill passwords. // ask if you want to save passwords but will continue to fill passwords.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment