Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5034)

Unified Diff: chrome/browser/content_settings/content_settings_override_provider.cc

Issue 542253003: Add a global on/off switch for content settings and expose a toggle on the Website Settings options… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@global-settings
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/content_settings_override_provider.cc
diff --git a/chrome/browser/content_settings/content_settings_override_provider.cc b/chrome/browser/content_settings/content_settings_override_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8470f939dcd23edea3189cb904dd66492ecd73ad
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_override_provider.cc
@@ -0,0 +1,136 @@
+// Copyright 2014 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/content_settings/content_settings_override_provider.h"
+
+#include <string>
+
+#include "base/auto_reset.h"
+#include "base/prefs/pref_service.h"
+#include "base/prefs/scoped_user_pref_update.h"
+#include "base/values.h"
+#include "chrome/browser/content_settings/content_settings_rule.h"
+#include "chrome/browser/content_settings/content_settings_utils.h"
+#include "chrome/common/content_settings.h"
+#include "chrome/common/pref_names.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
+#include "components/pref_registry/pref_registry_syncable.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+
+namespace content_settings {
+
+namespace {
+
+class OverrideRuleIterator : public RuleIterator {
+ public:
+ explicit OverrideRuleIterator(bool is_allowed) : is_done_(is_allowed) {}
+
+ virtual bool HasNext() const OVERRIDE { return !is_done_; }
+
+ virtual Rule Next() OVERRIDE {
+ DCHECK(!is_done_);
+ is_done_ = true;
+ return Rule(ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(),
+ new base::FundamentalValue(CONTENT_SETTING_BLOCK));
+ }
+
+ private:
+ bool is_done_;
+};
+
+} // namespace
+
+// static
+void OverrideProvider::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterDictionaryPref(
+ prefs::kOverrideContentSettings,
+ user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
+}
+
+OverrideProvider::OverrideProvider(PrefService* prefs, bool incognito)
+ : prefs_(prefs), is_incognito_(incognito) {
+ DCHECK(prefs_);
+
+ // Read global overrides.
+ ReadOverrideSettings();
+}
+
+OverrideProvider::~OverrideProvider() {
+}
+
+RuleIterator* OverrideProvider::GetRuleIterator(
+ ContentSettingsType content_type,
+ const ResourceIdentifier& resource_identifier,
+ bool incognito) const {
+ base::AutoLock lock(lock_);
+ if (resource_identifier.empty()) {
+ return new OverrideRuleIterator(allowed_settings_[content_type]);
+ }
+ return new EmptyRuleIterator();
+}
+
+void OverrideProvider::ClearAllContentSettingsRules(
+ ContentSettingsType content_type) {
+}
+
+bool OverrideProvider::SetWebsiteSetting(
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type,
+ const ResourceIdentifier& resource_identifier,
+ base::Value* in_value) {
+ return false;
+}
+
+void OverrideProvider::ShutdownOnUIThread() {
+ DCHECK(prefs_);
+ prefs_ = NULL;
+}
+
+void OverrideProvider::SetOverrideSetting(ContentSettingsType content_type,
+ bool enabled) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(prefs_);
+
+ // Disallow incognito to change the state.
+ DCHECK(!is_incognito_);
+
+ base::AutoLock lock(lock_);
+ DictionaryPrefUpdate update(prefs_, prefs::kOverrideContentSettings);
+ base::DictionaryValue* default_settings_dictionary = update.Get();
+ if (enabled) {
+ allowed_settings_[content_type] = true;
+ default_settings_dictionary->RemoveWithoutPathExpansion(
+ GetTypeName(content_type), NULL);
+ } else {
+ allowed_settings_[content_type] = false;
+ default_settings_dictionary->SetWithoutPathExpansion(
+ GetTypeName(content_type), new base::FundamentalValue(true));
+ }
+}
+
+bool OverrideProvider::IsEnabled(ContentSettingsType content_type) const {
+ base::AutoLock lock(lock_);
+ return allowed_settings_[content_type];
+}
+
+void OverrideProvider::ReadOverrideSettings() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ const base::DictionaryValue* blocked_settings_dictionary =
+ prefs_->GetDictionary(prefs::kOverrideContentSettings);
+
+ for (int type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
+ ContentSettingsType content_setting = ContentSettingsType(type);
+ if (blocked_settings_dictionary->HasKey(GetTypeName(content_setting)))
+ allowed_settings_[content_setting] = false;
Bernhard Bauer 2014/09/12 17:16:36 I would probably directly assign !dictionary->HasK
Daniel Nishi 2014/09/12 19:51:43 Done.
+ else
+ allowed_settings_[content_setting] = true;
+ }
+}
+
+} // namespace content_settings

Powered by Google App Engine
This is Rietveld 408576698