2011-05-27 Jochen Eisinger <jochen@chromium.org>
authorjochen@chromium.org <jochen@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 May 2011 03:27:16 +0000 (03:27 +0000)
committerjochen@chromium.org <jochen@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 May 2011 03:27:16 +0000 (03:27 +0000)
        Reviewed by Adam Barth.

        Check access policy on all storage operations
        https://bugs.webkit.org/show_bug.cgi?id=61581

        * platform/chromium/permissionclient/storage-permission-expected.txt: Added.
        * platform/chromium/permissionclient/storage-permission.html: Added.
2011-05-27  Jochen Eisinger  <jochen@chromium.org>

        Reviewed by Adam Barth.

        Add Frame parameter to all StorageArea methods. The chromium
        embedder uses the Frame as context to decide whether or not
        to allow usage of the storage API.
        https://bugs.webkit.org/show_bug.cgi?id=61581

        Test: platform/chromium/permissionclient/storage-permission.html

        * storage/Storage.cpp:
        (WebCore::Storage::length):
        (WebCore::Storage::key):
        (WebCore::Storage::getItem):
        (WebCore::Storage::contains):
        * storage/StorageArea.h:
        * storage/StorageAreaImpl.cpp:
        (WebCore::StorageAreaImpl::length):
        (WebCore::StorageAreaImpl::key):
        (WebCore::StorageAreaImpl::getItem):
        (WebCore::StorageAreaImpl::contains):
        * storage/StorageAreaImpl.h:
2011-05-27  Jochen Eisinger  <jochen@chromium.org>

        Reviewed by Adam Barth.

        Check access policy on all storage operations
        https://bugs.webkit.org/show_bug.cgi?id=61581

        * src/StorageAreaProxy.cpp:
        (WebCore::StorageAreaProxy::length):
        (WebCore::StorageAreaProxy::key):
        (WebCore::StorageAreaProxy::getItem):
        (WebCore::StorageAreaProxy::setItem):
        (WebCore::StorageAreaProxy::removeItem):
        (WebCore::StorageAreaProxy::clear):
        (WebCore::StorageAreaProxy::contains):
        (WebCore::StorageAreaProxy::canAccessStorage):
        * src/StorageAreaProxy.h:
        * src/WebStorageAreaImpl.cpp:
        (WebKit::WebStorageAreaImpl::length):
        (WebKit::WebStorageAreaImpl::key):
        (WebKit::WebStorageAreaImpl::getItem):
2011-05-27  Jochen Eisinger  <jochen@chromium.org>

        Reviewed by Adam Barth.

        Add layoutTestController.setStorageAllowed() to control whether access
        to the localStorage API is enabled via the WebPermissionClient
        https://bugs.webkit.org/show_bug.cgi?id=61581

        * DumpRenderTree/chromium/LayoutTestController.cpp:
        (LayoutTestController::LayoutTestController):
        (LayoutTestController::setStorageAllowed):
        * DumpRenderTree/chromium/LayoutTestController.h:
        * DumpRenderTree/chromium/TestShell.cpp:
        (TestShell::TestShell):
        (TestShell::createNewWindow):
        * DumpRenderTree/chromium/TestShell.h:
        * DumpRenderTree/chromium/WebPermissions.h: Added.
        (WebPermissions::WebPermissions):
        (WebPermissions::allowStorage):
        (WebPermissions::setStorageAllowed):
        (WebPermissions::reset):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87597 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/chromium/permissionclient/storage-permission-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/permissionclient/storage-permission.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/storage/Storage.cpp
Source/WebCore/storage/StorageArea.h
Source/WebCore/storage/StorageAreaImpl.cpp
Source/WebCore/storage/StorageAreaImpl.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/StorageAreaProxy.cpp
Source/WebKit/chromium/src/StorageAreaProxy.h
Source/WebKit/chromium/src/WebStorageAreaImpl.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/LayoutTestController.cpp
Tools/DumpRenderTree/chromium/LayoutTestController.h
Tools/DumpRenderTree/chromium/TestShell.cpp
Tools/DumpRenderTree/chromium/TestShell.h
Tools/DumpRenderTree/chromium/WebPermissions.h [new file with mode: 0644]

index 9efd69c..e5d7723 100644 (file)
@@ -1,3 +1,13 @@
+2011-05-27  Jochen Eisinger  <jochen@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Check access policy on all storage operations
+        https://bugs.webkit.org/show_bug.cgi?id=61581
+
+        * platform/chromium/permissionclient/storage-permission-expected.txt: Added.
+        * platform/chromium/permissionclient/storage-permission.html: Added.
+
 2011-05-27  Adam Klein  <adamk@chromium.org>
 
         Unreviewed. Hopefully last rebaseline from r87526.
