diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 16:36:16 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 16:36:16 +0000 |
commit | 3627b06dd62f0e4748ab57208eac7988c92932a2 (patch) | |
tree | ea09e487e10a072b1ce2b16c55bf90dfcd466e94 /chrome | |
parent | 2500710027b1034c281b4ef99e0907d96759996b (diff) | |
download | chromium_src-3627b06dd62f0e4748ab57208eac7988c92932a2.zip chromium_src-3627b06dd62f0e4748ab57208eac7988c92932a2.tar.gz chromium_src-3627b06dd62f0e4748ab57208eac7988c92932a2.tar.bz2 |
Move click-to-play to about:flags.
XIB changes: Add an outlet |pluginDefaultSettingMatrix_| to ContentSettingsDialogController, hooked up to the associated matrix, to remove the click-to-play radio button.
While I'm at it, clean up a bit:
* Remove the old --disable-click-to-play flag that reverted to the M6 behavior for blocked plugins
* Make ContentExceptionsWindowController use ContentSettingComboModel for the action popup.
* Make HostContentSettingsMapTest use AutoReset to reset command line switches.
BUG=62091
TEST=unit_tests
Review URL: http://codereview.chromium.org/4643007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65953 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
20 files changed, 198 insertions, 172 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 13c1e5d..a409a09 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4110,6 +4110,12 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION" desc="Description of the 'Experimental Extension APIs' lab."> Enables experimental extension APIs. Note that the extension gallery doesn't allow you to upload extensions that use experimental APIs. </message> + <message name="IDS_FLAGS_CLICK_TO_PLAY_NAME" desc="Name of the 'Click-to-Play' lab."> + Click-to-Play + </message> + <message name="IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION" desc="Description of the 'Click-to-Play' lab."> + Click on a blocked plug-in to run it. + </message> <!-- Instant --> <message name="IDS_INSTANT_OPT_IN_ENABLE" desc="Button shown in the omnibox dropdown for enabling instant"> diff --git a/chrome/app/nibs/ContentSettings.xib b/chrome/app/nibs/ContentSettings.xib index f760703..630946f 100644 --- a/chrome/app/nibs/ContentSettings.xib +++ b/chrome/app/nibs/ContentSettings.xib @@ -2386,26 +2386,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> - <string key="label">selectedIndex: pluginsEnabledIndex</string> - <reference key="source" ref="564209934"/> - <reference key="destination" ref="1001"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="564209934"/> - <reference key="NSDestination" ref="1001"/> - <string key="NSLabel">selectedIndex: pluginsEnabledIndex</string> - <string key="NSBinding">selectedIndex</string> - <string key="NSKeyPath">pluginsEnabledIndex</string> - <object class="NSDictionary" key="NSOptions"> - <string key="NS.key.0">NSAllowsEditingMultipleValuesSelection</string> - <boolean value="NO" key="NS.object.0"/> - </object> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">86</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> <string key="label">selectedIndex: javaScriptEnabledIndex</string> <reference key="source" ref="35110844"/> <reference key="destination" ref="1001"/> @@ -2648,6 +2628,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <int key="connectionID">213</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">pluginDefaultSettingMatrix_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="564209934"/> + </object> + <int key="connectionID">216</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBBindingConnection" key="connection"> + <string key="label">selectedTag: pluginsEnabledIndex</string> + <reference key="source" ref="564209934"/> + <reference key="destination" ref="1001"/> + <object class="NSNibBindingConnector" key="connector"> + <reference key="NSSource" ref="564209934"/> + <reference key="NSDestination" ref="1001"/> + <string key="NSLabel">selectedTag: pluginsEnabledIndex</string> + <string key="NSBinding">selectedTag</string> + <string key="NSKeyPath">pluginsEnabledIndex</string> + <int key="NSNibBindingConnectorVersion">2</int> + </object> + </object> + <int key="connectionID">217</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -3608,7 +3612,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <nil key="sourceID"/> - <int key="maxID">215</int> + <int key="maxID">217</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -3657,11 +3661,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>pluginDefaultSettingMatrix_</string> <string>tabViewPicker_</string> <string>tabView_</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSMatrix</string> <string>TabViewPickerTable</string> <string>NSTabView</string> </object> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index dc1391d..366e173 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -192,6 +192,13 @@ const Experiment kExperiments[] = { kOsAll, switches::kEnableExperimentalExtensionApis }, + { + "click-to-play", // Do not change; see above. + IDS_FLAGS_CLICK_TO_PLAY_NAME, + IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION, + kOsAll, + switches::kEnableClickToPlay + }, }; const Experiment* experiments = kExperiments; diff --git a/chrome/browser/cocoa/content_exceptions_window_controller.h b/chrome/browser/cocoa/content_exceptions_window_controller.h index ede76f7..98af089 100644 --- a/chrome/browser/cocoa/content_exceptions_window_controller.h +++ b/chrome/browser/cocoa/content_exceptions_window_controller.h @@ -10,6 +10,7 @@ #include "chrome/common/content_settings_types.h" class ContentExceptionsTableModel; +class ContentSettingComboModel; class UpdatingContentSettingsObserver; // Controller for the content exception dialogs. @@ -28,9 +29,7 @@ class UpdatingContentSettingsObserver; HostContentSettingsMap* settingsMap_; // weak HostContentSettingsMap* otrSettingsMap_; // weak scoped_ptr<ContentExceptionsTableModel> model_; - - // Is set if "Session" should be a valid option in the "action" popup. - BOOL showSession_; + scoped_ptr<ContentSettingComboModel> popup_model_; // Is set if adding and editing exceptions for the current OTR session should // be allowed. diff --git a/chrome/browser/cocoa/content_exceptions_window_controller.mm b/chrome/browser/cocoa/content_exceptions_window_controller.mm index e589261..b50204f 100644 --- a/chrome/browser/cocoa/content_exceptions_window_controller.mm +++ b/chrome/browser/cocoa/content_exceptions_window_controller.mm @@ -12,6 +12,7 @@ #import "base/scoped_nsobject.h" #include "base/sys_string_conversions.h" #include "chrome/browser/content_exceptions_table_model.h" +#include "chrome/browser/content_setting_combo_model.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" @@ -27,10 +28,7 @@ forOtr:(BOOL)isOtr; - (void)adjustEditingButtons; - (void)modelDidChange; -- (size_t)menuItemCount; - (NSString*)titleForIndex:(size_t)index; -- (ContentSetting)settingForIndex:(size_t)index; -- (size_t)indexForSetting:(ContentSetting)setting; @end //////////////////////////////////////////////////////////////////////////////// @@ -126,20 +124,6 @@ NSString* GetWindowTitle(ContentSettingsType settingsType) { const CGFloat kButtonBarHeight = 35.0; -// The settings shown in the combobox for plug-ins; -const ContentSetting kPluginSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_ASK, - CONTENT_SETTING_BLOCK }; - -// The settings shown in the combobox if showSession_ is false; -const ContentSetting kNoSessionSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK }; - -// The settings shown in the combobox if showSession_ is true; -const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_SESSION_ONLY, - CONTENT_SETTING_BLOCK }; - } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -175,7 +159,7 @@ static ContentExceptionsWindowController* otrSettingsMap_ = otrSettingsMap; model_.reset(new ContentExceptionsTableModel( settingsMap_, otrSettingsMap_, settingsType_)); - showSession_ = settingsType_ == CONTENT_SETTINGS_TYPE_COOKIES; + popup_model_.reset(new ContentSettingComboModel(settingsType_)); otrAllowed_ = otrSettingsMap != NULL; tableObserver_.reset(new UpdatingContentSettingsObserver(self)); updatesEnabled_ = YES; @@ -203,10 +187,12 @@ static ContentExceptionsWindowController* // Initialize menu for the data cell in the "action" column. scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@"exceptionMenu"]); - for (size_t i = 0; i < [self menuItemCount]; ++i) { - scoped_nsobject<NSMenuItem> allowItem([[NSMenuItem alloc] - initWithTitle:[self titleForIndex:i] action:NULL keyEquivalent:@""]); - [allowItem.get() setTag:[self settingForIndex:i]]; + for (int i = 0; i < popup_model_->GetItemCount(); ++i) { + NSString* title = + l10n_util::FixUpWindowsStyleLabel(popup_model_->GetItemAt(i)); + scoped_nsobject<NSMenuItem> allowItem( + [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@""]); + [allowItem.get() setTag:popup_model_->SettingForIndex(i)]; [menu.get() addItem:allowItem.get()]; } NSCell* menuCell = @@ -375,7 +361,8 @@ static ContentExceptionsWindowController* if ([identifier isEqualToString:@"pattern"]) { result = base::SysUTF8ToNSString(entry->first.AsString()); } else if ([identifier isEqualToString:@"action"]) { - result = [NSNumber numberWithInt:[self indexForSetting:entry->second]]; + result = + [NSNumber numberWithInt:popup_model_->IndexForSetting(entry->second)]; } else if ([identifier isEqualToString:@"otr"]) { result = [NSNumber numberWithInt:isOtr]; } else { @@ -436,7 +423,7 @@ static ContentExceptionsWindowController* } if ([identifier isEqualToString:@"action"]) { int index = [object intValue]; - entry.second = [self settingForIndex:index]; + entry.second = popup_model_->SettingForIndex(index); } if ([identifier isEqualToString:@"otr"]) { isOtr = [object intValue] != 0; @@ -500,43 +487,4 @@ static ContentExceptionsWindowController* [self adjustEditingButtons]; } -- (size_t)menuItemCount { - if (settingsType_ == CONTENT_SETTINGS_TYPE_PLUGINS) - return arraysize(kPluginSettings); - return showSession_ ? arraysize(kSessionSettings) - : arraysize(kNoSessionSettings); -} - -- (NSString*)titleForIndex:(size_t)index { - switch ([self settingForIndex:index]) { - case CONTENT_SETTING_ALLOW: - return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_ALLOW_BUTTON); - case CONTENT_SETTING_ASK: - return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_ASK_BUTTON); - case CONTENT_SETTING_BLOCK: - return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_BLOCK_BUTTON); - case CONTENT_SETTING_SESSION_ONLY: - return l10n_util::GetNSStringWithFixup( - IDS_EXCEPTIONS_SESSION_ONLY_BUTTON); - default: - NOTREACHED(); - } - return @""; -} - -- (ContentSetting)settingForIndex:(size_t)index { - if (settingsType_ == CONTENT_SETTINGS_TYPE_PLUGINS) - return kPluginSettings[index]; - return showSession_ ? kSessionSettings[index] : kNoSessionSettings[index]; -} - -- (size_t)indexForSetting:(ContentSetting)setting { - for (size_t i = 0; i < [self menuItemCount]; ++i) { - if ([self settingForIndex:i] == setting) - return i; - } - NOTREACHED(); - return 0; -} - @end diff --git a/chrome/browser/cocoa/content_setting_bubble_cocoa.mm b/chrome/browser/cocoa/content_setting_bubble_cocoa.mm index dda55f5..dc8b967 100644 --- a/chrome/browser/cocoa/content_setting_bubble_cocoa.mm +++ b/chrome/browser/cocoa/content_setting_bubble_cocoa.mm @@ -391,32 +391,17 @@ NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { } - (void)sizeToFitLoadPluginsButton { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableClickToPlay)) { - const ContentSettingBubbleModel::BubbleContent& content = - contentSettingBubbleModel_->bubble_content(); - [loadAllPluginsButton_ setEnabled:content.load_plugins_link_enabled]; - - // Resize horizontally to fit button if necessary. - NSRect windowFrame = [[self window] frame]; - int widthNeeded = NSWidth([loadAllPluginsButton_ frame]) + - 2 * NSMinX([loadAllPluginsButton_ frame]); - if (NSWidth(windowFrame) < widthNeeded) { - windowFrame.size.width = widthNeeded; - [[self window] setFrame:windowFrame display:NO]; - } - } else { - // Remove button and resize vertically. - int deltaY = kLoadAllPluginsButtonVerticalPadding + - NSHeight([loadAllPluginsButton_ frame]); - [loadAllPluginsButton_ removeFromSuperview]; - NSRect frame = [[self window] frame]; - frame.size.height -= deltaY; - [[self window] setFrame:frame display:NO]; - NSPoint radioOrigin = [allowBlockRadioGroup_ frame].origin; - radioOrigin.y -= deltaY; - [allowBlockRadioGroup_ setFrameOrigin:radioOrigin]; - [allowBlockRadioGroup_ setNeedsDisplay]; + const ContentSettingBubbleModel::BubbleContent& content = + contentSettingBubbleModel_->bubble_content(); + [loadAllPluginsButton_ setEnabled:content.load_plugins_link_enabled]; + + // Resize horizontally to fit button if necessary. + NSRect windowFrame = [[self window] frame]; + int widthNeeded = NSWidth([loadAllPluginsButton_ frame]) + + 2 * NSMinX([loadAllPluginsButton_ frame]); + if (NSWidth(windowFrame) < widthNeeded) { + windowFrame.size.width = widthNeeded; + [[self window] setFrame:windowFrame display:NO]; } } diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.h b/chrome/browser/cocoa/content_settings_dialog_controller.h index 45601ce..40e9a04 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.h +++ b/chrome/browser/cocoa/content_settings_dialog_controller.h @@ -48,6 +48,7 @@ class Profile; @private IBOutlet NSTabView* tabView_; IBOutlet TabViewPickerTable* tabViewPicker_; + IBOutlet NSMatrix* pluginDefaultSettingMatrix_; Profile* profile_; // weak IntegerPrefMember lastSelectedTab_; BooleanPrefMember clearSiteDataOnExit_; diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm index 910e127..d9fedc1 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller.mm @@ -187,6 +187,24 @@ class PrefObserverDisabler { label = [label stringByReplacingOccurrencesOfString:@":" withString:@""]; [tabViewPicker_ setHeading:label]; + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) { + // The |pluginsEnabledIndex| property is bound to the selected *tag*, + // so we don't have to worry about index shifts when removing a row + // from the matrix. + [pluginDefaultSettingMatrix_ removeRow:kPluginsAskIndex]; + NSArray* siblingViews = [[pluginDefaultSettingMatrix_ superview] subviews]; + for (NSView* view in siblingViews) { + NSRect frame = [view frame]; + if (frame.origin.y < [pluginDefaultSettingMatrix_ frame].origin.y) { + frame.origin.y += + ([pluginDefaultSettingMatrix_ cellSize].height + + [pluginDefaultSettingMatrix_ intercellSpacing].height); + [view setFrame:frame]; + } + } + } + NSRect frame = [[self window] frame]; frame.origin.y -= windowDelta; frame.size.height += windowDelta; @@ -430,9 +448,15 @@ class PrefObserverDisabler { ContentSetting setting = map->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); switch (setting) { - case CONTENT_SETTING_ALLOW: return kPluginsAllowIndex; - case CONTENT_SETTING_ASK: return kPluginsAskIndex; - case CONTENT_SETTING_BLOCK: return kPluginsBlockIndex; + case CONTENT_SETTING_ALLOW: + return kPluginsAllowIndex; + case CONTENT_SETTING_ASK: + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) + return kPluginsAskIndex; + // Fall through to the next case. + case CONTENT_SETTING_BLOCK: + return kPluginsBlockIndex; default: NOTREACHED(); return kPluginsAllowIndex; diff --git a/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm b/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm index 405082c..3558b62 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm @@ -4,6 +4,8 @@ #import "chrome/browser/cocoa/content_settings_dialog_controller.h" +#include "base/auto_reset.h" +#include "base/command_line.h" #import "base/scoped_nsobject.h" #include "base/ref_counted.h" #include "chrome/browser/cocoa/browser_test_helper.h" @@ -13,6 +15,7 @@ #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/common/pref_names.h" +#include "chrome/common/chrome_switches.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -164,9 +167,16 @@ TEST_F(ContentSettingsDialogControllerTest, PluginsSetting) { CONTENT_SETTING_BLOCK); EXPECT_EQ(kPluginsBlockIndex, [controller_ pluginsEnabledIndex]); - settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, - CONTENT_SETTING_ASK); - EXPECT_EQ(kPluginsAskIndex, [controller_ pluginsEnabledIndex]); + { + // Click-to-play needs to be enabled to set the content setting to ASK. + CommandLine* cmd = CommandLine::ForCurrentProcess(); + AutoReset<CommandLine> auto_reset(cmd, *cmd); + cmd->AppendSwitch(switches::kEnableClickToPlay); + + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, + CONTENT_SETTING_ASK); + EXPECT_EQ(kPluginsAskIndex, [controller_ pluginsEnabledIndex]); + } // Change dialog property, check setting. NSInteger setting; @@ -180,10 +190,16 @@ TEST_F(ContentSettingsDialogControllerTest, PluginsSetting) { settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); EXPECT_EQ(CONTENT_SETTING_BLOCK, setting); - [controller_ setPluginsEnabledIndex:kPluginsAskIndex]; - setting = - settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); - EXPECT_EQ(CONTENT_SETTING_ASK, setting); + { + CommandLine* cmd = CommandLine::ForCurrentProcess(); + AutoReset<CommandLine> auto_reset(cmd, *cmd); + cmd->AppendSwitch(switches::kEnableClickToPlay); + + [controller_ setPluginsEnabledIndex:kPluginsAskIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); + EXPECT_EQ(CONTENT_SETTING_ASK, setting); + } } TEST_F(ContentSettingsDialogControllerTest, PopupsSetting) { diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc index 2cc5d911..f7e89d4 100644 --- a/chrome/browser/content_setting_bubble_model.cc +++ b/chrome/browser/content_setting_bubble_model.cc @@ -297,16 +297,11 @@ class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { private: void SetLoadPluginsLinkTitle() { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableClickToPlay)) { - set_load_plugins_link_title( - l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL)); - } + set_load_plugins_link_title( + l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL)); } virtual void OnLoadPluginsLinkClicked() { - DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableClickToPlay)); UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); if (tab_contents()) { tab_contents()->render_view_host()->LoadBlockedPlugins(); diff --git a/chrome/browser/content_setting_bubble_model_unittest.cc b/chrome/browser/content_setting_bubble_model_unittest.cc index ac956b2..d9590e0 100644 --- a/chrome/browser/content_setting_bubble_model_unittest.cc +++ b/chrome/browser/content_setting_bubble_model_unittest.cc @@ -109,6 +109,7 @@ TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) { CommandLine* cmd = CommandLine::ForCurrentProcess(); AutoReset<CommandLine> auto_reset(cmd, *cmd); cmd->AppendSwitch(switches::kEnableResourceContentSettings); + cmd->AppendSwitch(switches::kEnableClickToPlay); HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); std::string fooPlugin = "foo"; diff --git a/chrome/browser/content_setting_combo_model.cc b/chrome/browser/content_setting_combo_model.cc index ec39a13..3606587 100644 --- a/chrome/browser/content_setting_combo_model.cc +++ b/chrome/browser/content_setting_combo_model.cc @@ -36,7 +36,8 @@ ContentSettingComboModel::~ContentSettingComboModel() { } int ContentSettingComboModel::GetItemCount() { - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS) + if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && + CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableClickToPlay)) return arraysize(kAskSettings); if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) return arraysize(kSessionSettings); @@ -60,7 +61,8 @@ string16 ContentSettingComboModel::GetItemAt(int index) { } ContentSetting ContentSettingComboModel::SettingForIndex(int index) { - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS) + if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && + CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableClickToPlay)) return kAskSettings[index]; if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) return kSessionSettings[index]; diff --git a/chrome/browser/gtk/options/content_filter_page_gtk.cc b/chrome/browser/gtk/options/content_filter_page_gtk.cc index 6645a22..d352f52 100644 --- a/chrome/browser/gtk/options/content_filter_page_gtk.cc +++ b/chrome/browser/gtk/options/content_filter_page_gtk.cc @@ -83,10 +83,17 @@ GtkWidget* ContentFilterPageGtk::InitGroup() { }; COMPILE_ASSERT(arraysize(kAskIDs) == CONTENT_SETTINGS_NUM_TYPES, kAskIDs_IncorrectSize); - if (kAskIDs[content_type_]) { + int askID = kAskIDs[content_type_]; + if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && + !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) { + askID = 0; + } + + if (askID) { ask_radio_ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(allow_radio_), - l10n_util::GetStringUTF8(kAskIDs[content_type_]).c_str()); + l10n_util::GetStringUTF8(askID).c_str()); gtk_box_pack_start(GTK_BOX(vbox), ask_radio_, FALSE, FALSE, 0); } diff --git a/chrome/browser/host_content_settings_map.cc b/chrome/browser/host_content_settings_map.cc index a7dda7e..2f90bfd 100644 --- a/chrome/browser/host_content_settings_map.cc +++ b/chrome/browser/host_content_settings_map.cc @@ -100,6 +100,20 @@ static bool ShouldAllowAllContent(const GURL& url) { url.SchemeIs(chrome::kGearsScheme) || url.SchemeIs(chrome::kUserScriptScheme); } + +// Map ASK for the plugins content type to BLOCK if click-to-play is +// not enabled. +ContentSetting ClickToPlayFixup(ContentSettingsType content_type, + ContentSetting setting) { + if (setting == CONTENT_SETTING_ASK && + content_type == CONTENT_SETTINGS_TYPE_PLUGINS && + !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) { + return CONTENT_SETTING_BLOCK; + } + return setting; +} + } // namespace @@ -432,6 +446,10 @@ void HostContentSettingsMap::SetDefaultContentSetting( ContentSetting setting) { DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || + setting != CONTENT_SETTING_ASK || + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)); PrefService* prefs = profile_->GetPrefs(); // The default settings may not be directly modified for OTR sessions. @@ -474,6 +492,10 @@ void HostContentSettingsMap::SetContentSetting( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK_NE(RequiresResourceIdentifier(content_type), resource_identifier.empty()); + DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || + setting != CONTENT_SETTING_ASK || + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)); const Pattern pattern(original_pattern.CanonicalizePattern()); @@ -796,6 +818,10 @@ void HostContentSettingsMap::GetSettingsFromDictionary( if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == CONTENT_SETTING_ASK) settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; + + settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] = + ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, + settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); } void HostContentSettingsMap::GetResourceSettingsFromDictionary( @@ -820,7 +846,8 @@ void HostContentSettingsMap::GetResourceSettingsFromDictionary( DCHECK(found); (*settings)[ContentSettingsTypeResourceIdentifierPair( ContentSettingsType(type), resource_identifier)] = - ContentSetting(setting); + ClickToPlayFixup(ContentSettingsType(type), + ContentSetting(setting)); } break; diff --git a/chrome/browser/host_content_settings_map_unittest.cc b/chrome/browser/host_content_settings_map_unittest.cc index b5c74a0..a66e971 100644 --- a/chrome/browser/host_content_settings_map_unittest.cc +++ b/chrome/browser/host_content_settings_map_unittest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/host_content_settings_map.h" +#include "base/auto_reset.h" #include "base/command_line.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" @@ -90,11 +91,18 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) { EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( GURL(chrome::kChromeUINewTabURL), CONTENT_SETTINGS_TYPE_IMAGES, "")); - host_content_settings_map->SetDefaultContentSetting( - CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK); - EXPECT_EQ(CONTENT_SETTING_ASK, - host_content_settings_map->GetDefaultContentSetting( - CONTENT_SETTINGS_TYPE_PLUGINS)); + { + // Click-to-play needs to be enabled to set the content setting to ASK. + CommandLine* cmd = CommandLine::ForCurrentProcess(); + AutoReset<CommandLine> auto_reset(cmd, *cmd); + cmd->AppendSwitch(switches::kEnableClickToPlay); + + host_content_settings_map->SetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK); + EXPECT_EQ(CONTENT_SETTING_ASK, + host_content_settings_map->GetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_PLUGINS)); + } host_content_settings_map->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); EXPECT_EQ(CONTENT_SETTING_ALLOW, @@ -566,9 +574,9 @@ TEST_F(HostContentSettingsMapTest, OffTheRecord) { TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) { // This feature is currently behind a flag. - CommandLine cl(*CommandLine::ForCurrentProcess()); - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kEnableResourceContentSettings); + CommandLine* cmd = CommandLine::ForCurrentProcess(); + AutoReset<CommandLine> auto_reset(cmd, *cmd); + cmd->AppendSwitch(switches::kEnableResourceContentSettings); TestingProfile profile; PrefService* prefs = profile.GetPrefs(); @@ -592,7 +600,6 @@ TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) { EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( host, CONTENT_SETTINGS_TYPE_POPUPS, "")); - *CommandLine::ForCurrentProcess() = cl; } // For a single Unicode encoded pattern, check if it gets converted to punycode @@ -624,9 +631,9 @@ TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { // settings for the punycode, and that Unicode pattern gets deleted. TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { // This feature is currently behind a flag. - CommandLine cl(*CommandLine::ForCurrentProcess()); - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kEnableResourceContentSettings); + CommandLine* cmd = CommandLine::ForCurrentProcess(); + AutoReset<CommandLine> auto_reset(cmd, *cmd); + cmd->AppendSwitch(switches::kEnableResourceContentSettings); TestingProfile profile; @@ -648,8 +655,6 @@ TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); EXPECT_STREQ("{\"[*.]xn--ira-ppa.com\":{\"per_plugin\":{\"pluginy\":2}}}", prefs_as_json.c_str()); - - *CommandLine::ForCurrentProcess() = cl; } TEST_F(HostContentSettingsMapTest, NonDefaultSettings) { @@ -676,9 +681,9 @@ TEST_F(HostContentSettingsMapTest, NonDefaultSettings) { TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { // This feature is currently behind a flag. - CommandLine cl(*CommandLine::ForCurrentProcess()); - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kEnableResourceContentSettings); + CommandLine* cmd = CommandLine::ForCurrentProcess(); + AutoReset<CommandLine> auto_reset(cmd, *cmd); + cmd->AppendSwitch(switches::kEnableResourceContentSettings); TestingProfile profile; HostContentSettingsMap* host_content_settings_map = @@ -700,14 +705,13 @@ TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2)); - *CommandLine::ForCurrentProcess() = cl; } TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) { // This feature is currently behind a flag. - CommandLine cl(*CommandLine::ForCurrentProcess()); - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kEnableResourceContentSettings); + CommandLine* cmd = CommandLine::ForCurrentProcess(); + AutoReset<CommandLine> auto_reset(cmd, *cmd); + cmd->AppendSwitch(switches::kEnableResourceContentSettings); TestingProfile profile; scoped_ptr<Value> value(base::JSONReader::Read( @@ -742,7 +746,6 @@ TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) { base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); EXPECT_STREQ("{\"[*.]example.com\":{\"per_plugin\":{\"otherplugin\":2}}}", prefs_as_json.c_str()); - *CommandLine::ForCurrentProcess() = cl; } } // namespace diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 04c02b8..c495abd 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -619,7 +619,7 @@ void BrowserRenderProcessHost::PropagateBrowserCommandLineToRenderer( switches::kBlockNonSandboxedPlugins, switches::kDisableOutdatedPlugins, switches::kEnableRemoting, - switches::kDisableClickToPlay, + switches::kEnableClickToPlay, switches::kEnableResourceContentSettings, switches::kPrelaunchGpuProcess, switches::kEnableAcceleratedDecoding, diff --git a/chrome/browser/ui/views/options/content_filter_page_view.cc b/chrome/browser/ui/views/options/content_filter_page_view.cc index 756045f..6b0c220 100644 --- a/chrome/browser/ui/views/options/content_filter_page_view.cc +++ b/chrome/browser/ui/views/options/content_filter_page_view.cc @@ -101,12 +101,16 @@ void ContentFilterPageView::InitControlLayout() { }; COMPILE_ASSERT(arraysize(kAskIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); - DCHECK_EQ(arraysize(kAskIDs), - static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); if (content_type_ != CONTENT_SETTINGS_TYPE_COOKIES) { - if (kAskIDs[content_type_] != 0) { + int askID = kAskIDs[content_type_]; + if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && + !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) { + askID = 0; + } + if (askID != 0) { ask_radio_ = new views::RadioButton( - l10n_util::GetString(kAskIDs[content_type_]), radio_button_group); + l10n_util::GetString(askID), radio_button_group); ask_radio_->set_listener(this); ask_radio_->SetMultiLine(true); layout->StartRow(0, single_column_set_id); diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 592bcd9..67253d6 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -162,9 +162,6 @@ const char kDisableBackgroundNetworking[] = "disable-background-networking"; // users with many windows/tabs and lots of memory. const char kDisableBackingStoreLimit[] = "disable-backing-store-limit"; -// Disable click-to-play for blocked plug-ins. -const char kDisableClickToPlay[] = "disable-click-to-play"; - // Disables establishing a backup TCP connection if a specified timeout is // exceeded. const char kDisableConnectBackupJobs[] = "disable-connect-backup-jobs"; @@ -396,6 +393,9 @@ const char kEnableBenchmarking[] = "enable-benchmarking"; // until there's a server endpoint deployed. const char kEnableClearServerData[] = "enable-clear-server-data"; +// Enable click-to-play for blocked plug-ins. +const char kEnableClickToPlay[] = "enable-click-to-play"; + // This applies only when the process type is "service". Enables the // Cloud Print Proxy component within the service process. const char kEnableCloudPrintProxy[] = "enable-cloud-print-proxy"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 16e1223..c1dedb2 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -56,7 +56,6 @@ extern const char kDisableAudio[]; extern const char kDisableAuthNegotiateCnameLookup[]; extern const char kDisableBackgroundNetworking[]; extern const char kDisableBackingStoreLimit[]; -extern const char kDisableClickToPlay[]; extern const char kDisableConnectBackupJobs[]; extern const char kDisableContentPrefetch[]; extern const char kDisableCustomJumpList[]; @@ -122,6 +121,7 @@ extern const char kEnableAuthNegotiatePort[]; extern const char kEnableBackgroundMode[]; extern const char kEnableBenchmarking[]; extern const char kEnableClearServerData[]; +extern const char kEnableClickToPlay[]; extern const char kEnableCloudPrintProxy[]; extern const char kEnableCloudPrint[]; extern const char kEnableConfirmToQuit[]; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 9b0a283..28d0f86 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -2726,12 +2726,7 @@ bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { } bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableClickToPlay)) { - return WebFrameClient::allowPlugins(frame, enabled_per_settings); - } - return enabled_per_settings && - AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS); + return WebFrameClient::allowPlugins(frame, enabled_per_settings); } |