Chromium Code Reviews| Index: chrome/renderer/content_settings_observer.cc |
| diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc |
| index e61a2f65ec69279e7c28ffb39f573addde69fb66..986ec147104767550402846d49fea79e75f88596 100644 |
| --- a/chrome/renderer/content_settings_observer.cc |
| +++ b/chrome/renderer/content_settings_observer.cc |
| @@ -56,9 +56,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(); |
| } |
| @@ -121,7 +123,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(); |
| @@ -201,16 +203,33 @@ 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)) { |
| + DCHECK(image_setting_rules_); |
| + if (IsWhitelistedForContentSettings(frame)) |
| return true; |
| + |
| + if (frame->document().securityOrigin().isEmpty() || |
| + frame->top()->document().securityOrigin().isEmpty()) { |
|
Bernhard Bauer
2011/10/17 13:13:19
Nit: If you move this check into the |if (enabled_
marja
2011/10/18 12:23:02
Done.
|
| + DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
| + return false; // Uninitialized document. |
| } |
| - if (IsWhitelistedForContentSettings(frame)) |
| - return true; |
| + bool allow = false; |
| + GURL top_url(frame->top()->document().securityOrigin().toString()); |
| + GURL image_gurl(image_url); |
| + if (enabled_per_settings) { |
| + ContentSettingsForOneType::const_iterator it; |
| + for (it = image_setting_rules_->begin(); |
| + it != image_setting_rules_->end(); ++it) { |
| + if (it->a.Matches(top_url) && it->b.Matches(image_gurl)) { |
| + allow = (it->c != CONTENT_SETTING_BLOCK); |
| + break; |
| + } |
| + } |
| + } |
| - DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
| - return false; // Other protocols fall through here. |
| + if (!allow) |
| + DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
| + return allow; |
| } |
| bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |