From 6a2d643cca5d23ea866042c3af04f55f44195d09 Mon Sep 17 00:00:00 2001
From: "jochen@chromium.org"
 <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Fri, 4 Nov 2011 13:28:02 +0000
Subject: Apply exemptions to content settings based on the primary url

the primary url is the cookie's security origin or, for all other content types, the main frame url

BUG=none
TEST=HostContentSettingsMapTest.ShouldAllowAllContent

Review URL: http://codereview.chromium.org/8457009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108644 0039d316-1c4b-4281-b951-d872f2087c98
---
 chrome/browser/content_settings/cookie_settings.cc |  3 +--
 .../content_settings/host_content_settings_map.cc  |  2 +-
 .../host_content_settings_map_unittest.cc          | 23 ++++++++++++++++++++++
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/chrome/browser/content_settings/cookie_settings.cc b/chrome/browser/content_settings/cookie_settings.cc
index dd5d788..9731399 100644
--- a/chrome/browser/content_settings/cookie_settings.cc
+++ b/chrome/browser/content_settings/cookie_settings.cc
@@ -201,8 +201,7 @@ ContentSetting CookieSettings::GetCookieSetting(
     const GURL& first_party_url,
     bool setting_cookie) const {
   if (HostContentSettingsMap::ShouldAllowAllContent(
-          first_party_url,
-          CONTENT_SETTINGS_TYPE_COOKIES)) {
+          url, CONTENT_SETTINGS_TYPE_COOKIES)) {
     return CONTENT_SETTING_ALLOW;
   }
 
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc
index 3b4d4db3..7f0c44a0 100644
--- a/chrome/browser/content_settings/host_content_settings_map.cc
+++ b/chrome/browser/content_settings/host_content_settings_map.cc
@@ -184,7 +184,7 @@ base::Value* HostContentSettingsMap::GetContentSettingValue(
          resource_identifier.empty());
 
   // Check if the scheme of the requesting url is whitelisted.
-  if (ShouldAllowAllContent(secondary_url, content_type))
+  if (ShouldAllowAllContent(primary_url, content_type))
     return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW);
 
   // The list of |content_settings_providers_| is ordered according to their
diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
index aff5b58..0965bc3 100644
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
@@ -1065,3 +1065,26 @@ TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
             host_content_settings_map->GetDefaultContentSetting(
                 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
 }
+
+TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) {
+  TestingProfile profile;
+  HostContentSettingsMap* host_content_settings_map =
+      profile.GetHostContentSettingsMap();
+
+  GURL host("http://example.com/");
+  GURL embedder("chrome://foo");
+  ContentSettingsPattern pattern =
+       ContentSettingsPattern::FromString("[*.]example.com");
+  host_content_settings_map->SetContentSetting(
+      pattern,
+      ContentSettingsPattern::Wildcard(),
+      CONTENT_SETTINGS_TYPE_IMAGES,
+      std::string(),
+      CONTENT_SETTING_BLOCK);
+  EXPECT_EQ(CONTENT_SETTING_BLOCK,
+            host_content_settings_map->GetContentSetting(
+                host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
+  EXPECT_EQ(CONTENT_SETTING_ALLOW,
+            host_content_settings_map->GetContentSetting(
+                embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
+}
-- 
cgit v1.1