diff --git a/LayoutTests/platform/chromium/permissionclient/storage-permission-expected.txt b/LayoutTests/platform/chromium/permissionclient/storage-permission-expected.txt
new file mode 100644 (file)
index 0000000..f4e379d
--- /dev/null
@@ -0,0 +1,16 @@
+This test verifies that all access to localStorage can be blocked
+Length is 0
+Value for FOO is null
+Length is 1
+Value for FOO is BAR
+Key for index 0 is FOO
+Disabling localStorage access.
+Length is 0
+Value for FOO is null
+Caught exception trying to change item: Error: QUOTA_EXCEEDED_ERR: DOM Exception 22
+Length is 0
+Value for FOO is null
+Key for index 0 is null
+Length is 0
+Value for FOO is null
+
diff --git a/LayoutTests/platform/chromium/permissionclient/storage-permission.html b/LayoutTests/platform/chromium/permissionclient/storage-permission.html
new file mode 100644 (file)
index 0000000..30086c1
--- /dev/null
@@ -0,0 +1,64 @@
+<html>
+<head>
+<script src="resources/clearLocalStorage.js"></script>
+<script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(a)
+{
+    document.getElementById("logger").innerHTML += a + "<br>";
+}
+
+function runTest()
+{
+    if (!window.localStorage) {
+        log("window.localStorage DOES NOT exist");
+        return;
+    }
+
+    if (window.layoutTestController && layoutTestController.setStorageAllowed)
+        layoutTestController.setStorageAllowed(true);
+    else
+        log("This test requires layoutTestController.setStorageAllowed, so it be can't run in a browser.");
+    
+    log("Length is " + localStorage.length);
+    log("Value for FOO is " + localStorage.getItem("FOO"));
+
+    localStorage.setItem("FOO", "BAR");
+    
+    log("Length is " + localStorage.length);
+    log("Value for FOO is " + localStorage.getItem("FOO"));
+    log("Key for index 0 is " + localStorage.key(0));
+    
+    log("Disabling localStorage access.");
+    if (window.layoutTestController && layoutTestController.setStorageAllowed)
+        layoutTestController.setStorageAllowed(false);
+
+    log("Length is " + localStorage.length);
+    log("Value for FOO is " + localStorage.getItem("FOO"));
+
+    try {
+        localStorage.setItem("FOO", "BAZ");
+    } catch(e) {
+        log("Caught exception trying to change item: " + e);
+    }
+    
+    log("Length is " + localStorage.length);
+    log("Value for FOO is " + localStorage.getItem("FOO"));
+    log("Key for index 0 is " + localStorage.key(0));
+    
+    localStorage.removeItem("FOO");
+    
+    log("Length is " + localStorage.length);
+    log("Value for FOO is " + localStorage.getItem("FOO"));
+}
+
+</script>
+</head>
+<body onload="runTest();">
+This test verifies that all access to localStorage can be blocked<br>
+<div id="logger"></div>
+</body>
+</html>
index 3fa482b..f44ad4c 100644 (file)
@@ -1,3 +1,27 @@
+2011-05-27  Jochen Eisinger  <jochen@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Add Frame parameter to all StorageArea methods. The chromium
+        embedder uses the Frame as context to decide whether or not
+        to allow usage of the storage API.
+        https://bugs.webkit.org/show_bug.cgi?id=61581
+
+        Test: platform/chromium/permissionclient/storage-permission.html
+
+        * storage/Storage.cpp:
+        (WebCore::Storage::length):
+        (WebCore::Storage::key):
+        (WebCore::Storage::getItem):
+        (WebCore::Storage::contains):
+        * storage/StorageArea.h:
+        * storage/StorageAreaImpl.cpp:
+        (WebCore::StorageAreaImpl::length):
+        (WebCore::StorageAreaImpl::key):
+        (WebCore::StorageAreaImpl::getItem):
+        (WebCore::StorageAreaImpl::contains):
+        * storage/StorageAreaImpl.h:
+
 2011-05-27  Nate Chapin  <japhet@chromium.org>
 
         Reviewed by Jian Li.
index 0259ca4..9e975ab 100644 (file)
@@ -59,7 +59,7 @@ unsigned Storage::length() const
     if (!m_frame || !m_frame->page() || m_frame->page()->settings()->privateBrowsingEnabled())
         return 0;
 
-    return m_storageArea->length();
+    return m_storageArea->length(m_frame);
 }
 
 String Storage::key(unsigned index) const
@@ -67,7 +67,7 @@ String Storage::key(unsigned index) const
     if (!m_frame || !m_frame->page() || m_frame->page()->settings()->privateBrowsingEnabled())
         return String();
 
-    return m_storageArea->key(index);
+    return m_storageArea->key(index, m_frame);
 }
 
 String Storage::getItem(const String& key) const
@@ -75,7 +75,7 @@ String Storage::getItem(const String& key) const
     if (!m_frame || !m_frame->page() || m_frame->page()->settings()->privateBrowsingEnabled())
         return String();
 
-    return m_storageArea->getItem(key);
+    return m_storageArea->getItem(key, m_frame);
 }
 
 void Storage::setItem(const String& key, const String& value, ExceptionCode& ec)
@@ -108,7 +108,7 @@ bool Storage::contains(const String& key) const
     if (!m_frame || !m_frame->page() || m_frame->page()->settings()->privateBrowsingEnabled())
         return false;
 
-    return m_storageArea->contains(key);
+    return m_storageArea->contains(key, m_frame);
 }
 
 }
index 6081240..1dc0138 100644 (file)
@@ -47,13 +47,14 @@ namespace WebCore {
         virtual ~StorageArea() { }
 
         // The HTML5 DOM Storage API
-        virtual unsigned length() const = 0;
-        virtual String key(unsigned index) const = 0;
-        virtual String getItem(const String& key) const = 0;
+        // FIXME: We should pass Document instead of Frame. Also, that parameter should go first.
+        virtual unsigned length(Frame* sourceFrame) const = 0;
+        virtual String key(unsigned index, Frame* sourceFrame) const = 0;
+        virtual String getItem(const String& key, Frame* sourceFrame) const = 0;
         virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame) = 0;
         virtual String removeItem(const String& key, Frame* sourceFrame) = 0;
         virtual bool clear(Frame* sourceFrame) = 0;
-        virtual bool contains(const String& key) const = 0;
+        virtual bool contains(const String& key, Frame* sourceFrame) const = 0;
     };
 
 } // namespace WebCore
index 0ebc874..d54f5ab 100644 (file)
@@ -107,7 +107,7 @@ static bool privateBrowsingEnabled(Frame* frame)
 #endif
 }
 
-unsigned StorageAreaImpl::length() const
+unsigned StorageAreaImpl::length(Frame*) const
 {
     ASSERT(!m_isShutdown);
     blockUntilImportComplete();
@@ -115,7 +115,7 @@ unsigned StorageAreaImpl::length() const
     return m_storageMap->length();
 }
 
-String StorageAreaImpl::key(unsigned index) const
+String StorageAreaImpl::key(unsigned index, Frame*) const
 {
     ASSERT(!m_isShutdown);
     blockUntilImportComplete();
@@ -123,7 +123,7 @@ String StorageAreaImpl::key(unsigned index) const
     return m_storageMap->key(index);
 }
 
-String StorageAreaImpl::getItem(const String& key) const
+String StorageAreaImpl::getItem(const String& key, Frame*) const
 {
     ASSERT(!m_isShutdown);
     blockUntilImportComplete();
@@ -204,7 +204,7 @@ bool StorageAreaImpl::clear(Frame* frame)
     return true;
 }
 
