summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 23:26:06 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 23:26:06 +0000
commit566fa0f2d549d5eb499aefbed9bbeb8d2a11adc2 (patch)
treef169be53d8bcf0f3d3107912de5fd3d2e875b1d4 /chrome/renderer
parenteb7f6abf44e7c88fb9c4470b003d608fee70016f (diff)
downloadchromium_src-566fa0f2d549d5eb499aefbed9bbeb8d2a11adc2.zip
chromium_src-566fa0f2d549d5eb499aefbed9bbeb8d2a11adc2.tar.gz
chromium_src-566fa0f2d549d5eb499aefbed9bbeb8d2a11adc2.tar.bz2
Cached response ContentSettingsObserver::AllowStorage
BUG=84554 TEST=RenderViewTest Review URL: http://codereview.chromium.org/7106001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87544 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/content_settings_observer.cc8
-rw-r--r--chrome/renderer/content_settings_observer.h4
-rw-r--r--chrome/renderer/content_settings_observer_browsertest.cc26
3 files changed, 38 insertions, 0 deletions
diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc
index 698a3c2..ef8ebfe 100644
--- a/chrome/renderer/content_settings_observer.cc
+++ b/chrome/renderer/content_settings_observer.cc
@@ -221,11 +221,18 @@ bool ContentSettingsObserver::AllowStorage(WebFrame* frame, bool local) {
return false; // Uninitialized document.
bool result = false;
+ StoragePermissionsKey key(GURL(frame->securityOrigin().toString()), local);
+ std::map<StoragePermissionsKey, bool>::const_iterator permissions =
+ cached_storage_permissions_.find(key);
+ if (permissions != cached_storage_permissions_.end())
+ return permissions->second;
+
Send(new ViewHostMsg_AllowDOMStorage(
routing_id(), GURL(frame->securityOrigin().toString()),
GURL(frame->top()->securityOrigin().toString()),
local ? DOM_STORAGE_LOCAL : DOM_STORAGE_SESSION,
&result));
+ cached_storage_permissions_[key] = result;
return result;
}
@@ -257,4 +264,5 @@ bool ContentSettingsObserver::AllowContentType(
void ContentSettingsObserver::ClearBlockedContentSettings() {
for (size_t i = 0; i < arraysize(content_blocked_); ++i)
content_blocked_[i] = false;
+ cached_storage_permissions_.clear();
}
diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h
index ed47c5f..4929edb 100644
--- a/chrome/renderer/content_settings_observer.h
+++ b/chrome/renderer/content_settings_observer.h
@@ -84,6 +84,10 @@ class ContentSettingsObserver
// Stores if images, scripts, and plugins have actually been blocked.
bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
+ // Caches the result of AllowStorage.
+ typedef std::pair<GURL, bool> StoragePermissionsKey;
+ std::map<StoragePermissionsKey, bool> cached_storage_permissions_;
+
bool plugins_temporarily_allowed_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
diff --git a/chrome/renderer/content_settings_observer_browsertest.cc b/chrome/renderer/content_settings_observer_browsertest.cc
index 920f50c..391bc30 100644
--- a/chrome/renderer/content_settings_observer_browsertest.cc
+++ b/chrome/renderer/content_settings_observer_browsertest.cc
@@ -10,6 +10,10 @@
#include "ipc/ipc_message_macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+
+using testing::_;
+using testing::DeleteArg;
namespace {
@@ -21,6 +25,9 @@ class MockContentSettingsObserver : public ContentSettingsObserver {
MOCK_METHOD2(OnContentBlocked,
void(ContentSettingsType, const std::string&));
+
+ MOCK_METHOD5(OnAllowDOMStorage,
+ void(int, const GURL&, const GURL&, bool, IPC::Message*));
};
MockContentSettingsObserver::MockContentSettingsObserver(
@@ -31,6 +38,8 @@ MockContentSettingsObserver::MockContentSettingsObserver(
bool MockContentSettingsObserver::Send(IPC::Message* message) {
IPC_BEGIN_MESSAGE_MAP(MockContentSettingsObserver, *message)
IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_AllowDOMStorage,
+ OnAllowDOMStorage)
IPC_MESSAGE_UNHANDLED(ADD_FAILURE())
IPC_END_MESSAGE_MAP()
@@ -61,6 +70,23 @@ TEST_F(RenderViewTest, DidBlockContentType) {
observer.DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, kBarPlugin);
}
+// Tests that multiple invokations of AllowDOMStorage result in a single IPC.
+TEST_F(RenderViewTest, AllowDOMStorage) {
+ // Load some HTML, so we have a valid security origin.
+ LoadHTML("<html></html>");
+ MockContentSettingsObserver observer(view_);
+ ON_CALL(observer,
+ OnAllowDOMStorage(_, _, _, _, _)).WillByDefault(DeleteArg<4>());
+ EXPECT_CALL(observer,
+ OnAllowDOMStorage(_, _, _, _, _));
+ observer.AllowStorage(view_->webview()->focusedFrame(), true);
+
+ // Accessing localStorage from the same origin again shouldn't result in a
+ // new IPC.
+ observer.AllowStorage(view_->webview()->focusedFrame(), true);
+ ::testing::Mock::VerifyAndClearExpectations(&observer);
+}
+
// Regression test for http://crbug.com/35011
TEST_F(RenderViewTest, JSBlockSentAfterPageLoad) {
// 1. Load page with JS.