summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-25 08:32:55 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-25 08:32:55 +0000
commit0f403b49c078588b57ba52d11e256850349ef5fc (patch)
treea2c8b436bfd59a64e08527211077f7aeaad7a06a /chrome/browser/autofill
parentd71c0d83f0e893de9b4ef707dcaaf3b766816122 (diff)
downloadchromium_src-0f403b49c078588b57ba52d11e256850349ef5fc.zip
chromium_src-0f403b49c078588b57ba52d11e256850349ef5fc.tar.gz
chromium_src-0f403b49c078588b57ba52d11e256850349ef5fc.tar.bz2
Implement policy for disabling auto fill.
This introduces a new policy setting named AutoFillEnabled that administrators can use to switch off the auto fill feature. The UI adjustments disable the autofill button and dialog in the preferences dialog appropriate. Preferences.xib change: Bind enabled state of the auto fill button to autoFillSettingsButtonEnabled @property. AutoFillDialog.xib change: Bind enabled state of the auto fill enabled checkbox and save button to the autoFillEnabledAvailable and saveEnabled @properties, respectively. BUG=49611 TEST=autofill_dialog_controller_mac_unittest.mm, manual testing Review URL: http://codereview.chromium.org/3140024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57302 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac.h25
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac.mm64
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm65
-rw-r--r--chrome/browser/autofill/autofill_dialog_gtk.cc4
4 files changed, 149 insertions, 9 deletions
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.h b/chrome/browser/autofill/autofill_dialog_controller_mac.h
index 3b17c24..d311084 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac.h
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac.h
@@ -15,9 +15,11 @@
#include "chrome/browser/autofill/autofill_dialog.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
+#include "chrome/browser/pref_member.h"
namespace AutoFillDialogControllerInternal {
class PersonalDataManagerObserver;
+class PrefObserver;
} // AutoFillDialogControllerInternal
@class AutoFillAddressSheetController;
@@ -26,7 +28,7 @@ class PersonalDataManagerObserver;
class Profile;
@class WindowSizeAutosaver;
-// A window controller for managing the autofill options dialog.
+// A window controller for managing the AutoFill options dialog.
// Application modally presents a dialog allowing the user to store
// personal address and credit card information.
@interface AutoFillDialogController : NSWindowController <NSTableViewDelegate> {
@@ -62,9 +64,18 @@ class Profile;
// Working list of input credit cards.
std::vector<CreditCard> creditCards_;
+ // Tracks the AutoFill enabled preference.
+ BooleanPrefMember prefAutoFillEnabled_;
+
// State of checkbox for enabling AutoFill in general.
BOOL autoFillEnabled_;
+ // Whether AutoFill is controlled by configuration management.
+ BOOL autoFillManaged_;
+
+ // Whether AutoFill is managed and disabled.
+ BOOL autoFillManagedAndDisabled_;
+
// State of checkbox for enabling Mac Address Book integration.
BOOL auxiliaryEnabled_;
@@ -90,6 +101,9 @@ class Profile;
// Manages PersonalDataManager loading.
scoped_ptr<AutoFillDialogControllerInternal::PersonalDataManagerObserver>
personalDataManagerObserver_;
+
+ // Watches for changes to the AutoFill enabled preference.
+ scoped_ptr<AutoFillDialogControllerInternal::PrefObserver> prefObserver_;
}
// Property representing state of the AutoFill enabled preference. Checkbox is
@@ -97,6 +111,15 @@ class Profile;
// to this property.
@property (nonatomic) BOOL autoFillEnabled;
+// Property indicating whether AutoFill is under control of configuration
+// management. The enabled state of the AutoFill enabled checkbox is bound to
+// this property.
+@property (nonatomic) BOOL autoFillManaged;
+
+// Property that is true iff AutoFill is managed and disabled. The save button's
+// enabled state is bound to this property.
+@property (nonatomic) BOOL autoFillManagedAndDisabled;
+
// Property representing state of Address Book "me" card usage. Checkbox is
// bound to this in nib.
@property (nonatomic) BOOL auxiliaryEnabled;
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
index fe28c53..44405c0 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
@@ -18,6 +18,8 @@
#import "chrome/browser/cocoa/window_size_autosaver.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_observer.h"
#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"
#include "grit/app_resources.h"
@@ -85,6 +87,10 @@ void UpdateProfileLabels(std::vector<AutoFillProfile>* input) {
- (void)onPersonalDataLoaded:(const std::vector<AutoFillProfile*>&)profiles
creditCards:(const std::vector<CreditCard*>&)creditCards;
+// Called upon changes to AutoFill preferences that should be reflected in the
+// UI.
+- (void)onPrefChanged:(const std::string&)prefName;
+
// Returns true if |row| is an index to a valid profile in |tableView_|, and
// false otherwise.
- (BOOL)isProfileRow:(NSInteger)row;
@@ -184,11 +190,37 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
creditCards:personal_data_manager_->credit_cards()];
}
+// Bridges preference changed notifications to the dialog controller.
+class PrefObserver : public NotificationObserver {
+ public:
+ explicit PrefObserver(AutoFillDialogController* controller)
+ : controller_(controller) {}
+
+ // Overridden from NotificationObserver:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::PREF_CHANGED) {
+ const std::string* pref = Details<std::string>(details).ptr();
+ if (pref) {
+ [controller_ onPrefChanged:*pref];
+ }
+ }
+ }
+
+ private:
+ AutoFillDialogController* controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefObserver);
+};
+
} // namespace AutoFillDialogControllerInternal
@implementation AutoFillDialogController
@synthesize autoFillEnabled = autoFillEnabled_;
+@synthesize autoFillManaged = autoFillManaged_;
+@synthesize autoFillManagedAndDisabled = autoFillManagedAndDisabled_;
@synthesize auxiliaryEnabled = auxiliaryEnabled_;
@synthesize itemIsSelected = itemIsSelected_;
@synthesize multipleSelected = multipleSelected_;
@@ -245,9 +277,10 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
// Called when the user clicks the save button.
- (IBAction)save:(id)sender {
- // If we have an |observer_| then communicate the changes back.
- if (observer_) {
- profile_->GetPrefs()->SetBoolean(prefs::kAutoFillEnabled, autoFillEnabled_);
+ // If we have an |observer_| then communicate the changes back, unless
+ // AutoFill has been disabled through policy in the mean time.
+ if (observer_ && !autoFillManagedAndDisabled_) {
+ prefAutoFillEnabled_.SetValueIfNotManaged(autoFillEnabled_);
profile_->GetPrefs()->SetBoolean(prefs::kAutoFillAuxiliaryProfilesEnabled,
auxiliaryEnabled_);
observer_->OnAutoFillDialogApply(&profiles_, &creditCards_);
@@ -631,7 +664,7 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
// This is the designated initializer for this class.
-// |profiles| are non-retained immutable list of autofill profiles.
+// |profiles| are non-retained immutable list of AutoFill profiles.
// |creditCards| are non-retained immutable list of credit card info.
- (id)initWithObserver:(AutoFillDialogObserver*)observer
profile:(Profile*)profile
@@ -650,9 +683,15 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
importedProfile_ = importedProfile;
importedCreditCard_ = importedCreditCard;
- // Use property here to trigger KVO binding.
- [self setAutoFillEnabled:profile_->GetPrefs()->GetBoolean(
- prefs::kAutoFillEnabled)];
+ // Initialize the preference observer and watch kAutoFillEnabled.
+ prefObserver_.reset(
+ new AutoFillDialogControllerInternal::PrefObserver(self));
+ prefAutoFillEnabled_.Init(prefs::kAutoFillEnabled, profile_->GetPrefs(),
+ prefObserver_.get());
+
+ // Call onPrefChanged in order to initialize UI state of the checkbox and
+ // save button.
+ [self onPrefChanged:prefs::kAutoFillEnabled];
// Use property here to trigger KVO binding.
[self setAuxiliaryEnabled:profile_->GetPrefs()->GetBoolean(
@@ -750,6 +789,17 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
UpdateProfileLabels(&profiles_);
}
+- (void)onPrefChanged:(const std::string&)prefName {
+ if (prefName == prefs::kAutoFillEnabled) {
+ [self setAutoFillEnabled:prefAutoFillEnabled_.GetValue()];
+ [self setAutoFillManaged:prefAutoFillEnabled_.IsManaged()];
+ [self setAutoFillManagedAndDisabled:
+ prefAutoFillEnabled_.IsManaged() && !prefAutoFillEnabled_.GetValue()];
+ } else {
+ NOTREACHED();
+ }
+}
+
- (BOOL)isProfileRow:(NSInteger)row {
if (row > 0 && static_cast<size_t>(row) <= profiles_.size())
return YES;
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
index 4509e68..6263102 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
@@ -4,6 +4,7 @@
#include "base/ref_counted.h"
#include "base/utf_string_conversions.h"
+#include "base/values.h"
#import "chrome/browser/autofill/autofill_address_model_mac.h"
#import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h"
#import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
@@ -16,6 +17,7 @@
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -767,4 +769,67 @@ TEST_F(AutoFillDialogControllerTest, AutoFillEnabledChanged) {
prefs::kAutoFillEnabled));
}
+TEST_F(AutoFillDialogControllerTest, PolicyRefresh) {
+ LoadDialog();
+ ASSERT_FALSE([controller_ autoFillManaged]);
+
+ // Disable AutoFill through configuration policy.
+ helper_.profile()->GetTestingPrefService()->SetManagedPref(
+ prefs::kAutoFillEnabled, Value::CreateBooleanValue(false));
+ ASSERT_TRUE([controller_ autoFillManaged]);
+ ASSERT_FALSE([controller_ autoFillEnabled]);
+
+ // Enabling through policy should switch to enabled but not editable.
+ helper_.profile()->GetTestingPrefService()->SetManagedPref(
+ prefs::kAutoFillEnabled, Value::CreateBooleanValue(true));
+ ASSERT_TRUE([controller_ autoFillManaged]);
+ ASSERT_TRUE([controller_ autoFillEnabled]);
+
+ [controller_ cancel:nil];
+}
+
+TEST_F(AutoFillDialogControllerTest, PolicyDisabledAndSave) {
+ // Disable AutoFill through configuration policy.
+ helper_.profile()->GetTestingPrefService()->SetManagedPref(
+ prefs::kAutoFillEnabled, Value::CreateBooleanValue(false));
+ helper_.profile()->GetPrefs()->SetBoolean(
+ prefs::kAutoFillAuxiliaryProfilesEnabled, false);
+ LoadDialog();
+
+ // Save should be disabled.
+ ASSERT_TRUE([controller_ autoFillManagedAndDisabled]);
+
+ [controller_ setAuxiliaryEnabled:YES];
+ [controller_ save:nil];
+
+ // Observer should not have been called.
+ ASSERT_FALSE(observer_.hit_);
+
+ // Auxiliary profiles setting should be unchanged.
+ ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean(
+ prefs::kAutoFillAuxiliaryProfilesEnabled));
+}
+
+TEST_F(AutoFillDialogControllerTest, PolicyEnabledAndSave) {
+ // Enable AutoFill through configuration policy.
+ helper_.profile()->GetTestingPrefService()->SetManagedPref(
+ prefs::kAutoFillEnabled, Value::CreateBooleanValue(true));
+ helper_.profile()->GetPrefs()->SetBoolean(
+ prefs::kAutoFillAuxiliaryProfilesEnabled, false);
+ LoadDialog();
+
+ // Save should be enabled.
+ ASSERT_FALSE([controller_ autoFillManagedAndDisabled]);
+
+ [controller_ setAuxiliaryEnabled:YES];
+ [controller_ save:nil];
+
+ // Observer should have been notified.
+ ASSERT_TRUE(observer_.hit_);
+
+ // Auxiliary profiles setting should have been saved.
+ ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean(
+ prefs::kAutoFillAuxiliaryProfilesEnabled));
+}
+
} // namespace
diff --git a/chrome/browser/autofill/autofill_dialog_gtk.cc b/chrome/browser/autofill/autofill_dialog_gtk.cc
index cc383d8..624f36b 100644
--- a/chrome/browser/autofill/autofill_dialog_gtk.cc
+++ b/chrome/browser/autofill/autofill_dialog_gtk.cc
@@ -273,7 +273,7 @@ void AutoFillDialog::OnAutoFillCheckToggled(GtkWidget* widget) {
UserMetrics::RecordAction(UserMetricsAction("Options_FormAutofill_Disable"),
profile_);
}
- enable_form_autofill_.SetValue(enabled);
+ enable_form_autofill_.SetValueIfNotManaged(enabled);
profile_->GetPrefs()->ScheduleSavePersistentPrefs();
UpdateWidgetState();
}
@@ -546,6 +546,8 @@ void AutoFillDialog::InitializeWidgets() {
}
void AutoFillDialog::UpdateWidgetState() {
+ gtk_widget_set_sensitive(form_autofill_enable_check_,
+ !enable_form_autofill_.IsManaged());
if (!personal_data_->IsDataLoaded() || !enable_form_autofill_.GetValue()) {
gtk_widget_set_sensitive(add_address_button_, FALSE);
gtk_widget_set_sensitive(add_credit_card_button_, FALSE);