diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-06 11:14:09 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-06 11:14:09 +0000 |
commit | ca352454df9a2c6dac0dd5927c92d73d4eee069d (patch) | |
tree | f8eae8e9d64812c7b284415fcb6ee11cc1aff9fc /chrome | |
parent | dc3d06cd952e621bf64f3abe46e1c3eaa6598064 (diff) | |
download | chromium_src-ca352454df9a2c6dac0dd5927c92d73d4eee069d.zip chromium_src-ca352454df9a2c6dac0dd5927c92d73d4eee069d.tar.gz chromium_src-ca352454df9a2c6dac0dd5927c92d73d4eee069d.tar.bz2 |
Introduce a resource identifier for content settings.
This will allow for having per plugin content settings, i.e. the content settings type would be plugin and the resource identifier would be to concrete plugin that is about to be loaded.
BUG=39252
TEST=unit_tests
Review URL: http://codereview.chromium.org/2878075
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
20 files changed, 609 insertions, 213 deletions
diff --git a/chrome/browser/appcache/chrome_appcache_service.cc b/chrome/browser/appcache/chrome_appcache_service.cc index c2e41a0..5f58b29 100644 --- a/chrome/browser/appcache/chrome_appcache_service.cc +++ b/chrome/browser/appcache/chrome_appcache_service.cc @@ -80,7 +80,7 @@ void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); ContentSetting setting = host_contents_settings_map_->GetContentSetting( - manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); + manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); DCHECK(setting != CONTENT_SETTING_DEFAULT); // We don't prompt for read access. return setting != CONTENT_SETTING_BLOCK; @@ -90,7 +90,7 @@ int ChromeAppCacheService::CanCreateAppCache( const GURL& manifest_url, net::CompletionCallback* callback) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); ContentSetting setting = host_contents_settings_map_->GetContentSetting( - manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); + manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); DCHECK(setting != CONTENT_SETTING_DEFAULT); if (setting == CONTENT_SETTING_ASK) { ChromeThread::PostTask( @@ -109,7 +109,7 @@ void ChromeAppCacheService::DoPrompt( // The setting may have changed (due to the "remember" option) ContentSetting setting = host_contents_settings_map_->GetContentSetting( - manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); + manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); if (setting != CONTENT_SETTING_ASK) { int rv = (setting != CONTENT_SETTING_BLOCK) ? net::OK : net::ERR_ACCESS_DENIED; diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 99622470..271d8b1 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -4495,7 +4495,7 @@ void AutomationProvider::SetContentSetting( map->SetDefaultContentSetting(content_type, setting); } else { map->SetContentSetting(HostContentSettingsMap::Pattern(host), - content_type, setting); + content_type, "", setting); } *success = true; } diff --git a/chrome/browser/cocoa/content_exceptions_window_controller_unittest.mm b/chrome/browser/cocoa/content_exceptions_window_controller_unittest.mm index 2c842b5..3ec1944 100644 --- a/chrome/browser/cocoa/content_exceptions_window_controller_unittest.mm +++ b/chrome/browser/cocoa/content_exceptions_window_controller_unittest.mm @@ -112,6 +112,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddRemove) { ClickAdd(controller); settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, + "", &settings); EXPECT_EQ(0u, settings.size()); @@ -121,6 +122,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddRemove) { [controller close]; settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, + "", &settings); EXPECT_EQ(0u, settings.size()); } @@ -138,6 +140,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddRemoveAll) { HostContentSettingsMap::SettingsForOneType settings; settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, + "", &settings); EXPECT_EQ(0u, settings.size()); } @@ -154,6 +157,7 @@ TEST_F(ContentExceptionsWindowControllerTest, Add) { HostContentSettingsMap::SettingsForOneType settings; settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, + "", &settings); EXPECT_EQ(1u, settings.size()); EXPECT_EQ(HostContentSettingsMap::Pattern("addedhost"), settings[0].first); @@ -169,6 +173,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddEscDoesNotAdd) { HostContentSettingsMap::SettingsForOneType settings; settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, + "", &settings); EXPECT_EQ(0u, settings.size()); EXPECT_FALSE([controller editingNewException]); @@ -191,6 +196,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddEditAddAdd) { HostContentSettingsMap::SettingsForOneType settings; settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, + "", &settings); EXPECT_EQ(0u, settings.size()); } @@ -198,6 +204,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddEditAddAdd) { TEST_F(ContentExceptionsWindowControllerTest, AddExistingEditAdd) { settingsMap_->SetContentSetting(HostContentSettingsMap::Pattern("myhost"), CONTENT_SETTINGS_TYPE_PLUGINS, + "", CONTENT_SETTING_BLOCK); ContentExceptionsWindowController* controller = @@ -213,6 +220,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddExistingEditAdd) { HostContentSettingsMap::SettingsForOneType settings; settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, + "", &settings); EXPECT_EQ(1u, settings.size()); } @@ -220,6 +228,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddExistingEditAdd) { TEST_F(ContentExceptionsWindowControllerTest, AddExistingDoesNotOverwrite) { settingsMap_->SetContentSetting(HostContentSettingsMap::Pattern("myhost"), CONTENT_SETTINGS_TYPE_COOKIES, + "", CONTENT_SETTING_SESSION_ONLY); ContentExceptionsWindowController* controller = @@ -233,6 +242,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddExistingDoesNotOverwrite) { HostContentSettingsMap::SettingsForOneType settings; settingsMap_->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_COOKIES, + "", &settings); EXPECT_EQ(1u, settings.size()); EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, settings[0].second); diff --git a/chrome/browser/content_exceptions_table_model.cc b/chrome/browser/content_exceptions_table_model.cc index d7f1bb6..e8bb22f 100644 --- a/chrome/browser/content_exceptions_table_model.cc +++ b/chrome/browser/content_exceptions_table_model.cc @@ -19,9 +19,12 @@ ContentExceptionsTableModel::ContentExceptionsTableModel( content_type_(type), observer_(NULL) { // Load the contents. - map->GetSettingsForOneType(type, &entries_); - if (off_the_record_map) - off_the_record_map->GetSettingsForOneType(type, &off_the_record_entries_); + map->GetSettingsForOneType(type, "", &entries_); + if (off_the_record_map) { + off_the_record_map->GetSettingsForOneType(type, + "", + &off_the_record_entries_); + } } void ContentExceptionsTableModel::AddException( @@ -35,7 +38,10 @@ void ContentExceptionsTableModel::AddException( entries(is_off_the_record).push_back( HostContentSettingsMap::PatternSettingPair(pattern, setting)); - map(is_off_the_record)->SetContentSetting(pattern, content_type_, setting); + map(is_off_the_record)->SetContentSetting(pattern, + content_type_, + "", + setting); if (observer_) observer_->OnItemsAdded(insert_position, 1); } @@ -47,7 +53,7 @@ void ContentExceptionsTableModel::RemoveException(int row) { const HostContentSettingsMap::PatternSettingPair& pair = entry_at(row); map(is_off_the_record)->SetContentSetting( - pair.first, content_type_, CONTENT_SETTING_DEFAULT); + pair.first, content_type_, "", CONTENT_SETTING_DEFAULT); entries(is_off_the_record).erase( entries(is_off_the_record).begin() + position_to_delete); if (observer_) diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc index 2b8e190..6c1c13b 100644 --- a/chrome/browser/content_setting_bubble_model.cc +++ b/chrome/browser/content_setting_bubble_model.cc @@ -166,7 +166,7 @@ class ContentSettingSingleRadioGroup : public ContentSettingTitleAndLinkModel { radio_group.radio_items.push_back(radio_block_label); radio_group.default_item = profile()->GetHostContentSettingsMap()->GetContentSetting(url, - content_type()) == CONTENT_SETTING_ALLOW ? 0 : 1; + content_type(), "") == CONTENT_SETTING_ALLOW ? 0 : 1; set_radio_group(radio_group); } @@ -174,6 +174,7 @@ class ContentSettingSingleRadioGroup : public ContentSettingTitleAndLinkModel { profile()->GetHostContentSettingsMap()->AddExceptionForURL( bubble_content().radio_group.url, content_type(), + "", radio_index == 0 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); } }; diff --git a/chrome/browser/cookie_modal_dialog.cc b/chrome/browser/cookie_modal_dialog.cc index f8e1c0e..ce1ff59 100644 --- a/chrome/browser/cookie_modal_dialog.cc +++ b/chrome/browser/cookie_modal_dialog.cc @@ -86,7 +86,7 @@ CookiePromptModalDialog::~CookiePromptModalDialog() { bool CookiePromptModalDialog::IsValid() { ContentSetting content_setting = host_content_settings_map_->GetContentSetting( - origin_, CONTENT_SETTINGS_TYPE_COOKIES); + origin_, CONTENT_SETTINGS_TYPE_COOKIES, ""); if (content_setting != CONTENT_SETTING_ASK) { if (content_setting == CONTENT_SETTING_ALLOW) { AllowSiteData(false, false); @@ -108,10 +108,11 @@ void CookiePromptModalDialog::AllowSiteData(bool remember, // to insert for exactly this URL. host_content_settings_map_->SetContentSetting( HostContentSettingsMap::Pattern::FromURLNoWildcard(origin_), - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); host_content_settings_map_->SetContentSetting( HostContentSettingsMap::Pattern::FromURL(origin_), CONTENT_SETTINGS_TYPE_COOKIES, + "", session_expire ? CONTENT_SETTING_SESSION_ONLY : CONTENT_SETTING_ALLOW); } @@ -127,10 +128,10 @@ void CookiePromptModalDialog::BlockSiteData(bool remember) { // to insert for exactly this URL. host_content_settings_map_->SetContentSetting( HostContentSettingsMap::Pattern::FromURLNoWildcard(origin_), - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); host_content_settings_map_->SetContentSetting( HostContentSettingsMap::Pattern::FromURL(origin_), - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); } if (delegate_) { diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index 67cc98b..37d682f 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -252,6 +252,7 @@ void CookieTreeOriginNode::CreateContentException( if (CanCreateContentException()) { content_settings->AddExceptionForURL(url_, CONTENT_SETTINGS_TYPE_COOKIES, + "", setting); } } diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc index c490922..1f7e457 100644 --- a/chrome/browser/cookies_tree_model_unittest.cc +++ b/chrome/browser/cookies_tree_model_unittest.cc @@ -538,7 +538,8 @@ TEST_F(CookiesTreeModelTest, ContentSettings) { EXPECT_EQ(2, observer.counter); EXPECT_EQ(pattern, observer.last_pattern); EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, - content_settings->GetContentSetting(host, CONTENT_SETTINGS_TYPE_COOKIES)); + content_settings->GetContentSetting( + host, CONTENT_SETTINGS_TYPE_COOKIES, "")); } } // namespace diff --git a/chrome/browser/dom_ui/content_settings_handler.cc b/chrome/browser/dom_ui/content_settings_handler.cc index a40d7e1..08841e1 100644 --- a/chrome/browser/dom_ui/content_settings_handler.cc +++ b/chrome/browser/dom_ui/content_settings_handler.cc @@ -261,7 +261,8 @@ void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() { HostContentSettingsMap::SettingsForOneType entries; const HostContentSettingsMap* settings_map = dom_ui_->GetProfile()->GetHostContentSettingsMap(); - settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, &entries); + settings_map->GetSettingsForOneType( + CONTENT_SETTINGS_TYPE_IMAGES, "", &entries); ListValue exceptions; for (size_t i = 0; i < entries.size(); ++i) { @@ -326,6 +327,7 @@ void ContentSettingsHandler::RemoveExceptions(const Value* value) { DCHECK(rv); settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern), CONTENT_SETTINGS_TYPE_IMAGES, + "", CONTENT_SETTING_DEFAULT); } } @@ -345,5 +347,6 @@ void ContentSettingsHandler::SetException(const Value* value) { dom_ui_->GetProfile()->GetHostContentSettingsMap(); settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern), CONTENT_SETTINGS_TYPE_IMAGES, + "", ContentSettingFromString(setting)); } diff --git a/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc b/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc index 6e603b5..ecfbaba 100644 --- a/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc +++ b/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc @@ -28,6 +28,7 @@ class ContentExceptionsWindowGtkUnittest : public testing::Test { host_content_settings_map_->SetContentSetting( HostContentSettingsMap::Pattern(pattern), CONTENT_SETTINGS_TYPE_JAVASCRIPT, + "", value); } diff --git a/chrome/browser/host_content_settings_map.cc b/chrome/browser/host_content_settings_map.cc index 2cf165e..3bf6d13 100644 --- a/chrome/browser/host_content_settings_map.cc +++ b/chrome/browser/host_content_settings_map.cc @@ -32,6 +32,8 @@ namespace { // - a.b.c.d (matches an exact IPv4 ip) // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) // - file:///tmp/test.html (a complete URL without a host) +// Version 2 adds a resource identifier for plugins. +// TODO(jochen): update once this feature is no longer behind a flag. const int kContentSettingsPatternVersion = 1; // The format of a domain wildcard. @@ -40,6 +42,62 @@ const char kDomainWildcard[] = "[*.]"; // The length of kDomainWildcard (without the trailing '\0') const size_t kDomainWildcardLength = arraysize(kDomainWildcard) - 1; +// The preference keys where resource identifiers are stored for +// ContentSettingsType values that support resource identifiers. +const char* kResourceTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { + NULL, + NULL, + NULL, + "per_plugin", + NULL, + NULL, // Not used for Geolocation + NULL, // Not used for Notifications +}; + +// The names of the ContentSettingsType values, for use with dictionary prefs. +const char* kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { + "cookies", + "images", + "javascript", + "plugins", + "popups", + NULL, // Not used for Geolocation + NULL, // Not used for Notifications +}; + +// The default setting for each content type. +const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES] = { + CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES + CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES + CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT + CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS + CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS + CONTENT_SETTING_ASK, // Not used for Geolocation + CONTENT_SETTING_ASK, // Not used for Notifications +}; + +// True if a given content settings type requires additional resource +// identifiers. +const bool kRequiresResourceIdentifier[CONTENT_SETTINGS_NUM_TYPES] = { + false, // CONTENT_SETTINGS_TYPE_COOKIES + false, // CONTENT_SETTINGS_TYPE_IMAGES + false, // CONTENT_SETTINGS_TYPE_JAVASCRIPT + true, // CONTENT_SETTINGS_TYPE_PLUGINS + false, // CONTENT_SETTINGS_TYPE_POPUPS + false, // Not used for Geolocation + false, // Not used for Notifications +}; + +// 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) { + return url.SchemeIs(chrome::kChromeInternalScheme) || + url.SchemeIs(chrome::kChromeUIScheme) || + url.SchemeIs(chrome::kExtensionScheme) || + url.SchemeIs(chrome::kGearsScheme) || + url.SchemeIs(chrome::kUserScriptScheme); +} } // namespace // static @@ -86,30 +144,6 @@ bool HostContentSettingsMap::Pattern::Matches(const GURL& url) const { (match + pattern_.length() - kDomainWildcardLength == host.length()); } -// static -const wchar_t* - HostContentSettingsMap::kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { - L"cookies", - L"images", - L"javascript", - L"plugins", - L"popups", - NULL, // Not used for Geolocation - NULL, // Not used for Notifications -}; - -// static -const ContentSetting - HostContentSettingsMap::kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES] = { - CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES - CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES - CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT - CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS - CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS - CONTENT_SETTING_ASK, // Not used for Geolocation - CONTENT_SETTING_ASK, // Not used for Notifications -}; - HostContentSettingsMap::HostContentSettingsMap(Profile* profile) : profile_(profile), block_third_party_cookies_(false), @@ -140,7 +174,7 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile) i != whitelist_pref->end(); ++i) { std::string host; (*i)->GetAsString(&host); - SetContentSetting(Pattern(host), CONTENT_SETTINGS_TYPE_POPUPS, + SetContentSetting(Pattern(host), CONTENT_SETTINGS_TYPE_POPUPS, "", CONTENT_SETTING_ALLOW); } prefs->ClearPref(prefs::kPopupWhitelistedHosts); @@ -161,9 +195,10 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile) ContentSettings settings; GetSettingsFromDictionary(host_settings_dictionary, &settings); for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { - if (settings.settings[j] != CONTENT_SETTING_DEFAULT) + if (settings.settings[j] != CONTENT_SETTING_DEFAULT && + !RequiresResourceIdentifier(ContentSettingsType(j))) SetContentSetting( - pattern, ContentSettingsType(j), settings.settings[j]); + pattern, ContentSettingsType(j), "", settings.settings[j]); } } prefs->ClearPref(prefs::kPerHostContentSettings); @@ -223,12 +258,99 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSetting( ContentSetting HostContentSettingsMap::GetContentSetting( const GURL& url, - ContentSettingsType content_type) const { - return GetContentSettings(url).settings[content_type]; + ContentSettingsType content_type, + const std::string& resource_identifier) const { + ContentSetting setting = GetNonDefaultContentSetting(url, + content_type, + resource_identifier); + if (setting == CONTENT_SETTING_DEFAULT) + return GetDefaultContentSetting(content_type); + return setting; +} + +ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( + const GURL& url, + ContentSettingsType content_type, + const std::string& resource_identifier) const { + if (ShouldAllowAllContent(url)) + return CONTENT_SETTING_ALLOW; + + if (!RequiresResourceIdentifier(content_type)) + return GetNonDefaultContentSettings(url).settings[content_type]; + + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) { + DCHECK(!resource_identifier.empty()); + } + + AutoLock auto_lock(lock_); + + const std::string host(net::GetHostOrSpecFromURL(url)); + ContentSettingsTypeResourceIdentifierPair + requested_setting(content_type, resource_identifier); + + // Check for exact matches first. + HostContentSettings::const_iterator i(host_content_settings_.find(host)); + if (i != host_content_settings_.end() && + i->second.content_settings_for_resources.find(requested_setting) != + i->second.content_settings_for_resources.end()) { + return i->second.content_settings_for_resources.find( + requested_setting)->second; + } + + // If this map is not for an off-the-record profile, these searches will never + // match. The additional off-the-record exceptions always overwrite the + // regular ones. + i = off_the_record_settings_.find(host); + if (i != off_the_record_settings_.end() && + i->second.content_settings_for_resources.find(requested_setting) != + i->second.content_settings_for_resources.end()) { + return i->second.content_settings_for_resources.find( + requested_setting)->second; + } + + // Match patterns starting with the most concrete pattern match. + for (std::string key = std::string(kDomainWildcard) + host; ; ) { + HostContentSettings::const_iterator i(off_the_record_settings_.find(key)); + if (i != off_the_record_settings_.end() && + i->second.content_settings_for_resources.find(requested_setting) != + i->second.content_settings_for_resources.end()) { + return i->second.content_settings_for_resources.find( + requested_setting)->second; + } + + i = host_content_settings_.find(key); + if (i != host_content_settings_.end() && + i->second.content_settings_for_resources.find(requested_setting) != + i->second.content_settings_for_resources.end()) { + return i->second.content_settings_for_resources.find( + requested_setting)->second; + } + + const size_t next_dot = key.find('.', kDomainWildcardLength); + if (next_dot == std::string::npos) + break; + key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1); + } + + return CONTENT_SETTING_DEFAULT; } ContentSettings HostContentSettingsMap::GetContentSettings( const GURL& url) const { + ContentSettings output = GetNonDefaultContentSettings(url); + + // Make the remaining defaults explicit. + for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) + if (output.settings[j] == CONTENT_SETTING_DEFAULT || + RequiresResourceIdentifier(ContentSettingsType(j))) + output.settings[j] = default_content_settings_.settings[j]; + + return output; +} + +ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( + const GURL& url) const { if (ShouldAllowAllContent(url)) return ContentSettings(CONTENT_SETTING_ALLOW); @@ -242,7 +364,7 @@ ContentSettings HostContentSettingsMap::GetContentSettings( // Check for exact matches first. HostContentSettings::const_iterator i(host_content_settings_.find(host)); if (i != host_content_settings_.end()) - output = i->second; + output = i->second.content_settings; // If this map is not for an off-the-record profile, these searches will never // match. The additional off-the-record exceptions always overwrite the @@ -250,8 +372,8 @@ ContentSettings HostContentSettingsMap::GetContentSettings( i = off_the_record_settings_.find(host); if (i != off_the_record_settings_.end()) { for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) - if (i->second.settings[j] != CONTENT_SETTING_DEFAULT) - output.settings[j] = i->second.settings[j]; + if (i->second.content_settings.settings[j] != CONTENT_SETTING_DEFAULT) + output.settings[j] = i->second.content_settings.settings[j]; } // Match patterns starting with the most concrete pattern match. @@ -260,14 +382,14 @@ ContentSettings HostContentSettingsMap::GetContentSettings( if (i != off_the_record_settings_.end()) { for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { if (output.settings[j] == CONTENT_SETTING_DEFAULT) - output.settings[j] = i->second.settings[j]; + output.settings[j] = i->second.content_settings.settings[j]; } } i = host_content_settings_.find(key); if (i != host_content_settings_.end()) { for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { if (output.settings[j] == CONTENT_SETTING_DEFAULT) - output.settings[j] = i->second.settings[j]; + output.settings[j] = i->second.content_settings.settings[j]; } } const size_t next_dot = key.find('.', kDomainWildcardLength); @@ -276,27 +398,40 @@ ContentSettings HostContentSettingsMap::GetContentSettings( key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1); } - // Make the remaining defaults explicit. - for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) - if (output.settings[j] == CONTENT_SETTING_DEFAULT) - output.settings[j] = default_content_settings_.settings[j]; - return output; } void HostContentSettingsMap::GetSettingsForOneType( ContentSettingsType content_type, + const std::string& resource_identifier, SettingsForOneType* settings) const { + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) { + DCHECK(!RequiresResourceIdentifier(content_type) || + !resource_identifier.empty()); + } DCHECK(settings); settings->clear(); const HostContentSettings* map_to_return = is_off_the_record_ ? &off_the_record_settings_ : &host_content_settings_; + ContentSettingsTypeResourceIdentifierPair + requested_setting(content_type, resource_identifier); AutoLock auto_lock(lock_); for (HostContentSettings::const_iterator i(map_to_return->begin()); i != map_to_return->end(); ++i) { - ContentSetting setting = i->second.settings[content_type]; + ContentSetting setting; + if (RequiresResourceIdentifier(content_type)) { + if (i->second.content_settings_for_resources.find(requested_setting) != + i->second.content_settings_for_resources.end()) + setting = i->second.content_settings_for_resources.find( + requested_setting)->second; + else + setting = CONTENT_SETTING_DEFAULT; + } else { + setting = i->second.content_settings.settings[content_type]; + } if (setting != CONTENT_SETTING_DEFAULT) { // Use of push_back() relies on the map iterator traversing in order of // ascending keys. @@ -321,7 +456,7 @@ void HostContentSettingsMap::SetDefaultContentSetting( DictionaryValue* default_settings_dictionary = prefs->GetMutableDictionary(prefs::kDefaultContentSettings); - std::wstring dictionary_path(kTypeNames[content_type]); + std::string dictionary_path(kTypeNames[content_type]); updating_preferences_ = true; { AutoLock auto_lock(lock_); @@ -340,17 +475,24 @@ void HostContentSettingsMap::SetDefaultContentSetting( } updating_preferences_ = false; - NotifyObservers(ContentSettingsDetails(content_type)); + NotifyObservers(ContentSettingsDetails(Pattern(), content_type, "")); } -void HostContentSettingsMap::SetContentSetting(const Pattern& pattern, - ContentSettingsType content_type, - ContentSetting setting) { +void HostContentSettingsMap::SetContentSetting( + const Pattern& pattern, + ContentSettingsType content_type, + const std::string& resource_identifier, + ContentSetting setting) { DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) { + DCHECK(!RequiresResourceIdentifier(content_type) || + !resource_identifier.empty()); + } bool early_exit = false; - std::wstring wide_pattern(UTF8ToWide(pattern.AsString())); + std::string pattern_str(pattern.AsString()); PrefService* prefs = NULL; DictionaryValue* all_settings_dictionary = NULL; HostContentSettings* map_to_modify = &off_the_record_settings_; @@ -364,15 +506,28 @@ void HostContentSettingsMap::SetContentSetting(const Pattern& pattern, { AutoLock auto_lock(lock_); if (!map_to_modify->count(pattern.AsString())) - (*map_to_modify)[pattern.AsString()] = ContentSettings(); + (*map_to_modify)[pattern.AsString()].content_settings = ContentSettings(); HostContentSettings::iterator i(map_to_modify->find(pattern.AsString())); - ContentSettings& settings = i->second; - settings.settings[content_type] = setting; - if (AllDefault(settings)) { + ContentSettings& settings = i->second.content_settings; + if (RequiresResourceIdentifier(content_type)) { + settings.settings[content_type] = CONTENT_SETTING_DEFAULT; + if (setting != CONTENT_SETTING_DEFAULT) { + i->second.content_settings_for_resources[ + ContentSettingsTypeResourceIdentifierPair(content_type, + resource_identifier)] = setting; + } else { + i->second.content_settings_for_resources.erase( + ContentSettingsTypeResourceIdentifierPair(content_type, + resource_identifier)); + } + } else { + settings.settings[content_type] = setting; + } + if (AllDefault(i->second)) { map_to_modify->erase(i); if (all_settings_dictionary) - all_settings_dictionary->RemoveWithoutPathExpansion(wide_pattern, NULL); + all_settings_dictionary->RemoveWithoutPathExpansion(pattern_str, NULL); // We can't just return because |NotifyObservers()| needs to be called, // without |lock_| being held. @@ -381,22 +536,40 @@ void HostContentSettingsMap::SetContentSetting(const Pattern& pattern, } if (!early_exit && all_settings_dictionary) { - DictionaryValue* host_settings_dictionary; + DictionaryValue* host_settings_dictionary = NULL; bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( - wide_pattern, &host_settings_dictionary); + pattern_str, &host_settings_dictionary); if (!found) { host_settings_dictionary = new DictionaryValue; all_settings_dictionary->SetWithoutPathExpansion( - wide_pattern, host_settings_dictionary); + pattern_str, host_settings_dictionary); DCHECK_NE(setting, CONTENT_SETTING_DEFAULT); } - std::wstring dictionary_path(kTypeNames[content_type]); - if (setting == CONTENT_SETTING_DEFAULT) { - host_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, - NULL); + if (RequiresResourceIdentifier(content_type)) { + std::string dictionary_path(kResourceTypeNames[content_type]); + DictionaryValue* resource_dictionary = NULL; + found = host_settings_dictionary->GetDictionary( + dictionary_path, &resource_dictionary); + if (!found) { + resource_dictionary = new DictionaryValue; + host_settings_dictionary->Set(dictionary_path, resource_dictionary); + } + if (setting == CONTENT_SETTING_DEFAULT) { + resource_dictionary->RemoveWithoutPathExpansion(resource_identifier, + NULL); + } else { + resource_dictionary->SetWithoutPathExpansion( + resource_identifier, Value::CreateIntegerValue(setting)); + } } else { - host_settings_dictionary->SetWithoutPathExpansion( - dictionary_path, Value::CreateIntegerValue(setting)); + std::string dictionary_path(kTypeNames[content_type]); + if (setting == CONTENT_SETTING_DEFAULT) { + host_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, + NULL); + } else { + host_settings_dictionary->SetWithoutPathExpansion( + dictionary_path, Value::CreateIntegerValue(setting)); + } } } @@ -405,19 +578,24 @@ void HostContentSettingsMap::SetContentSetting(const Pattern& pattern, ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns); updating_preferences_ = false; - NotifyObservers(ContentSettingsDetails(pattern, content_type)); + NotifyObservers(ContentSettingsDetails(pattern, content_type, "")); } void HostContentSettingsMap::AddExceptionForURL( const GURL& url, ContentSettingsType content_type, + const std::string& resource_identifier, ContentSetting setting) { // Make sure there is no entry that would override the pattern we are about // to insert for exactly this URL. SetContentSetting(Pattern::FromURLNoWildcard(url), content_type, + resource_identifier, CONTENT_SETTING_DEFAULT); - SetContentSetting(Pattern::FromURL(url), content_type, setting); + SetContentSetting(Pattern::FromURL(url), + content_type, + resource_identifier, + setting); } void HostContentSettingsMap::ClearSettingsForOneType( @@ -439,19 +617,24 @@ void HostContentSettingsMap::ClearSettingsForOneType( AutoLock auto_lock(lock_); for (HostContentSettings::iterator i(map_to_modify->begin()); i != map_to_modify->end(); ) { - if (i->second.settings[content_type] != CONTENT_SETTING_DEFAULT) { - i->second.settings[content_type] = CONTENT_SETTING_DEFAULT; - std::wstring wide_host(UTF8ToWide(i->first)); + if (RequiresResourceIdentifier(content_type) || + i->second.content_settings.settings[content_type] != + CONTENT_SETTING_DEFAULT) { + if (RequiresResourceIdentifier(content_type)) + i->second.content_settings_for_resources.clear(); + i->second.content_settings.settings[content_type] = + CONTENT_SETTING_DEFAULT; + std::string host(i->first); if (AllDefault(i->second)) { if (all_settings_dictionary) all_settings_dictionary-> - RemoveWithoutPathExpansion(wide_host, NULL); + RemoveWithoutPathExpansion(host, NULL); map_to_modify->erase(i++); } else if (all_settings_dictionary) { DictionaryValue* host_settings_dictionary; bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( - wide_host, &host_settings_dictionary); + host, &host_settings_dictionary); DCHECK(found); host_settings_dictionary->RemoveWithoutPathExpansion( kTypeNames[content_type], NULL); @@ -468,7 +651,19 @@ void HostContentSettingsMap::ClearSettingsForOneType( ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns); updating_preferences_ = false; - NotifyObservers(ContentSettingsDetails(content_type)); + NotifyObservers(ContentSettingsDetails(Pattern(), content_type, "")); +} + +bool HostContentSettingsMap::RequiresResourceIdentifier( + ContentSettingsType content_type) const { +// TODO(bauerb): Enable once all call sites are adopted. +#if 0 + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClickToPlay)) + return kRequiresResourceIdentifier[content_type]; + else +#endif + return false; } void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) { @@ -512,7 +707,8 @@ void HostContentSettingsMap::ResetToDefaults() { prefs->ClearPref(prefs::kContentSettingsPatterns); prefs->ClearPref(prefs::kBlockThirdPartyCookies); updating_preferences_ = false; - NotifyObservers(ContentSettingsDetails()); + NotifyObservers( + ContentSettingsDetails(Pattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); } } @@ -543,8 +739,10 @@ void HostContentSettingsMap::Observe(NotificationType type, return; } - if (!is_off_the_record_) - NotifyObservers(ContentSettingsDetails()); + if (!is_off_the_record_) { + NotifyObservers( + ContentSettingsDetails(Pattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); + } } else if (NotificationType::PROFILE_DESTROYED == type) { UnregisterObservers(); } else { @@ -556,28 +754,18 @@ HostContentSettingsMap::~HostContentSettingsMap() { UnregisterObservers(); } -// static -bool HostContentSettingsMap::ShouldAllowAllContent(const GURL& url) { - return url.SchemeIs(chrome::kChromeInternalScheme) || - url.SchemeIs(chrome::kChromeUIScheme) || - url.SchemeIs(chrome::kExtensionScheme) || - url.SchemeIs(chrome::kGearsScheme) || - url.SchemeIs(chrome::kUserScriptScheme); -} - void HostContentSettingsMap::GetSettingsFromDictionary( const DictionaryValue* dictionary, ContentSettings* settings) { for (DictionaryValue::key_iterator i(dictionary->begin_keys()); i != dictionary->end_keys(); ++i) { const std::string& content_type(*i); - int setting = CONTENT_SETTING_DEFAULT; - bool found = dictionary->GetIntegerWithoutPathExpansion(content_type, - &setting); - DCHECK(found); for (size_t type = 0; type < arraysize(kTypeNames); ++type) { - if ((kTypeNames[type] != NULL) && - (WideToUTF8(kTypeNames[type]) == content_type)) { + if ((kTypeNames[type] != NULL) && (kTypeNames[type] == content_type)) { + int setting = CONTENT_SETTING_DEFAULT; + bool found = dictionary->GetIntegerWithoutPathExpansion(content_type, + &setting); + DCHECK(found); settings->settings[type] = IntToContentSetting(setting); break; } @@ -592,6 +780,37 @@ void HostContentSettingsMap::GetSettingsFromDictionary( } } +void HostContentSettingsMap::GetResourceSettingsFromDictionary( + const DictionaryValue* dictionary, + ResourceContentSettings* settings) { + for (DictionaryValue::key_iterator i(dictionary->begin_keys()); + i != dictionary->end_keys(); ++i) { + const std::string& content_type(*i); + for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) { + if ((kResourceTypeNames[type] != NULL) && + (kResourceTypeNames[type] == content_type)) { + DictionaryValue* resource_dictionary = NULL; + bool found = dictionary->GetDictionary(content_type, + &resource_dictionary); + DCHECK(found); + for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys()); + j != resource_dictionary->end_keys(); ++j) { + const std::string& resource_identifier(*j); + int setting = CONTENT_SETTING_DEFAULT; + bool found = resource_dictionary->GetIntegerWithoutPathExpansion( + resource_identifier, &setting); + DCHECK(found); + (*settings)[ContentSettingsTypeResourceIdentifierPair( + ContentSettingsType(type), resource_identifier)] = + ContentSetting(setting); + } + + break; + } + } + } +} + void HostContentSettingsMap::ForceDefaultsToBeExplicit() { DCHECK_EQ(arraysize(kDefaultSettings), static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); @@ -602,12 +821,13 @@ void HostContentSettingsMap::ForceDefaultsToBeExplicit() { } } -bool HostContentSettingsMap::AllDefault(const ContentSettings& settings) const { - for (size_t i = 0; i < arraysize(settings.settings); ++i) { - if (settings.settings[i] != CONTENT_SETTING_DEFAULT) +bool HostContentSettingsMap::AllDefault( + const ExtendedContentSettings& settings) const { + for (size_t i = 0; i < arraysize(settings.content_settings.settings); ++i) { + if (settings.content_settings.settings[i] != CONTENT_SETTING_DEFAULT) return false; } - return true; + return settings.content_settings_for_resources.empty(); } void HostContentSettingsMap::ReadDefaultSettings(bool overwrite) { @@ -643,7 +863,10 @@ void HostContentSettingsMap::ReadExceptions(bool overwrite) { DCHECK(found); ContentSettings settings; GetSettingsFromDictionary(pattern_settings_dictionary, &settings); - host_content_settings_[pattern] = settings; + host_content_settings_[pattern].content_settings = settings; + GetResourceSettingsFromDictionary( + pattern_settings_dictionary, + &host_content_settings_[pattern].content_settings_for_resources); } } } diff --git a/chrome/browser/host_content_settings_map.h b/chrome/browser/host_content_settings_map.h index 2348138..0bf8044 100644 --- a/chrome/browser/host_content_settings_map.h +++ b/chrome/browser/host_content_settings_map.h @@ -73,15 +73,13 @@ class HostContentSettingsMap // for each pattern. class ContentSettingsDetails { public: - // Update the setting that matches this pattern/content type. - ContentSettingsDetails(const Pattern& pattern, ContentSettingsType type) - : pattern_(pattern), type_(type) {} - - // No pattern is specified. Update all settings for this content type. - explicit ContentSettingsDetails(ContentSettingsType type) : type_(type) {} - - // No content type or pattern is specified. Update all settings. - ContentSettingsDetails() : type_(CONTENT_SETTINGS_TYPE_DEFAULT) {} + // Update the setting that matches this pattern/content type/resource. + ContentSettingsDetails(const Pattern& pattern, + ContentSettingsType type, + const std::string& resource_identifier) + : pattern_(pattern), + type_(type), + resource_identifier_(resource_identifier) {} // The pattern whose settings have changed. const Pattern& pattern() const { return pattern_; } @@ -92,6 +90,11 @@ class HostContentSettingsMap // The type of the pattern whose settings have changed. ContentSettingsType type() const { return type_; } + // The resource identifier for the settings type that has changed. + const std::string& resource_identifier() const { + return resource_identifier_; + } + // True if all types should be updated. If update_all() is false, this will // be false as well (although the reverse does not hold true). bool update_all_types() const { @@ -101,6 +104,7 @@ class HostContentSettingsMap private: Pattern pattern_; ContentSettingsType type_; + std::string resource_identifier_; }; @@ -119,25 +123,52 @@ class HostContentSettingsMap ContentSettingsType content_type) const; // Returns a single ContentSetting which applies to a given URL. Note that - // certain internal schemes are whitelisted. + // certain internal schemes are whitelisted. For ContentSettingsTypes that + // require an resource identifier to be specified, the |resource_identifier| + // must be non-empty. // // This may be called on any thread. - ContentSetting GetContentSetting(const GURL& url, - ContentSettingsType content_type) const; - - // Returns all ContentSettings which apply to a given URL. + ContentSetting GetContentSetting( + const GURL& url, + ContentSettingsType content_type, + const std::string& resource_identifier) const; + + // Returns a single ContentSetting which applies to a given URL or + // CONTENT_SETTING_DEFAULT, if no exception applies. Note that certain + // internal schemes are whitelisted. For ContentSettingsTypes that require an + // resource identifier to be specified, the |resource_identifier| must be + // non-empty. + // + // This may be called on any thread. + ContentSetting GetNonDefaultContentSetting( + const GURL& url, + ContentSettingsType content_type, + const std::string& resource_identifier) const; + + // Returns all ContentSettings which apply to a given URL. For content + // setting types that require an additional resource identifier, the default + // content setting is returned. // // This may be called on any thread. ContentSettings GetContentSettings(const GURL& url) const; + // Returns all non-default ContentSettings which apply to a given URL. For + // content setting types that require an additional resource identifier, + // CONTENT_SETTING_DEFAULT is returned. + // + // This may be called on any thread. + ContentSettings GetNonDefaultContentSettings(const GURL& url) const; + // For a given content type, returns all patterns with a non-default setting, // mapped to their actual settings, in lexicographical order. |settings| // must be a non-NULL outparam. If this map was created for the // off-the-record profile, it will only return those settings differing from - // the main map. + // the main map. For ContentSettingsTypes that require an resource identifier + // to be specified, the |resource_identifier| must be non-empty. // // This may be called on any thread. void GetSettingsForOneType(ContentSettingsType content_type, + const std::string& resource_identifier, SettingsForOneType* settings) const; // Sets the default setting for a particular content type. This method must @@ -148,19 +179,26 @@ class HostContentSettingsMap ContentSetting setting); // Sets the blocking setting for a particular pattern and content type. - // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting for - // that type to be used when loading pages matching this pattern. + // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting + // for that type to be used when loading pages matching this pattern. For + // ContentSettingsTypes that require an resource identifier to be specified, + // the |resource_identifier| must be non-empty. // // This should only be called on the UI thread. void SetContentSetting(const Pattern& pattern, ContentSettingsType content_type, + const std::string& resource_identifier, ContentSetting setting); // Convenience method to add a content setting for a given URL, making sure - // that there is no setting overriding it. + // that there is no setting overriding it. For ContentSettingsTypes that + // require an resource identifier to be specified, the |resource_identifier| + // must be non-empty. + // // This should only be called on the UI thread. void AddExceptionForURL(const GURL& url, ContentSettingsType content_type, + const std::string& resource_identifier, ContentSetting setting); // Clears all host-specific settings for one content type. @@ -168,6 +206,10 @@ class HostContentSettingsMap // This should only be called on the UI thread. void ClearSettingsForOneType(ContentSettingsType content_type); + // Whether the |content_type| requires an additional resource identifier for + // accessing content settings. + bool RequiresResourceIdentifier(ContentSettingsType content_type) const; + // This setting trumps any host-specific settings. bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } @@ -193,29 +235,32 @@ class HostContentSettingsMap private: friend class base::RefCountedThreadSafe<HostContentSettingsMap>; - typedef std::map<std::string, ContentSettings> HostContentSettings; + typedef std::pair<ContentSettingsType, std::string> + ContentSettingsTypeResourceIdentifierPair; + typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting> + ResourceContentSettings; - // The names of the ContentSettingsType values, for use with dictionary prefs. - static const wchar_t* kTypeNames[CONTENT_SETTINGS_NUM_TYPES]; - - // The default setting for each content type. - static const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES]; + struct ExtendedContentSettings { + ContentSettings content_settings; + ResourceContentSettings content_settings_for_resources; + }; - // 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); + typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; // Sets the fields of |settings| based on the values in |dictionary|. void GetSettingsFromDictionary(const DictionaryValue* dictionary, ContentSettings* settings); + // Populates |settings| based on the values in |dictionary|. + void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary, + ResourceContentSettings* settings); + // Forces the default settings to be explicitly set instead of themselves // being CONTENT_SETTING_DEFAULT. void ForceDefaultsToBeExplicit(); // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. - bool AllDefault(const ContentSettings& settings) const; + bool AllDefault(const ExtendedContentSettings& settings) const; // Reads the default settings from the prefereces service. If |overwrite| is // true and the preference is missing, the local copy will be cleared as well. diff --git a/chrome/browser/host_content_settings_map_unittest.cc b/chrome/browser/host_content_settings_map_unittest.cc index 87826a0..7690c86 100644 --- a/chrome/browser/host_content_settings_map_unittest.cc +++ b/chrome/browser/host_content_settings_map_unittest.cc @@ -4,7 +4,11 @@ #include "chrome/browser/host_content_settings_map.h" +#include "base/command_line.h" +#include "base/json/json_reader.h" +#include "base/json/json_writer.h" #include "chrome/browser/pref_service.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" @@ -83,7 +87,7 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) { CONTENT_SETTINGS_TYPE_IMAGES)); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( GURL(chrome::kChromeUINewTabURL), - CONTENT_SETTINGS_TYPE_IMAGES)); + CONTENT_SETTINGS_TYPE_IMAGES, "")); host_content_settings_map->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK); EXPECT_EQ(CONTENT_SETTING_ASK, @@ -104,35 +108,35 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) { HostContentSettingsMap::Pattern pattern("[*.]example.com"); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_PLUGINS)); + host, CONTENT_SETTINGS_TYPE_PLUGINS, "")); // Check returning all settings for a host. ContentSettings desired_settings; desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_ALLOW; host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = CONTENT_SETTING_ALLOW; host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK); desired_settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = CONTENT_SETTING_BLOCK; host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW); + CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_ALLOW); desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = CONTENT_SETTING_ALLOW; desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = @@ -148,41 +152,44 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) { // Check returning all hosts for a setting. HostContentSettingsMap::Pattern pattern2("[*.]example.org"); host_content_settings_map->SetContentSetting(pattern2, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); host_content_settings_map->SetContentSetting(pattern2, - CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); HostContentSettingsMap::SettingsForOneType host_settings; host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, + "", &host_settings); EXPECT_EQ(1U, host_settings.size()); host_content_settings_map->GetSettingsForOneType( - CONTENT_SETTINGS_TYPE_PLUGINS, &host_settings); + CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); EXPECT_EQ(2U, host_settings.size()); host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, + "", &host_settings); EXPECT_EQ(0U, host_settings.size()); host_content_settings_map->ResetToDefaults(); host_content_settings_map->GetSettingsForOneType( - CONTENT_SETTINGS_TYPE_PLUGINS, &host_settings); + CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); EXPECT_EQ(0U, host_settings.size()); // Check clearing one type. HostContentSettingsMap::Pattern pattern3("[*.]example.net"); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); host_content_settings_map->SetContentSetting(pattern2, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); host_content_settings_map->SetContentSetting(pattern2, - CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); host_content_settings_map->SetContentSetting(pattern3, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); host_content_settings_map->ClearSettingsForOneType( CONTENT_SETTINGS_TYPE_IMAGES); host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, + "", &host_settings); EXPECT_EQ(0U, host_settings.size()); host_content_settings_map->GetSettingsForOneType( - CONTENT_SETTINGS_TYPE_PLUGINS, &host_settings); + CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); EXPECT_EQ(1U, host_settings.size()); } @@ -198,23 +205,23 @@ TEST_F(HostContentSettingsMapTest, Patterns) { HostContentSettingsMap::Pattern pattern2("example.org"); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host1, CONTENT_SETTINGS_TYPE_IMAGES)); + host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); host_content_settings_map->SetContentSetting(pattern1, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host1, CONTENT_SETTINGS_TYPE_IMAGES)); + host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host2, CONTENT_SETTINGS_TYPE_IMAGES)); + host2, CONTENT_SETTINGS_TYPE_IMAGES, "")); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host3, CONTENT_SETTINGS_TYPE_IMAGES)); + host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); host_content_settings_map->SetContentSetting(pattern2, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host3, CONTENT_SETTINGS_TYPE_IMAGES)); + host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); } TEST_F(HostContentSettingsMapTest, PatternSupport) { @@ -248,7 +255,7 @@ TEST_F(HostContentSettingsMapTest, Observer) { HostContentSettingsMap::Pattern pattern("[*.]example.com"); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_ALLOW); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); EXPECT_EQ(host_content_settings_map, observer.last_notifier); EXPECT_EQ(pattern, observer.last_pattern); EXPECT_FALSE(observer.last_update_all); @@ -293,7 +300,7 @@ TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_COOKIES)); + host, CONTENT_SETTINGS_TYPE_COOKIES, "")); // Make a copy of the pref's new value so we can reset it later. scoped_ptr<Value> new_value(prefs->FindPreference( @@ -303,13 +310,13 @@ TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { prefs->Set(prefs::kDefaultContentSettings, *default_value); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_COOKIES)); + host, CONTENT_SETTINGS_TYPE_COOKIES, "")); // Reseting the pref to its previous value should update the cache. prefs->Set(prefs::kDefaultContentSettings, *new_value); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_COOKIES)); + host, CONTENT_SETTINGS_TYPE_COOKIES, "")); } TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { @@ -327,10 +334,10 @@ TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { GURL host("http://example.com"); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_COOKIES)); + host, CONTENT_SETTINGS_TYPE_COOKIES, "")); // Make a copy of the pref's new value so we can reset it later. scoped_ptr<Value> new_value(prefs->FindPreference( @@ -340,13 +347,13 @@ TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { prefs->Set(prefs::kContentSettingsPatterns, *default_value); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_COOKIES)); + host, CONTENT_SETTINGS_TYPE_COOKIES, "")); // Reseting the pref to its previous value should update the cache. prefs->Set(prefs::kContentSettingsPatterns, *new_value); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_COOKIES)); + host, CONTENT_SETTINGS_TYPE_COOKIES, "")); } TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { @@ -359,73 +366,73 @@ TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES, "")); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_DEFAULT); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_DEFAULT); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS, "")); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_DEFAULT); + CONTENT_SETTINGS_TYPE_POPUPS, "", CONTENT_SETTING_DEFAULT); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); + CONTENT_SETTINGS_TYPE_POPUPS, "", CONTENT_SETTING_ALLOW); EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS)); + host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); } TEST_F(HostContentSettingsMapTest, NestedSettings) { @@ -439,11 +446,11 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) { HostContentSettingsMap::Pattern pattern3("a.b.example.com"); host_content_settings_map->SetContentSetting(pattern1, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); host_content_settings_map->SetContentSetting(pattern2, - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); host_content_settings_map->SetContentSetting(pattern3, - CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); host_content_settings_map->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); @@ -493,32 +500,127 @@ TEST_F(HostContentSettingsMapTest, OffTheRecord) { EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); EXPECT_EQ(CONTENT_SETTING_ALLOW, otr_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); // Changing content settings on the main map should also affect the // off-the-record map. host_content_settings_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); EXPECT_EQ(CONTENT_SETTING_BLOCK, otr_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); // Changing content settings on the off-the-record map should NOT affect the // main map. otr_map->SetContentSetting(pattern, - CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_ALLOW); + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); EXPECT_EQ(CONTENT_SETTING_ALLOW, otr_map->GetContentSetting( - host, CONTENT_SETTINGS_TYPE_IMAGES)); + host, CONTENT_SETTINGS_TYPE_IMAGES, "")); +} + +TEST_F(HostContentSettingsMapTest, NonDefaultSettings) { + TestingProfile profile; + HostContentSettingsMap* host_content_settings_map = + profile.GetHostContentSettingsMap(); + + GURL host("http://example.com/"); + HostContentSettingsMap::Pattern pattern("[*.]example.com"); + + ContentSettings desired_settings(CONTENT_SETTING_DEFAULT); + ContentSettings settings = + host_content_settings_map->GetNonDefaultContentSettings(host); + EXPECT_TRUE(SettingsEqual(desired_settings, settings)); + + host_content_settings_map->SetContentSetting(pattern, + CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); + desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = + CONTENT_SETTING_BLOCK; + settings = + host_content_settings_map->GetNonDefaultContentSettings(host); + EXPECT_TRUE(SettingsEqual(desired_settings, settings)); +} + +// TODO(bauerb): Enable once HostContentSettingsMap::RequiersResourceIdentifier +// is changed. +#if 0 +TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { + // This feature is currently behind a flag. + CommandLine cl(*CommandLine::ForCurrentProcess()); + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableClickToPlay); + + TestingProfile profile; + HostContentSettingsMap* host_content_settings_map = + profile.GetHostContentSettingsMap(); + + GURL host("http://example.com/"); + HostContentSettingsMap::Pattern pattern("[*.]example.com"); + std::string resource1("someplugin"); + std::string resource2("otherplugin"); + + EXPECT_EQ(CONTENT_SETTING_ALLOW, + host_content_settings_map->GetContentSetting( + host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); + host_content_settings_map->SetContentSetting(pattern, + CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_BLOCK); + EXPECT_EQ(CONTENT_SETTING_BLOCK, + host_content_settings_map->GetContentSetting( + host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); + EXPECT_EQ(CONTENT_SETTING_ALLOW, + host_content_settings_map->GetContentSetting( + host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2)); + *CommandLine::ForCurrentProcess() = cl; +} + +TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) { + // This feature is currently behind a flag. + CommandLine cl(*CommandLine::ForCurrentProcess()); + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableClickToPlay); + + TestingProfile profile; + profile.GetPrefs()->SetUserPref(prefs::kContentSettingsPatterns, + base::JSONReader::Read( + "{\"[*.]example.com\":{\"per_plugin\":{\"someplugin\":2}}}", false)); + HostContentSettingsMap* host_content_settings_map = + profile.GetHostContentSettingsMap(); + + GURL host("http://example.com/"); + HostContentSettingsMap::Pattern pattern("[*.]example.com"); + std::string resource1("someplugin"); + std::string resource2("otherplugin"); + + EXPECT_EQ(CONTENT_SETTING_BLOCK, + host_content_settings_map->GetContentSetting( + host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); + + host_content_settings_map->SetContentSetting(pattern, + CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_DEFAULT); + + const DictionaryValue* content_setting_prefs = + profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatterns); + std::string prefs_as_json; + base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); + EXPECT_STREQ("{}", prefs_as_json.c_str()); + + host_content_settings_map->SetContentSetting(pattern, + CONTENT_SETTINGS_TYPE_PLUGINS, resource2, CONTENT_SETTING_BLOCK); + + content_setting_prefs = + profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatterns); + base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); + EXPECT_STREQ("{\"[*.]example.com\":{\"per_plugin\":{\"otherplugin\":2}}}", + prefs_as_json.c_str()); + *CommandLine::ForCurrentProcess() = cl; } +#endif } // namespace diff --git a/chrome/browser/in_process_webkit/dom_storage_area.cc b/chrome/browser/in_process_webkit/dom_storage_area.cc index 6aefa21..7ec5b8c 100644 --- a/chrome/browser/in_process_webkit/dom_storage_area.cc +++ b/chrome/browser/in_process_webkit/dom_storage_area.cc @@ -99,7 +99,7 @@ bool DOMStorageArea::CheckContentSetting( DOMStorageDispatcherHost* sender) { ContentSetting content_setting = host_content_settings_map_->GetContentSetting( - origin_url_, CONTENT_SETTINGS_TYPE_COOKIES); + origin_url_, CONTENT_SETTINGS_TYPE_COOKIES, ""); if (content_setting == CONTENT_SETTING_ASK) { DOMStoragePermissionRequest request(origin_url_, key, value, diff --git a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc index e37d814..cd6603b 100644 --- a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc +++ b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc @@ -34,7 +34,7 @@ void DOMStoragePermissionRequest::PromptUser( // Cookie settings may have changed. ContentSetting setting = request->host_content_settings_map_->GetContentSetting( - request->url_, CONTENT_SETTINGS_TYPE_COOKIES); + request->url_, CONTENT_SETTINGS_TYPE_COOKIES, ""); if (setting != CONTENT_SETTING_ASK) { request->SendResponse(setting); return; diff --git a/chrome/browser/net/chrome_cookie_policy.cc b/chrome/browser/net/chrome_cookie_policy.cc index 552fec7..52325fd 100644 --- a/chrome/browser/net/chrome_cookie_policy.cc +++ b/chrome/browser/net/chrome_cookie_policy.cc @@ -139,7 +139,7 @@ int ChromeCookiePolicy::CanSetCookie(const GURL& url, int ChromeCookiePolicy::CheckPolicy(const GURL& url) const { ContentSetting setting = host_content_settings_map_->GetContentSetting( - url, CONTENT_SETTINGS_TYPE_COOKIES); + url, CONTENT_SETTINGS_TYPE_COOKIES, ""); if (setting == CONTENT_SETTING_BLOCK) return net::ERR_ACCESS_DENIED; if (setting == CONTENT_SETTING_ALLOW) diff --git a/chrome/browser/renderer_host/database_dispatcher_host.cc b/chrome/browser/renderer_host/database_dispatcher_host.cc index b4f0d5e..32908fa 100644 --- a/chrome/browser/renderer_host/database_dispatcher_host.cc +++ b/chrome/browser/renderer_host/database_dispatcher_host.cc @@ -389,7 +389,7 @@ void DatabaseDispatcherHost::OnAllowDatabase(const std::string& origin_url, GURL url = GURL(origin_url); ContentSetting content_setting = host_content_settings_map_->GetContentSetting( - url, CONTENT_SETTINGS_TYPE_COOKIES); + url, CONTENT_SETTINGS_TYPE_COOKIES, ""); if (content_setting == CONTENT_SETTING_ASK) { // Create a task for each possible outcome. scoped_ptr<Task> on_allow(NewRunnableMethod( diff --git a/chrome/browser/renderer_host/database_permission_request.cc b/chrome/browser/renderer_host/database_permission_request.cc index fb417e7..317c7f9 100644 --- a/chrome/browser/renderer_host/database_permission_request.cc +++ b/chrome/browser/renderer_host/database_permission_request.cc @@ -43,7 +43,7 @@ void DatabasePermissionRequest::RequestPermission() { // Cookie settings may have changed. ContentSetting setting = host_content_settings_map_->GetContentSetting( - url_, CONTENT_SETTINGS_TYPE_COOKIES); + url_, CONTENT_SETTINGS_TYPE_COOKIES, ""); if (setting != CONTENT_SETTING_ASK) { SendResponse(setting); return; diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 7f3e7aa..2992612 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1440,7 +1440,7 @@ void TabContents::AddPopup(TabContents* new_contents, if (creator.is_valid() && profile()->GetHostContentSettingsMap()->GetContentSetting( - creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) { + creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) { AddNewContents(new_contents, NEW_POPUP, initial_pos, true); } else { if (!blocked_popups_) diff --git a/chrome/test/testing_pref_service.h b/chrome/test/testing_pref_service.h index e08c6d1..d407ad2 100644 --- a/chrome/test/testing_pref_service.h +++ b/chrome/test/testing_pref_service.h @@ -6,7 +6,7 @@ #define CHROME_TEST_TESTING_PREF_SERVICE_H_ #pragma once -#include <chrome/browser/pref_service.h> +#include "chrome/browser/pref_service.h" class PrefStore; @@ -59,6 +59,8 @@ class TestingPrefService : public PrefService { // Pointers to the pref stores our value store uses. PrefStore* managed_prefs_; PrefStore* user_prefs_; + + DISALLOW_COPY_AND_ASSIGN(TestingPrefService); }; #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ |