| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/browser/user_metrics.h" | 30 #include "content/browser/user_metrics.h" |
| 31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
| 34 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
| 35 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 36 #include "net/base/static_cookie_policy.h" | 36 #include "net/base/static_cookie_policy.h" |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Returns true if we should allow all content types for this URL. This is | |
| 41 // true for various internal objects like chrome:// URLs, so UI and other | |
| 42 // things users think of as "not webpages" don't break. | |
| 43 bool ShouldAllowAllContent(const GURL& url, ContentSettingsType content_type) { | |
| 44 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) | |
| 45 return false; | |
| 46 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | |
| 47 url.SchemeIs(chrome::kChromeInternalScheme) || | |
| 48 url.SchemeIs(chrome::kChromeUIScheme) || | |
| 49 url.SchemeIs(chrome::kExtensionScheme); | |
| 50 } | |
| 51 | |
| 52 typedef std::vector<content_settings::Rule> Rules; | 40 typedef std::vector<content_settings::Rule> Rules; |
| 53 | 41 |
| 54 typedef std::pair<std::string, std::string> StringPair; | 42 typedef std::pair<std::string, std::string> StringPair; |
| 55 | 43 |
| 56 const char* kProviderNames[] = { | 44 const char* kProviderNames[] = { |
| 57 "policy", | 45 "policy", |
| 58 "extension", | 46 "extension", |
| 59 "preference", | 47 "preference", |
| 60 "default" | 48 "default" |
| 61 }; | 49 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 80 return CONTENT_SETTING_DEFAULT; | 68 return CONTENT_SETTING_DEFAULT; |
| 81 } | 69 } |
| 82 | 70 |
| 83 } // namespace | 71 } // namespace |
| 84 | 72 |
| 85 HostContentSettingsMap::HostContentSettingsMap( | 73 HostContentSettingsMap::HostContentSettingsMap( |
| 86 PrefService* prefs, | 74 PrefService* prefs, |
| 87 ExtensionService* extension_service, | 75 ExtensionService* extension_service, |
| 88 bool incognito) | 76 bool incognito) |
| 89 : prefs_(prefs), | 77 : prefs_(prefs), |
| 90 is_off_the_record_(incognito), | 78 is_off_the_record_(incognito) { |
| 91 updating_preferences_(false), | |
| 92 block_third_party_cookies_(false), | |
| 93 is_block_third_party_cookies_managed_(false) { | |
| 94 content_settings::ObservableProvider* policy_provider = | 79 content_settings::ObservableProvider* policy_provider = |
| 95 new content_settings::PolicyProvider(prefs_); | 80 new content_settings::PolicyProvider(prefs_); |
| 96 policy_provider->AddObserver(this); | 81 policy_provider->AddObserver(this); |
| 97 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 82 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
| 98 | 83 |
| 99 if (extension_service) { | 84 if (extension_service) { |
| 100 // |extension_service| can be NULL in unit tests. | 85 // |extension_service| can be NULL in unit tests. |
| 101 content_settings::ObservableProvider* extension_provider = | 86 content_settings::ObservableProvider* extension_provider = |
| 102 new content_settings::ExtensionProvider( | 87 new content_settings::ExtensionProvider( |
| 103 extension_service->GetExtensionContentSettingsStore(), | 88 extension_service->GetExtensionContentSettingsStore(), |
| 104 is_off_the_record_); | 89 is_off_the_record_); |
| 105 extension_provider->AddObserver(this); | 90 extension_provider->AddObserver(this); |
| 106 content_settings_providers_[EXTENSION_PROVIDER] = extension_provider; | 91 content_settings_providers_[EXTENSION_PROVIDER] = extension_provider; |
| 107 } | 92 } |
| 108 | 93 |
| 109 content_settings::ObservableProvider* pref_provider = | 94 content_settings::ObservableProvider* pref_provider = |
| 110 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 95 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
| 111 pref_provider->AddObserver(this); | 96 pref_provider->AddObserver(this); |
| 112 content_settings_providers_[PREF_PROVIDER] = pref_provider; | 97 content_settings_providers_[PREF_PROVIDER] = pref_provider; |
| 113 | 98 |
| 114 content_settings::ObservableProvider* default_provider = | 99 content_settings::ObservableProvider* default_provider = |
| 115 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 100 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
| 116 default_provider->AddObserver(this); | 101 default_provider->AddObserver(this); |
| 117 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 102 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
| 118 | |
| 119 MigrateObsoleteCookiePref(); | |
| 120 | |
| 121 // Read misc. global settings. | |
| 122 block_third_party_cookies_ = | |
| 123 prefs_->GetBoolean(prefs::kBlockThirdPartyCookies); | |
| 124 if (block_third_party_cookies_) { | |
| 125 UserMetrics::RecordAction( | |
| 126 UserMetricsAction("ThirdPartyCookieBlockingEnabled")); | |
| 127 } else { | |
| 128 UserMetrics::RecordAction( | |
| 129 UserMetricsAction("ThirdPartyCookieBlockingDisabled")); | |
| 130 } | |
| 131 is_block_third_party_cookies_managed_ = | |
| 132 prefs_->IsManagedPreference(prefs::kBlockThirdPartyCookies); | |
| 133 | |
| 134 pref_change_registrar_.Init(prefs_); | |
| 135 pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); | |
| 136 } | 103 } |
| 137 | 104 |
| 138 // static | 105 // static |
| 139 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { | 106 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { |
| 140 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, | |
| 141 false, | |
| 142 PrefService::SYNCABLE_PREF); | |
| 143 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, | 107 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, |
| 144 0, | 108 0, |
| 145 PrefService::UNSYNCABLE_PREF); | 109 PrefService::UNSYNCABLE_PREF); |
| 146 | 110 |
| 147 // Obsolete prefs, for migration: | |
| 148 prefs->RegisterIntegerPref(prefs::kCookieBehavior, | |
| 149 net::StaticCookiePolicy::ALLOW_ALL_COOKIES, | |
| 150 PrefService::UNSYNCABLE_PREF); | |
| 151 | |
| 152 // Register the prefs for the content settings providers. | 111 // Register the prefs for the content settings providers. |
| 153 content_settings::DefaultProvider::RegisterUserPrefs(prefs); | 112 content_settings::DefaultProvider::RegisterUserPrefs(prefs); |
| 154 content_settings::PrefProvider::RegisterUserPrefs(prefs); | 113 content_settings::PrefProvider::RegisterUserPrefs(prefs); |
| 155 content_settings::PolicyProvider::RegisterUserPrefs(prefs); | 114 content_settings::PolicyProvider::RegisterUserPrefs(prefs); |
| 156 } | 115 } |
| 157 | 116 |
| 158 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( | 117 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
| 159 ContentSettingsType content_type, | 118 ContentSettingsType content_type, |
| 160 content_settings::ProviderInterface* provider) const { | 119 content_settings::ProviderInterface* provider) const { |
| 161 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 120 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { | 153 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { |
| 195 ContentSettings output(CONTENT_SETTING_DEFAULT); | 154 ContentSettings output(CONTENT_SETTING_DEFAULT); |
| 196 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 155 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 197 if (!ContentTypeHasCompoundValue(ContentSettingsType(i))) | 156 if (!ContentTypeHasCompoundValue(ContentSettingsType(i))) |
| 198 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i), | 157 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i), |
| 199 NULL); | 158 NULL); |
| 200 } | 159 } |
| 201 return output; | 160 return output; |
| 202 } | 161 } |
| 203 | 162 |
| 204 ContentSetting HostContentSettingsMap::GetCookieContentSetting( | |
| 205 const GURL& url, | |
| 206 const GURL& first_party_url, | |
| 207 bool setting_cookie) const { | |
| 208 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) | |
| 209 return CONTENT_SETTING_ALLOW; | |
| 210 | |
| 211 // First get any host-specific settings. | |
| 212 scoped_ptr<base::Value> value; | |
| 213 for (ConstProviderIterator provider = content_settings_providers_.begin(); | |
| 214 provider != content_settings_providers_.end(); | |
| 215 ++provider) { | |
| 216 if (provider->first == DEFAULT_PROVIDER) | |
| 217 continue; | |
| 218 | |
| 219 value.reset(content_settings::GetContentSettingValueAndPatterns( | |
| 220 provider->second, url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, | |
| 221 std::string(), is_off_the_record_, NULL, NULL)); | |
| 222 if (value.get()) | |
| 223 break; | |
| 224 } | |
| 225 | |
| 226 // If no explicit exception has been made and third-party cookies are blocked | |
| 227 // by default, apply that rule. | |
| 228 if (!value.get() && BlockThirdPartyCookies()) { | |
| 229 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 230 switches::kBlockReadingThirdPartyCookies); | |
| 231 net::StaticCookiePolicy policy(strict ? | |
| 232 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : | |
| 233 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | |
| 234 int rv; | |
| 235 if (setting_cookie) | |
| 236 rv = policy.CanSetCookie(url, first_party_url); | |
| 237 else | |
| 238 rv = policy.CanGetCookies(url, first_party_url); | |
| 239 DCHECK_NE(net::ERR_IO_PENDING, rv); | |
| 240 if (rv != net::OK) | |
| 241 return CONTENT_SETTING_BLOCK; | |
| 242 } | |
| 243 | |
| 244 // If no other policy has changed the setting, use the default. | |
| 245 if (value.get()) | |
| 246 return content_settings::ValueToContentSetting(value.get()); | |
| 247 | |
| 248 return GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, NULL); | |
| 249 } | |
| 250 | |
| 251 ContentSetting HostContentSettingsMap::GetContentSetting( | 163 ContentSetting HostContentSettingsMap::GetContentSetting( |
| 252 const GURL& primary_url, | 164 const GURL& primary_url, |
| 253 const GURL& secondary_url, | 165 const GURL& secondary_url, |
| 254 ContentSettingsType content_type, | 166 ContentSettingsType content_type, |
| 255 const std::string& resource_identifier) const { | 167 const std::string& resource_identifier) const { |
| 256 scoped_ptr<base::Value> value(GetContentSettingValue( | 168 scoped_ptr<base::Value> value(GetContentSettingValue( |
| 257 primary_url, secondary_url, content_type, resource_identifier, | 169 primary_url, secondary_url, content_type, resource_identifier, |
| 258 NULL, NULL)); | 170 NULL, NULL)); |
| 259 return content_settings::ValueToContentSetting(value.get()); | 171 return content_settings::ValueToContentSetting(value.get()); |
| 260 } | 172 } |
| 261 | 173 |
| 262 base::Value* HostContentSettingsMap::GetContentSettingValue( | 174 base::Value* HostContentSettingsMap::GetContentSettingValue( |
| 263 const GURL& primary_url, | 175 const GURL& primary_url, |
| 264 const GURL& secondary_url, | 176 const GURL& secondary_url, |
| 265 ContentSettingsType content_type, | 177 ContentSettingsType content_type, |
| 266 const std::string& resource_identifier, | 178 const std::string& resource_identifier, |
| 267 ContentSettingsPattern* primary_pattern, | 179 ContentSettingsPattern* primary_pattern, |
| 268 ContentSettingsPattern* secondary_pattern) const { | 180 ContentSettingsPattern* secondary_pattern) const { |
| 269 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); | |
| 270 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 181 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || |
| 271 resource_identifier.empty()); | 182 resource_identifier.empty()); |
| 272 | 183 |
| 273 // Check if the scheme of the requesting url is whitelisted. | 184 // Check if the scheme of the requesting url is whitelisted. |
| 274 if (ShouldAllowAllContent(secondary_url, content_type)) | 185 if (ShouldAllowAllContent(secondary_url, content_type)) |
| 275 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); | 186 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); |
| 276 | 187 |
| 277 // The list of |content_settings_providers_| is ordered according to their | 188 // The list of |content_settings_providers_| is ordered according to their |
| 278 // precedence. | 189 // precedence. |
| 279 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 190 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 280 provider != content_settings_providers_.end(); | 191 provider != content_settings_providers_.end(); |
| 281 ++provider) { | 192 ++provider) { |
| 282 base::Value* value = content_settings::GetContentSettingValueAndPatterns( | 193 base::Value* value = content_settings::GetContentSettingValueAndPatterns( |
| 283 provider->second, primary_url, secondary_url, content_type, | 194 provider->second, primary_url, secondary_url, content_type, |
| 284 resource_identifier, is_off_the_record_, | 195 resource_identifier, is_off_the_record_, |
| 285 primary_pattern, secondary_pattern); | 196 primary_pattern, secondary_pattern); |
| 286 if (value) | 197 if (value) |
| 287 return value; | 198 return value; |
| 288 } | 199 } |
| 289 return NULL; | 200 return NULL; |
| 290 } | 201 } |
| 291 | 202 |
| 292 ContentSettings HostContentSettingsMap::GetContentSettings( | 203 ContentSettings HostContentSettingsMap::GetContentSettings( |
| 293 const GURL& primary_url, | 204 const GURL& primary_url) const { |
| 294 const GURL& secondary_url) const { | |
| 295 ContentSettings output; | 205 ContentSettings output; |
| 296 // If we require a resource identifier, set the content settings to default, | 206 // If we require a resource identifier, set the content settings to default, |
| 297 // otherwise make the defaults explicit. Values for content type | 207 // otherwise make the defaults explicit. Values for content type |
| 298 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type | 208 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type |
| 299 // |ContentSetting|. So we ignore them here. | 209 // |ContentSetting|. So we ignore them here. |
| 300 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | 210 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
| 301 ContentSettingsType type = ContentSettingsType(j); | 211 ContentSettingsType type = ContentSettingsType(j); |
| 302 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { | 212 if (!ContentTypeHasCompoundValue(type)) { |
| 303 output.settings[j] = GetCookieContentSetting( | |
| 304 primary_url, secondary_url, false); | |
| 305 } else if (!ContentTypeHasCompoundValue(type)) { | |
| 306 output.settings[j] = GetContentSetting( | 213 output.settings[j] = GetContentSetting( |
| 307 primary_url, | 214 primary_url, primary_url, ContentSettingsType(j), std::string()); |
| 308 secondary_url, | |
| 309 ContentSettingsType(j), | |
| 310 std::string()); | |
| 311 } | 215 } |
| 312 } | 216 } |
| 313 return output; | 217 return output; |
| 314 } | 218 } |
| 315 | 219 |
| 316 void HostContentSettingsMap::GetSettingsForOneType( | 220 void HostContentSettingsMap::GetSettingsForOneType( |
| 317 ContentSettingsType content_type, | 221 ContentSettingsType content_type, |
| 318 const std::string& resource_identifier, | 222 const std::string& resource_identifier, |
| 319 ContentSettingsForOneType* settings) const { | 223 ContentSettingsForOneType* settings) const { |
| 320 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 224 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 switches::kEnableClickToPlay)); | 342 switches::kEnableClickToPlay)); |
| 439 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 343 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 440 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 344 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 441 case CONTENT_SETTINGS_TYPE_INTENTS: | 345 case CONTENT_SETTINGS_TYPE_INTENTS: |
| 442 return (setting == CONTENT_SETTING_ASK); | 346 return (setting == CONTENT_SETTING_ASK); |
| 443 default: | 347 default: |
| 444 return false; | 348 return false; |
| 445 } | 349 } |
| 446 } | 350 } |
| 447 | 351 |
| 448 void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) { | |
| 449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 450 DCHECK(prefs_); | |
| 451 | |
| 452 // This setting may not be directly modified for OTR sessions. Instead, it | |
| 453 // is synced to the main profile's setting. | |
| 454 if (is_off_the_record_) { | |
| 455 NOTREACHED(); | |
| 456 return; | |
| 457 } | |
| 458 | |
| 459 // If the preference block-third-party-cookies is managed then do not allow to | |
| 460 // change it. | |
| 461 if (prefs_->IsManagedPreference(prefs::kBlockThirdPartyCookies)) { | |
| 462 NOTREACHED(); | |
| 463 return; | |
| 464 } | |
| 465 | |
| 466 { | |
| 467 base::AutoLock auto_lock(lock_); | |
| 468 block_third_party_cookies_ = block; | |
| 469 } | |
| 470 | |
| 471 prefs_->SetBoolean(prefs::kBlockThirdPartyCookies, block); | |
| 472 } | |
| 473 | |
| 474 void HostContentSettingsMap::OnContentSettingChanged( | 352 void HostContentSettingsMap::OnContentSettingChanged( |
| 475 ContentSettingsPattern primary_pattern, | 353 ContentSettingsPattern primary_pattern, |
| 476 ContentSettingsPattern secondary_pattern, | 354 ContentSettingsPattern secondary_pattern, |
| 477 ContentSettingsType content_type, | 355 ContentSettingsType content_type, |
| 478 std::string resource_identifier) { | 356 std::string resource_identifier) { |
| 479 const ContentSettingsDetails details(primary_pattern, | 357 const ContentSettingsDetails details(primary_pattern, |
| 480 secondary_pattern, | 358 secondary_pattern, |
| 481 content_type, | 359 content_type, |
| 482 resource_identifier); | 360 resource_identifier); |
| 483 content::NotificationService::current()->Notify( | 361 content::NotificationService::current()->Notify( |
| 484 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, | 362 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
| 485 content::Source<HostContentSettingsMap>(this), | 363 content::Source<HostContentSettingsMap>(this), |
| 486 content::Details<const ContentSettingsDetails>(&details)); | 364 content::Details<const ContentSettingsDetails>(&details)); |
| 487 } | 365 } |
| 488 | 366 |
| 489 void HostContentSettingsMap::Observe( | |
| 490 int type, | |
| 491 const content::NotificationSource& source, | |
| 492 const content::NotificationDetails& details) { | |
| 493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 494 | |
| 495 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | |
| 496 DCHECK_EQ(prefs_, content::Source<PrefService>(source).ptr()); | |
| 497 if (updating_preferences_) | |
| 498 return; | |
| 499 | |
| 500 std::string* name = content::Details<std::string>(details).ptr(); | |
| 501 if (*name == prefs::kBlockThirdPartyCookies) { | |
| 502 base::AutoLock auto_lock(lock_); | |
| 503 block_third_party_cookies_ = prefs_->GetBoolean( | |
| 504 prefs::kBlockThirdPartyCookies); | |
| 505 is_block_third_party_cookies_managed_ = | |
| 506 prefs_->IsManagedPreference( | |
| 507 prefs::kBlockThirdPartyCookies); | |
| 508 } else { | |
| 509 NOTREACHED() << "Unexpected preference observed"; | |
| 510 return; | |
| 511 } | |
| 512 } else { | |
| 513 NOTREACHED() << "Unexpected notification"; | |
| 514 } | |
| 515 } | |
| 516 | |
| 517 HostContentSettingsMap::~HostContentSettingsMap() { | 367 HostContentSettingsMap::~HostContentSettingsMap() { |
| 518 DCHECK(!prefs_); | 368 DCHECK(!prefs_); |
| 519 STLDeleteValues(&content_settings_providers_); | 369 STLDeleteValues(&content_settings_providers_); |
| 520 } | 370 } |
| 521 | 371 |
| 522 void HostContentSettingsMap::ShutdownOnUIThread() { | 372 void HostContentSettingsMap::ShutdownOnUIThread() { |
| 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 524 DCHECK(prefs_); | 374 DCHECK(prefs_); |
| 525 pref_change_registrar_.RemoveAll(); | |
| 526 prefs_ = NULL; | 375 prefs_ = NULL; |
| 527 for (ProviderIterator it = content_settings_providers_.begin(); | 376 for (ProviderIterator it = content_settings_providers_.begin(); |
| 528 it != content_settings_providers_.end(); | 377 it != content_settings_providers_.end(); |
| 529 ++it) { | 378 ++it) { |
| 530 it->second->ShutdownOnUIThread(); | 379 it->second->ShutdownOnUIThread(); |
| 531 } | 380 } |
| 532 } | 381 } |
| 533 | 382 |
| 534 void HostContentSettingsMap::MigrateObsoleteCookiePref() { | |
| 535 if (prefs_->HasPrefPath(prefs::kCookieBehavior)) { | |
| 536 int cookie_behavior = prefs_->GetInteger(prefs::kCookieBehavior); | |
| 537 prefs_->ClearPref(prefs::kCookieBehavior); | |
| 538 if (!prefs_->HasPrefPath(prefs::kDefaultContentSettings)) { | |
| 539 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | |
| 540 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | |
| 541 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | |
| 542 } | |
| 543 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | |
| 544 SetBlockThirdPartyCookies(cookie_behavior == | |
| 545 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | |
| 546 } | |
| 547 } | |
| 548 } | |
| 549 | |
| 550 void HostContentSettingsMap::AddSettingsForOneType( | 383 void HostContentSettingsMap::AddSettingsForOneType( |
| 551 const content_settings::ProviderInterface* provider, | 384 const content_settings::ProviderInterface* provider, |
| 552 ProviderType provider_type, | 385 ProviderType provider_type, |
| 553 ContentSettingsType content_type, | 386 ContentSettingsType content_type, |
| 554 const std::string& resource_identifier, | 387 const std::string& resource_identifier, |
| 555 ContentSettingsForOneType* settings, | 388 ContentSettingsForOneType* settings, |
| 556 bool incognito) const { | 389 bool incognito) const { |
| 557 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 390 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
| 558 provider->GetRuleIterator(content_type, | 391 provider->GetRuleIterator(content_type, |
| 559 resource_identifier, | 392 resource_identifier, |
| 560 incognito)); | 393 incognito)); |
| 561 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 394 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
| 562 while (rule_iterator->HasNext()) { | 395 while (rule_iterator->HasNext()) { |
| 563 const content_settings::Rule& rule = rule_iterator->Next(); | 396 const content_settings::Rule& rule = rule_iterator->Next(); |
| 564 settings->push_back(ContentSettingPatternSource( | 397 settings->push_back(ContentSettingPatternSource( |
| 565 rule.primary_pattern, rule.secondary_pattern, | 398 rule.primary_pattern, rule.secondary_pattern, |
| 566 content_settings::ValueToContentSetting(rule.value.get()), | 399 content_settings::ValueToContentSetting(rule.value.get()), |
| 567 kProviderNames[provider_type], | 400 kProviderNames[provider_type], |
| 568 incognito)); | 401 incognito)); |
| 569 } | 402 } |
| 570 } | 403 } |
| 404 |
| 405 bool HostContentSettingsMap::ShouldAllowAllContent( |
| 406 const GURL& url, |
| 407 ContentSettingsType content_type) { |
| 408 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 409 return false; |
| 410 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
| 411 url.SchemeIs(chrome::kChromeInternalScheme) || |
| 412 url.SchemeIs(chrome::kChromeUIScheme) || |
| 413 url.SchemeIs(chrome::kExtensionScheme); |
| 414 } |
| OLD | NEW |