diff options
24 files changed, 329 insertions, 146 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index d071e5f..80b2f9b 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -245,6 +245,7 @@ source_set("browser") { "//components/keyed_service/content", "//components/navigation_interception", "//components/password_manager/content/browser", + "//components/plugins/common", "//components/precache/content", "//components/sessions:sessions_content", "//components/storage_monitor", diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 532712d..01adb24 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -60,6 +60,7 @@ include_rules = [ "+components/os_crypt", "+components/password_manager", "+components/pdf/browser", + "+components/plugins/common", "+components/policy", "+components/power", "+components/precache", diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 7566679..06e5322 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -29,6 +29,7 @@ #include "components/metrics/metrics_hashes.h" #include "components/nacl/common/nacl_switches.h" #include "components/omnibox/omnibox_switches.h" +#include "components/plugins/common/plugins_switches.h" #include "components/proximity_auth/switches.h" #include "components/search/search_switches.h" #include "content/public/browser/user_metrics.h" @@ -2089,8 +2090,8 @@ const Experiment kExperiments[] = { IDS_FLAGS_ENABLE_PLUGIN_POWER_SAVER_NAME, IDS_FLAGS_ENABLE_PLUGIN_POWER_SAVER_DESCRIPTION, kOsDesktop, - ENABLE_DISABLE_VALUE_TYPE(switches::kEnablePluginPowerSaver, - switches::kDisablePluginPowerSaver) + ENABLE_DISABLE_VALUE_TYPE(plugins::switches::kEnablePluginPowerSaver, + plugins::switches::kDisablePluginPowerSaver) }, #endif #if defined(OS_CHROMEOS) diff --git a/chrome/browser/plugins/plugin_info_message_filter.cc b/chrome/browser/plugins/plugin_info_message_filter.cc index a8fd6b7..29cd4c3 100644 --- a/chrome/browser/plugins/plugin_info_message_filter.cc +++ b/chrome/browser/plugins/plugin_info_message_filter.cc @@ -15,13 +15,13 @@ #include "chrome/browser/plugins/plugin_finder.h" #include "chrome/browser/plugins/plugin_metadata.h" #include "chrome/browser/plugins/plugin_prefs.h" -#include "chrome/browser/plugins/plugins_field_trial.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_otr_state.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "components/content_settings/core/browser/content_settings_utils.h" #include "components/content_settings/core/browser/host_content_settings_map.h" +#include "components/content_settings/core/browser/plugins_field_trial.h" #include "components/content_settings/core/common/content_settings.h" #include "components/rappor/rappor_service.h" #include "content/public/browser/browser_thread.h" @@ -364,7 +364,7 @@ void PluginInfoMessageFilter::Context::DecidePluginStatus( plugin_metadata->identifier(), &plugin_setting, &uses_default_content_setting, &is_managed); - plugin_setting = PluginsFieldTrial::EffectiveContentSetting( + plugin_setting = content_settings::PluginsFieldTrial::EffectiveContentSetting( CONTENT_SETTINGS_TYPE_PLUGINS, plugin_setting); DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT); diff --git a/chrome/browser/plugins/plugins_field_trial.cc b/chrome/browser/plugins/plugins_field_trial.cc deleted file mode 100644 index 5a526f0..0000000 --- a/chrome/browser/plugins/plugins_field_trial.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/plugins/plugins_field_trial.h" - -#include "base/command_line.h" -#include "base/metrics/field_trial.h" -#include "chrome/common/chrome_switches.h" - -ContentSetting PluginsFieldTrial::EffectiveContentSetting( - ContentSettingsType type, - ContentSetting setting) { - if (type != CONTENT_SETTINGS_TYPE_PLUGINS) - return setting; - - // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior. - if (setting == ContentSetting::CONTENT_SETTING_ASK) - return ContentSetting::CONTENT_SETTING_BLOCK; - - // For Plugins, allow flag to override displayed content setting. - if (setting == ContentSetting::CONTENT_SETTING_ALLOW && - IsForcePluginPowerSaverEnabled()) { - return ContentSetting::CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; - } - - return setting; -} - -bool PluginsFieldTrial::IsForcePluginPowerSaverEnabled() { - const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); - if (cl->HasSwitch(switches::kDisablePluginPowerSaver)) - return false; - if (cl->HasSwitch(switches::kEnablePluginPowerSaver)) - return true; - - std::string group_name = - base::FieldTrialList::FindFullName("ForcePluginPowerSaver"); - return !group_name.empty() && group_name != "Disabled"; -} diff --git a/chrome/browser/resources/options/content_settings.js b/chrome/browser/resources/options/content_settings.js index b9aed82..db6fbf6 100644 --- a/chrome/browser/resources/options/content_settings.js +++ b/chrome/browser/resources/options/content_settings.js @@ -42,7 +42,6 @@ cr.define('options', function() { */ function ContentSettings() { this.activeNavTab = null; - this.pluginsAllowOptionDisabled = false; Page.call(this, 'content', loadTimeData.getString('contentSettingsPageTabTitle'), 'content-settings-page'); @@ -171,10 +170,6 @@ cr.define('options', function() { indicators[i].handlePrefChange(event); } } - - if (this.pluginsAllowOptionDisabled) { - $('plugins-allow-radio').disabled = true; - } }; /** @@ -298,14 +293,6 @@ cr.define('options', function() { }; /** - * Disable the 'allow' option in the Plugins section. - */ - ContentSettings.disablePluginsAllowOption = function() { - this.pluginsAllowOptionDisabled = true; - $('plugins-allow-radio').disabled = true; - }; - - /** * Updates the microphone/camera devices menu with the given entries. * @param {string} type The device type. * @param {Array} devices List of available devices. diff --git a/chrome/browser/ui/website_settings/permission_menu_model.cc b/chrome/browser/ui/website_settings/permission_menu_model.cc index bfacff9..19a39f9 100644 --- a/chrome/browser/ui/website_settings/permission_menu_model.cc +++ b/chrome/browser/ui/website_settings/permission_menu_model.cc @@ -4,8 +4,8 @@ #include "chrome/browser/ui/website_settings/permission_menu_model.h" -#include "chrome/browser/plugins/plugins_field_trial.h" #include "chrome/grit/generated_resources.h" +#include "components/content_settings/core/browser/plugins_field_trial.h" #include "ui/base/l10n/l10n_util.h" PermissionMenuModel::PermissionMenuModel( @@ -19,8 +19,9 @@ PermissionMenuModel::PermissionMenuModel( ContentSetting effective_default_setting = permission_.default_setting; #if defined(ENABLE_PLUGINS) - effective_default_setting = PluginsFieldTrial::EffectiveContentSetting( - permission_.type, permission_.default_setting); + effective_default_setting = + content_settings::PluginsFieldTrial::EffectiveContentSetting( + permission_.type, permission_.default_setting); #endif // defined(ENABLE_PLUGINS) switch (effective_default_setting) { @@ -99,8 +100,8 @@ bool PermissionMenuModel::IsCommandIdChecked(int command_id) const { ContentSetting setting = permission_.setting; #if defined(ENABLE_PLUGINS) - setting = PluginsFieldTrial::EffectiveContentSetting(permission_.type, - permission_.setting); + setting = content_settings::PluginsFieldTrial::EffectiveContentSetting( + permission_.type, permission_.setting); #endif // defined(ENABLE_PLUGINS) return setting == command_id; diff --git a/chrome/browser/ui/website_settings/website_settings_ui.cc b/chrome/browser/ui/website_settings/website_settings_ui.cc index 80f38db..a186b08 100644 --- a/chrome/browser/ui/website_settings/website_settings_ui.cc +++ b/chrome/browser/ui/website_settings/website_settings_ui.cc @@ -4,9 +4,9 @@ #include "chrome/browser/ui/website_settings/website_settings_ui.h" -#include "chrome/browser/plugins/plugins_field_trial.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" +#include "components/content_settings/core/browser/plugins_field_trial.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" @@ -182,7 +182,8 @@ base::string16 WebsiteSettingsUI::PermissionActionToUIString( #if defined(ENABLE_PLUGINS) effective_setting = - PluginsFieldTrial::EffectiveContentSetting(type, effective_setting); + content_settings::PluginsFieldTrial::EffectiveContentSetting( + type, effective_setting); #endif const int* button_text_ids = NULL; diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc index 864c2a2..0a78234 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.cc +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc @@ -21,7 +21,6 @@ #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" #include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/browser/notifications/desktop_notification_profile_util.h" -#include "chrome/browser/plugins/plugins_field_trial.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" @@ -32,6 +31,7 @@ #include "components/content_settings/core/browser/content_settings_details.h" #include "components/content_settings/core/browser/content_settings_utils.h" #include "components/content_settings/core/browser/host_content_settings_map.h" +#include "components/content_settings/core/browser/plugins_field_trial.h" #include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_pattern.h" #include "components/google/core/browser/google_util.h" @@ -527,12 +527,6 @@ void ContentSettingsHandler::InitializePage() { UpdateHandlersEnabledRadios(); UpdateAllExceptionsViewsFromModel(); UpdateProtectedContentExceptionsButton(); - - // For Plugins, allow flag to override displayed content setting. - if (PluginsFieldTrial::IsForcePluginPowerSaverEnabled()) { - web_ui()->CallJavascriptFunction( - "ContentSettings.disablePluginsAllowOption"); - } } void ContentSettingsHandler::OnContentSettingChanged( @@ -613,7 +607,8 @@ void ContentSettingsHandler::UpdateSettingDefaultFromModel( #if defined(ENABLE_PLUGINS) default_setting = - PluginsFieldTrial::EffectiveContentSetting(type, default_setting); + content_settings::PluginsFieldTrial::EffectiveContentSetting( + type, default_setting); #endif base::DictionaryValue filter_settings; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ba2374b..278066e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1996,8 +1996,6 @@ 'browser/plugins/plugin_prefs_factory.h', 'browser/plugins/plugin_status_pref_setter.cc', 'browser/plugins/plugin_status_pref_setter.h', - 'browser/plugins/plugins_field_trial.cc', - 'browser/plugins/plugins_field_trial.h', 'browser/renderer_host/pepper/chrome_browser_pepper_host_factory.cc', 'browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h', 'browser/renderer_host/pepper/device_id_fetcher.cc', @@ -3098,6 +3096,7 @@ '../components/components.gyp:navigation_interception', '../components/components.gyp:packed_ct_ev_whitelist', '../components/components.gyp:password_manager_content_browser', + '../components/components.gyp:plugins_common', '../components/components.gyp:power', '../components/components.gyp:precache_content', '../components/components.gyp:sessions_content', diff --git a/components/BUILD.gn b/components/BUILD.gn index 62c2946..c6ab797 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -70,6 +70,7 @@ group("all_components") { "//components/pdf/browser", "//components/pdf/common", "//components/pdf/renderer", + "//components/plugins/common", "//components/plugins/renderer", "//components/policy", "//components/power", diff --git a/components/components.gyp b/components/components.gyp index d6c5e0a8..c5c752d 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -49,6 +49,7 @@ 'ownership.gypi', 'packed_ct_ev_whitelist.gypi', 'password_manager.gypi', + 'plugins.gypi', 'policy.gypi', 'precache.gypi', 'pref_registry.gypi', @@ -88,7 +89,6 @@ 'browsing_data.gypi', 'cdm.gypi', 'navigation_interception.gypi', - 'plugins.gypi', 'power.gypi', 'visitedlink.gypi', 'web_cache.gypi', diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 39b57a2..a9e46e3 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -94,6 +94,7 @@ 'content_settings/core/browser/content_settings_provider_unittest.cc', 'content_settings/core/browser/content_settings_rule_unittest.cc', 'content_settings/core/browser/content_settings_utils_unittest.cc', + 'content_settings/core/browser/plugins_field_trial_unittest.cc', 'content_settings/core/common/content_settings_pattern_parser_unittest.cc', 'content_settings/core/common/content_settings_pattern_unittest.cc', ], @@ -1155,6 +1156,8 @@ '../testing/gtest.gyp:gtest', 'components.gyp:autofill_content_browser', 'components.gyp:autofill_content_renderer', + 'components.gyp:content_settings_core_browser', + 'components.gyp:content_settings_core_common', 'components.gyp:dom_distiller_content', 'components.gyp:dom_distiller_core', 'components.gyp:password_manager_content_renderer', diff --git a/components/content_settings.gypi b/components/content_settings.gypi index 89f2b1a..d0218fe 100644 --- a/components/content_settings.gypi +++ b/components/content_settings.gypi @@ -14,6 +14,7 @@ '../net/net.gyp:net', '../url/url.gyp:url_lib', 'content_settings_core_common', + 'plugins_common', 'pref_registry', ], 'variables': { 'enable_wexit_time_destructors': 1, }, @@ -52,6 +53,8 @@ 'content_settings/core/browser/host_content_settings_map.cc', 'content_settings/core/browser/host_content_settings_map.h', 'content_settings/core/browser/local_shared_objects_counter.h', + 'content_settings/core/browser/plugins_field_trial.cc', + 'content_settings/core/browser/plugins_field_trial.h', ], # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. 'msvs_disabled_warnings': [4267, ], diff --git a/components/content_settings/core/browser/BUILD.gn b/components/content_settings/core/browser/BUILD.gn index 1f19608..5fcff79 100644 --- a/components/content_settings/core/browser/BUILD.gn +++ b/components/content_settings/core/browser/BUILD.gn @@ -34,12 +34,15 @@ static_library("browser") { "host_content_settings_map.cc", "host_content_settings_map.h", "local_shared_objects_counter.h", + "plugins_field_trial.cc", + "plugins_field_trial.h", ] deps = [ "//base", "//base:prefs", "//components/content_settings/core/common", + "//components/plugins/common", "//components/pref_registry:pref_registry", "//net", "//url", @@ -56,6 +59,7 @@ source_set("unit_tests") { "content_settings_provider_unittest.cc", "content_settings_rule_unittest.cc", "content_settings_utils_unittest.cc", + "plugins_field_trial_unittest.cc", ] deps = [ diff --git a/components/content_settings/core/browser/DEPS b/components/content_settings/core/browser/DEPS index dcf594c..0bc7443 100644 --- a/components/content_settings/core/browser/DEPS +++ b/components/content_settings/core/browser/DEPS @@ -1,5 +1,7 @@ include_rules = [ + "+components/content_settings/core/common", "+components/content_settings/core/test", + "+components/plugins/common", "+components/pref_registry", "+net/base", "+net/cookies", diff --git a/components/content_settings/core/browser/content_settings_default_provider.cc b/components/content_settings/core/browser/content_settings_default_provider.cc index 0af5197..d6246c7 100644 --- a/components/content_settings/core/browser/content_settings_default_provider.cc +++ b/components/content_settings/core/browser/content_settings_default_provider.cc @@ -16,12 +16,15 @@ #include "base/prefs/scoped_user_pref_update.h" #include "components/content_settings/core/browser/content_settings_rule.h" #include "components/content_settings/core/browser/content_settings_utils.h" +#include "components/content_settings/core/browser/plugins_field_trial.h" #include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_pattern.h" #include "components/content_settings/core/common/pref_names.h" #include "components/pref_registry/pref_registry_syncable.h" #include "url/gurl.h" +namespace content_settings { + namespace { struct DefaultContentSettingInfo { @@ -36,11 +39,10 @@ struct DefaultContentSettingInfo { // default content setting. This array must be kept in sync with the enum // |ContentSettingsType|. const DefaultContentSettingInfo kDefaultSettings[] = { - {prefs::kDefaultCookiesSetting, CONTENT_SETTING_ALLOW}, {prefs::kDefaultImagesSetting, CONTENT_SETTING_ALLOW}, {prefs::kDefaultJavaScriptSetting, CONTENT_SETTING_ALLOW}, - {prefs::kDefaultPluginsSetting, CONTENT_SETTING_ALLOW}, + {prefs::kDefaultPluginsSetting, CONTENT_SETTING_DEFAULT}, {prefs::kDefaultPopupsSetting, CONTENT_SETTING_BLOCK}, {prefs::kDefaultGeolocationSetting, CONTENT_SETTING_ASK}, {prefs::kDefaultNotificationsSetting, CONTENT_SETTING_ASK}, @@ -63,17 +65,20 @@ const DefaultContentSettingInfo kDefaultSettings[] = { {prefs::kDefaultProtectedMediaIdentifierSetting, CONTENT_SETTING_ASK}, #endif {prefs::kDefaultAppBannerSetting, CONTENT_SETTING_DEFAULT} - }; static_assert(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, "kDefaultSettings should have CONTENT_SETTINGS_NUM_TYPES " "elements"); -} // namespace - -namespace content_settings { +ContentSetting GetDefaultValue(ContentSettingsType type) { + if (type == CONTENT_SETTINGS_TYPE_PLUGINS) + return PluginsFieldTrial::GetDefaultPluginsContentSetting(); + return kDefaultSettings[type].default_value; +} -namespace { +const char* GetPrefName(ContentSettingsType type) { + return kDefaultSettings[type].pref_name; +} class DefaultRuleIterator : public RuleIterator { public: @@ -116,10 +121,11 @@ void DefaultProvider::RegisterProfilePrefs( // TODO(msramek): The aggregate preference above is deprecated. Remove it // after two stable releases. for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { + ContentSettingsType type = static_cast<ContentSettingsType>(i); registry->RegisterIntegerPref( - kDefaultSettings[i].pref_name, - kDefaultSettings[i].default_value, - IsContentSettingsTypeSyncable(ContentSettingsType(i)) + GetPrefName(type), + GetDefaultValue(type), + IsContentSettingsTypeSyncable(type) ? user_prefs::PrefRegistrySyncable::SYNCABLE_PREF : user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); } @@ -159,57 +165,57 @@ DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito) UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultCookiesSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_COOKIES].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultImagesSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_IMAGES].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultJavaScriptSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_JAVASCRIPT].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_JAVASCRIPT))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultPluginsSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_PLUGINS].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultPopupsSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_POPUPS].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_POPUPS))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultLocationSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_GEOLOCATION].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_GEOLOCATION))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultNotificationsSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultMouseCursorSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_MOUSELOCK].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_MOUSELOCK))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultMediaStreamSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_MEDIASTREAM].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_MEDIASTREAM))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultMIDISysExSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_MIDI_SYSEX].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_MIDI_SYSEX))), CONTENT_SETTING_NUM_SETTINGS); UMA_HISTOGRAM_ENUMERATION( "ContentSettings.DefaultPushMessagingSetting", IntToContentSetting(prefs_->GetInteger( - kDefaultSettings[CONTENT_SETTINGS_TYPE_PUSH_MESSAGING].pref_name)), + GetPrefName(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING))), CONTENT_SETTING_NUM_SETTINGS); pref_change_registrar_.Init(prefs_); @@ -217,8 +223,10 @@ DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito) &DefaultProvider::OnPreferenceChanged, base::Unretained(this)); pref_change_registrar_.Add(prefs::kDefaultContentSettings, callback); - for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) - pref_change_registrar_.Add(kDefaultSettings[i].pref_name, callback); + for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { + ContentSettingsType type = static_cast<ContentSettingsType>(i); + pref_change_registrar_.Add(GetPrefName(type), callback); + } } DefaultProvider::~DefaultProvider() { @@ -308,23 +316,22 @@ void DefaultProvider::ShutdownOnUIThread() { void DefaultProvider::ReadDefaultSettings() { base::AutoLock lock(lock_); for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { - ContentSettingsType content_type = ContentSettingsType(i); - ChangeSetting(content_type, ReadIndividualPref(content_type).get()); + ContentSettingsType type = static_cast<ContentSettingsType>(i); + ChangeSetting(type, ReadIndividualPref(type).get()); } } bool DefaultProvider::IsValueEmptyOrDefault(ContentSettingsType content_type, - base::Value* value) { - return (!value || - ValueToContentSetting(value) - == kDefaultSettings[content_type].default_value); + base::Value* value) { + if (!value) return true; + return ValueToContentSetting(value) == GetDefaultValue(content_type); } void DefaultProvider::ChangeSetting(ContentSettingsType content_type, base::Value* value) { if (!value) { - default_settings_[content_type].reset(ContentSettingToValue( - kDefaultSettings[content_type].default_value).release()); + default_settings_[content_type].reset( + ContentSettingToValue(GetDefaultValue(content_type)).release()); } else { default_settings_[content_type].reset(value->DeepCopy()); } @@ -333,14 +340,14 @@ void DefaultProvider::ChangeSetting(ContentSettingsType content_type, void DefaultProvider::WriteIndividualPref(ContentSettingsType content_type, base::Value* value) { if (IsValueEmptyOrDefault(content_type, value)) { - prefs_->ClearPref(kDefaultSettings[content_type].pref_name); + prefs_->ClearPref(GetPrefName(content_type)); return; } - int int_value = kDefaultSettings[content_type].default_value; + int int_value = GetDefaultValue(content_type); bool is_integer = value->GetAsInteger(&int_value); DCHECK(is_integer); - prefs_->SetInteger(kDefaultSettings[content_type].pref_name, int_value); + prefs_->SetInteger(GetPrefName(content_type), int_value); } void DefaultProvider::WriteDictionaryPref(ContentSettingsType content_type, @@ -410,8 +417,9 @@ void DefaultProvider::OnPreferenceChanged(const std::string& name) { ContentSettingsType content_type = CONTENT_SETTINGS_TYPE_DEFAULT; for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { - if (kDefaultSettings[i].pref_name == name) { - content_type = ContentSettingsType(i); + ContentSettingsType type = static_cast<ContentSettingsType>(i); + if (GetPrefName(type) == name) { + content_type = type; break; } } @@ -449,7 +457,7 @@ void DefaultProvider::OnPreferenceChanged(const std::string& name) { scoped_ptr<base::Value> DefaultProvider::ReadIndividualPref( ContentSettingsType content_type) { - int int_value = prefs_->GetInteger(kDefaultSettings[content_type].pref_name); + int int_value = prefs_->GetInteger(GetPrefName(content_type)); return ContentSettingToValue(IntToContentSetting(int_value)).Pass(); } @@ -483,10 +491,10 @@ scoped_ptr<DefaultProvider::ValueMap> DefaultProvider::ReadDictionaryPref() { void DefaultProvider::ForceDefaultsToBeExplicit(ValueMap* value_map) { for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { - ContentSettingsType type = ContentSettingsType(i); + ContentSettingsType type = static_cast<ContentSettingsType>(i); if (!(*value_map)[type].get()) { (*value_map)[type].reset(ContentSettingToValue( - kDefaultSettings[i].default_value).release()); + GetDefaultValue(type)).release()); } } } @@ -524,8 +532,8 @@ void DefaultProvider::MigrateDefaultSettings() { scoped_ptr<DefaultProvider::ValueMap> value_map = ReadDictionaryPref(); for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { - ContentSettingsType content_type = ContentSettingsType(i); - WriteIndividualPref(content_type, (*value_map)[content_type].get()); + ContentSettingsType type = static_cast<ContentSettingsType>(i); + WriteIndividualPref(type, (*value_map)[type].get()); } prefs_->SetBoolean(prefs::kMigratedDefaultContentSettings, true); diff --git a/components/content_settings/core/browser/plugins_field_trial.cc b/components/content_settings/core/browser/plugins_field_trial.cc new file mode 100644 index 0000000..98cd97a --- /dev/null +++ b/components/content_settings/core/browser/plugins_field_trial.cc @@ -0,0 +1,49 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/content_settings/core/browser/plugins_field_trial.h" + +#include "base/command_line.h" +#include "base/metrics/field_trial.h" +#include "components/plugins/common/plugins_switches.h" + +namespace content_settings { + +// static +const char PluginsFieldTrial::kFieldTrialName[] = "ForcePluginPowerSaver"; + +// static +ContentSetting PluginsFieldTrial::EffectiveContentSetting( + ContentSettingsType type, + ContentSetting setting) { + if (type != CONTENT_SETTINGS_TYPE_PLUGINS) + return setting; + + // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior. + if (setting == ContentSetting::CONTENT_SETTING_ASK) + return ContentSetting::CONTENT_SETTING_BLOCK; + + return setting; +} + +// static +bool PluginsFieldTrial::IsPluginPowerSaverEnabled() { + const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); + if (cl->HasSwitch(plugins::switches::kDisablePluginPowerSaver)) + return false; + if (cl->HasSwitch(plugins::switches::kEnablePluginPowerSaver)) + return true; + + std::string group_name = base::FieldTrialList::FindFullName(kFieldTrialName); + return !group_name.empty() && group_name != "Disabled"; +} + +// static +ContentSetting PluginsFieldTrial::GetDefaultPluginsContentSetting() { + return IsPluginPowerSaverEnabled() ? + ContentSetting::CONTENT_SETTING_DETECT_IMPORTANT_CONTENT : + ContentSetting::CONTENT_SETTING_ALLOW; +} + +} // namespace content_settings diff --git a/chrome/browser/plugins/plugins_field_trial.h b/components/content_settings/core/browser/plugins_field_trial.h index 3b4d1c3..ccc39df 100644 --- a/chrome/browser/plugins/plugins_field_trial.h +++ b/components/content_settings/core/browser/plugins_field_trial.h @@ -2,27 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_PLUGINS_PLUGINS_FIELD_TRIAL_H_ -#define CHROME_BROWSER_PLUGINS_PLUGINS_FIELD_TRIAL_H_ +#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_H_ +#define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_H_ #include "base/macros.h" #include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_types.h" +namespace content_settings { + // This class manages the Plugins field trials. class PluginsFieldTrial { public: + static const char kFieldTrialName[]; + // Returns the effective content setting for plugins. Passes non-plugin // content settings through without modification. static ContentSetting EffectiveContentSetting(ContentSettingsType type, ContentSetting setting); - // Returns true if the Plugin Power Saver feature is forced on, overriding - // the user's Content Settings. - static bool IsForcePluginPowerSaverEnabled(); + // Returns true if the Plugin Power Saver feature is enabled. + static bool IsPluginPowerSaverEnabled(); + + // Get the default plugins content setting based on field trials/flags. + static ContentSetting GetDefaultPluginsContentSetting(); private: DISALLOW_IMPLICIT_CONSTRUCTORS(PluginsFieldTrial); }; -#endif // CHROME_BROWSER_PLUGINS_PLUGINS_FIELD_TRIAL_H_ +} // namespace content_settings + +#endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_H_ diff --git a/components/content_settings/core/browser/plugins_field_trial_unittest.cc b/components/content_settings/core/browser/plugins_field_trial_unittest.cc new file mode 100644 index 0000000..052f8a5 --- /dev/null +++ b/components/content_settings/core/browser/plugins_field_trial_unittest.cc @@ -0,0 +1,97 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/content_settings/core/browser/plugins_field_trial.h" + +#include "base/command_line.h" +#include "base/macros.h" +#include "base/metrics/field_trial.h" +#include "base/test/mock_entropy_provider.h" +#include "components/content_settings/core/browser/content_settings_default_provider.h" +#include "components/content_settings/core/common/content_settings.h" +#include "components/content_settings/core/common/pref_names.h" +#include "components/plugins/common/plugins_switches.h" +#include "components/pref_registry/testing_pref_service_syncable.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace content_settings { + +namespace { + +const auto& kFieldTrialName = PluginsFieldTrial::kFieldTrialName; + +void ForceFieldTrialGroup(const std::string& group_name) { + using base::FieldTrialList; + ASSERT_TRUE(FieldTrialList::CreateFieldTrial(kFieldTrialName, group_name)); +} + +} // namespace + +class PluginsFieldTrialTest : public testing::Test { + public: + PluginsFieldTrialTest() : field_trial_list_(new base::MockEntropyProvider) {} + + private: + base::FieldTrialList field_trial_list_; + + DISALLOW_COPY_AND_ASSIGN(PluginsFieldTrialTest); +}; + +TEST_F(PluginsFieldTrialTest, DisabledByDefault) { + base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); + ASSERT_FALSE(cl->HasSwitch(plugins::switches::kDisablePluginPowerSaver)); + ASSERT_FALSE(cl->HasSwitch(plugins::switches::kEnablePluginPowerSaver)); + ASSERT_FALSE(base::FieldTrialList::TrialExists(kFieldTrialName)); + EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); +} + +TEST_F(PluginsFieldTrialTest, FieldTrialEnabled) { + ForceFieldTrialGroup("Enabled"); + EXPECT_TRUE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); +} + +TEST_F(PluginsFieldTrialTest, FieldTrialDisabled) { + ForceFieldTrialGroup("Disabled"); + EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); +} + +TEST_F(PluginsFieldTrialTest, SwitchEnabled) { + base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); + cl->AppendSwitch(plugins::switches::kEnablePluginPowerSaver); + EXPECT_TRUE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); +} + +TEST_F(PluginsFieldTrialTest, SwitchDisabled) { + base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); + cl->AppendSwitch(plugins::switches::kDisablePluginPowerSaver); + EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); +} + +TEST_F(PluginsFieldTrialTest, SwitchOverridesFieldTrial1) { + ForceFieldTrialGroup("Disabled"); + base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); + cl->AppendSwitch(plugins::switches::kEnablePluginPowerSaver); + EXPECT_TRUE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); +} + +TEST_F(PluginsFieldTrialTest, SwitchOverridesFieldTrial2) { + ForceFieldTrialGroup("Enabled"); + base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); + cl->AppendSwitch(plugins::switches::kDisablePluginPowerSaver); + EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); +} + +TEST_F(PluginsFieldTrialTest, NoPrefLeftBehind) { + ForceFieldTrialGroup("Enabled"); + user_prefs::TestingPrefServiceSyncable prefs; + { + DefaultProvider::RegisterProfilePrefs(prefs.registry()); + DefaultProvider default_provider(&prefs, false); + } + EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, + prefs.GetInteger(prefs::kDefaultPluginsSetting)); + EXPECT_FALSE(prefs.HasPrefPath(prefs::kDefaultPluginsSetting)); +} + +} // namespace content_settings diff --git a/components/plugins.gypi b/components/plugins.gypi index a052b51..fde25c6 100644 --- a/components/plugins.gypi +++ b/components/plugins.gypi @@ -5,37 +5,55 @@ { 'targets': [ { - # GN version: //components/plugins/renderer - 'target_name': 'plugins_renderer', + # GN version: //components/plugins/common + 'target_name': 'plugins_common', 'type': 'static_library', - 'dependencies': [ - '../gin/gin.gyp:gin', - '../skia/skia.gyp:skia', - '../third_party/WebKit/public/blink.gyp:blink', - '../third_party/re2/re2.gyp:re2', - '../v8/tools/gyp/v8.gyp:v8', - ], 'include_dirs': [ '..', ], 'sources': [ - # Note: sources list duplicated in GN build. - 'plugins/renderer/loadable_plugin_placeholder.cc', - 'plugins/renderer/loadable_plugin_placeholder.h', - 'plugins/renderer/plugin_placeholder.cc', - 'plugins/renderer/plugin_placeholder.h', - 'plugins/renderer/webview_plugin.cc', - 'plugins/renderer/webview_plugin.h', + 'plugins/common/plugins_switches.cc', + 'plugins/common/plugins_switches.h', ], - 'conditions' : [ - ['OS=="android"', { + }, + ], + 'conditions': [ + ['OS!="ios"', { + 'targets': [ + { + # GN version: //components/plugins/renderer + 'target_name': 'plugins_renderer', + 'type': 'static_library', + 'dependencies': [ + '../gin/gin.gyp:gin', + '../skia/skia.gyp:skia', + '../third_party/WebKit/public/blink.gyp:blink', + '../third_party/re2/re2.gyp:re2', + '../v8/tools/gyp/v8.gyp:v8', + ], + 'include_dirs': [ + '..', + ], 'sources': [ # Note: sources list duplicated in GN build. - 'plugins/renderer/mobile_youtube_plugin.cc', - 'plugins/renderer/mobile_youtube_plugin.h', - ] - }], + 'plugins/renderer/loadable_plugin_placeholder.cc', + 'plugins/renderer/loadable_plugin_placeholder.h', + 'plugins/renderer/plugin_placeholder.cc', + 'plugins/renderer/plugin_placeholder.h', + 'plugins/renderer/webview_plugin.cc', + 'plugins/renderer/webview_plugin.h', + ], + 'conditions' : [ + ['OS=="android"', { + 'sources': [ + # Note: sources list duplicated in GN build. + 'plugins/renderer/mobile_youtube_plugin.cc', + 'plugins/renderer/mobile_youtube_plugin.h', + ] + }], + ], + }, ], - }, - ] + }], + ], } diff --git a/components/plugins/common/BUILD.gn b/components/plugins/common/BUILD.gn new file mode 100644 index 0000000..c0ca042 --- /dev/null +++ b/components/plugins/common/BUILD.gn @@ -0,0 +1,10 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +static_library("common") { + sources = [ + "plugins_switches.cc", + "plugins_switches.h", + ] +} diff --git a/components/plugins/common/plugins_switches.cc b/components/plugins/common/plugins_switches.cc new file mode 100644 index 0000000..83c9652 --- /dev/null +++ b/components/plugins/common/plugins_switches.cc @@ -0,0 +1,17 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/plugins/common/plugins_switches.h" + +namespace plugins { +namespace switches { + +// Disables the experimental Plugin Power Saver feature. +const char kDisablePluginPowerSaver[] = "disable-plugin-power-saver"; + +// Enables the experimental Plugin Power Saver feature. +const char kEnablePluginPowerSaver[] = "enable-plugin-power-saver"; + +} // namespace switches +} // namespace plugins diff --git a/components/plugins/common/plugins_switches.h b/components/plugins/common/plugins_switches.h new file mode 100644 index 0000000..57500b7 --- /dev/null +++ b/components/plugins/common/plugins_switches.h @@ -0,0 +1,17 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_PLUGINS_COMMON_PLUGIN_SWITCHES_H_ +#define COMPONENTS_PLUGINS_COMMON_PLUGIN_SWITCHES_H_ + +namespace plugins { +namespace switches { + +extern const char kDisablePluginPowerSaver[]; +extern const char kEnablePluginPowerSaver[]; + +} // namespace switches +} // namespace plugins + +#endif // COMPONENTS_PLUGINS_COMMON_PLUGIN_SWITCHES_H_ |