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

Side by Side 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: Forgot UsedContentSettingsProviders(). 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/content_settings/content_settings_override_provider.h"
6
7 #include <string>
8
9 #include "base/auto_reset.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/values.h"
13 #include "chrome/browser/content_settings/content_settings_rule.h"
14 #include "chrome/browser/content_settings/content_settings_utils.h"
15 #include "chrome/common/content_settings.h"
16 #include "chrome/common/pref_names.h"
17 #include "components/content_settings/core/common/content_settings_pattern.h"
18 #include "components/pref_registry/pref_registry_syncable.h"
19 #include "content/public/browser/browser_thread.h"
20
21
22 using content::BrowserThread;
23
24 namespace content_settings {
25
26 namespace {
27
28 class OverrideRuleIterator : public RuleIterator {
29 public:
30 explicit OverrideRuleIterator(const base::Value* value) {
31 if (value)
32 value_.reset(value->DeepCopy());
33 }
34
35 virtual bool HasNext() const OVERRIDE { return value_.get() != NULL; }
36
37 virtual Rule Next() OVERRIDE {
38 DCHECK(value_.get());
39 return Rule(ContentSettingsPattern::Wildcard(),
40 ContentSettingsPattern::Wildcard(),
41 value_.release());
42 }
43
44 private:
45 scoped_ptr<base::Value> value_;
Bernhard Bauer 2014/09/11 16:49:56 If we remove the ALLOW setting (instead falling th
Daniel Nishi 2014/09/11 20:58:12 Done.
46 };
47
48 } // namespace
49
50 // static
51 void OverrideProvider::RegisterProfilePrefs(
52 user_prefs::PrefRegistrySyncable* registry) {
53 registry->RegisterDictionaryPref(
54 prefs::kOverrideContentSettings,
55 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
56 }
57
58 OverrideProvider::OverrideProvider(PrefService* prefs, bool incognito)
59 : prefs_(prefs), is_incognito_(incognito) {
60 DCHECK(prefs_);
61
62 // Read global overrides.
63 ReadOverrideSettings();
64 }
65
66 OverrideProvider::~OverrideProvider() {
67 }
68
69 RuleIterator* OverrideProvider::GetRuleIterator(
70 ContentSettingsType content_type,
71 const ResourceIdentifier& resource_identifier,
72 bool incognito) const {
73 base::AutoLock lock(lock_);
74 if (resource_identifier.empty()) {
75 ValueMap::const_iterator it(override_settings_.find(content_type));
76 if (it != override_settings_.end())
77 return new OverrideRuleIterator(it->second.get());
78 }
79 return new EmptyRuleIterator();
80 }
81
82 void OverrideProvider::ClearAllContentSettingsRules(
83 ContentSettingsType content_type) {
84 }
85
86 bool OverrideProvider::SetWebsiteSetting(
87 const ContentSettingsPattern& primary_pattern,
88 const ContentSettingsPattern& secondary_pattern,
89 ContentSettingsType content_type,
90 const ResourceIdentifier& resource_identifier,
91 base::Value* in_value) {
92 DCHECK_CURRENTLY_ON(BrowserThread::UI);
93 DCHECK(prefs_);
94
95 // Disallow incognito to change the state.
96 DCHECK(!is_incognito_);
97
98 // Ignore non-global settings
99 if (primary_pattern != ContentSettingsPattern::Wildcard() ||
100 secondary_pattern != ContentSettingsPattern::Wildcard()) {
101 return false;
102 }
103
104 scoped_ptr<base::Value> value(in_value);
105 base::AutoLock lock(lock_);
106 DictionaryPrefUpdate update(prefs_, prefs::kOverrideContentSettings);
107 base::DictionaryValue* default_settings_dictionary = update.Get();
108 if (value.get() == NULL) {
109 override_settings_[content_type].reset(
110 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
111 default_settings_dictionary->SetWithoutPathExpansion(
112 GetTypeName(content_type),
113 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
114 } else {
115 ContentSetting setting = ValueToContentSetting(value.get());
116 if (setting != CONTENT_SETTING_ALLOW && setting != CONTENT_SETTING_BLOCK)
Bernhard Bauer 2014/09/11 16:49:56 This should be a DCHECK.
Daniel Nishi 2014/09/11 20:58:12 Function now just returns false.
117 NOTREACHED();
118
119 override_settings_[content_type].reset(value->DeepCopy());
120 default_settings_dictionary->SetWithoutPathExpansion(
121 GetTypeName(content_type), value.release());
122 }
123
124 return true;
125 }
126
127 void OverrideProvider::ShutdownOnUIThread() {
128 DCHECK(prefs_);
129 prefs_ = NULL;
130 }
131
132 bool OverrideProvider::IsEnabled(ContentSettingsType content_type) const {
133 base::AutoLock lock(lock_);
134 ValueMap::const_iterator it = override_settings_.find(content_type);
135 if (it == override_settings_.end())
136 return true;
137
138 ContentSetting ret = ValueToContentSetting(it->second.get());
139 return ret == CONTENT_SETTING_ALLOW;
140 }
141
142 void OverrideProvider::ReadOverrideSettings() {
143 DCHECK_CURRENTLY_ON(BrowserThread::UI);
144 const base::DictionaryValue* override_settings_dictionary =
145 prefs_->GetDictionary(prefs::kOverrideContentSettings);
146
147 if (override_settings_dictionary) {
148 for (base::DictionaryValue::Iterator i(*override_settings_dictionary);
149 !i.IsAtEnd();
150 i.Advance()) {
151 const std::string& content_type(i.key());
152 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
153 if (content_type == GetTypeName(ContentSettingsType(type))) {
154 ContentSetting setting = ValueToContentSetting(&(i.value()));
155 override_settings_[ContentSettingsType(type)].reset(
156 new base::FundamentalValue(setting));
157 break;
158 }
159 }
160 }
161 }
162 }
163 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698