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

Side by Side Diff: components/content_settings/core/browser/content_settings_registry.cc

Issue 1320673013: Remove HostContentSettingsMap::IsSettingAllowedForType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-issetting-allowed
Patch Set: Created 5 years, 2 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/content_settings/core/browser/content_settings_registry.h" 5 #include "components/content_settings/core/browser/content_settings_registry.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/content_settings/core/browser/content_settings_utils.h" 10 #include "components/content_settings/core/browser/content_settings_utils.h"
11 #include "components/content_settings/core/browser/website_settings_registry.h" 11 #include "components/content_settings/core/browser/website_settings_registry.h"
12 #include "components/content_settings/core/common/content_settings.h" 12 #include "components/content_settings/core/common/content_settings.h"
13 13
14 #if defined(ENABLE_PLUGINS) 14 #if defined(ENABLE_PLUGINS)
15 #include "components/content_settings/core/browser/plugins_field_trial.h" 15 #include "components/content_settings/core/browser/plugins_field_trial.h"
16 #endif 16 #endif
17 17
18 namespace content_settings { 18 namespace content_settings {
19 19
20 namespace { 20 namespace {
21 21
22 base::LazyInstance<content_settings::ContentSettingsRegistry> g_instance = 22 base::LazyInstance<ContentSettingsRegistry> g_instance =
23 LAZY_INSTANCE_INITIALIZER; 23 LAZY_INSTANCE_INITIALIZER;
24 24
25 // These functions return a vector of schemes in which various permissions will 25 // TODO(raymes): These overloaded functions make the registration code clearer.
26 // be whitelisted. 26 // When initializer lists are available they won't be needed. The initializer
27 const std::vector<std::string>& NoWhitelistedSchemes() { 27 // list can be implicitly or explicitly converted to a std::vector.
28 CR_DEFINE_STATIC_LOCAL(std::vector<std::string>, kNoWhitelistedSchemes, ()); 28 std::vector<std::string> WhitelistedSchemes() {
29 return kNoWhitelistedSchemes; 29 return std::vector<std::string>();
30 } 30 }
31 31
32 const std::vector<std::string>& WhitelistedForWebUI() { 32 std::vector<std::string> WhitelistedSchemes(const char* scheme1,
33 CR_DEFINE_STATIC_LOCAL(std::vector<std::string>, kWhitelistedForWebUI, ()); 33 const char* scheme2) {
34 if (kWhitelistedForWebUI.size() == 0) { 34 const char* schemes[] = {scheme1, scheme2};
35 kWhitelistedForWebUI.push_back(kChromeDevToolsScheme); 35 return std::vector<std::string>(schemes, schemes + arraysize(schemes));
36 kWhitelistedForWebUI.push_back(kChromeUIScheme);
37 }
38 return kWhitelistedForWebUI;
39 } 36 }
40 37
41 const std::vector<std::string>& WhitelistedForWebUIAndExtensions() { 38 std::vector<std::string> WhitelistedSchemes(const char* scheme1,
42 CR_DEFINE_STATIC_LOCAL(std::vector<std::string>, 39 const char* scheme2,
43 kWhitelistedForWebUIAndExtensions, ()); 40 const char* scheme3) {
44 if (kWhitelistedForWebUIAndExtensions.size() == 0) { 41 const char* schemes[] = {scheme1, scheme2, scheme3};
45 kWhitelistedForWebUIAndExtensions = WhitelistedForWebUI(); 42 return std::vector<std::string>(schemes, schemes + arraysize(schemes));
46 #if defined(ENABLE_EXTENSIONS) 43 }
47 kWhitelistedForWebUIAndExtensions.push_back(kExtensionScheme); 44
48 #endif 45 std::set<ContentSetting> ValidSettings() {
49 } 46 return std::set<ContentSetting>();
50 return kWhitelistedForWebUIAndExtensions; 47 }
48
49 std::set<ContentSetting> ValidSettings(ContentSetting setting1,
50 ContentSetting setting2) {
51 ContentSetting settings[] = {setting1, setting2};
52 return std::set<ContentSetting>(settings, settings + arraysize(settings));
53 }
54
55 std::set<ContentSetting> ValidSettings(ContentSetting setting1,
56 ContentSetting setting2,
57 ContentSetting setting3) {
58 ContentSetting settings[] = {setting1, setting2, setting3};
59 return std::set<ContentSetting>(settings, settings + arraysize(settings));
60 }
61
62 std::set<ContentSetting> ValidSettings(ContentSetting setting1,
63 ContentSetting setting2,
64 ContentSetting setting3,
65 ContentSetting setting4) {
66 ContentSetting settings[] = {setting1, setting2, setting3, setting4};
67 return std::set<ContentSetting>(settings, settings + arraysize(settings));
51 } 68 }
52 69
53 ContentSetting GetDefaultPluginsContentSetting() { 70 ContentSetting GetDefaultPluginsContentSetting() {
54 #if defined(ENABLE_PLUGINS) 71 #if defined(ENABLE_PLUGINS)
55 return PluginsFieldTrial::GetDefaultPluginsContentSetting(); 72 return PluginsFieldTrial::GetDefaultPluginsContentSetting();
56 #else 73 #else
57 return CONTENT_SETTING_BLOCK; 74 return CONTENT_SETTING_BLOCK;
58 #endif 75 #endif
59 } 76 }
60 77
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 118 }
102 119
103 void ContentSettingsRegistry::Init() { 120 void ContentSettingsRegistry::Init() {
104 // TODO(raymes): This registration code should not have to be in a single 121 // TODO(raymes): This registration code should not have to be in a single
105 // location. It should be possible to register a setting from the code 122 // location. It should be possible to register a setting from the code
106 // associated with it. 123 // associated with it.
107 124
108 // WARNING: The string names of the permissions passed in below are used to 125 // WARNING: The string names of the permissions passed in below are used to
109 // generate preference names and should never be changed! 126 // generate preference names and should never be changed!
110 127
111 // Content settings (those with allow/block/ask/etc. values).
112 Register(CONTENT_SETTINGS_TYPE_COOKIES, "cookies", CONTENT_SETTING_ALLOW, 128 Register(CONTENT_SETTINGS_TYPE_COOKIES, "cookies", CONTENT_SETTING_ALLOW,
113 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUI()); 129 WebsiteSettingsInfo::SYNCABLE,
130 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme),
131 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
132 CONTENT_SETTING_SESSION_ONLY));
133
114 Register(CONTENT_SETTINGS_TYPE_IMAGES, "images", CONTENT_SETTING_ALLOW, 134 Register(CONTENT_SETTINGS_TYPE_IMAGES, "images", CONTENT_SETTING_ALLOW,
115 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUIAndExtensions()); 135 WebsiteSettingsInfo::SYNCABLE,
136 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme,
137 kExtensionScheme),
138 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK));
139
116 Register(CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript", 140 Register(CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript",
117 CONTENT_SETTING_ALLOW, WebsiteSettingsInfo::SYNCABLE, 141 CONTENT_SETTING_ALLOW, WebsiteSettingsInfo::SYNCABLE,
118 WhitelistedForWebUIAndExtensions()); 142 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme,
143 kExtensionScheme),
144 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK));
145
119 Register(CONTENT_SETTINGS_TYPE_PLUGINS, "plugins", 146 Register(CONTENT_SETTINGS_TYPE_PLUGINS, "plugins",
120 GetDefaultPluginsContentSetting(), 147 GetDefaultPluginsContentSetting(), WebsiteSettingsInfo::SYNCABLE,
121 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUI()); 148 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme),
149 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
150 CONTENT_SETTING_ASK,
151 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT));
152
122 Register(CONTENT_SETTINGS_TYPE_POPUPS, "popups", CONTENT_SETTING_BLOCK, 153 Register(CONTENT_SETTINGS_TYPE_POPUPS, "popups", CONTENT_SETTING_BLOCK,
123 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUIAndExtensions()); 154 WebsiteSettingsInfo::SYNCABLE,
155 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme,
156 kExtensionScheme),
157 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK));
158
124 Register(CONTENT_SETTINGS_TYPE_GEOLOCATION, "geolocation", 159 Register(CONTENT_SETTINGS_TYPE_GEOLOCATION, "geolocation",
125 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE, 160 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE,
126 NoWhitelistedSchemes()); 161 WhitelistedSchemes(),
162 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
163 CONTENT_SETTING_ASK));
164
127 Register(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications", 165 Register(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications",
128 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE, 166 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE,
129 NoWhitelistedSchemes()); 167 WhitelistedSchemes(),
168 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
169 CONTENT_SETTING_ASK));
170
130 Register(CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen", CONTENT_SETTING_ASK, 171 Register(CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen", CONTENT_SETTING_ASK,
131 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUI()); 172 WebsiteSettingsInfo::SYNCABLE,
173 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme),
174 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_ASK));
175
132 Register(CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock", CONTENT_SETTING_ASK, 176 Register(CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock", CONTENT_SETTING_ASK,
133 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUI()); 177 WebsiteSettingsInfo::SYNCABLE,
178 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme),
179 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
180 CONTENT_SETTING_ASK));
181
134 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic", 182 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic",
135 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE, 183 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE,
136 WhitelistedForWebUI()); 184 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme),
185 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
186 CONTENT_SETTING_ASK));
187
137 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera", 188 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera",
138 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE, 189 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE,
139 WhitelistedForWebUI()); 190 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme),
191 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
192 CONTENT_SETTING_ASK));
193
140 Register(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker", 194 Register(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker",
141 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE, 195 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE,
142 WhitelistedForWebUI()); 196 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme),
197 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
198 CONTENT_SETTING_ASK));
199
143 Register(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, "automatic-downloads", 200 Register(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, "automatic-downloads",
144 CONTENT_SETTING_ASK, WebsiteSettingsInfo::SYNCABLE, 201 CONTENT_SETTING_ASK, WebsiteSettingsInfo::SYNCABLE,
145 WhitelistedForWebUIAndExtensions()); 202 WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme,
203 kExtensionScheme),
204 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
205 CONTENT_SETTING_ASK));
206
146 Register(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex", CONTENT_SETTING_ASK, 207 Register(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex", CONTENT_SETTING_ASK,
147 WebsiteSettingsInfo::SYNCABLE, NoWhitelistedSchemes()); 208 WebsiteSettingsInfo::SYNCABLE, WhitelistedSchemes(),
209 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
210 CONTENT_SETTING_ASK));
211
148 Register(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging", 212 Register(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging",
149 CONTENT_SETTING_ASK, WebsiteSettingsInfo::SYNCABLE, 213 CONTENT_SETTING_ASK, WebsiteSettingsInfo::SYNCABLE,
150 NoWhitelistedSchemes()); 214 WhitelistedSchemes(),
215 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
216 CONTENT_SETTING_ASK));
217
151 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 218 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
152 Register(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, 219 Register(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
153 "protected-media-identifier", CONTENT_SETTING_ASK, 220 "protected-media-identifier", CONTENT_SETTING_ASK,
154 WebsiteSettingsInfo::UNSYNCABLE, NoWhitelistedSchemes()); 221 WebsiteSettingsInfo::UNSYNCABLE, WhitelistedSchemes(),
222 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
223 CONTENT_SETTING_ASK));
155 #endif 224 #endif
225
156 Register(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, "durable-storage", 226 Register(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, "durable-storage",
157 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE, 227 CONTENT_SETTING_ASK, WebsiteSettingsInfo::UNSYNCABLE,
158 NoWhitelistedSchemes()); 228 WhitelistedSchemes(),
229 ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK));
159 230
160 // Content settings that aren't used to store any data. TODO(raymes): use a 231 // Content settings that aren't used to store any data. TODO(raymes): use a
161 // different mechanism rather than content settings to represent these. 232 // different mechanism rather than content settings to represent these.
162 // Since nothing is stored in them, there is no real point in them being a 233 // Since nothing is stored in them, there is no real point in them being a
163 // content setting. 234 // content setting.
164 Register(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, "protocol-handler", 235 Register(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, "protocol-handler",
165 CONTENT_SETTING_DEFAULT, WebsiteSettingsInfo::UNSYNCABLE, 236 CONTENT_SETTING_DEFAULT, WebsiteSettingsInfo::UNSYNCABLE,
166 NoWhitelistedSchemes()); 237 WhitelistedSchemes(), ValidSettings());
238
167 Register(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, "mixed-script", 239 Register(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, "mixed-script",
168 CONTENT_SETTING_DEFAULT, WebsiteSettingsInfo::UNSYNCABLE, 240 CONTENT_SETTING_DEFAULT, WebsiteSettingsInfo::UNSYNCABLE,
169 NoWhitelistedSchemes()); 241 WhitelistedSchemes(), ValidSettings());
170 242
171 // Deprecated. 243 // Deprecated.
172 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream", 244 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream",
173 CONTENT_SETTING_DEFAULT, WebsiteSettingsInfo::UNSYNCABLE, 245 CONTENT_SETTING_DEFAULT, WebsiteSettingsInfo::UNSYNCABLE,
174 NoWhitelistedSchemes()); 246 WhitelistedSchemes(), ValidSettings());
175 } 247 }
176 248
177 void ContentSettingsRegistry::Register( 249 void ContentSettingsRegistry::Register(
178 ContentSettingsType type, 250 ContentSettingsType type,
179 const std::string& name, 251 const std::string& name,
180 ContentSetting initial_default_value, 252 ContentSetting initial_default_value,
181 WebsiteSettingsInfo::SyncStatus sync_status, 253 WebsiteSettingsInfo::SyncStatus sync_status,
182 const std::vector<std::string>& whitelisted_schemes) { 254 const std::vector<std::string>& whitelisted_schemes,
255 const std::set<ContentSetting>& valid_settings) {
183 // Ensure that nothing has been registered yet for the given type. 256 // Ensure that nothing has been registered yet for the given type.
184 DCHECK(!website_settings_registry_->Get(type)); 257 DCHECK(!website_settings_registry_->Get(type));
185 scoped_ptr<base::Value> default_value( 258 scoped_ptr<base::Value> default_value(
186 new base::FundamentalValue(static_cast<int>(initial_default_value))); 259 new base::FundamentalValue(static_cast<int>(initial_default_value)));
187 const WebsiteSettingsInfo* website_settings_info = 260 const WebsiteSettingsInfo* website_settings_info =
188 website_settings_registry_->Register(type, name, default_value.Pass(), 261 website_settings_registry_->Register(type, name, default_value.Pass(),
189 sync_status, 262 sync_status,
190 WebsiteSettingsInfo::NOT_LOSSY); 263 WebsiteSettingsInfo::NOT_LOSSY);
191 DCHECK(!ContainsKey(content_settings_info_, type)); 264 DCHECK(!ContainsKey(content_settings_info_, type));
192 content_settings_info_.set( 265 content_settings_info_.set(
193 type, make_scoped_ptr(new ContentSettingsInfo(website_settings_info, 266 type, make_scoped_ptr(new ContentSettingsInfo(
194 whitelisted_schemes))); 267 website_settings_info, whitelisted_schemes, valid_settings)));
195 } 268 }
196 269
197 } // namespace content_settings 270 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698