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

Unified Diff: chrome/renderer/content_settings_observer.cc

Issue 7831075: Delegating the "are images allowed" decision to renderer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Test build fixes. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/content_settings_observer.cc
diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc
index a8d0e241d07c7fc8f64fbf02456103f877951732..b9fc58cb1a301869e3b7f104e6567fe7a4ce676c 100644
--- a/chrome/renderer/content_settings_observer.cc
+++ b/chrome/renderer/content_settings_observer.cc
@@ -55,9 +55,11 @@ static bool IsWhitelistedForContentSettings(WebFrame* frame) {
ContentSettings ContentSettingsObserver::default_settings_;
ContentSettingsObserver::ContentSettingsObserver(
- content::RenderView* render_view)
+ content::RenderView* render_view,
+ const ContentSettingsForOneType* image_setting_rules)
: content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<ContentSettingsObserver>(render_view),
+ image_setting_rules_(image_setting_rules),
plugins_temporarily_allowed_(false) {
ClearBlockedContentSettings();
}
@@ -120,7 +122,7 @@ void ContentSettingsObserver::DidCommitProvisionalLoad(
NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
if (!state->was_within_same_page()) {
// Clear "block" flags for the new page. This needs to happen before any of
- // allowScripts(), allowImages(), allowPlugins() is called for the new page
+ // allowScripts(), allowImage(), allowPlugins() is called for the new page
// so that these functions can correctly detect that a piece of content
// flipped from "not blocked" to "blocked".
ClearBlockedContentSettings();
@@ -200,16 +202,30 @@ bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) {
bool ContentSettingsObserver::AllowImage(WebFrame* frame,
bool enabled_per_settings,
const WebURL& image_url) {
- if (enabled_per_settings &&
- AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) {
- return true;
- }
-
+ DCHECK(image_setting_rules_);
if (IsWhitelistedForContentSettings(frame))
return true;
- DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
- return false; // Other protocols fall through here.
+ bool allow = false;
+ GURL top_url(frame->top()->document().securityOrigin().toString());
+ GURL image_gurl(image_url);
+ if (!frame->document().securityOrigin().isEmpty() &&
+ !frame->top()->document().securityOrigin().isEmpty() &&
+ enabled_per_settings) {
+ ContentSettingsForOneType::const_iterator it;
+ for (it = image_setting_rules_->begin();
+ it != image_setting_rules_->end(); ++it) {
+ if (it->primary_pattern.Matches(top_url) &&
+ it->secondary_pattern.Matches(image_gurl)) {
+ allow = (it->setting != CONTENT_SETTING_BLOCK);
+ break;
+ }
+ }
+ }
+
+ if (!allow)
+ DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
+ return allow;
}
bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame,

Powered by Google App Engine
This is Rietveld 408576698