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

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

Issue 7029031: Content settings extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 9 years, 6 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/content_settings/content_settings_extension_provider.h" 10 #include "chrome/browser/content_settings/content_settings_extension_provider.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 ++rule_iterator) { 287 ++rule_iterator) {
288 settings->push_back(std::make_pair(ContentSettingsPattern( 288 settings->push_back(std::make_pair(ContentSettingsPattern(
289 rule_iterator->requesting_url_pattern), 289 rule_iterator->requesting_url_pattern),
290 rule_iterator->content_setting)); 290 rule_iterator->content_setting));
291 } 291 }
292 } 292 }
293 293
294 void HostContentSettingsMap::SetDefaultContentSetting( 294 void HostContentSettingsMap::SetDefaultContentSetting(
295 ContentSettingsType content_type, 295 ContentSettingsType content_type,
296 ContentSetting setting) { 296 ContentSetting setting) {
297 DCHECK(IsSettingAllowedForType(setting, content_type));
297 for (DefaultProviderIterator provider = 298 for (DefaultProviderIterator provider =
298 default_content_settings_providers_.begin(); 299 default_content_settings_providers_.begin();
299 provider != default_content_settings_providers_.end(); ++provider) { 300 provider != default_content_settings_providers_.end(); ++provider) {
300 (*provider)->UpdateDefaultSetting(content_type, setting); 301 (*provider)->UpdateDefaultSetting(content_type, setting);
301 } 302 }
302 } 303 }
303 304
304 void HostContentSettingsMap::SetContentSetting( 305 void HostContentSettingsMap::SetContentSetting(
305 const ContentSettingsPattern& pattern, 306 const ContentSettingsPattern& pattern,
306 ContentSettingsType content_type, 307 ContentSettingsType content_type,
307 const std::string& resource_identifier, 308 const std::string& resource_identifier,
308 ContentSetting setting) { 309 ContentSetting setting) {
310 DCHECK(IsSettingAllowedForType(setting, content_type));
309 for (ProviderIterator provider = content_settings_providers_.begin(); 311 for (ProviderIterator provider = content_settings_providers_.begin();
310 provider != content_settings_providers_.end(); 312 provider != content_settings_providers_.end();
311 ++provider) { 313 ++provider) {
312 (*provider)->SetContentSetting( 314 (*provider)->SetContentSetting(
313 pattern, pattern, content_type, resource_identifier, setting); 315 pattern, pattern, content_type, resource_identifier, setting);
314 } 316 }
315 } 317 }
316 318
317 void HostContentSettingsMap::AddExceptionForURL( 319 void HostContentSettingsMap::AddExceptionForURL(
318 const GURL& url, 320 const GURL& url,
(...skipping 14 matching lines...) Expand all
333 335
334 void HostContentSettingsMap::ClearSettingsForOneType( 336 void HostContentSettingsMap::ClearSettingsForOneType(
335 ContentSettingsType content_type) { 337 ContentSettingsType content_type) {
336 for (ProviderIterator provider = content_settings_providers_.begin(); 338 for (ProviderIterator provider = content_settings_providers_.begin();
337 provider != content_settings_providers_.end(); 339 provider != content_settings_providers_.end();
338 ++provider) { 340 ++provider) {
339 (*provider)->ClearAllContentSettingsRules(content_type); 341 (*provider)->ClearAllContentSettingsRules(content_type);
340 } 342 }
341 } 343 }
342 344
345 // static
346 bool HostContentSettingsMap::IsSettingAllowedForType(
347 ContentSetting setting, ContentSettingsType content_type) {
348 // Prerendering doesn't have settings.
349 if (content_type == CONTENT_SETTINGS_TYPE_PRERENDER)
350 return false;
351
352 // For all other types, DEFAULT, ALLOW and BLOCK are always allowed.
353 if (setting == CONTENT_SETTING_DEFAULT ||
354 setting == CONTENT_SETTING_ALLOW ||
355 setting == CONTENT_SETTING_BLOCK) {
356 return true;
357 }
358 switch (content_type) {
359 case CONTENT_SETTINGS_TYPE_COOKIES:
360 return (setting == CONTENT_SETTING_SESSION_ONLY);
361 case CONTENT_SETTINGS_TYPE_PLUGINS:
362 return (setting == CONTENT_SETTING_ASK &&
363 CommandLine::ForCurrentProcess()->HasSwitch(
364 switches::kEnableClickToPlay));
365 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
366 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
367 return (setting == CONTENT_SETTING_ASK);
368 default:
369 return false;
370 }
371 }
372
343 void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) { 373 void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) {
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
345 375
346 // This setting may not be directly modified for OTR sessions. Instead, it 376 // This setting may not be directly modified for OTR sessions. Instead, it
347 // is synced to the main profile's setting. 377 // is synced to the main profile's setting.
348 if (is_off_the_record_) { 378 if (is_off_the_record_) {
349 NOTREACHED(); 379 NOTREACHED();
350 return; 380 return;
351 } 381 }
352 382
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, 492 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES,
463 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? 493 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ?
464 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); 494 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW);
465 } 495 }
466 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { 496 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) {
467 SetBlockThirdPartyCookies(cookie_behavior == 497 SetBlockThirdPartyCookies(cookie_behavior ==
468 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 498 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
469 } 499 }
470 } 500 }
471 } 501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698