summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordubroy@chromium.org <dubroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-20 09:25:54 +0000
committerdubroy@chromium.org <dubroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-20 09:25:54 +0000
commit526b34fa1a9a9b32041f31d23f927a0a04c06e7a (patch)
tree786a4189e569a1f0e0225c89c5c858f2baed2931
parent44533b693adbc1c5e3f11d91391461317950fa07 (diff)
downloadchromium_src-526b34fa1a9a9b32041f31d23f927a0a04c06e7a.zip
chromium_src-526b34fa1a9a9b32041f31d23f927a0a04c06e7a.tar.gz
chromium_src-526b34fa1a9a9b32041f31d23f927a0a04c06e7a.tar.bz2
[Mac] Website settings: Update the content settings when the menu selection is changed.
BUG=135407 TEST=WebsiteSettingsBubbleControllerTest in unit_tests. Review URL: https://chromiumcodereview.appspot.com/10803005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147629 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/cocoa/website_settings_bubble_controller.h2
-rw-r--r--chrome/browser/ui/cocoa/website_settings_bubble_controller.mm94
-rw-r--r--chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm34
3 files changed, 110 insertions, 20 deletions
diff --git a/chrome/browser/ui/cocoa/website_settings_bubble_controller.h b/chrome/browser/ui/cocoa/website_settings_bubble_controller.h
index 46950d7..400bc7b 100644
--- a/chrome/browser/ui/cocoa/website_settings_bubble_controller.h
+++ b/chrome/browser/ui/cocoa/website_settings_bubble_controller.h
@@ -55,6 +55,8 @@ class WebsiteSettingsUIBridge;
- (id)initWithParentWindow:(NSWindow*)parentWindow
websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge;
+- (void)permissionValueChanged:(id)sender;
+
@end
// Provides a bridge between the WebSettingsUI C++ interface and the Cocoa
diff --git a/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm b/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm
index bba9fd2..22cf074 100644
--- a/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm
+++ b/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm
@@ -53,6 +53,14 @@ const CGFloat kTabViewContentsPadding = kFramePadding;
// The spacing between individual items in the Permissions tab.
const CGFloat kPermissionsTabSpacing = 8;
+// In the permission changing menu, the order of the menu items (which
+// correspond to different content settings).
+const ContentSetting kPermissionsMenuSettings[] = {
+ CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_BLOCK,
+ CONTENT_SETTING_DEFAULT
+};
+
} // namespace
// A simple container to hold all the contents of the website settings bubble.
@@ -384,6 +392,35 @@ const CGFloat kPermissionsTabSpacing = 8;
return spacer;
}
+// Sets the button title appropriately based on the current setting and the
+// default setting.
+- (void)setTitleOfButton:(NSPopUpButton*)button {
+ ContentSetting setting = [self contentSettingForButton:button];
+
+ // All menu items are tagged with the default setting.
+ ContentSetting defaultSetting = static_cast<ContentSetting>(
+ [[button selectedItem] tag]);
+
+ // Update the title to match the current permission setting.
+ scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]);
+ [titleItem setTitle:base::SysUTF16ToNSString(
+ WebsiteSettingsUI::PermissionActionToUIString(setting,
+ defaultSetting))];
+ [[button cell] setUsesItemFromMenu:NO];
+ [[button cell] setMenuItem:titleItem.get()];
+ [button sizeToFit];
+}
+
+- (ContentSetting)contentSettingForButton:(NSPopUpButton*)button {
+ // Determine the setting based on the index of the selected menu item.
+ NSUInteger buttonIndex = [button indexOfSelectedItem];
+ if (buttonIndex >= arraysize(kPermissionsMenuSettings)) {
+ NOTREACHED();
+ return CONTENT_SETTING_DEFAULT;
+ }
+ return kPermissionsMenuSettings[buttonIndex];
+}
+
// Add a pop-up button for |permissionInfo| to the given view.
- (NSPopUpButton*)addPopUpButtonForPermission:
(const WebsiteSettingsUI::PermissionInfo&)permissionInfo
@@ -400,31 +437,50 @@ const CGFloat kPermissionsTabSpacing = 8;
[button setShowsBorderOnlyWhileMouseInside:YES];
[[button cell] setHighlightsBy:NSCellLightsByGray];
- // Set the button title.
- [[button cell] setUsesItemFromMenu:NO];
- scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]);
- [titleItem setTitle:base::SysUTF16ToNSString(
- WebsiteSettingsUI::PermissionActionToUIString(
- permissionInfo.setting, permissionInfo.default_setting))];
- [[button cell] setMenuItem:titleItem.get()];
- [button sizeToFit];
-
// Create the popup menu.
- [button addItemWithTitle:l10n_util::GetNSStringF(
- IDS_WEBSITE_SETTINGS_PERMISSION_LABEL,
- WebsiteSettingsUI::PermissionValueToUIString(CONTENT_SETTING_ALLOW))];
- [button addItemWithTitle:l10n_util::GetNSStringF(
- IDS_WEBSITE_SETTINGS_PERMISSION_LABEL,
- WebsiteSettingsUI::PermissionValueToUIString(CONTENT_SETTING_BLOCK))];
- [button addItemWithTitle:l10n_util::GetNSStringF(
- IDS_WEBSITE_SETTINGS_DEFAULT_PERMISSION_LABEL,
- WebsiteSettingsUI::PermissionValueToUIString(
- permissionInfo.default_setting))];
+ for (unsigned int i = 0; i < arraysize(kPermissionsMenuSettings); ++i) {
+ ContentSetting setting = kPermissionsMenuSettings[i];
+ if (setting == CONTENT_SETTING_DEFAULT) {
+ [button addItemWithTitle:l10n_util::GetNSStringF(
+ IDS_WEBSITE_SETTINGS_DEFAULT_PERMISSION_LABEL,
+ WebsiteSettingsUI::PermissionValueToUIString(
+ permissionInfo.default_setting))];
+ } else {
+ [button addItemWithTitle:l10n_util::GetNSStringF(
+ IDS_WEBSITE_SETTINGS_PERMISSION_LABEL,
+ WebsiteSettingsUI::PermissionValueToUIString(setting))];
+ }
+ // Tag all of the menu items with the default setting. It's required to
+ // generate the button title (e.g. "Allowed by default").
+ [[button lastItem] setTag:permissionInfo.default_setting];
+
+ // Select the item corresponding to the current setting.
+ if (setting == permissionInfo.setting)
+ [button selectItem:[button lastItem]];
+ }
+ [button setTag:permissionInfo.type];
+
+ [button setAction:@selector(permissionValueChanged:)];
+ [button setTarget:self];
+
+ [self setTitleOfButton:button];
[view addSubview:button.get()];
return button.get();
}
+// Handler for the permission-changing menus.
+- (void)permissionValueChanged:(id)sender {
+ DCHECK([sender isKindOfClass:[NSPopUpButton class]]);
+ NSPopUpButton* button = static_cast<NSPopUpButton*>(sender);
+ ContentSettingsType type = static_cast<ContentSettingsType>([button tag]);
+ ContentSetting newSetting = [self contentSettingForButton:button];
+
+ [self setTitleOfButton:button];
+ if (presenter_.get())
+ presenter_->OnSitePermissionChanged(type, newSetting);
+}
+
// Adds a new row to the UI listing the permissions. Returns the amount of
// vertical space that was taken up by the row.
- (CGFloat)addPermission:
diff --git a/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm
index b24b402..556ab9a 100644
--- a/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm
@@ -45,6 +45,13 @@
namespace {
+// Indices of the menu items in the permission menu.
+enum PermissionMenuIndices {
+ kMenuIndexContentSettingAllow = 0,
+ kMenuIndexContentSettingBlock,
+ kMenuIndexContentSettingDefault
+};
+
class WebsiteSettingsBubbleControllerTest : public CocoaTest {
public:
WebsiteSettingsBubbleControllerTest() {
@@ -186,7 +193,7 @@ TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) {
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
};
- // Create a list of 6 different permissions.
+ // Create a list of 6 different permissions, all set to "Allow".
PermissionInfoList list;
WebsiteSettingsUI::PermissionInfo info;
info.setting = CONTENT_SETTING_ALLOW;
@@ -208,6 +215,31 @@ TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) {
[labels addObject:[static_cast<NSTextField*>(view) stringValue]];
}
EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]);
+
+ // Find the first permission pop-up button
+ NSPopUpButton* button = nil;
+ for (NSView* view in subviews) {
+ if ([view isKindOfClass:[NSPopUpButton class]]) {
+ button = static_cast<NSPopUpButton*>(view);
+ break;
+ }
+ }
+ ASSERT_NSNE(nil, button);
+
+ // Check that the button title is updated when the setting is changed.
+
+ NSString* original_title = [[[button cell] menuItem] title];
+ [button selectItemAtIndex:kMenuIndexContentSettingBlock];
+ [controller_ permissionValueChanged:button];
+ EXPECT_NSNE(original_title, [[[button cell] menuItem] title]);
+
+ [button selectItemAtIndex:kMenuIndexContentSettingDefault];
+ [controller_ permissionValueChanged:button];
+ EXPECT_NSNE(original_title, [[[button cell] menuItem] title]);
+
+ [button selectItemAtIndex:kMenuIndexContentSettingAllow];
+ [controller_ permissionValueChanged:button];
+ EXPECT_NSEQ(original_title, [[[button cell] menuItem] title]);
}
} // namespace