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