diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 11:06:45 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 11:06:45 +0000 |
commit | 5c5d72328f3e5ee3e7679e90f2de764aa16f904e (patch) | |
tree | c840522afc2b85679ea57cd1ce78ad7d491d79f9 | |
parent | 816feecc5cbcf283cb65149af5a19d81d76ef999 (diff) | |
download | chromium_src-5c5d72328f3e5ee3e7679e90f2de764aa16f904e.zip chromium_src-5c5d72328f3e5ee3e7679e90f2de764aa16f904e.tar.gz chromium_src-5c5d72328f3e5ee3e7679e90f2de764aa16f904e.tar.bz2 |
Experiment: Add a sync IPC call for every image load.
This will be reverted as soon as the page cyclers have ran.
BUG=NONE
TEST=NONE
Review URL: http://codereview.chromium.org/7903003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101944 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 72 insertions, 6 deletions
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc index 0b15023..07ec158 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.cc +++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc @@ -131,6 +131,7 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDatabase, OnAllowDatabase) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDOMStorage, OnAllowDOMStorage) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowFileSystem, OnAllowFileSystem) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowImage, OnAllowImage) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowIndexedDB, OnAllowIndexedDB) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetPluginContentSetting, OnGetPluginContentSetting) @@ -464,6 +465,14 @@ void ChromeRenderMessageFilter::OnAllowFileSystem(int render_view_id, render_process_id_, render_view_id, origin_url, !*allowed)); } +void ChromeRenderMessageFilter::OnAllowImage(const GURL& top_origin_url, + const GURL& image_url, + bool* allowed) { + ContentSetting setting = host_content_settings_map_->GetContentSetting( + top_origin_url, image_url, CONTENT_SETTINGS_TYPE_IMAGES, ""); + *allowed = setting != CONTENT_SETTING_BLOCK; +} + void ChromeRenderMessageFilter::OnAllowIndexedDB(int render_view_id, const GURL& origin_url, const GURL& top_origin_url, diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h index adfcf44..094d0e4 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.h +++ b/chrome/browser/renderer_host/chrome_render_message_filter.h @@ -109,6 +109,9 @@ class ChromeRenderMessageFilter : public BrowserMessageFilter { const GURL& origin_url, const GURL& top_origin_url, bool* allowed); + void OnAllowImage(const GURL& top_origin_url, + const GURL& image_url, + bool* allowed); void OnAllowIndexedDB(int render_view_id, const GURL& origin_url, const GURL& top_origin_url, diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 7d92fa2..f50df24 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -355,6 +355,13 @@ IPC_SYNC_MESSAGE_CONTROL3_1(ChromeViewHostMsg_AllowFileSystem, GURL /* top origin url */, bool /* allowed */) +// Sent by the renderer process to check whether displaying images is +// allowed by content settings. +IPC_SYNC_MESSAGE_CONTROL2_1(ChromeViewHostMsg_AllowImage, + GURL /* top origin url */, + GURL /* image_url */, + bool /* allowed */) + // Sent by the renderer process to check whether access to Indexed DBis // granted by content settings. IPC_SYNC_MESSAGE_CONTROL4_1(ChromeViewHostMsg_AllowIndexedDB, diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc index 8383fa4..95eeb0b 100644 --- a/chrome/renderer/content_settings_observer.cc +++ b/chrome/renderer/content_settings_observer.cc @@ -54,6 +54,7 @@ static bool IsWhitelistedForContentSettings(WebFrame* frame) { } // namespace ContentSettings ContentSettingsObserver::default_settings_; +bool ContentSettingsObserver::allow_all_images_ = false; ContentSettingsObserver::ContentSettingsObserver(RenderView* render_view) : RenderViewObserver(render_view), @@ -120,7 +121,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(); @@ -199,16 +200,40 @@ 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)) { + // Shortcut for tests + if (allow_all_images_) return true; - } if (IsWhitelistedForContentSettings(frame)) return true; - DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); - return false; // Other protocols fall through here. + if (frame->document().securityOrigin().isEmpty() || + frame->top()->document().securityOrigin().isEmpty()) { + DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); + return false; // Uninitialized document. + } + + ImagePermissionsKey key( + GURL(image_url), + GURL(frame->top()->document().securityOrigin().toString())); + + bool result = false; + std::map<ImagePermissionsKey, bool>::const_iterator permissions = + cached_image_permissions_.find(key); + if (permissions != cached_image_permissions_.end()) { + result = permissions->second; + } else { + Send(new ChromeViewHostMsg_AllowImage( + GURL(frame->top()->document().securityOrigin().toString()), + GURL(image_url), + &result)); + cached_image_permissions_[key] = result; + } + + if (!result) + DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); + + return result; } bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, @@ -274,6 +299,11 @@ void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); } +// static +void ContentSettingsObserver::SetAllowAllImages(bool allow) { + allow_all_images_ = allow; +} + void ContentSettingsObserver::OnSetContentSettingsForLoadingURL( const GURL& url, const ContentSettings& content_settings) { @@ -295,4 +325,5 @@ void ContentSettingsObserver::ClearBlockedContentSettings() { for (size_t i = 0; i < arraysize(content_blocked_); ++i) content_blocked_[i] = false; cached_storage_permissions_.clear(); + cached_image_permissions_.clear(); } diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h index c86e10d..b275b28 100644 --- a/chrome/renderer/content_settings_observer.h +++ b/chrome/renderer/content_settings_observer.h @@ -63,6 +63,9 @@ class ContentSettingsObserver void DidNotAllowPlugins(WebKit::WebFrame* frame); void DidNotAllowScript(WebKit::WebFrame* frame); + // To be used in tests + static void SetAllowAllImages(bool allow); + private: // RenderViewObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message); @@ -98,8 +101,15 @@ class ContentSettingsObserver typedef std::pair<GURL, bool> StoragePermissionsKey; std::map<StoragePermissionsKey, bool> cached_storage_permissions_; + // Caches the result of AllowImages. + typedef std::pair<GURL, GURL> ImagePermissionsKey; + std::map<ImagePermissionsKey, bool> cached_image_permissions_; + bool plugins_temporarily_allowed_; + // To be used in tests + static bool allow_all_images_; + DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); }; diff --git a/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc b/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc index 77c254d..43cb25e 100644 --- a/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc +++ b/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc @@ -11,6 +11,7 @@ #include "base/shared_memory.h" #include "base/time.h" #include "chrome/common/render_messages.h" +#include "chrome/renderer/content_settings_observer.h" #include "chrome/renderer/mock_render_process.h" #include "content/common/dom_storage_common.h" #include "content/common/main_function_params.h" @@ -57,6 +58,9 @@ bool RenderViewFakeResourcesTest::Visit(RenderView* render_view) { } void RenderViewFakeResourcesTest::SetUp() { + // Make ContentSettingObserver bypass IPC. + ContentSettingsObserver::SetAllowAllImages(true); + // Set up the renderer. This code is largely adapted from // render_view_test.cc and renderer_main.cc. Note that we use a // MockRenderProcess (because we don't need to use IPC for painting), @@ -94,6 +98,8 @@ void RenderViewFakeResourcesTest::SetUp() { } void RenderViewFakeResourcesTest::TearDown() { + ContentSettingsObserver::SetAllowAllImages(false); + // Try very hard to collect garbage before shutting down. GetMainFrame()->collectGarbage(); GetMainFrame()->collectGarbage(); |