diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-27 13:43:42 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-27 13:43:42 +0000 |
commit | c144060968bce7873e4079bd2293272fe03b520f (patch) | |
tree | 6d1f7cc551e53d2626ff522ec46adb18da6c991c /chrome/browser | |
parent | 78d4939cf2732a79ff823a0b00938e6aef77cf97 (diff) | |
download | chromium_src-c144060968bce7873e4079bd2293272fe03b520f.zip chromium_src-c144060968bce7873e4079bd2293272fe03b520f.tar.gz chromium_src-c144060968bce7873e4079bd2293272fe03b520f.tar.bz2 |
Delegating the "are images allowed" decision to renderer.
This enables making the decision based on both image url and the page url. E.g., blocking third-party images.
BUG=81179
TEST=RenderViewTest.ImagesBlockedByDefault, RenderViewTest.ImagesAllowedByDefault
Review URL: http://codereview.chromium.org/7831075
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
10 files changed, 55 insertions, 58 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index d1651a8..388a27c 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -286,6 +286,10 @@ void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( profile->IsOffTheRecord())); SendExtensionWebRequestStatusToHost(host); + ContentSettingsForOneType settings; + HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); + map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &settings); + host->Send(new ChromeViewMsg_SetImageSettingRules(settings)); } void ChromeContentBrowserClient::PluginProcessHostCreated( diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc index 5d76b92..c345ae2 100644 --- a/chrome/browser/content_settings/host_content_settings_map.cc +++ b/chrome/browser/content_settings/host_content_settings_map.cc @@ -316,7 +316,7 @@ ContentSettings HostContentSettingsMap::GetContentSettings( void HostContentSettingsMap::GetSettingsForOneType( ContentSettingsType content_type, const std::string& resource_identifier, - SettingsForOneType* settings) const { + ContentSettingsForOneType* settings) const { DCHECK(content_settings::SupportsResourceIdentifier(content_type) || resource_identifier.empty()); DCHECK(settings); @@ -552,7 +552,7 @@ void HostContentSettingsMap::AddSettingsForOneType( ProviderType provider_type, ContentSettingsType content_type, const std::string& resource_identifier, - SettingsForOneType* settings, + ContentSettingsForOneType* settings, bool incognito) const { scoped_ptr<content_settings::RuleIterator> rule_iterator( provider->GetRuleIterator(content_type, @@ -561,7 +561,7 @@ void HostContentSettingsMap::AddSettingsForOneType( ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); while (rule_iterator->HasNext()) { const content_settings::Rule& rule = rule_iterator->Next(); - settings->push_back(PatternSettingSourceTuple( + settings->push_back(ContentSettingPatternSource( rule.primary_pattern, rule.secondary_pattern, content_settings::ValueToContentSetting(rule.value.get()), kProviderNames[provider_type], diff --git a/chrome/browser/content_settings/host_content_settings_map.h b/chrome/browser/content_settings/host_content_settings_map.h index 4c167b9..4980656 100644 --- a/chrome/browser/content_settings/host_content_settings_map.h +++ b/chrome/browser/content_settings/host_content_settings_map.h @@ -49,15 +49,6 @@ class HostContentSettingsMap NUM_PROVIDER_TYPES, }; - // TODO(markusheintz): I sold my soul to the devil on order to add this tuple. - // I really want my soul back, so I really will change this ASAP. - typedef Tuple5<ContentSettingsPattern, - ContentSettingsPattern, - ContentSetting, - std::string, - bool> PatternSettingSourceTuple; - typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; - HostContentSettingsMap(PrefService* prefs, ExtensionService* extension_service, bool incognito); @@ -126,16 +117,13 @@ class HostContentSettingsMap const GURL& secondary_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 - // incognito profile, it will only return those settings differing from - // the main map. For ContentSettingsTypes that require an resource identifier - // to be specified, the |resource_identifier| must be non-empty. + // mapped to their actual settings, in the precedence order of the rules. + // |settings| must be a non-NULL outparam. // // This may be called on any thread. void GetSettingsForOneType(ContentSettingsType content_type, const std::string& resource_identifier, - SettingsForOneType* settings) const; + ContentSettingsForOneType* settings) const; // Sets the default setting for a particular content type. This method must // not be invoked on an incognito map. @@ -236,7 +224,7 @@ class HostContentSettingsMap ProviderType provider_type, ContentSettingsType content_type, const std::string& resource_identifier, - SettingsForOneType* settings, + ContentSettingsForOneType* settings, bool incognito) const; // Weak; owned by the Profile. 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 208b8ba..6cd7e7c9 100644 --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc @@ -180,7 +180,7 @@ TEST_F(HostContentSettingsMapTest, IndividualSettings) { CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), CONTENT_SETTING_BLOCK); - HostContentSettingsMap::SettingsForOneType host_settings; + ContentSettingsForOneType host_settings; host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &host_settings); @@ -233,7 +233,7 @@ TEST_F(HostContentSettingsMapTest, Clear) { CONTENT_SETTING_BLOCK); host_content_settings_map->ClearSettingsForOneType( CONTENT_SETTINGS_TYPE_IMAGES); - HostContentSettingsMap::SettingsForOneType host_settings; + ContentSettingsForOneType host_settings; host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &host_settings); diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc index 4e1a5c0..b15e1f7 100644 --- a/chrome/browser/content_settings/tab_specific_content_settings.cc +++ b/chrome/browser/content_settings/tab_specific_content_settings.cc @@ -489,6 +489,9 @@ void TabSpecificContentSettings::Observe( map->GetDefaultContentSettings())); Send(new ChromeViewMsg_SetContentSettingsForCurrentURL( entry_url, map->GetContentSettings(entry_url, entry_url))); + ContentSettingsForOneType settings; + map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &settings); + Send(new ChromeViewMsg_SetImageSettingRules(settings)); } } diff --git a/chrome/browser/extensions/extension_special_storage_policy.cc b/chrome/browser/extensions/extension_special_storage_policy.cc index 2064f37..eddaedf 100644 --- a/chrome/browser/extensions/extension_special_storage_policy.cc +++ b/chrome/browser/extensions/extension_special_storage_policy.cc @@ -45,11 +45,11 @@ bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { if (host_content_settings_map_->GetDefaultContentSetting( CONTENT_SETTINGS_TYPE_COOKIES, NULL) == CONTENT_SETTING_SESSION_ONLY) return true; - HostContentSettingsMap::SettingsForOneType entries; + ContentSettingsForOneType 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) + if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) return true; } return false; diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index ca4857d..4a43f94 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -23,6 +23,7 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/content_settings.h" #include "chrome/common/content_settings_pattern.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" @@ -292,7 +293,7 @@ void DesktopNotificationService::ResetToDefaultContentSetting() { } void DesktopNotificationService::GetNotificationsSettings( - HostContentSettingsMap::SettingsForOneType* settings) { + ContentSettingsForOneType* settings) { profile_->GetHostContentSettingsMap()->GetSettingsForOneType( CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NO_RESOURCE_IDENTIFIER, diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h index 8ab6b4c..eed1167 100644 --- a/chrome/browser/notifications/desktop_notification_service.h +++ b/chrome/browser/notifications/desktop_notification_service.h @@ -14,7 +14,6 @@ #include "base/memory/scoped_ptr.h" #include "base/string16.h" #include "chrome/browser/content_settings/content_settings_provider.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/common/content_settings.h" #include "content/public/browser/notification_observer.h" @@ -107,8 +106,7 @@ class DesktopNotificationService : public content::NotificationObserver, // Returns all notifications settings. |settings| is cleared before // notifications setting are passed to it. - void GetNotificationsSettings( - HostContentSettingsMap::SettingsForOneType* settings); + void GetNotificationsSettings(ContentSettingsForOneType* settings); // Clears the notifications setting for the given pattern. void ClearSetting(const ContentSettingsPattern& pattern); diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc index c60e627..008589f 100644 --- a/chrome/browser/notifications/desktop_notification_service_unittest.cc +++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc @@ -8,7 +8,6 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" @@ -162,33 +161,33 @@ TEST_F(DesktopNotificationServiceTest, GetNotificationsSettings) { service_->DenyPermission(GURL("http://denied2.com")); service_->DenyPermission(GURL("http://denied.com")); - HostContentSettingsMap::SettingsForOneType settings; + ContentSettingsForOneType settings; service_->GetNotificationsSettings(&settings); // |settings| contains the default setting and 4 exceptions. ASSERT_EQ(5u, settings.size()); EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( GURL("http://allowed.com")), - settings[0].a); + settings[0].primary_pattern); EXPECT_EQ(CONTENT_SETTING_ALLOW, - settings[0].c); + settings[0].setting); EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( GURL("http://allowed2.com")), - settings[1].a); + settings[1].primary_pattern); EXPECT_EQ(CONTENT_SETTING_ALLOW, - settings[1].c); + settings[1].setting); EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( GURL("http://denied.com")), - settings[2].a); + settings[2].primary_pattern); EXPECT_EQ(CONTENT_SETTING_BLOCK, - settings[2].c); + settings[2].setting); EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( GURL("http://denied2.com")), - settings[3].a); + settings[3].primary_pattern); EXPECT_EQ(CONTENT_SETTING_BLOCK, - settings[3].c); + settings[3].setting); EXPECT_EQ(ContentSettingsPattern::Wildcard(), - settings[4].a); + settings[4].primary_pattern); EXPECT_EQ(CONTENT_SETTING_ASK, - settings[4].c); + settings[4].setting); } diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc index 3ccff843..7f6b9e09 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.cc +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc @@ -24,6 +24,7 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/content_settings.h" #include "chrome/common/content_settings_pattern.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" @@ -468,7 +469,7 @@ void ContentSettingsHandler::UpdateGeolocationExceptionsView() { Profile* profile = Profile::FromWebUI(web_ui_); HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); - HostContentSettingsMap::SettingsForOneType all_settings; + ContentSettingsForOneType all_settings; map->GetSettingsForOneType( CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), @@ -476,11 +477,12 @@ void ContentSettingsHandler::UpdateGeolocationExceptionsView() { // Group geolocation settings by primary_pattern. AllPatternsSettings all_patterns_settings; - for (HostContentSettingsMap::SettingsForOneType::iterator i = + for (ContentSettingsForOneType::iterator i = all_settings.begin(); i != all_settings.end(); ++i) { - all_patterns_settings[i->a][i->b] = i->c; + all_patterns_settings[i->primary_pattern][i->secondary_pattern] = + i->setting; } ListValue exceptions; @@ -528,17 +530,17 @@ void ContentSettingsHandler::UpdateNotificationExceptionsView() { DesktopNotificationService* service = DesktopNotificationServiceFactory::GetForProfile(profile); - HostContentSettingsMap::SettingsForOneType settings; + ContentSettingsForOneType settings; service->GetNotificationsSettings(&settings); ListValue exceptions; - for (HostContentSettingsMap::SettingsForOneType::const_iterator i = + for (ContentSettingsForOneType::const_iterator i = settings.begin(); i != settings.end(); ++i) { - const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); exceptions.Append( - GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d)); + GetNotificationExceptionForPage(i->primary_pattern, i->setting, + i->source)); } StringValue type_string( @@ -553,16 +555,16 @@ void ContentSettingsHandler::UpdateNotificationExceptionsView() { void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( ContentSettingsType type) { - HostContentSettingsMap::SettingsForOneType entries; + ContentSettingsForOneType entries; GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); ListValue exceptions; for (size_t i = 0; i < entries.size(); ++i) { // Skip default settings from extensions and policy, and the default content // settings; all of them will affect the default setting UI. - if (entries[i].a == ContentSettingsPattern::Wildcard() && - entries[i].b == ContentSettingsPattern::Wildcard() && - entries[i].d != "preference") { + if (entries[i].primary_pattern == ContentSettingsPattern::Wildcard() && + entries[i].secondary_pattern == ContentSettingsPattern::Wildcard() && + entries[i].source != "preference") { continue; } // The content settings UI does not support secondary content settings @@ -571,9 +573,10 @@ void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( // able to modify content settings with a secondary pattern other than the // wildcard pattern. So only show settings that the user is able to modify. // TODO(bauerb): Support a read-only view for those patterns. - if (entries[i].b == ContentSettingsPattern::Wildcard()) { + if (entries[i].secondary_pattern == ContentSettingsPattern::Wildcard()) { exceptions.Append( - GetExceptionForPage(entries[i].a, entries[i].c, entries[i].d)); + GetExceptionForPage(entries[i].primary_pattern, entries[i].setting, + entries[i].source)); } else { LOG(ERROR) << "Secondary content settings patterns are not " << "supported by the content settings UI"; @@ -597,7 +600,7 @@ void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( if (!otr_settings_map) return; - HostContentSettingsMap::SettingsForOneType otr_entries; + ContentSettingsForOneType otr_entries; otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); ListValue otr_exceptions; @@ -605,7 +608,7 @@ void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( // Off-the-record HostContentSettingsMap contains incognito content settings // as well as normal content settings. Here, we use the incongnito settings // only. - if (!otr_entries[i].e) + if (!otr_entries[i].incognito) continue; // The content settings UI does not support secondary content settings // pattern yet. For content settings set through the content settings UI the @@ -613,11 +616,12 @@ void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( // able to modify content settings with a secondary pattern other than the // wildcard pattern. So only show settings that the user is able to modify. // TODO(bauerb): Support a read-only view for those patterns. - if (otr_entries[i].b == ContentSettingsPattern::Wildcard()) { + if (otr_entries[i].secondary_pattern == + ContentSettingsPattern::Wildcard()) { otr_exceptions.Append( - GetExceptionForPage(otr_entries[i].a, - otr_entries[i].c, - otr_entries[i].d)); + GetExceptionForPage(otr_entries[i].primary_pattern, + otr_entries[i].setting, + otr_entries[i].source)); } else { LOG(ERROR) << "Secondary content settings patterns are not " << "supported by the content settings UI"; |