-bool StorageAreaImpl::contains(const String& key) const
+bool StorageAreaImpl::contains(const String& key, Frame*) const
 {
     ASSERT(!m_isShutdown);
     blockUntilImportComplete();
index 9f87e69..1aa5a05 100644 (file)
@@ -45,13 +45,13 @@ namespace WebCore {
         virtual ~StorageAreaImpl();
 
         // The HTML5 DOM Storage API (and contains)
-        virtual unsigned length() const;
-        virtual String key(unsigned index) const;
-        virtual String getItem(const String& key) const;
+        virtual unsigned length(Frame* sourceFrame) const;
+        virtual String key(unsigned index, Frame* sourceFrame) const;
+        virtual String getItem(const String& key, Frame* sourceFrame) const;
         virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);
         virtual String removeItem(const String& key, Frame* sourceFrame);
         virtual bool clear(Frame* sourceFrame);
-        virtual bool contains(const String& key) const;
+        virtual bool contains(const String& key, Frame* sourceFrame) const;
 
         PassRefPtr<StorageAreaImpl> copy();
         void close();
index b2b703a..8c0f200 100644 (file)
@@ -1,5 +1,27 @@
 2011-05-27  Jochen Eisinger  <jochen@chromium.org>
 
+        Reviewed by Adam Barth.
+
+        Check access policy on all storage operations
+        https://bugs.webkit.org/show_bug.cgi?id=61581
+
+        * src/StorageAreaProxy.cpp:
+        (WebCore::StorageAreaProxy::length):
+        (WebCore::StorageAreaProxy::key):
+        (WebCore::StorageAreaProxy::getItem):
+        (WebCore::StorageAreaProxy::setItem):
+        (WebCore::StorageAreaProxy::removeItem):
+        (WebCore::StorageAreaProxy::clear):
+        (WebCore::StorageAreaProxy::contains):
+        (WebCore::StorageAreaProxy::canAccessStorage):
+        * src/StorageAreaProxy.h:
+        * src/WebStorageAreaImpl.cpp:
+        (WebKit::WebStorageAreaImpl::length):
+        (WebKit::WebStorageAreaImpl::key):
+        (WebKit::WebStorageAreaImpl::getItem):
+
+2011-05-27  Jochen Eisinger  <jochen@chromium.org>
+
         Reviewed by Darin Fisher.
 
         [chromium] drop unused WebFrame parameter to WebStorageArea::setItem
index 4e2817f..4a83c2d 100644 (file)
@@ -63,28 +63,32 @@ StorageAreaProxy::~StorageAreaProxy()
 {
 }
 
-unsigned StorageAreaProxy::length() const
+unsigned StorageAreaProxy::length(Frame* frame) const
 {
-    return m_storageArea->length();
+    if (canAccessStorage(frame))
+        return m_storageArea->length();
+    return 0;
 }
 
-String StorageAreaProxy::key(unsigned index) const
+String StorageAreaProxy::key(unsigned index, Frame* frame) const
 {
-    return m_storageArea->key(index);
+    if (canAccessStorage(frame))
+        return m_storageArea->key(index);
+    return String();
 }
 
-String StorageAreaProxy::getItem(const String& key) const
+String StorageAreaProxy::getItem(const String& key, Frame* frame) const
 {
-    return m_storageArea->getItem(key);
+    if (canAccessStorage(frame))
+        return m_storageArea->getItem(key);
+    return String();
 }
 
 String StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)
 {
     WebKit::WebStorageArea::Result result = WebKit::WebStorageArea::ResultOK;
     WebKit::WebString oldValue;
-    WebKit::WebFrameImpl* webFrame = WebKit::WebFrameImpl::fromFrame(frame);
-    WebKit::WebViewImpl* webView = webFrame->viewImpl();
-    if (webView->permissionClient() && !webView->permissionClient()->allowStorage(webFrame, m_storageType == LocalStorage))
+    if (!canAccessStorage(frame))
         ec = QUOTA_EXCEEDED_ERR;
     else {
         m_storageArea->setItem(key, value, frame->document()->url(), result, oldValue);
@@ -98,6 +102,8 @@ String StorageAreaProxy::setItem(const String& key, const String& value, Excepti
 
 String StorageAreaProxy::removeItem(const String& key, Frame* frame)
 {
+    if (!canAccessStorage(frame))
+        return String();
     WebKit::WebString oldValue;
     m_storageArea->removeItem(key, frame->document()->url(), oldValue);
     if (!oldValue.isNull())
@@ -107,6 +113,8 @@ String StorageAreaProxy::removeItem(const String& key, Frame* frame)
 
 bool StorageAreaProxy::clear(Frame* frame)
 {
+    if (!canAccessStorage(frame))
+        return false;
     bool clearedSomething;
     m_storageArea->clear(frame->document()->url(), clearedSomething);
     if (clearedSomething)
@@ -114,9 +122,9 @@ bool StorageAreaProxy::clear(Frame* frame)
     return clearedSomething;
 }
 
-bool StorageAreaProxy::contains(const String& key) const
+bool StorageAreaProxy::contains(const String& key, Frame* frame) const
 {
-    return !getItem(key).isNull();
+    return !getItem(key, frame).isNull();
 }
 
 // Copied from WebCore/storage/StorageEventDispatcher.cpp out of necessity.  It's probably best to keep it current.
@@ -162,6 +170,13 @@ void StorageAreaProxy::storageEvent(const String& key, const String& oldValue, c
     }
 }
 
+bool StorageAreaProxy::canAccessStorage(Frame* frame) const
+{
+    WebKit::WebFrameImpl* webFrame = WebKit::WebFrameImpl::fromFrame(frame);
+    WebKit::WebViewImpl* webView = webFrame->viewImpl();
+    return !webView->permissionClient() || webView->permissionClient()->allowStorage(webFrame, m_storageType == LocalStorage);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(DOM_STORAGE)
index b169828..fd91bad 100644 (file)
@@ -43,16 +43,17 @@ public:
     virtual ~StorageAreaProxy();
 
     // The HTML5 DOM Storage API
-    virtual unsigned length() const;
-    virtual String key(unsigned index) const;
-    virtual String getItem(const String& key) const;
+    virtual unsigned length(Frame* sourceFrame) const;
+    virtual String key(unsigned index, Frame* sourceFrame) const;
+    virtual String getItem(const String& key, Frame* sourceFrame) const;
     virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);
     virtual String removeItem(const String& key, Frame* sourceFrame);
     virtual bool clear(Frame* sourceFrame);
-    virtual bool contains(const String& key) const;
+    virtual bool contains(const String& key, Frame* sourceFrame) const;
 
 private:
     void storageEvent(const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*, Frame* sourceFrame);
+    bool canAccessStorage(Frame*) const;
 
     OwnPtr<WebKit::WebStorageArea> m_storageArea;
     StorageType m_storageType;
index 9a7fd5c..da8208f 100644 (file)
@@ -53,17 +53,17 @@ WebStorageAreaImpl::~WebStorageAreaImpl()
 
 unsigned WebStorageAreaImpl::length()
 {
-    return m_storageArea->length();
+    return m_storageArea->length(0);
 }
 
 WebString WebStorageAreaImpl::key(unsigned index)
 {
-    return m_storageArea->key(index);
+    return m_storageArea->key(index, 0);
 }
 
 WebString WebStorageAreaImpl::getItem(const WebString& key)
 {
-    return m_storageArea->getItem(key);
+    return m_storageArea->getItem(key, 0);
 }
 
 void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, Result& result, WebString& oldValue)
index 947cb8f..ce5c1e6 100644 (file)
@@ -1,3 +1,25 @@
+2011-05-27  Jochen Eisinger  <jochen@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Add layoutTestController.setStorageAllowed() to control whether access
+        to the localStorage API is enabled via the WebPermissionClient
+        https://bugs.webkit.org/show_bug.cgi?id=61581
+
+        * DumpRenderTree/chromium/LayoutTestController.cpp:
+        (LayoutTestController::LayoutTestController):
+        (LayoutTestController::setStorageAllowed):
+        * DumpRenderTree/chromium/LayoutTestController.h:
+        * DumpRenderTree/chromium/TestShell.cpp:
+        (TestShell::TestShell):
+        (TestShell::createNewWindow):
+        * DumpRenderTree/chromium/TestShell.h:
+        * DumpRenderTree/chromium/WebPermissions.h: Added.
+        (WebPermissions::WebPermissions):
+        (WebPermissions::allowStorage):
+        (WebPermissions::setStorageAllowed):
+        (WebPermissions::reset):
+
 2011-05-27  Dirk Pranke  <dpranke@chromium.org>
 
         Reviewed by Eric Seidel.
index d4abbc7..f138e40 100644 (file)
@@ -47,6 +47,7 @@
 #include "WebInputElement.h"
 #include "WebKit.h"
 #include "WebNotificationPresenter.h"
+#include "WebPermissions.h"
 #include "WebScriptSource.h"
 #include "WebSecurityPolicy.h"
 #include "WebSettings.h"
@@ -214,6 +215,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("deleteLocalStorageForOrigin", &LayoutTestController::deleteLocalStorageForOrigin);
     bindMethod("observeStorageTrackerNotifications", &LayoutTestController::observeStorageTrackerNotifications);
     bindMethod("syncLocalStorage", &LayoutTestController::syncLocalStorage);
+    bindMethod("setStorageAllowed", &LayoutTestController::setStorageAllowed);
     
     // The fallback method is called when an unknown method is invoked.
     bindFallbackMethod(&LayoutTestController::fallbackMethod);
@@ -1820,6 +1822,13 @@ void LayoutTestController::syncLocalStorage(const CppArgumentList&, CppVariant*)
     // Not Implemented
 }
 
+void LayoutTestController::setStorageAllowed(const CppArgumentList& arguments, CppVariant* result)
+{
+    if (arguments.size() > 0 && arguments[0].isBool())
+        m_shell->webPermissions()->setStorageAllowed(arguments[0].toBoolean());
+    result->setNull();
+}
+
 void LayoutTestController::setPluginsEnabled(const CppArgumentList& arguments, CppVariant* result)
 {
     if (arguments.size() > 0 && arguments[0].isBool()) {
index 252d4f1..9b1710f 100644 (file)
@@ -369,6 +369,7 @@ public:
     void localStorageDiskUsageForOrigin(const CppArgumentList&, CppVariant*);
     void observeStorageTrackerNotifications(const CppArgumentList&, CppVariant*);
     void syncLocalStorage(const CppArgumentList&, CppVariant*);
+    void setStorageAllowed(const CppArgumentList&, CppVariant*);
 
     // Enable or disable plugins.
     void setPluginsEnabled(const CppArgumentList&, CppVariant*);
index e88f40f..a298ff7 100644 (file)
@@ -40,6 +40,7 @@
 #include "WebFrame.h"
 #include "WebHistoryItem.h"
 #include "WebKit.h"
+#include "WebPermissions.h"
 #include "WebRuntimeFeatures.h"
 #include "WebScriptController.h"
 #include "WebSettings.h"
@@ -113,6 +114,7 @@ TestShell::TestShell(bool testShellMode)
     WebRuntimeFeatures::enableIndexedDatabase(true);
     WebRuntimeFeatures::enableFileSystem(true);
     WebRuntimeFeatures::enableJavaScriptI18NAPI(true);
+    m_webPermissions = adoptPtr(new WebPermissions());
     m_accessibilityController = adoptPtr(new AccessibilityController(this));
     m_layoutTestController = adoptPtr(new LayoutTestController(this));
     m_eventSender = adoptPtr(new EventSender(this));
@@ -242,6 +244,7 @@ void TestShell::resizeWindowForTest(WebViewHost* window, const WebURL& url)
 void TestShell::resetTestController()
 {
     resetWebSettings(*webView());
+    m_webPermissions->reset();
     m_accessibilityController->reset();
     m_layoutTestController->reset();
     m_eventSender->reset();
@@ -596,6 +599,7 @@ WebViewHost* TestShell::createNewWindow(const WebKit::WebURL& url, DRTDevToolsAg
 {
     WebViewHost* host = new WebViewHost(this);
     WebView* view = WebView::create(host);
+    view->setPermissionClient(webPermissions());
     view->setDevToolsAgentClient(devToolsAgent);
     host->setWebWidget(view);
     m_prefs.applyTo(view);
index 2db4c94..337657f 100644 (file)
@@ -58,6 +58,7 @@ class WebURL;
 class DRTDevToolsAgent;
 class DRTDevToolsCallArgs;
 class DRTDevToolsClient;
+class WebPermissions;
 
 struct TestParams {
     bool dumpTree;
@@ -96,6 +97,8 @@ public:
     WebPreferences* preferences() { return &m_prefs; }
     void applyPreferences() { m_prefs.applyTo(m_webView); }
 
+    WebPermissions* webPermissions() { return m_webPermissions.get(); }
+
     void bindJSObjectsToWindow(WebKit::WebFrame*);
     void runFileTest(const TestParams&);
     void callJSGC();
@@ -191,6 +194,7 @@ private:
     bool m_testShellMode;
     WebViewHost* m_webViewHost;
     WebViewHost* m_devTools;
+    OwnPtr<WebPermissions> m_webPermissions;
     OwnPtr<DRTDevToolsAgent> m_drtDevToolsAgent;
     OwnPtr<DRTDevToolsClient> m_drtDevToolsClient;
     OwnPtr<AccessibilityController> m_accessibilityController;
diff --git a/Tools/DumpRenderTree/chromium/WebPermissions.h b/Tools/DumpRenderTree/chromium/WebPermissions.h
new file mode 100644 (file)
index 0000000..9ead6fc
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPermissions_h
+#define WebPermissions_h
+
+#include "WebPermissionClient.h"
+
+class WebPermissions : public WebKit::WebPermissionClient {
+public:
+    WebPermissions() : m_storageAllowed(true) { }
+
+    virtual bool allowStorage(WebKit::WebFrame*, bool local) { return m_storageAllowed; }
+
+    // Sets the policy whether to allow storage or not.
+    void setStorageAllowed(bool storageAllowed) { m_storageAllowed = storageAllowed; }
+
+    // Resets the policy to allow all access.
+    void reset() { m_storageAllowed = true; }
+
+private:
+    bool m_storageAllowed;
+};
+
+#endif