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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 7828022: Add a method to the HostContentSettings map to return the |Value| of a content setting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update example value of AutoSelectCertificate policy in policy_template.json Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/host_content_settings_map.h" 5 #include "chrome/browser/content_settings/host_content_settings_map.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 typedef content_settings::ProviderInterface::Rules Rules; 63 typedef content_settings::ProviderInterface::Rules Rules;
64 64
65 typedef std::pair<std::string, std::string> StringPair; 65 typedef std::pair<std::string, std::string> StringPair;
66 66
67 const char* kProviderNames[] = { 67 const char* kProviderNames[] = {
68 "policy", 68 "policy",
69 "extension", 69 "extension",
70 "preference" 70 "preference"
71 }; 71 };
72 72
73 bool ContentTypeHasCompoundValue(ContentSettingsType type) {
74 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are
75 // of type dictionary/map. Compound types like dictionaries can't be mapped to
76 // the type |ContentSetting|.
77 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE;
78 }
79
73 } // namespace 80 } // namespace
74 81
75 HostContentSettingsMap::HostContentSettingsMap( 82 HostContentSettingsMap::HostContentSettingsMap(
76 PrefService* prefs, 83 PrefService* prefs,
77 ExtensionService* extension_service, 84 ExtensionService* extension_service,
78 bool incognito) 85 bool incognito)
79 : prefs_(prefs), 86 : prefs_(prefs),
80 is_off_the_record_(incognito), 87 is_off_the_record_(incognito),
81 updating_preferences_(false), 88 updating_preferences_(false),
82 block_third_party_cookies_(false), 89 block_third_party_cookies_(false),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 161
155 // Register the prefs for the content settings providers. 162 // Register the prefs for the content settings providers.
156 content_settings::PrefDefaultProvider::RegisterUserPrefs(prefs); 163 content_settings::PrefDefaultProvider::RegisterUserPrefs(prefs);
157 content_settings::PolicyDefaultProvider::RegisterUserPrefs(prefs); 164 content_settings::PolicyDefaultProvider::RegisterUserPrefs(prefs);
158 content_settings::PrefProvider::RegisterUserPrefs(prefs); 165 content_settings::PrefProvider::RegisterUserPrefs(prefs);
159 content_settings::PolicyProvider::RegisterUserPrefs(prefs); 166 content_settings::PolicyProvider::RegisterUserPrefs(prefs);
160 } 167 }
161 168
162 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( 169 ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
163 ContentSettingsType content_type) const { 170 ContentSettingsType content_type) const {
171 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
164 ContentSetting setting = CONTENT_SETTING_DEFAULT; 172 ContentSetting setting = CONTENT_SETTING_DEFAULT;
165 for (ConstDefaultProviderIterator provider = 173 for (ConstDefaultProviderIterator provider =
166 default_content_settings_providers_.begin(); 174 default_content_settings_providers_.begin();
167 provider != default_content_settings_providers_.end(); ++provider) { 175 provider != default_content_settings_providers_.end(); ++provider) {
168 ContentSetting provided_setting = 176 ContentSetting provided_setting =
169 (*provider)->ProvideDefaultSetting(content_type); 177 (*provider)->ProvideDefaultSetting(content_type);
170 if (provided_setting != CONTENT_SETTING_DEFAULT) 178 if (provided_setting != CONTENT_SETTING_DEFAULT)
171 setting = provided_setting; 179 setting = provided_setting;
172 } 180 }
173 // The method GetDefaultContentSetting always has to return an explicit 181 // The method GetDefaultContentSetting always has to return an explicit
174 // value that is to be used as default. We here rely on the 182 // value that is to be used as default. We here rely on the
175 // PrefContentSettingProvider to always provide a value. 183 // PrefContentSettingProvider to always provide a value.
176 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); 184 CHECK_NE(CONTENT_SETTING_DEFAULT, setting);
177 return setting; 185 return setting;
178 } 186 }
179 187
180 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { 188 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const {
181 ContentSettings output(CONTENT_SETTING_DEFAULT); 189 ContentSettings output(CONTENT_SETTING_DEFAULT);
182 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) 190 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
183 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); 191 if (!ContentTypeHasCompoundValue(ContentSettingsType(i)))
192 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i));
wtc 2011/09/06 22:11:42 Indent by two spaces.
markusheintz_ 2011/09/07 19:29:48 Done.
193 }
184 return output; 194 return output;
185 } 195 }
186 196
187 ContentSetting HostContentSettingsMap::GetCookieContentSetting( 197 ContentSetting HostContentSettingsMap::GetCookieContentSetting(
188 const GURL& url, 198 const GURL& url,
189 const GURL& first_party_url, 199 const GURL& first_party_url,
190 bool setting_cookie) const { 200 bool setting_cookie) const {
191 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) 201 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES))
192 return CONTENT_SETTING_ALLOW; 202 return CONTENT_SETTING_ALLOW;
193 203
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 const GURL& secondary_url, 235 const GURL& secondary_url,
226 ContentSettingsType content_type, 236 ContentSettingsType content_type,
227 const std::string& resource_identifier) const { 237 const std::string& resource_identifier) const {
228 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); 238 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
229 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), 239 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type),
230 resource_identifier.empty()); 240 resource_identifier.empty());
231 return GetContentSettingInternal( 241 return GetContentSettingInternal(
232 primary_url, secondary_url, content_type, resource_identifier); 242 primary_url, secondary_url, content_type, resource_identifier);
233 } 243 }
234 244
245 Value* HostContentSettingsMap::GetContentSettingValue(
246 const GURL& primary_url,
247 const GURL& secondary_url,
248 ContentSettingsType content_type,
249 const std::string& resource_identifier) const {
250 // Check if the scheme of the requesting url is whitelisted.
251 if (ShouldAllowAllContent(secondary_url, content_type))
252 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW);
253
254 // First check if there are specific settings for the |primary_url| and
255 // |secondary_url|. The list of |content_settings_providers_| is ordered
256 // according to their priority.
257 for (ConstProviderIterator provider = content_settings_providers_.begin();
258 provider != content_settings_providers_.end();
259 ++provider) {
260 Value* value = (*provider)->GetContentSettingValue(
261 primary_url, secondary_url, content_type, resource_identifier);
262 if (value)
263 return value;
264 }
265
266 // If no specific settings were found for the |primary_url|, |secondary_url|
267 // pair, then the default value for the given |content_type| should be
268 // returned. For CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE the default is
269 // 'no filter available'. That's why we return |NULL| for this content type.
270 if (content_type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE)
271 return NULL;
272 return Value::CreateIntegerValue(GetDefaultContentSetting(content_type));
273 }
274
235 ContentSetting HostContentSettingsMap::GetContentSettingInternal( 275 ContentSetting HostContentSettingsMap::GetContentSettingInternal(
236 const GURL& primary_url, 276 const GURL& primary_url,
237 const GURL& secondary_url, 277 const GURL& secondary_url,
238 ContentSettingsType content_type, 278 ContentSettingsType content_type,
239 const std::string& resource_identifier) const { 279 const std::string& resource_identifier) const {
240 ContentSetting setting = GetNonDefaultContentSetting( 280 ContentSetting setting = GetNonDefaultContentSetting(
241 primary_url, secondary_url, content_type, resource_identifier); 281 primary_url, secondary_url, content_type, resource_identifier);
242 if (setting == CONTENT_SETTING_DEFAULT) 282 if (setting == CONTENT_SETTING_DEFAULT)
243 return GetDefaultContentSetting(content_type); 283 return GetDefaultContentSetting(content_type);
244 return setting; 284 return setting;
(...skipping 21 matching lines...) Expand all
266 return provided_setting; 306 return provided_setting;
267 } 307 }
268 308
269 ContentSettings HostContentSettingsMap::GetContentSettings( 309 ContentSettings HostContentSettingsMap::GetContentSettings(
270 const GURL& primary_url, 310 const GURL& primary_url,
271 const GURL& secondary_url) const { 311 const GURL& secondary_url) const {
272 ContentSettings output = GetNonDefaultContentSettings( 312 ContentSettings output = GetNonDefaultContentSettings(
273 primary_url, secondary_url); 313 primary_url, secondary_url);
274 314
275 // If we require a resource identifier, set the content settings to default, 315 // If we require a resource identifier, set the content settings to default,
276 // otherwise make the defaults explicit. 316 // otherwise make the defaults explicit. Values for content type
317 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type
318 // |ContentSetting|. So we ignore them here.
277 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { 319 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
278 // A managed default content setting has the highest priority and hence 320 // A managed default content setting has the highest priority and hence
279 // will overwrite any previously set value. 321 // will overwrite any previously set value.
280 if (output.settings[j] == CONTENT_SETTING_DEFAULT && 322 if (output.settings[j] == CONTENT_SETTING_DEFAULT &&
281 j != CONTENT_SETTINGS_TYPE_PLUGINS) { 323 j != CONTENT_SETTINGS_TYPE_PLUGINS &&
324 !ContentTypeHasCompoundValue(ContentSettingsType(j))) {
282 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); 325 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j));
283 } 326 }
284 } 327 }
285 return output; 328 return output;
286 } 329 }
287 330
288 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( 331 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings(
289 const GURL& primary_url, 332 const GURL& primary_url,
290 const GURL& secondary_url) const { 333 const GURL& secondary_url) const {
291 ContentSettings output(CONTENT_SETTING_DEFAULT); 334 ContentSettings output(CONTENT_SETTING_DEFAULT);
292 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { 335 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
293 output.settings[j] = GetNonDefaultContentSetting( 336 if (!ContentTypeHasCompoundValue(ContentSettingsType(j))) {
294 primary_url, 337 output.settings[j] = GetNonDefaultContentSetting(
295 secondary_url, 338 primary_url,
296 ContentSettingsType(j), 339 secondary_url,
297 ""); 340 ContentSettingsType(j),
341 "");
342 }
298 } 343 }
299 return output; 344 return output;
300 } 345 }
301 346
302 void HostContentSettingsMap::GetSettingsForOneType( 347 void HostContentSettingsMap::GetSettingsForOneType(
303 ContentSettingsType content_type, 348 ContentSettingsType content_type,
304 const std::string& resource_identifier, 349 const std::string& resource_identifier,
305 SettingsForOneType* settings) const { 350 SettingsForOneType* settings) const {
306 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), 351 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type),
307 resource_identifier.empty()); 352 resource_identifier.empty());
(...skipping 27 matching lines...) Expand all
335 i != settings_map.end(); 380 i != settings_map.end();
336 ++i) { 381 ++i) {
337 settings->push_back(i->second); 382 settings->push_back(i->second);
338 } 383 }
339 } 384 }
340 } 385 }
341 386
342 void HostContentSettingsMap::SetDefaultContentSetting( 387 void HostContentSettingsMap::SetDefaultContentSetting(
343 ContentSettingsType content_type, 388 ContentSettingsType content_type,
344 ContentSetting setting) { 389 ContentSetting setting) {
390 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
345 DCHECK(IsSettingAllowedForType(setting, content_type)); 391 DCHECK(IsSettingAllowedForType(setting, content_type));
346 for (DefaultProviderIterator provider = 392 for (DefaultProviderIterator provider =
347 default_content_settings_providers_.begin(); 393 default_content_settings_providers_.begin();
348 provider != default_content_settings_providers_.end(); ++provider) { 394 provider != default_content_settings_providers_.end(); ++provider) {
349 (*provider)->UpdateDefaultSetting(content_type, setting); 395 (*provider)->UpdateDefaultSetting(content_type, setting);
350 } 396 }
351 } 397 }
352 398
353 void HostContentSettingsMap::SetContentSetting( 399 void HostContentSettingsMap::SetContentSetting(
354 const ContentSettingsPattern& primary_pattern, 400 const ContentSettingsPattern& primary_pattern,
355 const ContentSettingsPattern& secondary_pattern, 401 const ContentSettingsPattern& secondary_pattern,
356 ContentSettingsType content_type, 402 ContentSettingsType content_type,
357 const std::string& resource_identifier, 403 const std::string& resource_identifier,
358 ContentSetting setting) { 404 ContentSetting setting) {
405 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
359 DCHECK(IsSettingAllowedForType(setting, content_type)); 406 DCHECK(IsSettingAllowedForType(setting, content_type));
360 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), 407 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type),
361 resource_identifier.empty()); 408 resource_identifier.empty());
362 for (ProviderIterator provider = content_settings_providers_.begin(); 409 for (ProviderIterator provider = content_settings_providers_.begin();
363 provider != content_settings_providers_.end(); 410 provider != content_settings_providers_.end();
364 ++provider) { 411 ++provider) {
365 (*provider)->SetContentSetting( 412 (*provider)->SetContentSetting(
366 primary_pattern, 413 primary_pattern,
367 secondary_pattern, 414 secondary_pattern,
368 content_type, 415 content_type,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, 591 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES,
545 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? 592 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ?
546 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); 593 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW);
547 } 594 }
548 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { 595 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) {
549 SetBlockThirdPartyCookies(cookie_behavior == 596 SetBlockThirdPartyCookies(cookie_behavior ==
550 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 597 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
551 } 598 }
552 } 599 }
553 } 600 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698