diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-11 18:49:40 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-11 18:49:40 +0000 |
commit | 551c0ffd523786298b5313a50564494afd056745 (patch) | |
tree | 916024ccb7f0edeff9455b6b2d4f1521bf73f8a5 /chrome/browser | |
parent | 4e18aae06487749184fdd752f1dc457cc15e4a96 (diff) | |
download | chromium_src-551c0ffd523786298b5313a50564494afd056745.zip chromium_src-551c0ffd523786298b5313a50564494afd056745.tar.gz chromium_src-551c0ffd523786298b5313a50564494afd056745.tar.bz2 |
Add two AutoFill prefs. autofill.infobar_shown is true if the autofill infobar has been shown to the user. autofill.enabled is true if the user has accepted the autofill confirmation infobar.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/541001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35917 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autofill/autofill_infobar_delegate.cc | 10 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 40 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.h | 10 | ||||
-rw-r--r-- | chrome/browser/browser_prefs.cc | 2 |
4 files changed, 54 insertions, 8 deletions
diff --git a/chrome/browser/autofill/autofill_infobar_delegate.cc b/chrome/browser/autofill/autofill_infobar_delegate.cc index 9333b3a..0263cca 100644 --- a/chrome/browser/autofill/autofill_infobar_delegate.cc +++ b/chrome/browser/autofill/autofill_infobar_delegate.cc @@ -7,7 +7,10 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "chrome/browser/autofill/autofill_manager.h" +#include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -17,8 +20,11 @@ AutoFillInfoBarDelegate::AutoFillInfoBarDelegate(TabContents* tab_contents, AutoFillManager* host) : ConfirmInfoBarDelegate(tab_contents), host_(host) { - if (tab_contents) + if (tab_contents) { + PrefService* prefs = tab_contents->profile()->GetPrefs(); + prefs->SetBoolean(prefs::kAutoFillInfoBarShown, true); tab_contents->AddInfoBar(this); + } } AutoFillInfoBarDelegate::~AutoFillInfoBarDelegate() { @@ -61,7 +67,7 @@ std::wstring AutoFillInfoBarDelegate::GetButtonLabel( bool AutoFillInfoBarDelegate::Accept() { if (host_) { - host_->SaveFormData(); + host_->OnInfoBarAccepted(); host_ = NULL; } return true; diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index 5632d63..4f8001a 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -13,6 +13,8 @@ #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" #include "webkit/glue/form_field_values.h" AutoFillManager::AutoFillManager(TabContents* tab_contents) @@ -24,6 +26,12 @@ AutoFillManager::AutoFillManager(TabContents* tab_contents) AutoFillManager::~AutoFillManager() { } +// static +void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterBooleanPref(prefs::kAutoFillInfoBarShown, false); + prefs->RegisterBooleanPref(prefs::kAutoFillEnabled, false); +} + void AutoFillManager::FormFieldValuesSubmitted( const webkit_glue::FormFieldValues& form) { // TODO(jhawkins): Remove this switch when AutoFill++ is fully implemented. @@ -40,11 +48,15 @@ void AutoFillManager::FormFieldValuesSubmitted( // Determine the possible field types. DeterminePossibleFieldTypes(upload_form_structure_.get()); - if (!personal_data_->ImportFormData(form_structures_, this)) - return; - - // Ask the user for permission to save form information. - infobar_.reset(new AutoFillInfoBarDelegate(tab_contents_, this)); + PrefService* prefs = tab_contents_->profile()->GetPrefs(); + bool autofill_enabled = prefs->GetBoolean(prefs::kAutoFillEnabled); + bool infobar_shown = prefs->GetBoolean(prefs::kAutoFillInfoBarShown); + if (!infobar_shown) { + // Ask the user for permission to save form information. + infobar_.reset(new AutoFillInfoBarDelegate(tab_contents_, this)); + } else if (autofill_enabled) { + HandleSubmit(); + } } void AutoFillManager::DeterminePossibleFieldTypes( @@ -61,9 +73,25 @@ void AutoFillManager::DeterminePossibleFieldTypes( } } -void AutoFillManager::SaveFormData() { +void AutoFillManager::HandleSubmit() { + // If there wasn't enough data to import then we don't want to send an upload + // to the server. + if (!personal_data_->ImportFormData(form_structures_, this)) + return; + UploadFormData(); +} + +void AutoFillManager::OnInfoBarAccepted() { + PrefService* prefs = tab_contents_->profile()->GetPrefs(); + prefs->SetBoolean(prefs::kAutoFillEnabled, true); + // TODO(jhawkins): AutoFillDialog + + HandleSubmit(); +} + +void AutoFillManager::SaveFormData() { // TODO(jhawkins): Save the form data to the web database. } diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index dac7ffd..385c993 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -17,6 +17,7 @@ class FormFieldValues; class AutoFillInfoBarDelegate; class FormStructure; class PersonalDataManager; +class PrefService; class TabContents; // Manages saving and restoring the user's personal information entered into web @@ -26,6 +27,9 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill { explicit AutoFillManager(TabContents* tab_contents); virtual ~AutoFillManager(); + // Registers our Enable/Disable AutoFill pref. + static void RegisterUserPrefs(PrefService* prefs); + // RenderViewHostDelegate::AutoFill implementation. virtual void FormFieldValuesSubmitted( const webkit_glue::FormFieldValues& form); @@ -34,6 +38,12 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill { // types. void DeterminePossibleFieldTypes(FormStructure* form_structure); + // Handles the form data submitted by the user. + void HandleSubmit(); + + // Called by the AutoFillInfoBarDelegate when the user accepts the infobar. + void OnInfoBarAccepted(); + // Saves the form data to the web database. void SaveFormData(); diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 300f762..ced36f5 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -4,6 +4,7 @@ #include "chrome/browser/browser_prefs.h" +#include "chrome/browser/autofill/autofill_manager.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/blocked_popup_container.h" #include "chrome/browser/browser.h" @@ -83,6 +84,7 @@ void RegisterLocalState(PrefService* local_state) { void RegisterUserPrefs(PrefService* user_prefs) { // User prefs + AutoFillManager::RegisterUserPrefs(user_prefs); SessionStartupPref::RegisterUserPrefs(user_prefs); Browser::RegisterUserPrefs(user_prefs); PasswordManager::RegisterUserPrefs(user_prefs); |