diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 01:22:51 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 01:22:51 +0000 |
commit | 2a10f681c582df15719956061b6742a55bccb46a (patch) | |
tree | 4e4ee689cafbecb9b211f437f478b7588f6c05c2 /webkit | |
parent | 4f9b2a7e42fc567073f4999a888b3140bec460bb (diff) | |
download | chromium_src-2a10f681c582df15719956061b6742a55bccb46a.zip chromium_src-2a10f681c582df15719956061b6742a55bccb46a.tar.gz chromium_src-2a10f681c582df15719956061b6742a55bccb46a.tar.bz2 |
The final CL for plumbing DOM Storage.
Add webKitClient plumbing for getting/creating storage namespaces. Add a chromium implementation for WebStorageArea and WebStorageNamespace which communicates via IPC with the dom_storage_dispatcher_host in the browser process. Flesh out the StorageAreaProxy and StorageNamespaceProxy to use the aforementioned implementations.
The WebStorageArea implementation includes decently aggressive caching optimizations. There's still a lot of work to do, though.
BUG=4360
TEST=none
Review URL: http://codereview.chromium.org/147248
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21495 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/api/public/WebKitClient.h | 12 | ||||
-rw-r--r-- | webkit/api/src/StorageAreaProxy.cpp | 94 | ||||
-rw-r--r-- | webkit/api/src/StorageAreaProxy.h | 59 | ||||
-rw-r--r-- | webkit/api/src/StorageNamespaceProxy.cpp | 37 | ||||
-rw-r--r-- | webkit/api/src/StorageNamespaceProxy.h | 18 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 11 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker_main.cc | 11 | ||||
-rw-r--r-- | webkit/webkit.gyp | 2 |
8 files changed, 239 insertions, 5 deletions
diff --git a/webkit/api/public/WebKitClient.h b/webkit/api/public/WebKitClient.h index 9721750..6e84c8d 100644 --- a/webkit/api/public/WebKitClient.h +++ b/webkit/api/public/WebKitClient.h @@ -40,6 +40,7 @@ namespace WebKit { class WebMimeRegistry; class WebPluginListBuilder; class WebSandboxSupport; + class WebStorageNamespace; class WebString; class WebThemeEngine; class WebURL; @@ -62,6 +63,17 @@ namespace WebKit { virtual WebThemeEngine* themeEngine() = 0; + // DOM Storage -------------------------------------------------- + + // Return a LocalStorage namespace that corresponds to the following + // path. + virtual WebStorageNamespace* createLocalStorageNamespace( + const WebString& path) = 0; + + // Return a new SessionStorage namespace. + virtual WebStorageNamespace* createSessionStorageNamespace() = 0; + + // File ---------------------------------------------------------------- virtual bool getFileSize(const WebString& path, long long& result) = 0; diff --git a/webkit/api/src/StorageAreaProxy.cpp b/webkit/api/src/StorageAreaProxy.cpp new file mode 100644 index 0000000..0709a2b --- /dev/null +++ b/webkit/api/src/StorageAreaProxy.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2009 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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. + */ + +#include "config.h" +#include "StorageAreaProxy.h" + +#if ENABLE(DOM_STORAGE) + +#include "ExceptionCode.h" +#include "Frame.h" +#include "SecurityOrigin.h" +#include "StorageAreaImpl.h" +#include "WebStorageArea.h" +#include "WebString.h" + +namespace WebCore { + +StorageAreaProxy::StorageAreaProxy(WebKit::WebStorageArea* storageArea) + : m_storageArea(storageArea) +{ +} + +StorageAreaProxy::~StorageAreaProxy() +{ +} + +unsigned StorageAreaProxy::length() const +{ + return m_storageArea->length(); +} + +String StorageAreaProxy::key(unsigned index, ExceptionCode& ec) const +{ + bool keyException = false; + String value = m_storageArea->key(index, keyException); + ec = keyException ? INDEX_SIZE_ERR : 0; + return value; +} + +String StorageAreaProxy::getItem(const String& key) const +{ + return m_storageArea->getItem(key); +} + +void StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame*) +{ + // FIXME: Is frame any use to us? Probably not. + bool quotaException = false; + m_storageArea->setItem(key, value, quotaException); + ec = quotaException ? QUOTA_EXCEEDED_ERR : 0; +} + +void StorageAreaProxy::removeItem(const String& key, Frame*) +{ + // FIXME: Is frame any use to us? Probably not. + m_storageArea->removeItem(key); +} + +void StorageAreaProxy::clear(Frame* frame) +{ + // FIXME: Is frame any use to us? Probably not. + m_storageArea->clear(); +} + +bool StorageAreaProxy::contains(const String& key) const +{ + return !getItem(key).isNull(); +} + +} // namespace WebCore + +#endif // ENABLE(DOM_STORAGE) diff --git a/webkit/api/src/StorageAreaProxy.h b/webkit/api/src/StorageAreaProxy.h new file mode 100644 index 0000000..6b6b565 --- /dev/null +++ b/webkit/api/src/StorageAreaProxy.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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 StorageAreaProxy_h +#define StorageAreaProxy_h + +#if ENABLE(DOM_STORAGE) + +#include "StorageArea.h" + +namespace WebKit { class WebStorageArea; } + +namespace WebCore { + + class StorageAreaProxy : public StorageArea { + public: + StorageAreaProxy(WebKit::WebStorageArea* storageArea); + virtual ~StorageAreaProxy(); + + // The HTML5 DOM Storage API + virtual unsigned length() const; + virtual String key(unsigned index, ExceptionCode& ec) const; + virtual String getItem(const String& key) const; + virtual void setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame); + virtual void removeItem(const String& key, Frame* sourceFrame); + virtual void clear(Frame* sourceFrame); + virtual bool contains(const String& key) const; + + private: + OwnPtr<WebKit::WebStorageArea> m_storageArea; + }; + +} // namespace WebCore + +#endif // ENABLE(DOM_STORAGE) + +#endif // StorageAreaProxy_h diff --git a/webkit/api/src/StorageNamespaceProxy.cpp b/webkit/api/src/StorageNamespaceProxy.cpp index 8955c33..c567d58 100644 --- a/webkit/api/src/StorageNamespaceProxy.cpp +++ b/webkit/api/src/StorageNamespaceProxy.cpp @@ -28,18 +28,47 @@ #if ENABLE(DOM_STORAGE) +#include "SecurityOrigin.h" +#include "StorageAreaProxy.h" +#include "WebKit.h" +#include "WebKitClient.h" +#include "WebStorageNamespace.h" +#include "WebString.h" + namespace WebCore { PassRefPtr<StorageNamespace> StorageNamespace::localStorageNamespace(const String& path) { - ASSERT_NOT_REACHED(); - return NULL; + return new StorageNamespaceProxy(WebKit::webKitClient()->createLocalStorageNamespace(path)); } PassRefPtr<StorageNamespace> StorageNamespace::sessionStorageNamespace() { - ASSERT_NOT_REACHED(); - return NULL; + return new StorageNamespaceProxy(WebKit::webKitClient()->createSessionStorageNamespace()); +} + +StorageNamespaceProxy::StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace) + : m_storageNamespace(storageNamespace) +{ +} + +StorageNamespaceProxy::~StorageNamespaceProxy() +{ +} + +PassRefPtr<StorageNamespace> StorageNamespaceProxy::copy() +{ + return adoptRef(new StorageNamespaceProxy(m_storageNamespace->copy())); +} + +PassRefPtr<StorageArea> StorageNamespaceProxy::storageArea(SecurityOrigin* origin) +{ + return adoptRef(new StorageAreaProxy(m_storageNamespace->createStorageArea(origin->toString()))); +} + +void StorageNamespaceProxy::close() +{ + m_storageNamespace->close(); } } // namespace WebCore diff --git a/webkit/api/src/StorageNamespaceProxy.h b/webkit/api/src/StorageNamespaceProxy.h index 0b9058c..c531057 100644 --- a/webkit/api/src/StorageNamespaceProxy.h +++ b/webkit/api/src/StorageNamespaceProxy.h @@ -30,7 +30,23 @@ #include "StorageNamespace.h" -// FIXME: Implement the StorageNamespaceProxy +namespace WebKit { class WebStorageNamespace; } + +namespace WebCore { + + class StorageNamespaceProxy : public StorageNamespace { + public: + StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace); + virtual ~StorageNamespaceProxy(); + virtual PassRefPtr<StorageArea> storageArea(SecurityOrigin*); + virtual PassRefPtr<StorageNamespace> copy(); + virtual void close(); + + private: + OwnPtr<WebKit::WebStorageNamespace> m_storageNamespace; + }; + +} // namespace WebCore #endif // ENABLE(DOM_STORAGE) diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index eafff01..2f455ba 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -12,6 +12,8 @@ #include "media/base/media.h" #include "webkit/api/public/WebData.h" #include "webkit/api/public/WebKit.h" +#include "webkit/api/public/WebStorageArea.h" +#include "webkit/api/public/WebStorageNamespace.h" #include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" #include "webkit/glue/simple_webmimeregistry_impl.h" @@ -126,6 +128,15 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { return ASCIIToUTF16("en-US"); } + virtual WebKit::WebStorageNamespace* createLocalStorageNamespace( + const WebKit::WebString& path) { + return WebKit::WebStorageNamespace::createLocalStorageNamespace(path); + } + + virtual WebKit::WebStorageNamespace* createSessionStorageNamespace() { + return WebKit::WebStorageNamespace::createSessionStorageNamespace(); + } + private: webkit_glue::SimpleWebMimeRegistryImpl mime_registry_; scoped_ptr<WebKit::WebClipboard> clipboard_; diff --git a/webkit/tools/test_shell/test_worker/test_worker_main.cc b/webkit/tools/test_shell/test_worker/test_worker_main.cc index 29f739a..30b52da 100644 --- a/webkit/tools/test_shell/test_worker/test_worker_main.cc +++ b/webkit/tools/test_shell/test_worker/test_worker_main.cc @@ -90,6 +90,17 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl { helper_->DispatchToMainThread(func); } + virtual WebKit::WebStorageNamespace* createLocalStorageNamespace( + const WebKit::WebString& path) { + NOTREACHED(); + return 0; + } + + virtual WebKit::WebStorageNamespace* createSessionStorageNamespace() { + NOTREACHED(); + return 0; + } + private: TestWebWorkerHelper* helper_; }; diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 632d56e..bd09baf 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -1042,6 +1042,8 @@ 'api/src/LocalizedStrings.cpp', 'api/src/MediaPlayerPrivateChromium.cpp', 'api/src/ResourceHandle.cpp', + 'api/src/StorageAreaProxy.cpp', + 'api/src/StorageAreaProxy.h', 'api/src/StorageNamespaceProxy.cpp', 'api/src/StorageNamespaceProxy.h', 'api/src/TemporaryGlue.h', |