diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-29 18:51:39 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-29 18:51:39 +0000 |
commit | 365b0c66be25d8dfbc325a9ddf756e00a6e1b81f (patch) | |
tree | bb0c0de5cc77d4d622394a1073d9e33c2bc3df92 /chrome/browser/cocoa | |
parent | 931e016f4fa0d1fefb5c1380f32230262f0e1cd2 (diff) | |
download | chromium_src-365b0c66be25d8dfbc325a9ddf756e00a6e1b81f.zip chromium_src-365b0c66be25d8dfbc325a9ddf756e00a6e1b81f.tar.gz chromium_src-365b0c66be25d8dfbc325a9ddf756e00a6e1b81f.tar.bz2 |
Mac: Disable UI elements in the content settings dialog if the controls are managed.
This disables the radio buttons and the exceptions button in the first 5 tabs (cookies, images, javascript, plugins, popups), and the "block 3rd party cookies" checkbox in the cookies tab.
xib change: Hook up the "enabled" bindings of the buttons / radio buttons / checkbox to the new functions. (The cookie radio group's enabled state and exceptions button's enabled state is now bound to cookieSettingsManaged with a NSNegateBoolean value transformer. Likewise for images, javascript, plugins, popups.)
BUG=63181
TEST=none
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=67560
Review URL: http://codereview.chromium.org/5205008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67569 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/content_settings_dialog_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/cocoa/content_settings_dialog_controller.mm | 92 |
2 files changed, 86 insertions, 13 deletions
diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.h b/chrome/browser/cocoa/content_settings_dialog_controller.h index 40e9a04..432a3dc 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.h +++ b/chrome/browser/cocoa/content_settings_dialog_controller.h @@ -92,4 +92,11 @@ class Profile; @property(nonatomic) NSInteger pluginsEnabledIndex; @property(nonatomic) NSInteger geolocationSettingIndex; @property(nonatomic) NSInteger notificationsSettingIndex; + +@property(nonatomic, readonly) BOOL blockThirdPartyCookiesManaged; +@property(nonatomic, readonly) BOOL cookieSettingsManaged; +@property(nonatomic, readonly) BOOL imagesSettingsManaged; +@property(nonatomic, readonly) BOOL javaScriptSettingsManaged; +@property(nonatomic, readonly) BOOL pluginsSettingsManaged; +@property(nonatomic, readonly) BOOL popupsSettingsManaged; @end diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm index 5503f74..5126647 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller.mm @@ -46,7 +46,11 @@ ContentSettingsDialogController* g_instance = nil; // Callback when preferences are changed. |prefName| is the name of the // pref that has changed. -- (void)prefChanged:(std::string*)prefName; +- (void)prefChanged:(const std::string&)prefName; + +// Callback when content settings are changed. +- (void)contentSettingsChanged: + (HostContentSettingsMap::ContentSettingsDetails*)details; @end @@ -63,8 +67,22 @@ class PrefObserverBridge : public NotificationObserver { virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (!disabled_ && type == NotificationType::PREF_CHANGED) { - [controller_ prefChanged:Details<std::string>(details).ptr()]; + if (disabled_) + return; + + // This is currently used by most notifications. + if (type == NotificationType::PREF_CHANGED) { + std::string* detail = Details<std::string>(details).ptr(); + if (detail) + [controller_ prefChanged:*detail]; + } + + // This is sent when the "is managed" state changes. + // TODO(markusheintz): Move all content settings to this notification. + if (type == NotificationType::CONTENT_SETTINGS_CHANGED) { + HostContentSettingsMap::ContentSettingsDetails* settings_details = + Details<HostContentSettingsMap::ContentSettingsDetails>(details).ptr(); + [controller_ contentSettingsChanged:settings_details]; } } @@ -78,7 +96,7 @@ class PrefObserverBridge : public NotificationObserver { }; // A C++ utility class to disable notifications for PrefsObserverBridge. -// The intended usage is to create on the stack. +// The intended usage is to create this on the stack. class PrefObserverDisabler { public: PrefObserverDisabler(PrefObserverBridge *bridge) : bridge_(bridge) { @@ -266,6 +284,11 @@ class PrefObserverDisabler { } } +- (BOOL)cookieSettingsManaged { + return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( + CONTENT_SETTINGS_TYPE_COOKIES); +} + - (BOOL)blockThirdPartyCookies { HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); return settingsMap->BlockThirdPartyCookies(); @@ -278,6 +301,11 @@ class PrefObserverDisabler { settingsMap->SetBlockThirdPartyCookies(value); } +- (BOOL)blockThirdPartyCookiesManaged { + HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); + return settingsMap->IsBlockThirdPartyCookiesManaged(); +} + - (BOOL)clearSiteDataOnExit { return clearSiteDataOnExit_.GetValue(); } @@ -405,6 +433,11 @@ class PrefObserverDisabler { return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; } +- (BOOL)imagesSettingsManaged { + return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( + CONTENT_SETTINGS_TYPE_IMAGES); +} + - (void)setJavaScriptEnabledIndex:(NSInteger)value { ContentSetting setting = value == kContentSettingsEnabledIndex ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; @@ -422,6 +455,11 @@ class PrefObserverDisabler { return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; } +- (BOOL)javaScriptSettingsManaged { + return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( + CONTENT_SETTINGS_TYPE_JAVASCRIPT); +} + - (void)setPluginsEnabledIndex:(NSInteger)value { ContentSetting setting = CONTENT_SETTING_DEFAULT; switch (value) { @@ -463,6 +501,11 @@ class PrefObserverDisabler { } } +- (BOOL)pluginsSettingsManaged { + return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( + CONTENT_SETTINGS_TYPE_PLUGINS); +} + - (void)setPopupsEnabledIndex:(NSInteger)value { ContentSetting setting = value == kContentSettingsEnabledIndex ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; @@ -480,6 +523,11 @@ class PrefObserverDisabler { return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; } +- (BOOL)popupsSettingsManaged { + return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( + CONTENT_SETTINGS_TYPE_POPUPS); +} + - (void)setGeolocationSettingIndex:(NSInteger)value { ContentSetting setting = CONTENT_SETTING_DEFAULT; switch (value) { @@ -538,22 +586,22 @@ class PrefObserverDisabler { // Callback when preferences are changed. |prefName| is the name of the // pref that has changed and should not be NULL. -- (void)prefChanged:(std::string*)prefName { - DCHECK(prefName); - if (!prefName) return; - if (*prefName == prefs::kClearSiteDataOnExit) { +- (void)prefChanged:(const std::string&)prefName { + if (prefName == prefs::kClearSiteDataOnExit) { [self willChangeValueForKey:@"clearSiteDataOnExit"]; [self didChangeValueForKey:@"clearSiteDataOnExit"]; } - if (*prefName == prefs::kBlockThirdPartyCookies) { + if (prefName == prefs::kBlockThirdPartyCookies) { [self willChangeValueForKey:@"blockThirdPartyCookies"]; [self didChangeValueForKey:@"blockThirdPartyCookies"]; + [self willChangeValueForKey:@"blockThirdPartyCookiesManaged"]; + [self didChangeValueForKey:@"blockThirdPartyCookiesManaged"]; } - if (*prefName == prefs::kBlockNonsandboxedPlugins) { + if (prefName == prefs::kBlockNonsandboxedPlugins) { [self willChangeValueForKey:@"pluginsEnabledIndex"]; [self didChangeValueForKey:@"pluginsEnabledIndex"]; } - if (*prefName == prefs::kDefaultContentSettings) { + if (prefName == prefs::kDefaultContentSettings) { // We don't know exactly which setting has changed, so we'll tickle all // of the properties that apply to kDefaultContentSettings. This will // keep the UI up-to-date. @@ -567,15 +615,33 @@ class PrefObserverDisabler { [self didChangeValueForKey:@"pluginsEnabledIndex"]; [self willChangeValueForKey:@"popupsEnabledIndex"]; [self didChangeValueForKey:@"popupsEnabledIndex"]; + + // Updates the "Enable" state of the radio groups and the exception buttons. + [self willChangeValueForKey:@"cookieSettingsManaged"]; + [self didChangeValueForKey:@"cookieSettingsManaged"]; + [self willChangeValueForKey:@"imagesSettingsManaged"]; + [self didChangeValueForKey:@"imagesSettingsManaged"]; + [self willChangeValueForKey:@"javaScriptSettingsManaged"]; + [self didChangeValueForKey:@"javaScriptSettingsManaged"]; + [self willChangeValueForKey:@"pluginsSettingsManaged"]; + [self didChangeValueForKey:@"pluginsSettingsManaged"]; + [self willChangeValueForKey:@"popupsSettingsManaged"]; + [self didChangeValueForKey:@"popupsSettingsManaged"]; } - if (*prefName == prefs::kGeolocationDefaultContentSetting) { + if (prefName == prefs::kGeolocationDefaultContentSetting) { [self willChangeValueForKey:@"geolocationSettingIndex"]; [self didChangeValueForKey:@"geolocationSettingIndex"]; } - if (*prefName == prefs::kDesktopNotificationDefaultContentSetting) { + if (prefName == prefs::kDesktopNotificationDefaultContentSetting) { [self willChangeValueForKey:@"notificationsSettingIndex"]; [self didChangeValueForKey:@"notificationsSettingIndex"]; } } +- (void)contentSettingsChanged: + (HostContentSettingsMap::ContentSettingsDetails*)details { + [self prefChanged:prefs::kBlockNonsandboxedPlugins]; + [self prefChanged:prefs::kDefaultContentSettings]; +} + @end |