diff options
Diffstat (limited to 'components/content_settings')
15 files changed, 214 insertions, 330 deletions
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 6adccfd..8b6127c 100644 --- a/components/content_settings/core/browser/content_settings_default_provider.cc +++ b/components/content_settings/core/browser/content_settings_default_provider.cc @@ -18,6 +18,8 @@ #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/browser/website_settings_info.h" +#include "components/content_settings/core/browser/website_settings_registry.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" @@ -35,58 +37,25 @@ const char kObsoleteDefaultContentSettings[] = const char kObsoleteMigratedDefaultContentSettings[] = "profile.migrated_default_content_settings"; -struct DefaultContentSettingInfo { - // The profile preference associated with this default setting. - const char* pref_name; - - // The default value of this default setting. - const ContentSetting default_value; -}; - -// The corresponding preference and default value for each 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_DEFAULT}, - {prefs::kDefaultPopupsSetting, CONTENT_SETTING_BLOCK}, - {prefs::kDefaultGeolocationSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultNotificationsSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultAutoSelectCertificateSetting, CONTENT_SETTING_DEFAULT}, - {prefs::kDefaultFullScreenSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultMouseLockSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultMixedScriptSetting, CONTENT_SETTING_DEFAULT}, - {prefs::kDefaultMediaStreamSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultMediaStreamMicSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultMediaStreamCameraSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultProtocolHandlersSetting, CONTENT_SETTING_DEFAULT}, - {prefs::kDefaultPpapiBrokerSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultAutomaticDownloadsSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultMidiSysexSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultPushMessagingSetting, CONTENT_SETTING_ASK}, - {prefs::kDefaultSSLCertDecisionsSetting, CONTENT_SETTING_ALLOW}, -#if defined(OS_WIN) - {prefs::kDefaultMetroSwitchToDesktopSetting, CONTENT_SETTING_ASK}, -#elif defined(OS_ANDROID) || defined(OS_CHROMEOS) - {prefs::kDefaultProtectedMediaIdentifierSetting, CONTENT_SETTING_ASK}, -#endif - {prefs::kDefaultAppBannerSetting, CONTENT_SETTING_DEFAULT}, - {prefs::kDefaultSiteEngagementSetting, CONTENT_SETTING_DEFAULT}, - {prefs::kDefaultDurableStorageSetting, CONTENT_SETTING_ASK}, -}; -static_assert(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, - "kDefaultSettings should have CONTENT_SETTINGS_NUM_TYPES " - "elements"); - ContentSetting GetDefaultValue(ContentSettingsType type) { if (type == CONTENT_SETTINGS_TYPE_PLUGINS) return PluginsFieldTrial::GetDefaultPluginsContentSetting(); - return kDefaultSettings[type].default_value; + + const WebsiteSettingsInfo* info = + WebsiteSettingsRegistry::GetInstance()->Get(type); + const base::Value* initial_default = info->initial_default_value(); + if (!initial_default) + return CONTENT_SETTING_DEFAULT; + int result = 0; + bool success = initial_default->GetAsInteger(&result); + DCHECK(success); + return static_cast<ContentSetting>(result); } -const char* GetPrefName(ContentSettingsType type) { - return kDefaultSettings[type].pref_name; +const std::string& GetPrefName(ContentSettingsType type) { + return WebsiteSettingsRegistry::GetInstance() + ->Get(type) + ->default_value_pref_name(); } class DefaultRuleIterator : public RuleIterator { diff --git a/components/content_settings/core/browser/content_settings_pref.cc b/components/content_settings/core/browser/content_settings_pref.cc index 535bcc6..2443e27 100644 --- a/components/content_settings/core/browser/content_settings_pref.cc +++ b/components/content_settings/core/browser/content_settings_pref.cc @@ -50,7 +50,7 @@ ContentSettingsPref::ContentSettingsPref( ContentSettingsType content_type, PrefService* prefs, PrefChangeRegistrar* registrar, - const char* pref_name, + const std::string& pref_name, bool incognito, NotifyObserversCallback notify_callback) : content_type_(content_type), diff --git a/components/content_settings/core/browser/content_settings_pref.h b/components/content_settings/core/browser/content_settings_pref.h index 2dd554b..5b9e5bb 100644 --- a/components/content_settings/core/browser/content_settings_pref.h +++ b/components/content_settings/core/browser/content_settings_pref.h @@ -43,7 +43,7 @@ class ContentSettingsPref { ContentSettingsPref(ContentSettingsType content_type, PrefService* prefs, PrefChangeRegistrar* registrar, - const char* pref_name, + const std::string& pref_name, bool incognito, NotifyObserversCallback notify_callback); ~ContentSettingsPref(); @@ -110,7 +110,7 @@ class ContentSettingsPref { PrefChangeRegistrar* registrar_; // Name of the dictionary preference managed by this class. - const char* pref_name_; + const std::string& pref_name_; bool is_incognito_; diff --git a/components/content_settings/core/browser/content_settings_pref_provider.cc b/components/content_settings/core/browser/content_settings_pref_provider.cc index 8e77612..352d32c 100644 --- a/components/content_settings/core/browser/content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/content_settings_pref_provider.cc @@ -23,6 +23,8 @@ #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/host_content_settings_map.h" +#include "components/content_settings/core/browser/website_settings_info.h" +#include "components/content_settings/core/browser/website_settings_registry.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" @@ -37,43 +39,6 @@ const char kObsoleteContentSettingsPatternPairs[] = const char kObsoleteMigratedContentSettingsPatternPairs[] = "profile.migrated_content_settings_exceptions"; -// A list of exception preferences corresponding to individual content settings -// types. Must be kept in sync with the enum |ContentSettingsType|. -const char* kContentSettingsExceptionsPrefs[] = { - prefs::kContentSettingsCookiesPatternPairs, - prefs::kContentSettingsImagesPatternPairs, - prefs::kContentSettingsJavaScriptPatternPairs, - prefs::kContentSettingsPluginsPatternPairs, - prefs::kContentSettingsPopupsPatternPairs, - prefs::kContentSettingsGeolocationPatternPairs, - prefs::kContentSettingsNotificationsPatternPairs, - prefs::kContentSettingsAutoSelectCertificatePatternPairs, - prefs::kContentSettingsFullScreenPatternPairs, - prefs::kContentSettingsMouseLockPatternPairs, - prefs::kContentSettingsMixedScriptPatternPairs, - prefs::kContentSettingsMediaStreamPatternPairs, - prefs::kContentSettingsMediaStreamMicPatternPairs, - prefs::kContentSettingsMediaStreamCameraPatternPairs, - prefs::kContentSettingsProtocolHandlersPatternPairs, - prefs::kContentSettingsPpapiBrokerPatternPairs, - prefs::kContentSettingsAutomaticDownloadsPatternPairs, - prefs::kContentSettingsMidiSysexPatternPairs, - prefs::kContentSettingsPushMessagingPatternPairs, - prefs::kContentSettingsSSLCertDecisionsPatternPairs, -#if defined(OS_WIN) - prefs::kContentSettingsMetroSwitchToDesktopPatternPairs, -#elif defined(OS_ANDROID) || defined(OS_CHROMEOS) - prefs::kContentSettingsProtectedMediaIdentifierPatternPairs, -#endif - prefs::kContentSettingsAppBannerPatternPairs, - prefs::kContentSettingsSiteEngagementPatternPairs, - prefs::kContentSettingsDurableStoragePatternPairs, -}; -static_assert(arraysize(kContentSettingsExceptionsPrefs) - == CONTENT_SETTINGS_NUM_TYPES, - "kContentSettingsExceptionsPrefs should have " - "CONTENT_SETTINGS_NUM_TYPES elements"); - } // namespace namespace content_settings { @@ -89,9 +54,11 @@ void PrefProvider::RegisterProfilePrefs( prefs::kContentSettingsVersion, ContentSettingsPattern::kContentSettingsPatternVersion); + WebsiteSettingsRegistry* website_settings = + WebsiteSettingsRegistry::GetInstance(); for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { registry->RegisterDictionaryPref( - kContentSettingsExceptionsPrefs[i], + website_settings->Get(static_cast<ContentSettingsType>(i))->pref_name(), PrefRegistrationFlagsForType(ContentSettingsType(i))); } @@ -100,18 +67,8 @@ void PrefProvider::RegisterProfilePrefs( registry->RegisterDictionaryPref( kObsoleteContentSettingsPatternPairs, user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); - registry->RegisterBooleanPref( - kObsoleteMigratedContentSettingsPatternPairs, false); -} - -// static -bool PrefProvider::IsContentSettingsExceptionsPref( - const std::string& pref_name) { - for (const char* pref : kContentSettingsExceptionsPrefs) { - if (pref_name == pref) - return true; - } - return false; + registry->RegisterBooleanPref(kObsoleteMigratedContentSettingsPatternPairs, + false); } PrefProvider::PrefProvider(PrefService* prefs, bool incognito) @@ -130,10 +87,14 @@ PrefProvider::PrefProvider(PrefService* prefs, bool incognito) } pref_change_registrar_.Init(prefs_); + + WebsiteSettingsRegistry* website_settings = + WebsiteSettingsRegistry::GetInstance(); for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { content_settings_prefs_.push_back(new ContentSettingsPref( ContentSettingsType(i), prefs_, &pref_change_registrar_, - kContentSettingsExceptionsPrefs[i], is_incognito_, + website_settings->Get(static_cast<ContentSettingsType>(i))->pref_name(), + is_incognito_, base::Bind(&PrefProvider::Notify, base::Unretained(this)))); } diff --git a/components/content_settings/core/browser/content_settings_pref_provider.h b/components/content_settings/core/browser/content_settings_pref_provider.h index 7a64603..97ea51e 100644 --- a/components/content_settings/core/browser/content_settings_pref_provider.h +++ b/components/content_settings/core/browser/content_settings_pref_provider.h @@ -39,10 +39,6 @@ class PrefProvider : public ObservableProvider { PrefProvider(PrefService* prefs, bool incognito); ~PrefProvider() override; - // Whether |pref_name| is a name of one of the preferences for content - // settings exceptions. - static bool IsContentSettingsExceptionsPref(const std::string& pref_name); - // ProviderInterface implementations. RuleIterator* GetRuleIterator(ContentSettingsType content_type, const ResourceIdentifier& resource_identifier, diff --git a/components/content_settings/core/browser/content_settings_utils.cc b/components/content_settings/core/browser/content_settings_utils.cc index 6a9a655..0b40d22 100644 --- a/components/content_settings/core/browser/content_settings_utils.cc +++ b/components/content_settings/core/browser/content_settings_utils.cc @@ -30,10 +30,6 @@ const char kPatternSeparator[] = ","; namespace content_settings { -std::string GetTypeName(ContentSettingsType type) { - return WebsiteSettingsRegistry::GetInstance()->Get(type)->name(); -} - std::string ContentSettingToString(ContentSetting setting) { switch (setting) { case CONTENT_SETTING_ALLOW: diff --git a/components/content_settings/core/browser/content_settings_utils.h b/components/content_settings/core/browser/content_settings_utils.h index b1f712a..39e39b4 100644 --- a/components/content_settings/core/browser/content_settings_utils.h +++ b/components/content_settings/core/browser/content_settings_utils.h @@ -28,11 +28,6 @@ class RuleIterator; typedef std::pair<ContentSettingsPattern, ContentSettingsPattern> PatternPair; -// Deprecated, do not call this! -// Call WebsiteSettingsRegistry::GetInstance()->Get(type)->name() instead. -// TODO(raymes): Inline this function at it's callsites. -std::string GetTypeName(ContentSettingsType type); - std::string ContentSettingToString(ContentSetting setting); ContentSetting ContentSettingFromString(const std::string& name); diff --git a/components/content_settings/core/browser/plugins_field_trial_unittest.cc b/components/content_settings/core/browser/plugins_field_trial_unittest.cc index b052d99..2511f16 100644 --- a/components/content_settings/core/browser/plugins_field_trial_unittest.cc +++ b/components/content_settings/core/browser/plugins_field_trial_unittest.cc @@ -9,8 +9,9 @@ #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/browser/website_settings_info.h" +#include "components/content_settings/core/browser/website_settings_registry.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" @@ -84,9 +85,13 @@ TEST_F(PluginsFieldTrialTest, NoPrefLeftBehind) { DefaultProvider::RegisterProfilePrefs(prefs.registry()); DefaultProvider default_provider(&prefs, false); } + const std::string& default_plugin_setting_pref_name = + WebsiteSettingsRegistry::GetInstance() + ->Get(CONTENT_SETTINGS_TYPE_PLUGINS) + ->default_value_pref_name(); EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, - prefs.GetInteger(prefs::kDefaultPluginsSetting)); - EXPECT_FALSE(prefs.HasPrefPath(prefs::kDefaultPluginsSetting)); + prefs.GetInteger(default_plugin_setting_pref_name)); + EXPECT_FALSE(prefs.HasPrefPath(default_plugin_setting_pref_name)); } } // namespace content_settings diff --git a/components/content_settings/core/browser/website_settings_info.cc b/components/content_settings/core/browser/website_settings_info.cc index fa19d9c..0a9cfce 100644 --- a/components/content_settings/core/browser/website_settings_info.cc +++ b/components/content_settings/core/browser/website_settings_info.cc @@ -4,11 +4,40 @@ #include "components/content_settings/core/browser/website_settings_info.h" +#include "base/logging.h" +#include "base/strings/string_util.h" +#include "base/values.h" + +namespace { + +const char* kPrefPrefix = "profile.content_settings.exceptions."; +const char* kDefaultPrefPrefix = "profile.default_content_setting_values."; + +std::string GetPrefName(const std::string& name, const char* prefix) { + std::string pref_name = name; + base::ReplaceChars(pref_name, "-", "_", &pref_name); + return std::string(prefix).append(pref_name); +} + +} // namespace + namespace content_settings { -WebsiteSettingsInfo::WebsiteSettingsInfo(ContentSettingsType type, - const std::string& name) - : type_(type), name_(name) {} +WebsiteSettingsInfo::WebsiteSettingsInfo( + ContentSettingsType type, + const std::string& name, + scoped_ptr<base::Value> initial_default_value) + : type_(type), + name_(name), + pref_name_(GetPrefName(name, kPrefPrefix)), + default_value_pref_name_(GetPrefName(name, kDefaultPrefPrefix)), + initial_default_value_(initial_default_value.Pass()) { + // For legacy reasons the default value is currently restricted to be an int. + // TODO(raymes): We should migrate the underlying pref to be a dictionary + // rather than an int. + DCHECK(!initial_default_value_ || + initial_default_value_->IsType(base::Value::TYPE_INTEGER)); +} WebsiteSettingsInfo::~WebsiteSettingsInfo() {} diff --git a/components/content_settings/core/browser/website_settings_info.h b/components/content_settings/core/browser/website_settings_info.h index 435b9df0..cdbe329 100644 --- a/components/content_settings/core/browser/website_settings_info.h +++ b/components/content_settings/core/browser/website_settings_info.h @@ -8,24 +8,43 @@ #include <string> #include "base/macros.h" +#include "base/memory/scoped_ptr.h" #include "components/content_settings/core/common/content_settings_types.h" +namespace base { +class Value; +} // namespace base + namespace content_settings { // This class stores the properties related to a website setting. // TODO(raymes): Move more properties into this class. class WebsiteSettingsInfo { public: - WebsiteSettingsInfo(ContentSettingsType type, const std::string& name); + WebsiteSettingsInfo(ContentSettingsType type, + const std::string& name, + scoped_ptr<base::Value> initial_default_value); ~WebsiteSettingsInfo(); ContentSettingsType type() const { return type_; } const std::string& name() const { return name_; } + const std::string& pref_name() const { return pref_name_; } + const std::string& default_value_pref_name() const { + return default_value_pref_name_; + } + const base::Value* initial_default_value() const { + return initial_default_value_.get(); + } + private: const ContentSettingsType type_; const std::string name_; + const std::string pref_name_; + const std::string default_value_pref_name_; + const scoped_ptr<base::Value> initial_default_value_; + DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsInfo); }; diff --git a/components/content_settings/core/browser/website_settings_registry.cc b/components/content_settings/core/browser/website_settings_registry.cc index c59c32e..fe2e048 100644 --- a/components/content_settings/core/browser/website_settings_registry.cc +++ b/components/content_settings/core/browser/website_settings_registry.cc @@ -5,6 +5,8 @@ #include "components/content_settings/core/browser/website_settings_registry.h" #include "base/logging.h" +#include "base/values.h" +#include "components/content_settings/core/common/content_settings.h" namespace { @@ -27,39 +29,66 @@ WebsiteSettingsRegistry::WebsiteSettingsRegistry() { // location. It should be possible to register a setting from the code // associated with it. - Register(CONTENT_SETTINGS_TYPE_COOKIES, "cookies"); - Register(CONTENT_SETTINGS_TYPE_IMAGES, "images"); - Register(CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"); - Register(CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"); - Register(CONTENT_SETTINGS_TYPE_POPUPS, "popups"); - Register(CONTENT_SETTINGS_TYPE_GEOLOCATION, "geolocation"); - Register(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"); - Register(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, - "auto-select-certificate"); - Register(CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"); - Register(CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"); - Register(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, "mixed-script"); - Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream"); - Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic"); - Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera"); - Register(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, - "register-protocol-handler"); - Register(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker"); - Register(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, - "multiple-automatic-downloads"); - Register(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex"); - Register(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging"); - Register(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, "ssl-cert-decisions"); + // WARNING: The string names of the permissions passed in below are used to + // generate preference names and should never be changed! + + // Content settings (those with allow/block/ask/etc. values). + RegisterContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, "cookies", + CONTENT_SETTING_ALLOW); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_IMAGES, "images", + CONTENT_SETTING_ALLOW); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript", + CONTENT_SETTING_ALLOW); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, "plugins", + CONTENT_SETTING_DEFAULT); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, "popups", + CONTENT_SETTING_BLOCK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, "geolocation", + CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications", + CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen", + CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock", + CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, "mixed-script", + CONTENT_SETTING_DEFAULT); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, + "media-stream-mic", CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, + "media-stream-camera", CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, + "protocol-handler", CONTENT_SETTING_DEFAULT); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker", + CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, + "automatic-downloads", CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex", + CONTENT_SETTING_ASK); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging", + CONTENT_SETTING_ASK); +#if defined(OS_ANDROID) || defined(OS_CHROMEOS) + RegisterContentSetting(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, + "protected-media-identifier", CONTENT_SETTING_ASK); +#endif + RegisterContentSetting(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, + "durable-storage", CONTENT_SETTING_ASK); + + // Website settings. + RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, + "auto-select-certificate"); + RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, + "ssl-cert-decisions"); + RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_APP_BANNER, "app-banner"); + RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, + "site-engagement"); + + // Deprecated. + RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream"); #if defined(OS_WIN) - Register(CONTENT_SETTINGS_TYPE_METRO_SWITCH_TO_DESKTOP, - "metro-switch-to-desktop"); -#elif defined(OS_ANDROID) || defined(OS_CHROMEOS) - Register(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, - "protected-media-identifier"); + RegisterContentSetting(CONTENT_SETTINGS_TYPE_METRO_SWITCH_TO_DESKTOP, + "metro-switch-to-desktop", CONTENT_SETTING_ASK); #endif - Register(CONTENT_SETTINGS_TYPE_APP_BANNER, "app-banner"); - Register(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, "site-engagement"); - Register(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, "durable-storage"); } WebsiteSettingsRegistry::~WebsiteSettingsRegistry() {} @@ -80,11 +109,26 @@ const WebsiteSettingsInfo* WebsiteSettingsRegistry::GetByName( return nullptr; } -void WebsiteSettingsRegistry::Register(ContentSettingsType type, - const std::string& name) { - DCHECK_GE(type, 0); - DCHECK_LT(type, static_cast<int>(website_settings_info_.size())); - website_settings_info_[type] = new WebsiteSettingsInfo(type, name); +void WebsiteSettingsRegistry::RegisterWebsiteSetting(ContentSettingsType type, + const std::string& name) { + StoreWebsiteSettingsInfo(new WebsiteSettingsInfo(type, name, nullptr)); +} + +void WebsiteSettingsRegistry::RegisterContentSetting( + ContentSettingsType type, + const std::string& name, + ContentSetting initial_default_value) { + scoped_ptr<base::Value> default_value( + new base::FundamentalValue(static_cast<int>(initial_default_value))); + StoreWebsiteSettingsInfo( + new WebsiteSettingsInfo(type, name, default_value.Pass())); +} + +void WebsiteSettingsRegistry::StoreWebsiteSettingsInfo( + WebsiteSettingsInfo* info) { + DCHECK_GE(info->type(), 0); + DCHECK_LT(info->type(), static_cast<int>(website_settings_info_.size())); + website_settings_info_[info->type()] = info; } } // namespace content_settings diff --git a/components/content_settings/core/browser/website_settings_registry.h b/components/content_settings/core/browser/website_settings_registry.h index 8d10a3d..e8ca8c3 100644 --- a/components/content_settings/core/browser/website_settings_registry.h +++ b/components/content_settings/core/browser/website_settings_registry.h @@ -11,6 +11,7 @@ #include "base/macros.h" #include "base/memory/scoped_vector.h" #include "components/content_settings/core/browser/website_settings_info.h" +#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_types.h" namespace content_settings { @@ -27,17 +28,28 @@ class WebsiteSettingsRegistry { const WebsiteSettingsInfo* GetByName(const std::string& name) const; private: + friend class WebsiteSettingsRegistryTest; + friend struct base::DefaultLazyInstanceTraits<WebsiteSettingsRegistry>; + WebsiteSettingsRegistry(); ~WebsiteSettingsRegistry(); - // Register a new WebsiteSettingsInfo. - void Register(ContentSettingsType type, const std::string& name); + // Register a new website setting. This maps an arbitrary base::Value to an + // origin. + void RegisterWebsiteSetting(ContentSettingsType type, + const std::string& name); + // Register a new content setting. This maps an ALLOW/ASK/BLOCK value (see the + // ContentSetting enum) to an origin. + void RegisterContentSetting(ContentSettingsType type, + const std::string& name, + ContentSetting initial_default_value); + + // Helper used by Register/RegisterPermission. + void StoreWebsiteSettingsInfo(WebsiteSettingsInfo* info); ScopedVector<WebsiteSettingsInfo> website_settings_info_; DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsRegistry); - friend class WebsiteSettingsRegistryTest; - friend struct base::DefaultLazyInstanceTraits<WebsiteSettingsRegistry>; }; } // namespace content_settings diff --git a/components/content_settings/core/browser/website_settings_registry_unittest.cc b/components/content_settings/core/browser/website_settings_registry_unittest.cc index 5f9da12..f9ae40b 100644 --- a/components/content_settings/core/browser/website_settings_registry_unittest.cc +++ b/components/content_settings/core/browser/website_settings_registry_unittest.cc @@ -3,8 +3,10 @@ // found in the LICENSE file. #include "base/logging.h" +#include "base/values.h" #include "components/content_settings/core/browser/website_settings_info.h" #include "components/content_settings/core/browser/website_settings_registry.h" +#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_types.h" #include "testing/gtest/include/gtest/gtest.h" @@ -39,4 +41,25 @@ TEST_F(WebsiteSettingsRegistryTest, GetByName) { EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_COOKIES), info); } +TEST_F(WebsiteSettingsRegistryTest, Properties) { + const WebsiteSettingsInfo* info = + registry()->Get(CONTENT_SETTINGS_TYPE_COOKIES); + ASSERT_TRUE(info); + EXPECT_EQ("profile.content_settings.exceptions.cookies", info->pref_name()); + EXPECT_EQ("profile.default_content_setting_values.cookies", + info->default_value_pref_name()); + int setting; + ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); + EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); + + info = registry()->Get(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); + ASSERT_TRUE(info); + EXPECT_EQ("profile.content_settings.exceptions.media_stream_camera", + info->pref_name()); + EXPECT_EQ("profile.default_content_setting_values.media_stream_camera", + info->default_value_pref_name()); + ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); + EXPECT_EQ(CONTENT_SETTING_ASK, setting); +} + } // namespace content_settings diff --git a/components/content_settings/core/common/pref_names.cc b/components/content_settings/core/common/pref_names.cc index 0bf3013..50b8ab0 100644 --- a/components/content_settings/core/common/pref_names.cc +++ b/components/content_settings/core/common/pref_names.cc @@ -18,121 +18,11 @@ const char kContentSettingsVersion[] = "profile.content_settings.pref_version"; const char kContentSettingsWindowLastTabIndex[] = "content_settings_window.last_tab_index"; -// Preferences storing the default values for individual content settings. -const char kDefaultCookiesSetting[] = - "profile.default_content_setting_values.cookies"; -const char kDefaultImagesSetting[] = - "profile.default_content_setting_values.images"; -const char kDefaultJavaScriptSetting[] = - "profile.default_content_setting_values.javascript"; -const char kDefaultPluginsSetting[] = - "profile.default_content_setting_values.plugins"; -const char kDefaultPopupsSetting[] = - "profile.default_content_setting_values.popups"; -const char kDefaultGeolocationSetting[] = - "profile.default_content_setting_values.geolocation"; -const char kDefaultNotificationsSetting[] = - "profile.default_content_setting_values.notifications"; -const char kDefaultAutoSelectCertificateSetting[] = - "profile.default_content_setting_values.auto_select_certificate"; -const char kDefaultFullScreenSetting[] = - "profile.default_content_setting_values.fullscreen"; -const char kDefaultMouseLockSetting[] = - "profile.default_content_setting_values.mouselock"; -const char kDefaultMixedScriptSetting[] = - "profile.default_content_setting_values.mixed_script"; -const char kDefaultMediaStreamSetting[] = - "profile.default_content_setting_values.media_stream"; -const char kDefaultMediaStreamMicSetting[] = - "profile.default_content_setting_values.media_stream_mic"; -const char kDefaultMediaStreamCameraSetting[] = - "profile.default_content_setting_values.media_stream_camera"; -const char kDefaultProtocolHandlersSetting[] = - "profile.default_content_setting_values.protocol_handlers"; -const char kDefaultPpapiBrokerSetting[] = - "profile.default_content_setting_values.ppapi_broker"; -const char kDefaultAutomaticDownloadsSetting[] = - "profile.default_content_setting_values.automatic_downloads"; -const char kDefaultMidiSysexSetting[] = - "profile.default_content_setting_values.midi_sysex"; -const char kDefaultPushMessagingSetting[] = - "profile.default_content_setting_values.push_messaging"; -const char kDefaultSSLCertDecisionsSetting[] = - "profile.default_content_setting_values.ssl_cert_decisions"; -#if defined(OS_WIN) -const char kDefaultMetroSwitchToDesktopSetting[] = - "profile.default_content_setting_values.metro_switch_to_desktop"; -#elif defined(OS_ANDROID) || defined(OS_CHROMEOS) -const char kDefaultProtectedMediaIdentifierSetting[] = - "profile.default_content_setting_values.protected_media_identifier"; -#endif -const char kDefaultAppBannerSetting[] = - "profile.default_content_setting_values.app_banner"; -const char kDefaultSiteEngagementSetting[] = - "profile.default_content_setting_values.site_engagement"; -const char kDefaultDurableStorageSetting[] = - "profile.default_content_setting_values.durable_storage"; - // Boolean indicating whether the media stream default setting had been // migrated into two separate microphone and camera settings. const char kMigratedDefaultMediaStreamSetting[] = "profile.migrated_default_media_stream_content_settings"; -// Preferences storing the content settings exceptions. -const char kContentSettingsCookiesPatternPairs[] = - "profile.content_settings.exceptions.cookies"; -const char kContentSettingsImagesPatternPairs[] = - "profile.content_settings.exceptions.images"; -const char kContentSettingsJavaScriptPatternPairs[] = - "profile.content_settings.exceptions.javascript"; -const char kContentSettingsPluginsPatternPairs[] = - "profile.content_settings.exceptions.plugins"; -const char kContentSettingsPopupsPatternPairs[] = - "profile.content_settings.exceptions.popups"; -const char kContentSettingsGeolocationPatternPairs[] = - "profile.content_settings.exceptions.geolocation"; -const char kContentSettingsNotificationsPatternPairs[] = - "profile.content_settings.exceptions.notifications"; -const char kContentSettingsAutoSelectCertificatePatternPairs[] = - "profile.content_settings.exceptions.auto_select_certificate"; -const char kContentSettingsFullScreenPatternPairs[] = - "profile.content_settings.exceptions.fullscreen"; -const char kContentSettingsMouseLockPatternPairs[] = - "profile.content_settings.exceptions.mouselock"; -const char kContentSettingsMixedScriptPatternPairs[] = - "profile.content_settings.exceptions.mixed_script"; -const char kContentSettingsMediaStreamPatternPairs[] = - "profile.content_settings.exceptions.media_stream"; -const char kContentSettingsMediaStreamMicPatternPairs[] = - "profile.content_settings.exceptions.media_stream_mic"; -const char kContentSettingsMediaStreamCameraPatternPairs[] = - "profile.content_settings.exceptions.media_stream_camera"; -const char kContentSettingsProtocolHandlersPatternPairs[] = - "profile.content_settings.exceptions.protocol_handlers"; -const char kContentSettingsPpapiBrokerPatternPairs[] = - "profile.content_settings.exceptions.ppapi_broker"; -const char kContentSettingsAutomaticDownloadsPatternPairs[] = - "profile.content_settings.exceptions.automatic_downloads"; -const char kContentSettingsMidiSysexPatternPairs[] = - "profile.content_settings.exceptions.midi_sysex"; -const char kContentSettingsPushMessagingPatternPairs[] = - "profile.content_settings.exceptions.push_messaging"; -const char kContentSettingsSSLCertDecisionsPatternPairs[] = - "profile.content_settings.exceptions.ssl_cert_decisions"; -#if defined(OS_WIN) -const char kContentSettingsMetroSwitchToDesktopPatternPairs[] = - "profile.content_settings.exceptions.metro_switch_to_desktop"; -#elif defined(OS_ANDROID) || defined(OS_CHROMEOS) -const char kContentSettingsProtectedMediaIdentifierPatternPairs[] = - "profile.content_settings.exceptions.protected_media_identifier"; -#endif -const char kContentSettingsAppBannerPatternPairs[] = - "profile.content_settings.exceptions.app_banner"; -const char kContentSettingsSiteEngagementPatternPairs[] = - "profile.content_settings.exceptions.site_engagement"; -const char kContentSettingsDurableStoragePatternPairs[] = - "profile.content_settings.exceptions.durable_storage"; - // Preferences that are exclusively used to store managed values for default // content settings. const char kManagedDefaultCookiesSetting[] = diff --git a/components/content_settings/core/common/pref_names.h b/components/content_settings/core/common/pref_names.h index ba3862c..795d8b75 100644 --- a/components/content_settings/core/common/pref_names.h +++ b/components/content_settings/core/common/pref_names.h @@ -9,71 +9,16 @@ namespace prefs { +// NOTE: This file does not contain all content settings related pref names as +// some of these are generated by WebsiteSettingsInfo from content settings +// names. + extern const char kBlockThirdPartyCookies[]; extern const char kContentSettingsVersion[]; extern const char kContentSettingsWindowLastTabIndex[]; -extern const char kDefaultCookiesSetting[]; -extern const char kDefaultImagesSetting[]; -extern const char kDefaultJavaScriptSetting[]; -extern const char kDefaultPluginsSetting[]; -extern const char kDefaultPopupsSetting[]; -extern const char kDefaultGeolocationSetting[]; -extern const char kDefaultNotificationsSetting[]; -extern const char kDefaultAutoSelectCertificateSetting[]; -extern const char kDefaultFullScreenSetting[]; -extern const char kDefaultMouseLockSetting[]; -extern const char kDefaultMixedScriptSetting[]; -extern const char kDefaultMediaStreamSetting[]; -extern const char kDefaultMediaStreamMicSetting[]; -extern const char kDefaultMediaStreamCameraSetting[]; -extern const char kDefaultProtocolHandlersSetting[]; -extern const char kDefaultPpapiBrokerSetting[]; -extern const char kDefaultAutomaticDownloadsSetting[]; -extern const char kDefaultMidiSysexSetting[]; -extern const char kDefaultPushMessagingSetting[]; -extern const char kDefaultSSLCertDecisionsSetting[]; -#if defined(OS_WIN) -extern const char kDefaultMetroSwitchToDesktopSetting[]; -#elif defined(OS_ANDROID) || defined(OS_CHROMEOS) -extern const char kDefaultProtectedMediaIdentifierSetting[]; -#endif -extern const char kDefaultAppBannerSetting[]; -extern const char kDefaultSiteEngagementSetting[]; -extern const char kDefaultDurableStorageSetting[]; - extern const char kMigratedDefaultMediaStreamSetting[]; -// Preferences storing the default values for individual content settings. -extern const char kContentSettingsCookiesPatternPairs[]; -extern const char kContentSettingsImagesPatternPairs[]; -extern const char kContentSettingsJavaScriptPatternPairs[]; -extern const char kContentSettingsPluginsPatternPairs[]; -extern const char kContentSettingsPopupsPatternPairs[]; -extern const char kContentSettingsGeolocationPatternPairs[]; -extern const char kContentSettingsNotificationsPatternPairs[]; -extern const char kContentSettingsAutoSelectCertificatePatternPairs[]; -extern const char kContentSettingsFullScreenPatternPairs[]; -extern const char kContentSettingsMouseLockPatternPairs[]; -extern const char kContentSettingsMixedScriptPatternPairs[]; -extern const char kContentSettingsMediaStreamPatternPairs[]; -extern const char kContentSettingsMediaStreamMicPatternPairs[]; -extern const char kContentSettingsMediaStreamCameraPatternPairs[]; -extern const char kContentSettingsProtocolHandlersPatternPairs[]; -extern const char kContentSettingsPpapiBrokerPatternPairs[]; -extern const char kContentSettingsAutomaticDownloadsPatternPairs[]; -extern const char kContentSettingsMidiSysexPatternPairs[]; -extern const char kContentSettingsPushMessagingPatternPairs[]; -extern const char kContentSettingsSSLCertDecisionsPatternPairs[]; -#if defined(OS_WIN) -extern const char kContentSettingsMetroSwitchToDesktopPatternPairs[]; -#elif defined(OS_ANDROID) || defined(OS_CHROMEOS) -extern const char kContentSettingsProtectedMediaIdentifierPatternPairs[]; -#endif -extern const char kContentSettingsAppBannerPatternPairs[]; -extern const char kContentSettingsSiteEngagementPatternPairs[]; -extern const char kContentSettingsDurableStoragePatternPairs[]; - extern const char kManagedDefaultCookiesSetting[]; extern const char kManagedDefaultImagesSetting[]; extern const char kManagedDefaultJavaScriptSetting[]; |