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 <list> | 7 #include <list> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/string_util.h" | |
11 #include "base/utf_string_conversions.h" | |
12 #include "chrome/browser/content_settings/content_settings_details.h" | 10 #include "chrome/browser/content_settings/content_settings_details.h" |
13 #include "chrome/browser/content_settings/content_settings_extension_provider.h" | 11 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
14 #include "chrome/browser/content_settings/content_settings_observable_provider.h " | 12 #include "chrome/browser/content_settings/content_settings_observable_provider.h " |
15 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 13 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
16 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 14 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
17 #include "chrome/browser/content_settings/content_settings_provider.h" | 15 #include "chrome/browser/content_settings/content_settings_provider.h" |
18 #include "chrome/browser/content_settings/content_settings_utils.h" | 16 #include "chrome/browser/content_settings/content_settings_utils.h" |
17 #include "chrome/browser/content_settings/cookie_settings.h" | |
19 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
22 #include "chrome/browser/profiles/profile.h" | |
23 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
27 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
28 #include "content/browser/user_metrics.h" | 26 #include "content/browser/user_metrics.h" |
29 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
30 #include "content/common/notification_source.h" | 28 #include "content/common/notification_source.h" |
31 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
32 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
33 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
34 #include "net/base/static_cookie_policy.h" | 32 #include "net/base/static_cookie_policy.h" |
35 | 33 |
36 namespace { | 34 namespace { |
37 | 35 |
38 // Returns true if we should allow all content types for this URL. This is | |
39 // true for various internal objects like chrome:// URLs, so UI and other | |
40 // things users think of as "not webpages" don't break. | |
41 static bool ShouldAllowAllContent(const GURL& url) { | |
42 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | |
43 url.SchemeIs(chrome::kChromeInternalScheme) || | |
44 url.SchemeIs(chrome::kChromeUIScheme) || | |
45 url.SchemeIs(chrome::kExtensionScheme); | |
46 } | |
47 | |
48 typedef linked_ptr<content_settings::DefaultProviderInterface> | 36 typedef linked_ptr<content_settings::DefaultProviderInterface> |
49 DefaultContentSettingsProviderPtr; | 37 DefaultContentSettingsProviderPtr; |
50 typedef std::vector<DefaultContentSettingsProviderPtr>::iterator | 38 typedef std::vector<DefaultContentSettingsProviderPtr>::iterator |
51 DefaultProviderIterator; | 39 DefaultProviderIterator; |
52 typedef std::vector<DefaultContentSettingsProviderPtr>::const_iterator | 40 typedef std::vector<DefaultContentSettingsProviderPtr>::const_iterator |
53 ConstDefaultProviderIterator; | 41 ConstDefaultProviderIterator; |
54 | 42 |
55 typedef linked_ptr<content_settings::ProviderInterface> ProviderPtr; | 43 typedef linked_ptr<content_settings::ProviderInterface> ProviderPtr; |
56 typedef std::vector<ProviderPtr>::iterator ProviderIterator; | 44 typedef std::vector<ProviderPtr>::iterator ProviderIterator; |
57 typedef std::vector<ProviderPtr>::const_iterator ConstProviderIterator; | 45 typedef std::vector<ProviderPtr>::const_iterator ConstProviderIterator; |
58 | 46 |
59 typedef content_settings::ProviderInterface::Rules Rules; | 47 typedef content_settings::ProviderInterface::Rules Rules; |
60 | 48 |
61 typedef std::pair<std::string, std::string> StringPair; | 49 typedef std::pair<std::string, std::string> StringPair; |
62 | 50 |
63 const char* kProviderNames[] = { | 51 const char* kProviderNames[] = { |
64 "policy", | 52 "policy", |
65 "extension", | 53 "extension", |
66 "preference" | 54 "preference" |
67 }; | 55 }; |
68 | 56 |
69 } // namespace | 57 } // namespace |
70 | 58 |
71 HostContentSettingsMap::HostContentSettingsMap( | 59 HostContentSettingsMap::HostContentSettingsMap( |
72 PrefService* prefs, | 60 PrefService* prefs, |
73 ExtensionService* extension_service, | 61 ExtensionService* extension_service, |
74 bool incognito) | 62 bool incognito) |
75 : prefs_(prefs), | 63 : prefs_(prefs), |
76 is_off_the_record_(incognito), | 64 is_off_the_record_(incognito) { |
77 updating_preferences_(false), | |
78 block_third_party_cookies_(false), | |
79 is_block_third_party_cookies_managed_(false) { | |
80 // The order in which the default content settings providers are created is | 65 // The order in which the default content settings providers are created is |
81 // critical, as providers that are further down in the list (i.e. added later) | 66 // critical, as providers that are further down in the list (i.e. added later) |
82 // override providers further up. | 67 // override providers further up. |
83 content_settings::PrefDefaultProvider* default_provider = | 68 content_settings::PrefDefaultProvider* default_provider = |
84 new content_settings::PrefDefaultProvider(prefs_, is_off_the_record_); | 69 new content_settings::PrefDefaultProvider(prefs_, is_off_the_record_); |
85 default_provider->AddObserver(this); | 70 default_provider->AddObserver(this); |
86 default_content_settings_providers_.push_back( | 71 default_content_settings_providers_.push_back( |
87 make_linked_ptr(default_provider)); | 72 make_linked_ptr(default_provider)); |
88 | 73 |
89 content_settings::PolicyDefaultProvider* policy_default_provider = | 74 content_settings::PolicyDefaultProvider* policy_default_provider = |
90 new content_settings::PolicyDefaultProvider(prefs_); | 75 new content_settings::PolicyDefaultProvider(prefs_); |
91 policy_default_provider->AddObserver(this); | 76 policy_default_provider->AddObserver(this); |
92 default_content_settings_providers_.push_back( | 77 default_content_settings_providers_.push_back( |
93 make_linked_ptr(policy_default_provider)); | 78 make_linked_ptr(policy_default_provider)); |
94 | 79 |
95 // TODO(markusheintz): Discuss whether it is sensible to move migration code | |
96 // to PrefContentSettingsProvider. | |
97 MigrateObsoleteCookiePref(); | |
98 | |
99 // Read misc. global settings. | 80 // Read misc. global settings. |
100 block_third_party_cookies_ = | |
101 prefs_->GetBoolean(prefs::kBlockThirdPartyCookies); | |
102 if (block_third_party_cookies_) { | |
103 UserMetrics::RecordAction( | |
104 UserMetricsAction("ThirdPartyCookieBlockingEnabled")); | |
105 } else { | |
106 UserMetrics::RecordAction( | |
107 UserMetricsAction("ThirdPartyCookieBlockingDisabled")); | |
108 } | |
109 is_block_third_party_cookies_managed_ = | |
110 prefs_->IsManagedPreference(prefs::kBlockThirdPartyCookies); | |
111 | 81 |
112 // User defined non default content settings are provided by the PrefProvider. | 82 // User defined non default content settings are provided by the PrefProvider. |
113 // The order in which the content settings providers are created is critical, | 83 // The order in which the content settings providers are created is critical, |
114 // as providers that are further up in the list (i.e. added earlier) override | 84 // as providers that are further up in the list (i.e. added earlier) override |
115 // providers further down. | 85 // providers further down. |
116 content_settings::ObservableProvider* provider = | 86 content_settings::ObservableProvider* provider = |
117 new content_settings::PolicyProvider(prefs_, policy_default_provider); | 87 new content_settings::PolicyProvider(prefs_, policy_default_provider); |
118 provider->AddObserver(this); | 88 provider->AddObserver(this); |
119 content_settings_providers_.push_back(make_linked_ptr(provider)); | 89 content_settings_providers_.push_back(make_linked_ptr(provider)); |
120 | 90 |
121 if (extension_service) { | 91 if (extension_service) { |
122 // |extension_service| can be NULL in unit tests. | 92 // |extension_service| can be NULL in unit tests. |
123 provider = new content_settings::ExtensionProvider( | 93 provider = new content_settings::ExtensionProvider( |
124 extension_service->GetExtensionContentSettingsStore(), | 94 extension_service->GetExtensionContentSettingsStore(), |
125 is_off_the_record_); | 95 is_off_the_record_); |
126 provider->AddObserver(this); | 96 provider->AddObserver(this); |
127 content_settings_providers_.push_back(make_linked_ptr(provider)); | 97 content_settings_providers_.push_back(make_linked_ptr(provider)); |
128 } | 98 } |
129 provider = new content_settings::PrefProvider(prefs_, is_off_the_record_); | 99 provider = new content_settings::PrefProvider(prefs_, is_off_the_record_); |
130 provider->AddObserver(this); | 100 provider->AddObserver(this); |
131 content_settings_providers_.push_back(make_linked_ptr(provider)); | 101 content_settings_providers_.push_back(make_linked_ptr(provider)); |
132 | |
133 pref_change_registrar_.Init(prefs_); | |
134 pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); | |
135 } | 102 } |
136 | 103 |
137 // static | 104 // static |
138 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { | 105 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { |
139 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, | 106 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, |
140 false, | 107 false, |
141 PrefService::SYNCABLE_PREF); | 108 PrefService::SYNCABLE_PREF); |
142 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, | 109 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, |
143 0, | 110 0, |
144 PrefService::UNSYNCABLE_PREF); | 111 PrefService::UNSYNCABLE_PREF); |
(...skipping 28 matching lines...) Expand all Loading... | |
173 return setting; | 140 return setting; |
174 } | 141 } |
175 | 142 |
176 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { | 143 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { |
177 ContentSettings output(CONTENT_SETTING_DEFAULT); | 144 ContentSettings output(CONTENT_SETTING_DEFAULT); |
178 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) | 145 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) |
179 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); | 146 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); |
180 return output; | 147 return output; |
181 } | 148 } |
182 | 149 |
183 ContentSetting HostContentSettingsMap::GetCookieContentSetting( | |
184 const GURL& url, | |
185 const GURL& first_party_url, | |
186 bool setting_cookie) const { | |
187 if (ShouldAllowAllContent(first_party_url)) | |
188 return CONTENT_SETTING_ALLOW; | |
189 | |
190 // First get any host-specific settings. | |
191 ContentSetting setting = GetNonDefaultContentSetting(url, | |
192 first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | |
193 | |
194 // If no explicit exception has been made and third-party cookies are blocked | |
195 // by default, apply that rule. | |
196 if (setting == CONTENT_SETTING_DEFAULT && BlockThirdPartyCookies()) { | |
197 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( | |
198 switches::kBlockReadingThirdPartyCookies); | |
199 net::StaticCookiePolicy policy(strict ? | |
200 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : | |
201 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | |
202 int rv; | |
203 if (setting_cookie) | |
204 rv = policy.CanSetCookie(url, first_party_url); | |
205 else | |
206 rv = policy.CanGetCookies(url, first_party_url); | |
207 DCHECK_NE(net::ERR_IO_PENDING, rv); | |
208 if (rv != net::OK) | |
209 setting = CONTENT_SETTING_BLOCK; | |
210 } | |
211 | |
212 // If no other policy has changed the setting, use the default. | |
213 if (setting == CONTENT_SETTING_DEFAULT) | |
214 setting = GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); | |
215 | |
216 return setting; | |
217 } | |
218 | |
219 ContentSetting HostContentSettingsMap::GetContentSetting( | 150 ContentSetting HostContentSettingsMap::GetContentSetting( |
220 const GURL& primary_url, | 151 const GURL& primary_url, |
221 const GURL& secondary_url, | 152 const GURL& secondary_url, |
222 ContentSettingsType content_type, | 153 ContentSettingsType content_type, |
223 const std::string& resource_identifier) const { | 154 const std::string& resource_identifier) const { |
224 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); | 155 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); |
225 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), | 156 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), |
226 resource_identifier.empty()); | 157 resource_identifier.empty()); |
227 return GetContentSettingInternal( | 158 return GetContentSettingInternal( |
228 primary_url, secondary_url, content_type, resource_identifier); | 159 primary_url, secondary_url, content_type, resource_identifier); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 // TODO(markusheintz): Only the rules that are applied should be added. | 262 // TODO(markusheintz): Only the rules that are applied should be added. |
332 for (std::map<StringPair, PatternSettingSourceTuple>::iterator i( | 263 for (std::map<StringPair, PatternSettingSourceTuple>::iterator i( |
333 settings_map.begin()); | 264 settings_map.begin()); |
334 i != settings_map.end(); | 265 i != settings_map.end(); |
335 ++i) { | 266 ++i) { |
336 settings->push_back(i->second); | 267 settings->push_back(i->second); |
337 } | 268 } |
338 } | 269 } |
339 } | 270 } |
340 | 271 |
272 CookieSettings* HostContentSettingsMap::GetCookieSettings() { | |
Bernhard Bauer
2011/08/28 19:18:49
Uhh, this isn't thread safe at all. CookieSettings
markusheintz_
2011/08/29 08:47:09
I guess that's my fault as I suggested to have suc
marja
2011/09/01 11:03:19
This code is removed now, as CookieSettings is a P
| |
273 if (!cookie_settings_.get()) { | |
274 cookie_settings_ = new CookieSettings(this, prefs_, is_off_the_record_); | |
275 } | |
276 return cookie_settings_.get(); | |
277 } | |
278 | |
341 void HostContentSettingsMap::SetDefaultContentSetting( | 279 void HostContentSettingsMap::SetDefaultContentSetting( |
342 ContentSettingsType content_type, | 280 ContentSettingsType content_type, |
343 ContentSetting setting) { | 281 ContentSetting setting) { |
344 DCHECK(IsSettingAllowedForType(setting, content_type)); | 282 DCHECK(IsSettingAllowedForType(setting, content_type)); |
345 for (DefaultProviderIterator provider = | 283 for (DefaultProviderIterator provider = |
346 default_content_settings_providers_.begin(); | 284 default_content_settings_providers_.begin(); |
347 provider != default_content_settings_providers_.end(); ++provider) { | 285 provider != default_content_settings_providers_.end(); ++provider) { |
348 (*provider)->UpdateDefaultSetting(content_type, setting); | 286 (*provider)->UpdateDefaultSetting(content_type, setting); |
349 } | 287 } |
350 } | 288 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 switches::kEnableWebIntents)) | 351 switches::kEnableWebIntents)) |
414 return false; | 352 return false; |
415 | 353 |
416 // DEFAULT, ALLOW and BLOCK are always allowed. | 354 // DEFAULT, ALLOW and BLOCK are always allowed. |
417 if (setting == CONTENT_SETTING_DEFAULT || | 355 if (setting == CONTENT_SETTING_DEFAULT || |
418 setting == CONTENT_SETTING_ALLOW || | 356 setting == CONTENT_SETTING_ALLOW || |
419 setting == CONTENT_SETTING_BLOCK) { | 357 setting == CONTENT_SETTING_BLOCK) { |
420 return true; | 358 return true; |
421 } | 359 } |
422 switch (content_type) { | 360 switch (content_type) { |
423 case CONTENT_SETTINGS_TYPE_COOKIES: | 361 case CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY: |
424 return (setting == CONTENT_SETTING_SESSION_ONLY); | 362 return (setting == CONTENT_SETTING_SESSION_ONLY); |
425 case CONTENT_SETTINGS_TYPE_PLUGINS: | 363 case CONTENT_SETTINGS_TYPE_PLUGINS: |
426 return (setting == CONTENT_SETTING_ASK && | 364 return (setting == CONTENT_SETTING_ASK && |
427 CommandLine::ForCurrentProcess()->HasSwitch( | 365 CommandLine::ForCurrentProcess()->HasSwitch( |
428 switches::kEnableClickToPlay)); | 366 switches::kEnableClickToPlay)); |
429 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 367 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
430 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 368 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
431 case CONTENT_SETTINGS_TYPE_INTENTS: | 369 case CONTENT_SETTINGS_TYPE_INTENTS: |
432 return (setting == CONTENT_SETTING_ASK); | 370 return (setting == CONTENT_SETTING_ASK); |
433 default: | 371 default: |
434 return false; | 372 return false; |
435 } | 373 } |
436 } | 374 } |
437 | 375 |
438 void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) { | |
439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
440 DCHECK(prefs_); | |
441 | |
442 // This setting may not be directly modified for OTR sessions. Instead, it | |
443 // is synced to the main profile's setting. | |
444 if (is_off_the_record_) { | |
445 NOTREACHED(); | |
446 return; | |
447 } | |
448 | |
449 // If the preference block-third-party-cookies is managed then do not allow to | |
450 // change it. | |
451 if (prefs_->IsManagedPreference(prefs::kBlockThirdPartyCookies)) { | |
452 NOTREACHED(); | |
453 return; | |
454 } | |
455 | |
456 { | |
457 base::AutoLock auto_lock(lock_); | |
458 block_third_party_cookies_ = block; | |
459 } | |
460 | |
461 prefs_->SetBoolean(prefs::kBlockThirdPartyCookies, block); | |
462 } | |
463 | |
464 void HostContentSettingsMap::OnContentSettingChanged( | 376 void HostContentSettingsMap::OnContentSettingChanged( |
465 ContentSettingsPattern primary_pattern, | 377 ContentSettingsPattern primary_pattern, |
466 ContentSettingsPattern secondary_pattern, | 378 ContentSettingsPattern secondary_pattern, |
467 ContentSettingsType content_type, | 379 ContentSettingsType content_type, |
468 std::string resource_identifier) { | 380 std::string resource_identifier) { |
469 const ContentSettingsDetails details(primary_pattern, | 381 const ContentSettingsDetails details(primary_pattern, |
470 secondary_pattern, | 382 secondary_pattern, |
471 content_type, | 383 content_type, |
472 resource_identifier); | 384 resource_identifier); |
473 NotificationService::current()->Notify( | 385 NotificationService::current()->Notify( |
474 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, | 386 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
475 Source<HostContentSettingsMap>(this), | 387 Source<HostContentSettingsMap>(this), |
476 Details<const ContentSettingsDetails>(&details)); | 388 Details<const ContentSettingsDetails>(&details)); |
477 } | 389 } |
478 | 390 |
479 void HostContentSettingsMap::Observe(int type, | 391 // static |
480 const NotificationSource& source, | 392 // Returns true if we should allow all content types for this URL. This is |
481 const NotificationDetails& details) { | 393 // true for various internal objects like chrome:// URLs, so UI and other |
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 394 // things users think of as "not webpages" don't break. |
483 | 395 bool HostContentSettingsMap::ShouldAllowAllContent(const GURL& url) { |
484 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 396 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
485 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); | 397 url.SchemeIs(chrome::kChromeInternalScheme) || |
486 if (updating_preferences_) | 398 url.SchemeIs(chrome::kChromeUIScheme) || |
487 return; | 399 url.SchemeIs(chrome::kExtensionScheme); |
488 | |
489 std::string* name = Details<std::string>(details).ptr(); | |
490 if (*name == prefs::kBlockThirdPartyCookies) { | |
491 base::AutoLock auto_lock(lock_); | |
492 block_third_party_cookies_ = prefs_->GetBoolean( | |
493 prefs::kBlockThirdPartyCookies); | |
494 is_block_third_party_cookies_managed_ = | |
495 prefs_->IsManagedPreference( | |
496 prefs::kBlockThirdPartyCookies); | |
497 } else { | |
498 NOTREACHED() << "Unexpected preference observed"; | |
499 return; | |
500 } | |
501 } else { | |
502 NOTREACHED() << "Unexpected notification"; | |
503 } | |
504 } | 400 } |
505 | 401 |
506 HostContentSettingsMap::~HostContentSettingsMap() { | 402 HostContentSettingsMap::~HostContentSettingsMap() { |
507 DCHECK(!prefs_); | 403 DCHECK(!prefs_); |
508 } | 404 } |
509 | 405 |
510 bool HostContentSettingsMap::IsDefaultContentSettingManaged( | 406 bool HostContentSettingsMap::IsDefaultContentSettingManaged( |
511 ContentSettingsType content_type) const { | 407 ContentSettingsType content_type) const { |
512 for (ConstDefaultProviderIterator provider = | 408 for (ConstDefaultProviderIterator provider = |
513 default_content_settings_providers_.begin(); | 409 default_content_settings_providers_.begin(); |
514 provider != default_content_settings_providers_.end(); ++provider) { | 410 provider != default_content_settings_providers_.end(); ++provider) { |
515 if ((*provider)->DefaultSettingIsManaged(content_type)) | 411 if ((*provider)->DefaultSettingIsManaged(content_type)) |
516 return true; | 412 return true; |
517 } | 413 } |
518 return false; | 414 return false; |
519 } | 415 } |
520 | 416 |
521 void HostContentSettingsMap::ShutdownOnUIThread() { | 417 void HostContentSettingsMap::ShutdownOnUIThread() { |
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
523 DCHECK(prefs_); | 419 DCHECK(prefs_); |
524 pref_change_registrar_.RemoveAll(); | 420 |
421 if (cookie_settings_.get()) | |
422 cookie_settings_->ShutdownOnUIThread(); | |
423 | |
525 prefs_ = NULL; | 424 prefs_ = NULL; |
526 for (ProviderIterator it = content_settings_providers_.begin(); | 425 for (ProviderIterator it = content_settings_providers_.begin(); |
527 it != content_settings_providers_.end(); | 426 it != content_settings_providers_.end(); |
528 ++it) { | 427 ++it) { |
529 (*it)->ShutdownOnUIThread(); | 428 (*it)->ShutdownOnUIThread(); |
530 } | 429 } |
531 for (DefaultProviderIterator it = default_content_settings_providers_.begin(); | 430 for (DefaultProviderIterator it = default_content_settings_providers_.begin(); |
532 it != default_content_settings_providers_.end(); | 431 it != default_content_settings_providers_.end(); |
533 ++it) { | 432 ++it) { |
534 (*it)->ShutdownOnUIThread(); | 433 (*it)->ShutdownOnUIThread(); |
535 } | 434 } |
536 } | 435 } |
537 | |
538 void HostContentSettingsMap::MigrateObsoleteCookiePref() { | |
539 if (prefs_->HasPrefPath(prefs::kCookieBehavior)) { | |
540 int cookie_behavior = prefs_->GetInteger(prefs::kCookieBehavior); | |
541 prefs_->ClearPref(prefs::kCookieBehavior); | |
542 if (!prefs_->HasPrefPath(prefs::kDefaultContentSettings)) { | |
543 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | |
544 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | |
545 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | |
546 } | |
547 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | |
548 SetBlockThirdPartyCookies(cookie_behavior == | |
549 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | |
550 } | |
551 } | |
552 } | |
OLD | NEW |