| 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" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/content_settings/content_settings_extension_provider.h" | 12 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
| 13 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 13 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
| 14 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 14 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 15 #include "chrome/browser/content_settings/content_settings_provider.h" | 15 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 16 #include "chrome/browser/content_settings/content_settings_utils.h" | 16 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
| 25 #include "content/browser/user_metrics.h" | 26 #include "content/browser/user_metrics.h" |
| 26 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
| 27 #include "content/common/notification_source.h" | 28 #include "content/common/notification_source.h" |
| 28 #include "content/common/notification_type.h" | |
| 29 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 30 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 31 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
| 32 #include "net/base/static_cookie_policy.h" | 32 #include "net/base/static_cookie_policy.h" |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Returns true if we should allow all content types for this URL. This is | 36 // Returns true if we should allow all content types for this URL. This is |
| 37 // true for various internal objects like chrome:// URLs, so UI and other | 37 // true for various internal objects like chrome:// URLs, so UI and other |
| 38 // things users think of as "not webpages" don't break. | 38 // things users think of as "not webpages" don't break. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 new content_settings::ExtensionProvider( | 116 new content_settings::ExtensionProvider( |
| 117 this, | 117 this, |
| 118 extension_service->GetExtensionContentSettingsStore(), | 118 extension_service->GetExtensionContentSettingsStore(), |
| 119 is_off_the_record_))); | 119 is_off_the_record_))); |
| 120 } | 120 } |
| 121 content_settings_providers_.push_back( | 121 content_settings_providers_.push_back( |
| 122 make_linked_ptr(new content_settings::PrefProvider(profile))); | 122 make_linked_ptr(new content_settings::PrefProvider(profile))); |
| 123 | 123 |
| 124 pref_change_registrar_.Init(prefs); | 124 pref_change_registrar_.Init(prefs); |
| 125 pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); | 125 pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); |
| 126 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 126 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 127 Source<Profile>(profile_)); | 127 Source<Profile>(profile_)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // static | 130 // static |
| 131 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { | 131 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { |
| 132 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, | 132 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, |
| 133 false, | 133 false, |
| 134 PrefService::SYNCABLE_PREF); | 134 PrefService::SYNCABLE_PREF); |
| 135 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, | 135 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, |
| 136 0, | 136 0, |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 439 } |
| 440 | 440 |
| 441 { | 441 { |
| 442 base::AutoLock auto_lock(lock_); | 442 base::AutoLock auto_lock(lock_); |
| 443 block_third_party_cookies_ = block; | 443 block_third_party_cookies_ = block; |
| 444 } | 444 } |
| 445 | 445 |
| 446 profile_->GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, block); | 446 profile_->GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, block); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void HostContentSettingsMap::Observe(NotificationType type, | 449 void HostContentSettingsMap::Observe(int type, |
| 450 const NotificationSource& source, | 450 const NotificationSource& source, |
| 451 const NotificationDetails& details) { | 451 const NotificationDetails& details) { |
| 452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 453 | 453 |
| 454 if (type == NotificationType::PREF_CHANGED) { | 454 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 455 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 455 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
| 456 if (updating_preferences_) | 456 if (updating_preferences_) |
| 457 return; | 457 return; |
| 458 | 458 |
| 459 std::string* name = Details<std::string>(details).ptr(); | 459 std::string* name = Details<std::string>(details).ptr(); |
| 460 if (*name == prefs::kBlockThirdPartyCookies) { | 460 if (*name == prefs::kBlockThirdPartyCookies) { |
| 461 base::AutoLock auto_lock(lock_); | 461 base::AutoLock auto_lock(lock_); |
| 462 block_third_party_cookies_ = profile_->GetPrefs()->GetBoolean( | 462 block_third_party_cookies_ = profile_->GetPrefs()->GetBoolean( |
| 463 prefs::kBlockThirdPartyCookies); | 463 prefs::kBlockThirdPartyCookies); |
| 464 is_block_third_party_cookies_managed_ = | 464 is_block_third_party_cookies_managed_ = |
| 465 profile_->GetPrefs()->IsManagedPreference( | 465 profile_->GetPrefs()->IsManagedPreference( |
| 466 prefs::kBlockThirdPartyCookies); | 466 prefs::kBlockThirdPartyCookies); |
| 467 } else { | 467 } else { |
| 468 NOTREACHED() << "Unexpected preference observed"; | 468 NOTREACHED() << "Unexpected preference observed"; |
| 469 return; | 469 return; |
| 470 } | 470 } |
| 471 } else if (type == NotificationType::PROFILE_DESTROYED) { | 471 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
| 472 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 472 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
| 473 UnregisterObservers(); | 473 UnregisterObservers(); |
| 474 } else { | 474 } else { |
| 475 NOTREACHED() << "Unexpected notification"; | 475 NOTREACHED() << "Unexpected notification"; |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 | 478 |
| 479 HostContentSettingsMap::~HostContentSettingsMap() { | 479 HostContentSettingsMap::~HostContentSettingsMap() { |
| 480 UnregisterObservers(); | 480 UnregisterObservers(); |
| 481 } | 481 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 497 ++it) { | 497 ++it) { |
| 498 (*it)->ShutdownOnUIThread(); | 498 (*it)->ShutdownOnUIThread(); |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 void HostContentSettingsMap::UnregisterObservers() { | 502 void HostContentSettingsMap::UnregisterObservers() { |
| 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 504 if (!profile_) | 504 if (!profile_) |
| 505 return; | 505 return; |
| 506 pref_change_registrar_.RemoveAll(); | 506 pref_change_registrar_.RemoveAll(); |
| 507 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 507 notification_registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 508 Source<Profile>(profile_)); | 508 Source<Profile>(profile_)); |
| 509 profile_ = NULL; | 509 profile_ = NULL; |
| 510 } | 510 } |
| 511 | 511 |
| 512 void HostContentSettingsMap::MigrateObsoleteCookiePref(PrefService* prefs) { | 512 void HostContentSettingsMap::MigrateObsoleteCookiePref(PrefService* prefs) { |
| 513 if (prefs->HasPrefPath(prefs::kCookieBehavior)) { | 513 if (prefs->HasPrefPath(prefs::kCookieBehavior)) { |
| 514 int cookie_behavior = prefs->GetInteger(prefs::kCookieBehavior); | 514 int cookie_behavior = prefs->GetInteger(prefs::kCookieBehavior); |
| 515 prefs->ClearPref(prefs::kCookieBehavior); | 515 prefs->ClearPref(prefs::kCookieBehavior); |
| 516 if (!prefs->HasPrefPath(prefs::kDefaultContentSettings)) { | 516 if (!prefs->HasPrefPath(prefs::kDefaultContentSettings)) { |
| 517 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 517 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
| 518 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 518 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
| 519 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 519 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
| 520 } | 520 } |
| 521 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 521 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
| 522 SetBlockThirdPartyCookies(cookie_behavior == | 522 SetBlockThirdPartyCookies(cookie_behavior == |
| 523 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 523 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 } | 526 } |
| OLD | NEW |