summaryrefslogtreecommitdiff
path: root/chromium/components/content_settings
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-18 14:34:04 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-10-04 11:15:27 +0000
commite6430e577f105ad8813c92e75c54660c4985026e (patch)
tree88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/components/content_settings
parent53d399fe6415a96ea6986ec0d402a9c07da72453 (diff)
downloadqtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/components/content_settings')
-rw-r--r--chromium/components/content_settings/core/browser/BUILD.gn4
-rw-r--r--chromium/components/content_settings/core/browser/DEPS1
-rw-r--r--chromium/components/content_settings/core/browser/content_settings_default_provider.cc5
-rw-r--r--chromium/components/content_settings/core/browser/content_settings_pref.cc1
-rw-r--r--chromium/components/content_settings/core/browser/content_settings_pref_provider.cc29
-rw-r--r--chromium/components/content_settings/core/browser/content_settings_registry.cc10
-rw-r--r--chromium/components/content_settings/core/browser/content_settings_utils.cc41
-rw-r--r--chromium/components/content_settings/core/browser/content_settings_utils.h18
-rw-r--r--chromium/components/content_settings/core/browser/cookie_settings.cc1
-rw-r--r--chromium/components/content_settings/core/browser/host_content_settings_map.cc18
-rw-r--r--chromium/components/content_settings/core/browser/host_content_settings_map.h1
-rw-r--r--chromium/components/content_settings/core/browser/website_settings_registry.cc24
-rw-r--r--chromium/components/content_settings/core/common/BUILD.gn8
-rw-r--r--chromium/components/content_settings/core/common/DEPS1
-rw-r--r--chromium/components/content_settings/core/common/OWNERS3
-rw-r--r--chromium/components/content_settings/core/common/content_settings.cc92
-rw-r--r--chromium/components/content_settings/core/common/content_settings.h12
-rw-r--r--chromium/components/content_settings/core/common/content_settings.mojom4
-rw-r--r--chromium/components/content_settings/core/common/content_settings_pattern.cc121
-rw-r--r--chromium/components/content_settings/core/common/content_settings_pattern.h3
-rw-r--r--chromium/components/content_settings/core/common/content_settings_pattern_unittest.cc4
-rw-r--r--chromium/components/content_settings/core/common/content_settings_struct_traits.cc3
-rw-r--r--chromium/components/content_settings/core/common/content_settings_struct_traits.h8
-rw-r--r--chromium/components/content_settings/core/common/content_settings_types.h17
-rw-r--r--chromium/components/content_settings/core/common/content_settings_utils.cc47
-rw-r--r--chromium/components/content_settings/core/common/content_settings_utils.h27
26 files changed, 278 insertions, 225 deletions
diff --git a/chromium/components/content_settings/core/browser/BUILD.gn b/chromium/components/content_settings/core/browser/BUILD.gn
index 44e44e36352..2a1becd0f34 100644
--- a/chromium/components/content_settings/core/browser/BUILD.gn
+++ b/chromium/components/content_settings/core/browser/BUILD.gn
@@ -58,6 +58,10 @@ static_library("browser") {
"//url",
]
+ if (!is_ios) {
+ deps += [ "//media" ]
+ }
+
configs += [
"//build/config/compiler:no_size_t_to_int_warning",
"//build/config/compiler:wexit_time_destructors",
diff --git a/chromium/components/content_settings/core/browser/DEPS b/chromium/components/content_settings/core/browser/DEPS
index 01dbe2ae6df..aea66d24de1 100644
--- a/chromium/components/content_settings/core/browser/DEPS
+++ b/chromium/components/content_settings/core/browser/DEPS
@@ -6,6 +6,7 @@ include_rules = [
"+components/sync_preferences",
"+components/url_formatter",
"+extensions/features",
+ "+media/base/media_switches.h",
"+net/base",
"+net/cookies",
"+services/preferences/public",
diff --git a/chromium/components/content_settings/core/browser/content_settings_default_provider.cc b/chromium/components/content_settings/core/browser/content_settings_default_provider.cc
index ffa75aa7da7..d0cb24cc4cb 100644
--- a/chromium/components/content_settings/core/browser/content_settings_default_provider.cc
+++ b/chromium/components/content_settings/core/browser/content_settings_default_provider.cc
@@ -19,6 +19,7 @@
#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/content_settings_utils.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry.h"
@@ -189,8 +190,8 @@ DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito)
GetPrefName(CONTENT_SETTINGS_TYPE_AUTOPLAY))),
CONTENT_SETTING_NUM_SETTINGS);
UMA_HISTOGRAM_ENUMERATION("ContentSettings.DefaultSubresourceFilterSetting",
- IntToContentSetting(prefs_->GetInteger(GetPrefName(
- CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER))),
+ IntToContentSetting(prefs_->GetInteger(
+ GetPrefName(CONTENT_SETTINGS_TYPE_ADS))),
CONTENT_SETTING_NUM_SETTINGS);
#endif
pref_change_registrar_.Init(prefs_);
diff --git a/chromium/components/content_settings/core/browser/content_settings_pref.cc b/chromium/components/content_settings/core/browser/content_settings_pref.cc
index 99e132b8151..49c2112bd3d 100644
--- a/chromium/components/content_settings/core/browser/content_settings_pref.cc
+++ b/chromium/components/content_settings/core/browser/content_settings_pref.cc
@@ -19,6 +19,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.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/content_settings_utils.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "services/preferences/public/cpp/dictionary_value_update.h"
diff --git a/chromium/components/content_settings/core/browser/content_settings_pref_provider.cc b/chromium/components/content_settings/core/browser/content_settings_pref_provider.cc
index fc1d59bb35c..6eaff3f94fe 100644
--- a/chromium/components/content_settings/core/browser/content_settings_pref_provider.cc
+++ b/chromium/components/content_settings/core/browser/content_settings_pref_provider.cc
@@ -45,7 +45,6 @@ const char kObsoleteMouseLockExceptionsPref[] =
"profile.content_settings.exceptions.mouselock";
#endif // !defined(OS_ANDROID)
#endif // !defined(OS_IOS)
-const char kObsoleteLastUsed[] = "last_used";
} // namespace
@@ -253,34 +252,6 @@ void PrefProvider::DiscardObsoletePreferences() {
prefs_->Set(permission_autoblocker_data_pref, *old_dict);
prefs_->ClearPref(prompt_no_decision_count_pref);
#endif // !defined(OS_IOS)
-
- // TODO(timloh): See crbug.com/691893. This removal code was added in M58,
- // so is probably fine to remove in M60 or later.
- for (const WebsiteSettingsInfo* info :
- *WebsiteSettingsRegistry::GetInstance()) {
- if (!prefs_->GetDictionary(info->pref_name()))
- continue;
-
- prefs::ScopedDictionaryPrefUpdate update(prefs_, info->pref_name());
- auto all_settings = update.Get();
- std::vector<std::string> values_to_clean;
- for (base::DictionaryValue::Iterator i(*all_settings->AsConstDictionary());
- !i.IsAtEnd(); i.Advance()) {
- const base::DictionaryValue* pattern_settings = nullptr;
- bool is_dictionary = i.value().GetAsDictionary(&pattern_settings);
- DCHECK(is_dictionary);
- if (pattern_settings->GetWithoutPathExpansion(kObsoleteLastUsed, nullptr))
- values_to_clean.push_back(i.key());
- }
-
- for (const std::string& key : values_to_clean) {
- std::unique_ptr<prefs::DictionaryValueUpdate> pattern_settings;
- all_settings->GetDictionaryWithoutPathExpansion(key, &pattern_settings);
- pattern_settings->RemoveWithoutPathExpansion(kObsoleteLastUsed, nullptr);
- if (pattern_settings->empty())
- all_settings->RemoveWithoutPathExpansion(key, nullptr);
- }
- }
}
void PrefProvider::SetClockForTesting(std::unique_ptr<base::Clock> clock) {
diff --git a/chromium/components/content_settings/core/browser/content_settings_registry.cc b/chromium/components/content_settings/core/browser/content_settings_registry.cc
index 6b18f449543..9413166bcf6 100644
--- a/chromium/components/content_settings/core/browser/content_settings_registry.cc
+++ b/chromium/components/content_settings/core/browser/content_settings_registry.cc
@@ -274,7 +274,15 @@ void ContentSettingsRegistry::Init() {
WebsiteSettingsRegistry::PLATFORM_ANDROID,
ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE);
- Register(CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, "subresource-filter",
+ Register(CONTENT_SETTINGS_TYPE_SOUND, "sound", CONTENT_SETTING_ALLOW,
+ WebsiteSettingsInfo::UNSYNCABLE, WhitelistedSchemes(),
+ ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK),
+ WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE,
+ WebsiteSettingsRegistry::DESKTOP |
+ WebsiteSettingsRegistry::PLATFORM_ANDROID,
+ ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE);
+
+ Register(CONTENT_SETTINGS_TYPE_ADS, "subresource-filter",
CONTENT_SETTING_BLOCK, WebsiteSettingsInfo::UNSYNCABLE,
WhitelistedSchemes(),
ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK),
diff --git a/chromium/components/content_settings/core/browser/content_settings_utils.cc b/chromium/components/content_settings/core/browser/content_settings_utils.cc
index 55d33720378..2efa8f774ed 100644
--- a/chromium/components/content_settings/core/browser/content_settings_utils.cc
+++ b/chromium/components/content_settings/core/browser/content_settings_utils.cc
@@ -6,15 +6,14 @@
#include <stddef.h>
-#include <memory>
#include <vector>
#include "base/logging.h"
#include "base/macros.h"
-#include "base/memory/ptr_util.h"
#include "base/strings/string_split.h"
#include "base/values.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/content_settings/core/common/content_settings_utils.h"
namespace {
@@ -120,34 +119,6 @@ PatternPair ParsePatternString(const std::string& pattern_str) {
return pattern_pair;
}
-ContentSetting ValueToContentSetting(const base::Value* value) {
- ContentSetting setting = CONTENT_SETTING_DEFAULT;
- bool valid = ParseContentSettingValue(value, &setting);
- DCHECK(valid);
- return setting;
-}
-
-bool ParseContentSettingValue(const base::Value* value,
- ContentSetting* setting) {
- if (!value) {
- *setting = CONTENT_SETTING_DEFAULT;
- return true;
- }
- int int_value = -1;
- if (!value->GetAsInteger(&int_value))
- return false;
- *setting = IntToContentSetting(int_value);
- return *setting != CONTENT_SETTING_DEFAULT;
-}
-
-std::unique_ptr<base::Value> ContentSettingToValue(ContentSetting setting) {
- if (setting <= CONTENT_SETTING_DEFAULT ||
- setting >= CONTENT_SETTING_NUM_SETTINGS) {
- return nullptr;
- }
- return base::MakeUnique<base::Value>(setting);
-}
-
void GetRendererContentSettingRules(const HostContentSettingsMap* map,
RendererContentSettingRules* rules) {
#if !defined(OS_ANDROID)
@@ -158,12 +129,10 @@ void GetRendererContentSettingRules(const HostContentSettingsMap* map,
#else
// Android doesn't use image content settings, so ALLOW rule is added for
// all origins.
- rules->image_rules.push_back(
- ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
- ContentSettingsPattern::Wildcard(),
- CONTENT_SETTING_ALLOW,
- std::string(),
- map->is_incognito()));
+ rules->image_rules.push_back(ContentSettingPatternSource(
+ ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
+ ContentSettingToValue(CONTENT_SETTING_ALLOW), std::string(),
+ map->is_incognito()));
#endif
map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
diff --git a/chromium/components/content_settings/core/browser/content_settings_utils.h b/chromium/components/content_settings/core/browser/content_settings_utils.h
index fdcaf0bc6fa..476398d7e31 100644
--- a/chromium/components/content_settings/core/browser/content_settings_utils.h
+++ b/chromium/components/content_settings/core/browser/content_settings_utils.h
@@ -5,7 +5,6 @@
#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_UTILS_H_
#define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_UTILS_H_
-#include <memory>
#include <string>
#include <utility>
@@ -14,10 +13,6 @@
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
-namespace base {
-class Value;
-}
-
class HostContentSettingsMap;
namespace content_settings {
@@ -58,25 +53,12 @@ std::string ContentSettingToString(ContentSetting setting);
// Returns true if |name| specifies a valid content setting, false otherwise.
bool ContentSettingFromString(const std::string& name, ContentSetting* setting);
-// Converts |Value| to |ContentSetting|.
-ContentSetting ValueToContentSetting(const base::Value* value);
-
-// Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
-// a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
-// is encoded as a NULL value, so it is not allowed as an integer value.
-bool ParseContentSettingValue(const base::Value* value,
- ContentSetting* setting);
-
PatternPair ParsePatternString(const std::string& pattern_str);
std::string CreatePatternString(
const ContentSettingsPattern& item_pattern,
const ContentSettingsPattern& top_level_frame_pattern);
-// Returns a |base::Value*| representation of |setting| if |setting| is
-// a valid content setting. Otherwise, returns a nullptr.
-std::unique_ptr<base::Value> ContentSettingToValue(ContentSetting setting);
-
// Populates |rules| with content setting rules for content types that are
// handled by the renderer.
void GetRendererContentSettingRules(const HostContentSettingsMap* map,
diff --git a/chromium/components/content_settings/core/browser/cookie_settings.cc b/chromium/components/content_settings/core/browser/cookie_settings.cc
index e9603c73ff7..6dbac81c6ae 100644
--- a/chromium/components/content_settings/core/browser/cookie_settings.cc
+++ b/chromium/components/content_settings/core/browser/cookie_settings.cc
@@ -9,6 +9,7 @@
#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/common/content_settings_pattern.h"
+#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
diff --git a/chromium/components/content_settings/core/browser/host_content_settings_map.cc b/chromium/components/content_settings/core/browser/host_content_settings_map.cc
index 52a6708ea74..19483f291ca 100644
--- a/chromium/components/content_settings/core/browser/host_content_settings_map.cc
+++ b/chromium/components/content_settings/core/browser/host_content_settings_map.cc
@@ -16,6 +16,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/clock.h"
+#include "base/values.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/content_settings_default_provider.h"
#include "components/content_settings/core/browser/content_settings_details.h"
@@ -29,6 +30,7 @@
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/browser/website_settings_registry.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
+#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
@@ -55,6 +57,7 @@ const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = {
{"policy", content_settings::SETTING_SOURCE_POLICY},
{"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED},
{"extension", content_settings::SETTING_SOURCE_EXTENSION},
+ {"notification_android", content_settings::SETTING_SOURCE_USER},
{"preference", content_settings::SETTING_SOURCE_USER},
{"default", content_settings::SETTING_SOURCE_USER},
};
@@ -384,6 +387,8 @@ void HostContentSettingsMap::SetWebsiteSettingCustomScope(
std::unique_ptr<base::Value> value) {
DCHECK(SupportsResourceIdentifier(content_type) ||
resource_identifier.empty());
+ // TODO(crbug.com/731126): Verify that assumptions for notification content
+ // settings are met.
UsedContentSettingsProviders();
for (const auto& provider_pair : content_settings_providers_) {
@@ -526,7 +531,7 @@ void HostContentSettingsMap::MigrateDomainScopedSettings(bool after_sync) {
if (setting_entry.source != "preference")
continue;
// Migrate ALLOW settings only.
- if (setting_entry.setting != CONTENT_SETTING_ALLOW)
+ if (setting_entry.GetContentSetting() != CONTENT_SETTING_ALLOW)
continue;
// Skip default settings.
if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard())
@@ -733,7 +738,7 @@ void HostContentSettingsMap::AddSettingsForOneType(
while (rule_iterator->HasNext()) {
const content_settings::Rule& rule = rule_iterator->Next();
- ContentSetting setting_value = CONTENT_SETTING_DEFAULT;
+ std::unique_ptr<base::Value> setting_value;
// TODO(bauerb): Return rules as a list of values, not content settings.
// Handle the case using base::Values for its exceptions and default
// setting. Here we assume all the exceptions are granted as
@@ -742,12 +747,13 @@ void HostContentSettingsMap::AddSettingsForOneType(
content_type) &&
rule.value.get() &&
rule.primary_pattern != ContentSettingsPattern::Wildcard()) {
- setting_value = CONTENT_SETTING_ALLOW;
+ setting_value =
+ content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW);
} else {
- setting_value = content_settings::ValueToContentSetting(rule.value.get());
+ setting_value = base::MakeUnique<base::Value>(*(rule.value));
}
settings->push_back(ContentSettingPatternSource(
- rule.primary_pattern, rule.secondary_pattern, setting_value,
+ rule.primary_pattern, rule.secondary_pattern, std::move(setting_value),
kProviderNamesSourceMap[provider_type].provider_name, incognito));
}
}
@@ -910,4 +916,4 @@ HostContentSettingsMap::GetContentSettingValueAndPatterns(
void HostContentSettingsMap::SetClockForTesting(
std::unique_ptr<base::Clock> clock) {
pref_provider_->SetClockForTesting(std::move(clock));
-} \ No newline at end of file
+}
diff --git a/chromium/components/content_settings/core/browser/host_content_settings_map.h b/chromium/components/content_settings/core/browser/host_content_settings_map.h
index b5c7798b02f..b9f4bfb3689 100644
--- a/chromium/components/content_settings/core/browser/host_content_settings_map.h
+++ b/chromium/components/content_settings/core/browser/host_content_settings_map.h
@@ -57,6 +57,7 @@ class HostContentSettingsMap : public content_settings::Observer,
POLICY_PROVIDER,
SUPERVISED_PROVIDER,
CUSTOM_EXTENSION_PROVIDER,
+ NOTIFICATION_ANDROID_PROVIDER,
PREF_PROVIDER,
DEFAULT_PROVIDER,
NUM_PROVIDER_TYPES
diff --git a/chromium/components/content_settings/core/browser/website_settings_registry.cc b/chromium/components/content_settings/core/browser/website_settings_registry.cc
index 4d49cef938c..b04fff48149 100644
--- a/chromium/components/content_settings/core/browser/website_settings_registry.cc
+++ b/chromium/components/content_settings/core/browser/website_settings_registry.cc
@@ -8,8 +8,13 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
+#include "build/build_config.h"
#include "components/content_settings/core/common/content_settings.h"
+#if !defined(OS_IOS)
+#include "media/base/media_switches.h"
+#endif // !defined(OS_IOS)
+
namespace {
base::LazyInstance<content_settings::WebsiteSettingsRegistry>::DestructorAtExit
@@ -168,11 +173,20 @@ void WebsiteSettingsRegistry::Init() {
// Set when an origin is activated for subresource filtering and the
// associated UI is shown to the user. Cleared when a site is de-activated or
// the first URL matching the origin is removed from history.
- Register(
- CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER_DATA, "subresource-filter-data",
- nullptr, WebsiteSettingsInfo::UNSYNCABLE, WebsiteSettingsInfo::NOT_LOSSY,
- WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE,
- DESKTOP | PLATFORM_ANDROID, WebsiteSettingsInfo::INHERIT_IN_INCOGNITO);
+ Register(CONTENT_SETTINGS_TYPE_ADS_DATA, "subresource-filter-data", nullptr,
+ WebsiteSettingsInfo::UNSYNCABLE, WebsiteSettingsInfo::NOT_LOSSY,
+ WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE,
+ DESKTOP | PLATFORM_ANDROID,
+ WebsiteSettingsInfo::INHERIT_IN_INCOGNITO);
+#if !defined(OS_IOS)
+ if (base::FeatureList::IsEnabled(media::kRecordMediaEngagementScores)) {
+ Register(CONTENT_SETTINGS_TYPE_MEDIA_ENGAGEMENT, "media-engagement",
+ nullptr, WebsiteSettingsInfo::SYNCABLE, WebsiteSettingsInfo::LOSSY,
+ WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE,
+ DESKTOP | PLATFORM_ANDROID,
+ WebsiteSettingsInfo::INHERIT_IN_INCOGNITO);
+ }
+#endif //! defined(OS_IOS)
}
} // namespace content_settings
diff --git a/chromium/components/content_settings/core/common/BUILD.gn b/chromium/components/content_settings/core/common/BUILD.gn
index 42404221620..a70021e8a51 100644
--- a/chromium/components/content_settings/core/common/BUILD.gn
+++ b/chromium/components/content_settings/core/common/BUILD.gn
@@ -13,6 +13,8 @@ static_library("common") {
"content_settings_pattern_parser.cc",
"content_settings_pattern_parser.h",
"content_settings_types.h",
+ "content_settings_utils.cc",
+ "content_settings_utils.h",
"pref_names.cc",
"pref_names.h",
]
@@ -21,6 +23,8 @@ static_library("common") {
deps = [
"//base",
+ "//mojo/common:common_custom_types",
+ "//mojo/common:struct_traits",
"//mojo/public/cpp/bindings:struct_traits",
"//net",
"//url",
@@ -47,4 +51,8 @@ mojom("mojo_bindings") {
sources = [
"content_settings.mojom",
]
+
+ public_deps = [
+ "//mojo/common:common_custom_types",
+ ]
}
diff --git a/chromium/components/content_settings/core/common/DEPS b/chromium/components/content_settings/core/common/DEPS
index 4e501b277a1..54fa71b60e1 100644
--- a/chromium/components/content_settings/core/common/DEPS
+++ b/chromium/components/content_settings/core/common/DEPS
@@ -1,4 +1,5 @@
include_rules = [
+ "+mojo/common",
"+mojo/public/cpp/bindings",
"+net/base",
"+testing",
diff --git a/chromium/components/content_settings/core/common/OWNERS b/chromium/components/content_settings/core/common/OWNERS
index ac44cd00686..fda0d857f5e 100644
--- a/chromium/components/content_settings/core/common/OWNERS
+++ b/chromium/components/content_settings/core/common/OWNERS
@@ -3,3 +3,6 @@ per-file *.mojom=file://ipc/SECURITY_OWNERS
per-file *_struct_traits*.*=set noparent
per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
+
+per-file *.typemap=set noparent
+per-file *.typemap=file://ipc/SECURITY_OWNERS
diff --git a/chromium/components/content_settings/core/common/content_settings.cc b/chromium/components/content_settings/core/common/content_settings.cc
index 4cf2d132898..4b32cb96c3e 100644
--- a/chromium/components/content_settings/core/common/content_settings.cc
+++ b/chromium/components/content_settings/core/common/content_settings.cc
@@ -4,17 +4,15 @@
#include "components/content_settings/core/common/content_settings.h"
-#include "base/containers/hash_tables.h"
+#include <algorithm>
+
#include "base/logging.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "build/build_config.h"
+#include "components/content_settings/core/common/content_settings_utils.h"
-ContentSetting IntToContentSetting(int content_setting) {
- return ((content_setting < 0) ||
- (content_setting >= CONTENT_SETTING_NUM_SETTINGS)) ?
- CONTENT_SETTING_DEFAULT : static_cast<ContentSetting>(content_setting);
-}
+namespace {
struct HistogramValue {
ContentSettingsType type;
@@ -25,9 +23,13 @@ struct HistogramValue {
// specified in the ContentType enum in histograms.xml. Since these values are
// used for histograms, please do not reuse the same value for a different
// content setting. Always append to the end and increment.
+//
// TODO(raymes): We should use a sparse histogram here on the hash of the
// content settings type name instead.
-HistogramValue kHistogramValue[] = {
+//
+// The array size must be explicit for the static_asserts below.
+constexpr size_t kNumHistogramValues = 30;
+constexpr HistogramValue kHistogramValue[kNumHistogramValues] = {
{CONTENT_SETTINGS_TYPE_COOKIES, 0},
{CONTENT_SETTINGS_TYPE_IMAGES, 1},
{CONTENT_SETTINGS_TYPE_JAVASCRIPT, 2},
@@ -44,9 +46,7 @@ HistogramValue kHistogramValue[] = {
{CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, 16},
{CONTENT_SETTINGS_TYPE_MIDI_SYSEX, 17},
{CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, 19},
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
{CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, 21},
-#endif
{CONTENT_SETTINGS_TYPE_APP_BANNER, 22},
{CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, 23},
{CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, 24},
@@ -55,43 +55,81 @@ HistogramValue kHistogramValue[] = {
{CONTENT_SETTINGS_TYPE_AUTOPLAY, 28},
{CONTENT_SETTINGS_TYPE_IMPORTANT_SITE_INFO, 30},
{CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA, 31},
- {CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, 32},
- {CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER_DATA, 33},
+ {CONTENT_SETTINGS_TYPE_ADS, 32},
+ {CONTENT_SETTINGS_TYPE_ADS_DATA, 33},
+ {CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, 34},
+ {CONTENT_SETTINGS_TYPE_MEDIA_ENGAGEMENT, 35},
+ {CONTENT_SETTINGS_TYPE_SOUND, 36},
};
+} // namespace
+
+ContentSetting IntToContentSetting(int content_setting) {
+ return ((content_setting < 0) ||
+ (content_setting >= CONTENT_SETTING_NUM_SETTINGS))
+ ? CONTENT_SETTING_DEFAULT
+ : static_cast<ContentSetting>(content_setting);
+}
+
int ContentSettingTypeToHistogramValue(ContentSettingsType content_setting,
size_t* num_values) {
- // Translate the list above into a map for fast lookup.
- typedef base::hash_map<int, int> Map;
- CR_DEFINE_STATIC_LOCAL(Map, kMap, ());
- if (kMap.empty()) {
- for (const HistogramValue& histogram_value : kHistogramValue)
- kMap[histogram_value.type] = histogram_value.value;
- }
-
- DCHECK(base::ContainsKey(kMap, content_setting));
*num_values = arraysize(kHistogramValue);
- return kMap[content_setting];
+
+ // Verify the array is sorted by enum type and contains all values.
+ DCHECK(std::is_sorted(std::begin(kHistogramValue), std::end(kHistogramValue),
+ [](const HistogramValue& a, const HistogramValue& b) {
+ return a.type < b.type;
+ }));
+ static_assert(kHistogramValue[kNumHistogramValues - 1].type ==
+ CONTENT_SETTINGS_NUM_TYPES - 1,
+ "Update content settings histogram lookup");
+
+ const HistogramValue* found = std::lower_bound(
+ std::begin(kHistogramValue), std::end(kHistogramValue), content_setting,
+ [](const HistogramValue& a, ContentSettingsType b) {
+ return a.type < b;
+ });
+ if (found != std::end(kHistogramValue) && found->type == content_setting)
+ return found->value;
+ NOTREACHED();
+ return -1;
}
ContentSettingPatternSource::ContentSettingPatternSource(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
- ContentSetting setting,
+ std::unique_ptr<base::Value> setting_value,
const std::string& source,
bool incognito)
: primary_pattern(primary_pattern),
secondary_pattern(secondary_pattern),
- setting(setting),
+ setting_value(std::move(setting_value)),
source(source),
incognito(incognito) {}
-ContentSettingPatternSource::ContentSettingPatternSource()
- : setting(CONTENT_SETTING_DEFAULT), incognito(false) {
-}
+ContentSettingPatternSource::ContentSettingPatternSource() : incognito(false) {}
ContentSettingPatternSource::ContentSettingPatternSource(
- const ContentSettingPatternSource& other) = default;
+ const ContentSettingPatternSource& other) {
+ *this = other;
+}
+
+ContentSettingPatternSource& ContentSettingPatternSource::operator=(
+ const ContentSettingPatternSource& other) {
+ primary_pattern = other.primary_pattern;
+ secondary_pattern = other.secondary_pattern;
+ if (other.setting_value)
+ setting_value = base::MakeUnique<base::Value>(*(other.setting_value));
+ source = other.source;
+ incognito = other.incognito;
+ return *this;
+}
+
+ContentSettingPatternSource::~ContentSettingPatternSource() {}
+
+ContentSetting ContentSettingPatternSource::GetContentSetting() const {
+ return content_settings::ValueToContentSetting(setting_value.get());
+}
RendererContentSettingRules::RendererContentSettingRules() {}
diff --git a/chromium/components/content_settings/core/common/content_settings.h b/chromium/components/content_settings/core/common/content_settings.h
index c441e280eaa..e28e51eed34 100644
--- a/chromium/components/content_settings/core/common/content_settings.h
+++ b/chromium/components/content_settings/core/common/content_settings.h
@@ -7,9 +7,12 @@
#include <stddef.h>
+#include <memory>
#include <string>
#include <vector>
+#include "base/memory/ptr_util.h"
+#include "base/values.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
@@ -43,14 +46,19 @@ int ContentSettingTypeToHistogramValue(ContentSettingsType content_setting,
struct ContentSettingPatternSource {
ContentSettingPatternSource(const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_patttern,
- ContentSetting setting,
+ std::unique_ptr<base::Value> setting_value,
const std::string& source,
bool incognito);
ContentSettingPatternSource(const ContentSettingPatternSource& other);
ContentSettingPatternSource();
+ ContentSettingPatternSource& operator=(
+ const ContentSettingPatternSource& other);
+ ~ContentSettingPatternSource();
+ ContentSetting GetContentSetting() const;
+
ContentSettingsPattern primary_pattern;
ContentSettingsPattern secondary_pattern;
- ContentSetting setting;
+ std::unique_ptr<base::Value> setting_value;
std::string source;
bool incognito;
};
diff --git a/chromium/components/content_settings/core/common/content_settings.mojom b/chromium/components/content_settings/core/common/content_settings.mojom
index 5c4c5d92a92..3669aec081a 100644
--- a/chromium/components/content_settings/core/common/content_settings.mojom
+++ b/chromium/components/content_settings/core/common/content_settings.mojom
@@ -4,6 +4,8 @@
module content_settings.mojom;
+import "mojo/common/values.mojom";
+
// This mirrors the C++ type in content_settings_pattern.h.
struct PatternParts {
// Lowercase string of the URL scheme to match. This string is empty if the
@@ -59,7 +61,7 @@ enum ContentSetting {
struct ContentSettingPatternSource {
ContentSettingsPattern primary_pattern;
ContentSettingsPattern secondary_pattern;
- ContentSetting setting;
+ mojo.common.mojom.Value setting_value;
string source;
bool incognito;
};
diff --git a/chromium/components/content_settings/core/common/content_settings_pattern.cc b/chromium/components/content_settings/core/common/content_settings_pattern.cc
index a83a6959a02..e88351a5d0b 100644
--- a/chromium/components/content_settings/core/common/content_settings_pattern.cc
+++ b/chromium/components/content_settings/core/common/content_settings_pattern.cc
@@ -10,6 +10,7 @@
#include <vector>
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "components/content_settings/core/common/content_settings_pattern_parser.h"
@@ -100,7 +101,7 @@ typedef ContentSettingsPattern::BuilderInterface BuilderInterface;
class ContentSettingsPattern::Builder :
public ContentSettingsPattern::BuilderInterface {
public:
- explicit Builder(bool use_legacy_validate);
+ explicit Builder();
~Builder() override;
// BuilderInterface:
@@ -124,20 +125,14 @@ class ContentSettingsPattern::Builder :
// Returns true when the pattern |parts| represent a valid pattern.
static bool Validate(const PatternParts& parts);
- static bool LegacyValidate(const PatternParts& parts);
-
bool is_valid_;
- bool use_legacy_validate_;
-
PatternParts parts_;
DISALLOW_COPY_AND_ASSIGN(Builder);
};
-ContentSettingsPattern::Builder::Builder(bool use_legacy_validate)
- : is_valid_(true),
- use_legacy_validate_(use_legacy_validate) {}
+ContentSettingsPattern::Builder::Builder() : is_valid_(true) {}
ContentSettingsPattern::Builder::~Builder() {}
@@ -201,17 +196,11 @@ ContentSettingsPattern ContentSettingsPattern::Builder::Build() {
return ContentSettingsPattern();
if (!Canonicalize(&parts_))
return ContentSettingsPattern();
- if (use_legacy_validate_) {
- is_valid_ = LegacyValidate(parts_);
- } else {
- is_valid_ = Validate(parts_);
- }
+ is_valid_ = Validate(parts_);
if (!is_valid_)
return ContentSettingsPattern();
// A pattern is invalid if canonicalization is not idempotent.
- // This check is here because it should be checked no matter
- // use_legacy_validate_ is.
PatternParts parts(parts_);
if (!Canonicalize(&parts))
return ContentSettingsPattern();
@@ -302,41 +291,6 @@ bool ContentSettingsPattern::Builder::Validate(const PatternParts& parts) {
return true;
}
-// static
-bool ContentSettingsPattern::Builder::LegacyValidate(
- const PatternParts& parts) {
- // If the pattern is for a "file-pattern" test if it is valid.
- if (parts.scheme == std::string(url::kFileScheme) &&
- !parts.is_scheme_wildcard &&
- parts.host.empty() &&
- parts.port.empty())
- return true;
-
- // If the pattern is for an extension URL test if it is valid.
- if (IsNonWildcardDomainNonPortScheme(parts.scheme) &&
- !parts.is_scheme_wildcard &&
- !parts.host.empty() &&
- !parts.has_domain_wildcard &&
- parts.port.empty() &&
- !parts.is_port_wildcard)
- return true;
-
- // Non-file patterns are invalid if either the scheme, host or port part is
- // empty.
- if ((!parts.is_scheme_wildcard) ||
- (parts.host.empty() && !parts.has_domain_wildcard) ||
- (!parts.is_port_wildcard))
- return false;
-
- // Test if the scheme is supported or a wildcard.
- if (!parts.is_scheme_wildcard &&
- parts.scheme != std::string(url::kHttpScheme) &&
- parts.scheme != std::string(url::kHttpsScheme)) {
- return false;
- }
- return true;
-}
-
// ////////////////////////////////////////////////////////////////////////////
// ContentSettingsPattern::PatternParts
//
@@ -367,9 +321,8 @@ ContentSettingsPattern::PatternParts::~PatternParts() {}
const int ContentSettingsPattern::kContentSettingsPatternVersion = 1;
// static
-BuilderInterface* ContentSettingsPattern::CreateBuilder(
- bool validate) {
- return new Builder(validate);
+std::unique_ptr<BuilderInterface> ContentSettingsPattern::CreateBuilder() {
+ return base::MakeUnique<Builder>();
}
// static
@@ -385,71 +338,67 @@ ContentSettingsPattern ContentSettingsPattern::Wildcard() {
// static
ContentSettingsPattern ContentSettingsPattern::FromURL(
const GURL& url) {
- std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
- ContentSettingsPattern::CreateBuilder(false));
+ ContentSettingsPattern::Builder builder;
const GURL* local_url = &url;
if (url.SchemeIsFileSystem() && url.inner_url()) {
local_url = url.inner_url();
}
if (local_url->SchemeIsFile()) {
- builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
+ builder.WithScheme(local_url->scheme())->WithPath(local_url->path());
} else {
// Please keep the order of the ifs below as URLs with an IP as host can
// also have a "http" scheme.
if (local_url->HostIsIPAddress()) {
- builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
+ builder.WithScheme(local_url->scheme())->WithHost(local_url->host());
} else if (local_url->SchemeIs(url::kHttpScheme)) {
- builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(
+ builder.WithSchemeWildcard()->WithDomainWildcard()->WithHost(
local_url->host());
} else if (local_url->SchemeIs(url::kHttpsScheme)) {
- builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost(
- local_url->host());
+ builder.WithScheme(local_url->scheme())
+ ->WithDomainWildcard()
+ ->WithHost(local_url->host());
} else {
// Unsupported scheme
}
if (local_url->port().empty()) {
if (local_url->SchemeIs(url::kHttpsScheme))
- builder->WithPort(GetDefaultPort(url::kHttpsScheme));
+ builder.WithPort(GetDefaultPort(url::kHttpsScheme));
else
- builder->WithPortWildcard();
+ builder.WithPortWildcard();
} else {
- builder->WithPort(local_url->port());
+ builder.WithPort(local_url->port());
}
}
- return builder->Build();
+ return builder.Build();
}
// static
ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard(
const GURL& url) {
- std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
- ContentSettingsPattern::CreateBuilder(false));
-
+ ContentSettingsPattern::Builder builder;
const GURL* local_url = &url;
if (url.SchemeIsFileSystem() && url.inner_url()) {
local_url = url.inner_url();
}
if (local_url->SchemeIsFile()) {
- builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
+ builder.WithScheme(local_url->scheme())->WithPath(local_url->path());
} else {
- builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
+ builder.WithScheme(local_url->scheme())->WithHost(local_url->host());
if (local_url->port().empty()) {
- builder->WithPort(GetDefaultPort(local_url->scheme()));
+ builder.WithPort(GetDefaultPort(local_url->scheme()));
} else {
- builder->WithPort(local_url->port());
+ builder.WithPort(local_url->port());
}
}
- return builder->Build();
+ return builder.Build();
}
// static
ContentSettingsPattern ContentSettingsPattern::FromString(
const std::string& pattern_spec) {
- std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
- ContentSettingsPattern::CreateBuilder(false));
- content_settings::PatternParser::Parse(pattern_spec,
- builder.get());
- return builder->Build();
+ ContentSettingsPattern::Builder builder;
+ content_settings::PatternParser::Parse(pattern_spec, &builder);
+ return builder.Build();
}
// static
@@ -481,27 +430,25 @@ bool ContentSettingsPattern::MigrateFromDomainToOrigin(
if (domain_pattern.parts_.host.empty())
return false;
- std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
- ContentSettingsPattern::CreateBuilder(false));
-
+ ContentSettingsPattern::Builder builder;
if (domain_pattern.parts_.is_scheme_wildcard)
- builder->WithScheme(url::kHttpScheme);
+ builder.WithScheme(url::kHttpScheme);
else
- builder->WithScheme(domain_pattern.parts_.scheme);
+ builder.WithScheme(domain_pattern.parts_.scheme);
- builder->WithHost(domain_pattern.parts_.host);
+ builder.WithHost(domain_pattern.parts_.host);
if (domain_pattern.parts_.is_port_wildcard) {
if (domain_pattern.parts_.scheme == url::kHttpsScheme) {
- builder->WithPort(GetDefaultPort(url::kHttpsScheme));
+ builder.WithPort(GetDefaultPort(url::kHttpsScheme));
} else {
- builder->WithPort(GetDefaultPort(url::kHttpScheme));
+ builder.WithPort(GetDefaultPort(url::kHttpScheme));
}
} else {
- builder->WithPort(domain_pattern.parts_.port);
+ builder.WithPort(domain_pattern.parts_.port);
}
- *origin_pattern = builder->Build();
+ *origin_pattern = builder.Build();
return true;
}
diff --git a/chromium/components/content_settings/core/common/content_settings_pattern.h b/chromium/components/content_settings/core/common/content_settings_pattern.h
index 7d6fc8d00dd..fe292d53d47 100644
--- a/chromium/components/content_settings/core/common/content_settings_pattern.h
+++ b/chromium/components/content_settings/core/common/content_settings_pattern.h
@@ -7,6 +7,7 @@
#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_
#define COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_
+#include <memory>
#include <string>
#include "base/gtest_prod_util.h"
@@ -136,7 +137,7 @@ class ContentSettingsPattern {
virtual ContentSettingsPattern Build() = 0;
};
- static BuilderInterface* CreateBuilder(bool use_legacy_validate);
+ static std::unique_ptr<BuilderInterface> CreateBuilder();
// The version of the pattern format implemented.
static const int kContentSettingsPatternVersion;
diff --git a/chromium/components/content_settings/core/common/content_settings_pattern_unittest.cc b/chromium/components/content_settings/core/common/content_settings_pattern_unittest.cc
index d5aab80ab86..0a3938488c8 100644
--- a/chromium/components/content_settings/core/common/content_settings_pattern_unittest.cc
+++ b/chromium/components/content_settings/core/common/content_settings_pattern_unittest.cc
@@ -184,8 +184,8 @@ TEST(ContentSettingsPatternTest, FromURLNoWildcard) {
// The static Wildcard() method goes through a fast path and avoids the Builder
// pattern. Ensure that it yields the exact same behavior.
TEST(ContentSettingsPatternTest, ValidWildcardFastPath) {
- std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
- ContentSettingsPattern::CreateBuilder(true));
+ std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder =
+ ContentSettingsPattern::CreateBuilder();
builder->WithSchemeWildcard()->WithDomainWildcard()->WithPortWildcard()->
WithPathWildcard();
ContentSettingsPattern built_wildcard = builder->Build();
diff --git a/chromium/components/content_settings/core/common/content_settings_struct_traits.cc b/chromium/components/content_settings/core/common/content_settings_struct_traits.cc
index 11ad9c92ed6..b5bac4a40d9 100644
--- a/chromium/components/content_settings/core/common/content_settings_struct_traits.cc
+++ b/chromium/components/content_settings/core/common/content_settings_struct_traits.cc
@@ -88,7 +88,8 @@ bool StructTraits<content_settings::mojom::ContentSettingPatternSourceDataView,
out->incognito = data.incognito();
return data.ReadPrimaryPattern(&out->primary_pattern) &&
data.ReadSecondaryPattern(&out->secondary_pattern) &&
- data.ReadSetting(&out->setting) && data.ReadSource(&out->source);
+ data.ReadSettingValue(&out->setting_value) &&
+ data.ReadSource(&out->source);
}
// static
diff --git a/chromium/components/content_settings/core/common/content_settings_struct_traits.h b/chromium/components/content_settings/core/common/content_settings_struct_traits.h
index 10c78efeafd..ab3fee43862 100644
--- a/chromium/components/content_settings/core/common/content_settings_struct_traits.h
+++ b/chromium/components/content_settings/core/common/content_settings_struct_traits.h
@@ -7,8 +7,11 @@
#include <string>
+#include "base/memory/ptr_util.h"
+#include "base/values.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings.mojom.h"
+#include "mojo/common/values_struct_traits.h"
#include "mojo/public/cpp/bindings/enum_traits.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
@@ -96,8 +99,9 @@ struct StructTraits<
return r.secondary_pattern;
}
- static ContentSetting setting(const ContentSettingPatternSource& r) {
- return r.setting;
+ static const std::unique_ptr<base::Value>& setting_value(
+ const ContentSettingPatternSource& r) {
+ return r.setting_value;
}
static const std::string& source(const ContentSettingPatternSource& r) {
diff --git a/chromium/components/content_settings/core/common/content_settings_types.h b/chromium/components/content_settings/core/common/content_settings_types.h
index 580a94ac8c6..e752e9e96e4 100644
--- a/chromium/components/content_settings/core/common/content_settings_types.h
+++ b/chromium/components/content_settings/core/common/content_settings_types.h
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2017 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.
@@ -48,11 +48,11 @@ enum ContentSettingsType {
CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT,
CONTENT_SETTINGS_TYPE_IMPORTANT_SITE_INFO,
CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA,
- CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER,
+ CONTENT_SETTINGS_TYPE_ADS,
// Website setting which stores metadata for the subresource filter to aid in
// decisions for whether or not to show the UI.
- CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER_DATA,
+ CONTENT_SETTINGS_TYPE_ADS_DATA,
// This is special-cased in the permissions layer to always allow, and as
// such doesn't have associated prefs data.
@@ -67,8 +67,15 @@ enum ContentSettingsType {
// verdicts of each origin.
CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION,
- // WARNING: This enum is going to be removed soon. Do not depend on NUM_TYPES.
- CONTENT_SETTINGS_NUM_TYPES_DO_NOT_USE,
+ // Website setting which stores engagement data for media related to a
+ // specific origin.
+ CONTENT_SETTINGS_TYPE_MEDIA_ENGAGEMENT,
+
+ // Website setting which stores whether or not the site can play audible
+ // sound. This will not block playback but instead the user will not hear it.
+ CONTENT_SETTINGS_TYPE_SOUND,
+
+ CONTENT_SETTINGS_NUM_TYPES,
};
struct ContentSettingsTypeHash {
diff --git a/chromium/components/content_settings/core/common/content_settings_utils.cc b/chromium/components/content_settings/core/common/content_settings_utils.cc
new file mode 100644
index 00000000000..3f86905a69b
--- /dev/null
+++ b/chromium/components/content_settings/core/common/content_settings_utils.cc
@@ -0,0 +1,47 @@
+// Copyright 2017 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/common/content_settings_utils.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/values.h"
+
+namespace content_settings {
+
+namespace {
+
+// Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
+// a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
+// is encoded as a NULL value, so it is not allowed as an integer value.
+bool ParseContentSettingValue(const base::Value* value,
+ ContentSetting* setting) {
+ if (!value) {
+ *setting = CONTENT_SETTING_DEFAULT;
+ return true;
+ }
+ int int_value = -1;
+ if (!value->GetAsInteger(&int_value))
+ return false;
+ *setting = IntToContentSetting(int_value);
+ return *setting != CONTENT_SETTING_DEFAULT;
+}
+
+} // namespace
+
+ContentSetting ValueToContentSetting(const base::Value* value) {
+ ContentSetting setting = CONTENT_SETTING_DEFAULT;
+ bool valid = ParseContentSettingValue(value, &setting);
+ DCHECK(valid);
+ return setting;
+}
+
+std::unique_ptr<base::Value> ContentSettingToValue(ContentSetting setting) {
+ if (setting <= CONTENT_SETTING_DEFAULT ||
+ setting >= CONTENT_SETTING_NUM_SETTINGS) {
+ return nullptr;
+ }
+ return base::MakeUnique<base::Value>(setting);
+}
+
+} // namespace content_settings
diff --git a/chromium/components/content_settings/core/common/content_settings_utils.h b/chromium/components/content_settings/core/common/content_settings_utils.h
new file mode 100644
index 00000000000..640483d9338
--- /dev/null
+++ b/chromium/components/content_settings/core/common/content_settings_utils.h
@@ -0,0 +1,27 @@
+// Copyright 2017 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_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_UTILS_H_
+#define COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_UTILS_H_
+
+#include <memory>
+
+#include "components/content_settings/core/common/content_settings.h"
+
+namespace base {
+class Value;
+}
+
+namespace content_settings {
+
+// Converts |value| to |ContentSetting|.
+ContentSetting ValueToContentSetting(const base::Value* value);
+
+// Returns a base::Value representation of |setting| if |setting| is
+// a valid content setting. Otherwise, returns a nullptr.
+std::unique_ptr<base::Value> ContentSettingToValue(ContentSetting setting);
+
+} // namespace content_settings
+
+#endif // COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_UTILS_H_