diff options
Diffstat (limited to 'chrome/browser')
5 files changed, 66 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_special_storage_policy.cc b/chrome/browser/extensions/extension_special_storage_policy.cc index 95a2486..de58fb9 100644 --- a/chrome/browser/extensions/extension_special_storage_policy.cc +++ b/chrome/browser/extensions/extension_special_storage_policy.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/common/content_settings.h" +#include "chrome/common/content_settings_types.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_thread.h" @@ -37,6 +38,22 @@ bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { return (content_setting == CONTENT_SETTING_SESSION_ONLY); } +bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { + if (host_content_settings_map_ == NULL) + return false; + if (host_content_settings_map_->GetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_COOKIES) == CONTENT_SETTING_SESSION_ONLY) + return true; + HostContentSettingsMap::SettingsForOneType entries; + host_content_settings_map_->GetSettingsForOneType( + CONTENT_SETTINGS_TYPE_COOKIES, "", &entries); + for (size_t i = 0; i < entries.size(); ++i) { + if (entries[i].c == CONTENT_SETTING_SESSION_ONLY) + return true; + } + return false; +} + bool ExtensionSpecialStoragePolicy::IsFileHandler( const std::string& extension_id) { base::AutoLock locker(lock_); diff --git a/chrome/browser/extensions/extension_special_storage_policy.h b/chrome/browser/extensions/extension_special_storage_policy.h index 8ce9d30..bce392c 100644 --- a/chrome/browser/extensions/extension_special_storage_policy.h +++ b/chrome/browser/extensions/extension_special_storage_policy.h @@ -30,6 +30,7 @@ class ExtensionSpecialStoragePolicy : public quota::SpecialStoragePolicy { virtual bool IsStorageUnlimited(const GURL& origin); virtual bool IsStorageSessionOnly(const GURL& origin); virtual bool IsFileHandler(const std::string& extension_id); + virtual bool HasSessionOnlyOrigins(); // Methods used by the ExtensionService to populate this class. void GrantRightsForExtension(const Extension* extension); diff --git a/chrome/browser/extensions/extension_special_storage_policy_unittest.cc b/chrome/browser/extensions/extension_special_storage_policy_unittest.cc index bd7f274..938b3f9 100644 --- a/chrome/browser/extensions/extension_special_storage_policy_unittest.cc +++ b/chrome/browser/extensions/extension_special_storage_policy_unittest.cc @@ -3,9 +3,13 @@ // found in the LICENSE file. #include "base/values.h" +#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/extensions/extension_special_storage_policy.h" +#include "chrome/common/content_settings.h" +#include "chrome/common/content_settings_types.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" +#include "chrome/test/base/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" namespace keys = extension_manifest_keys; @@ -210,3 +214,42 @@ TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) { EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); } + +TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { + MessageLoop message_loop; + BrowserThread ui_thread(BrowserThread::UI, &message_loop); + + TestingProfile profile; + HostContentSettingsMap* host_content_settings_map = + profile.GetHostContentSettingsMap(); + scoped_refptr<ExtensionSpecialStoragePolicy> policy( + new ExtensionSpecialStoragePolicy(host_content_settings_map)); + + EXPECT_FALSE(policy->HasSessionOnlyOrigins()); + + // The default setting can be session-only. + host_content_settings_map->SetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_SESSION_ONLY); + EXPECT_TRUE(policy->HasSessionOnlyOrigins()); + + host_content_settings_map->SetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW); + EXPECT_FALSE(policy->HasSessionOnlyOrigins()); + + // Or the session-onlyness can affect individual origins. + ContentSettingsPattern pattern = + ContentSettingsPattern::FromString("pattern.com"); + + host_content_settings_map->SetContentSetting( + pattern, ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_SESSION_ONLY); + + EXPECT_TRUE(policy->HasSessionOnlyOrigins()); + + // Clearing an origin-spesific rule. + host_content_settings_map->SetContentSetting( + pattern, ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); + + EXPECT_FALSE(policy->HasSessionOnlyOrigins()); +} diff --git a/chrome/browser/extensions/mock_extension_special_storage_policy.cc b/chrome/browser/extensions/mock_extension_special_storage_policy.cc index 7cf86cd..fd9bb3e 100644 --- a/chrome/browser/extensions/mock_extension_special_storage_policy.cc +++ b/chrome/browser/extensions/mock_extension_special_storage_policy.cc @@ -26,3 +26,7 @@ bool MockExtensionSpecialStoragePolicy::IsFileHandler( const std::string& extension_id) { return file_handlers_.find(extension_id) != file_handlers_.end(); } + +bool MockExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { + return !session_only_.empty(); +} diff --git a/chrome/browser/extensions/mock_extension_special_storage_policy.h b/chrome/browser/extensions/mock_extension_special_storage_policy.h index b4ce548..90fffbe 100644 --- a/chrome/browser/extensions/mock_extension_special_storage_policy.h +++ b/chrome/browser/extensions/mock_extension_special_storage_policy.h @@ -24,6 +24,7 @@ class MockExtensionSpecialStoragePolicy : public ExtensionSpecialStoragePolicy { virtual bool IsStorageUnlimited(const GURL& origin); virtual bool IsStorageSessionOnly(const GURL& origin); virtual bool IsFileHandler(const std::string& extension_id); + virtual bool HasSessionOnlyOrigins(); void AddProtected(const GURL& origin) { protected_.insert(origin); |