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

Unified Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 7713034: HostContentSettingsMap refactoring. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Code review comments. Threading fixes. Mac + win fixes. Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/host_content_settings_map.cc
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc
index 16ad3a22d66fa5b1d1767958a305407092dec33f..a58bf2ea6f49cccc551c213f21fb33bcd9e5a845 100644
--- a/chrome/browser/content_settings/host_content_settings_map.cc
+++ b/chrome/browser/content_settings/host_content_settings_map.cc
@@ -7,8 +7,6 @@
#include <list>
#include "base/command_line.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/content_settings/content_settings_extension_provider.h"
#include "chrome/browser/content_settings/content_settings_observable_provider.h"
@@ -19,7 +17,6 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -35,19 +32,6 @@
namespace {
-// Returns true if we should allow all content types for this URL. This is
-// true for various internal objects like chrome:// URLs, so UI and other
-// things users think of as "not webpages" don't break.
-static bool ShouldAllowAllContent(const GURL& url,
- ContentSettingsType content_type) {
- if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
- return false;
- return url.SchemeIs(chrome::kChromeDevToolsScheme) ||
- url.SchemeIs(chrome::kChromeInternalScheme) ||
- url.SchemeIs(chrome::kChromeUIScheme) ||
- url.SchemeIs(chrome::kExtensionScheme);
-}
-
typedef linked_ptr<content_settings::DefaultProviderInterface>
DefaultContentSettingsProviderPtr;
typedef std::vector<DefaultContentSettingsProviderPtr>::iterator
@@ -76,10 +60,7 @@ HostContentSettingsMap::HostContentSettingsMap(
ExtensionService* extension_service,
bool incognito)
: prefs_(prefs),
- is_off_the_record_(incognito),
- updating_preferences_(false),
- block_third_party_cookies_(false),
- is_block_third_party_cookies_managed_(false) {
+ is_off_the_record_(incognito) {
// The order in which the default content settings providers are created is
// critical, as providers that are further down in the list (i.e. added later)
// override providers further up.
@@ -95,22 +76,7 @@ HostContentSettingsMap::HostContentSettingsMap(
default_content_settings_providers_.push_back(
make_linked_ptr(policy_default_provider));
- // TODO(markusheintz): Discuss whether it is sensible to move migration code
- // to PrefContentSettingsProvider.
- MigrateObsoleteCookiePref();
-
// Read misc. global settings.
- block_third_party_cookies_ =
- prefs_->GetBoolean(prefs::kBlockThirdPartyCookies);
- if (block_third_party_cookies_) {
- UserMetrics::RecordAction(
- UserMetricsAction("ThirdPartyCookieBlockingEnabled"));
- } else {
- UserMetrics::RecordAction(
- UserMetricsAction("ThirdPartyCookieBlockingDisabled"));
- }
- is_block_third_party_cookies_managed_ =
- prefs_->IsManagedPreference(prefs::kBlockThirdPartyCookies);
// User defined non default content settings are provided by the PrefProvider.
// The order in which the content settings providers are created is critical,
@@ -132,9 +98,6 @@ HostContentSettingsMap::HostContentSettingsMap(
provider = new content_settings::PrefProvider(prefs_, is_off_the_record_);
provider->AddObserver(this);
content_settings_providers_.push_back(make_linked_ptr(provider));
-
- pref_change_registrar_.Init(prefs_);
- pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this);
}
// static
@@ -183,42 +146,6 @@ ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const {
return output;
}
-ContentSetting HostContentSettingsMap::GetCookieContentSetting(
- const GURL& url,
- const GURL& first_party_url,
- bool setting_cookie) const {
- if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES))
- return CONTENT_SETTING_ALLOW;
-
- // First get any host-specific settings.
- ContentSetting setting = GetNonDefaultContentSetting(url,
- first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "");
-
- // If no explicit exception has been made and third-party cookies are blocked
- // by default, apply that rule.
- if (setting == CONTENT_SETTING_DEFAULT && BlockThirdPartyCookies()) {
- bool strict = CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kBlockReadingThirdPartyCookies);
- net::StaticCookiePolicy policy(strict ?
- net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
- net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
- int rv;
- if (setting_cookie)
- rv = policy.CanSetCookie(url, first_party_url);
- else
- rv = policy.CanGetCookies(url, first_party_url);
- DCHECK_NE(net::ERR_IO_PENDING, rv);
- if (rv != net::OK)
- setting = CONTENT_SETTING_BLOCK;
- }
-
- // If no other policy has changed the setting, use the default.
- if (setting == CONTENT_SETTING_DEFAULT)
- setting = GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES);
-
- return setting;
-}
-
ContentSetting HostContentSettingsMap::GetContentSetting(
const GURL& primary_url,
const GURL& secondary_url,
@@ -413,6 +340,12 @@ bool HostContentSettingsMap::IsSettingAllowedForType(
switches::kEnableWebIntents))
return false;
+ if (content_type == CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY) {
+ return (setting == CONTENT_SETTING_DEFAULT ||
+ setting == CONTENT_SETTING_ALLOW ||
+ setting == CONTENT_SETTING_SESSION_ONLY);
+ }
+
// DEFAULT, ALLOW and BLOCK are always allowed.
if (setting == CONTENT_SETTING_DEFAULT ||
setting == CONTENT_SETTING_ALLOW ||
@@ -420,8 +353,6 @@ bool HostContentSettingsMap::IsSettingAllowedForType(
return true;
}
switch (content_type) {
- case CONTENT_SETTINGS_TYPE_COOKIES:
- return (setting == CONTENT_SETTING_SESSION_ONLY);
case CONTENT_SETTINGS_TYPE_PLUGINS:
return (setting == CONTENT_SETTING_ASK &&
CommandLine::ForCurrentProcess()->HasSwitch(
@@ -435,32 +366,6 @@ bool HostContentSettingsMap::IsSettingAllowedForType(
}
}
-void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(prefs_);
-
- // This setting may not be directly modified for OTR sessions. Instead, it
- // is synced to the main profile's setting.
- if (is_off_the_record_) {
- NOTREACHED();
- return;
- }
-
- // If the preference block-third-party-cookies is managed then do not allow to
- // change it.
- if (prefs_->IsManagedPreference(prefs::kBlockThirdPartyCookies)) {
- NOTREACHED();
- return;
- }
-
- {
- base::AutoLock auto_lock(lock_);
- block_third_party_cookies_ = block;
- }
-
- prefs_->SetBoolean(prefs::kBlockThirdPartyCookies, block);
-}
-
void HostContentSettingsMap::OnContentSettingChanged(
ContentSettingsPattern primary_pattern,
ContentSettingsPattern secondary_pattern,
@@ -476,31 +381,19 @@ void HostContentSettingsMap::OnContentSettingChanged(
Details<const ContentSettingsDetails>(&details));
}
-void HostContentSettingsMap::Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- if (type == chrome::NOTIFICATION_PREF_CHANGED) {
- DCHECK_EQ(prefs_, Source<PrefService>(source).ptr());
- if (updating_preferences_)
- return;
-
- std::string* name = Details<std::string>(details).ptr();
- if (*name == prefs::kBlockThirdPartyCookies) {
- base::AutoLock auto_lock(lock_);
- block_third_party_cookies_ = prefs_->GetBoolean(
- prefs::kBlockThirdPartyCookies);
- is_block_third_party_cookies_managed_ =
- prefs_->IsManagedPreference(
- prefs::kBlockThirdPartyCookies);
- } else {
- NOTREACHED() << "Unexpected preference observed";
- return;
- }
- } else {
- NOTREACHED() << "Unexpected notification";
- }
+// static
+// Returns true if we should allow all content types for this URL. This is
+// true for various internal objects like chrome:// URLs, so UI and other
+// things users think of as "not webpages" don't break.
+bool HostContentSettingsMap::ShouldAllowAllContent(
+ const GURL& url,
+ ContentSettingsType content_type) {
+ if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ return false;
+ return url.SchemeIs(chrome::kChromeDevToolsScheme) ||
+ url.SchemeIs(chrome::kChromeInternalScheme) ||
+ url.SchemeIs(chrome::kChromeUIScheme) ||
+ url.SchemeIs(chrome::kExtensionScheme);
}
HostContentSettingsMap::~HostContentSettingsMap() {
@@ -521,7 +414,7 @@ bool HostContentSettingsMap::IsDefaultContentSettingManaged(
void HostContentSettingsMap::ShutdownOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(prefs_);
- pref_change_registrar_.RemoveAll();
+
prefs_ = NULL;
for (ProviderIterator it = content_settings_providers_.begin();
it != content_settings_providers_.end();
@@ -534,19 +427,3 @@ void HostContentSettingsMap::ShutdownOnUIThread() {
(*it)->ShutdownOnUIThread();
}
}
-
-void HostContentSettingsMap::MigrateObsoleteCookiePref() {
- if (prefs_->HasPrefPath(prefs::kCookieBehavior)) {
- int cookie_behavior = prefs_->GetInteger(prefs::kCookieBehavior);
- prefs_->ClearPref(prefs::kCookieBehavior);
- if (!prefs_->HasPrefPath(prefs::kDefaultContentSettings)) {
- SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES,
- (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ?
- CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW);
- }
- if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) {
- SetBlockThirdPartyCookies(cookie_behavior ==
- net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
- }
- }
-}

Powered by Google App Engine
This is Rietveld 408576698