summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/in_process_webkit/browser_webkitclient_impl.cc19
-rw-r--r--chrome/browser/in_process_webkit/browser_webkitclient_impl.h3
-rw-r--r--chrome/browser/renderer_host/render_sandbox_host_linux.cc8
-rw-r--r--chrome/chrome.gyp4
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.cc17
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.h3
-rw-r--r--chrome/renderer/renderer_webstoragearea_impl.cc171
-rw-r--r--chrome/renderer/renderer_webstoragearea_impl.h76
-rw-r--r--chrome/renderer/renderer_webstoragenamespace_impl.cc65
-rw-r--r--chrome/renderer/renderer_webstoragenamespace_impl.h35
-rw-r--r--chrome/worker/worker_webkitclient_impl.cc13
-rw-r--r--chrome/worker/worker_webkitclient_impl.h3
-rw-r--r--webkit/api/public/WebKitClient.h12
-rw-r--r--webkit/api/src/StorageAreaProxy.cpp94
-rw-r--r--webkit/api/src/StorageAreaProxy.h59
-rw-r--r--webkit/api/src/StorageNamespaceProxy.cpp37
-rw-r--r--webkit/api/src/StorageNamespaceProxy.h18
-rw-r--r--webkit/tools/test_shell/test_shell_webkit_init.h11
-rw-r--r--webkit/tools/test_shell/test_worker/test_worker_main.cc11
-rw-r--r--webkit/webkit.gyp2
20 files changed, 656 insertions, 5 deletions
diff --git a/chrome/browser/in_process_webkit/browser_webkitclient_impl.cc b/chrome/browser/in_process_webkit/browser_webkitclient_impl.cc
index a1d6638..96119b4 100644
--- a/chrome/browser/in_process_webkit/browser_webkitclient_impl.cc
+++ b/chrome/browser/in_process_webkit/browser_webkitclient_impl.cc
@@ -82,3 +82,22 @@ WebKit::WebData BrowserWebKitClientImpl::loadResource(const char* name) {
NOTREACHED();
return WebKit::WebData();
}
+
+WebKit::WebStorageNamespace*
+BrowserWebKitClientImpl::createLocalStorageNamespace(
+ const WebKit::WebString& path) {
+ // The "WebStorage" interface is used for renderer WebKit -> browser WebKit
+ // communication only. "WebStorageClient" will be used for browser WebKit ->
+ // renderer WebKit. So this will never be implemented.
+ NOTREACHED();
+ return 0;
+}
+
+WebKit::WebStorageNamespace*
+BrowserWebKitClientImpl::createSessionStorageNamespace() {
+ // The "WebStorage" interface is used for renderer WebKit -> browser WebKit
+ // communication only. "WebStorageClient" will be used for browser WebKit ->
+ // renderer WebKit. So this will never be implemented.
+ NOTREACHED();
+ return 0;
+}
diff --git a/chrome/browser/in_process_webkit/browser_webkitclient_impl.h b/chrome/browser/in_process_webkit/browser_webkitclient_impl.h
index 4f7abf0..68b4243 100644
--- a/chrome/browser/in_process_webkit/browser_webkitclient_impl.h
+++ b/chrome/browser/in_process_webkit/browser_webkitclient_impl.h
@@ -28,6 +28,9 @@ class BrowserWebKitClientImpl : public webkit_glue::WebKitClientImpl {
virtual WebKit::WebURLLoader* createURLLoader();
virtual void getPluginList(bool refresh, WebKit::WebPluginListBuilder*);
virtual WebKit::WebData loadResource(const char* name);
+ virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
+ const WebKit::WebString& path);
+ virtual WebKit::WebStorageNamespace* createSessionStorageNamespace();
};
#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_CLIENT_IMPL_H_
diff --git a/chrome/browser/renderer_host/render_sandbox_host_linux.cc b/chrome/browser/renderer_host/render_sandbox_host_linux.cc
index 7038441..31f6631 100644
--- a/chrome/browser/renderer_host/render_sandbox_host_linux.cc
+++ b/chrome/browser/renderer_host/render_sandbox_host_linux.cc
@@ -23,6 +23,8 @@
#include "webkit/api/public/WebData.h"
#include "webkit/api/public/WebKit.h"
#include "webkit/api/public/WebKitClient.h"
+#include "webkit/api/public/WebStorageArea.h"
+#include "webkit/api/public/WebStorageNamespace.h"
#include "SkFontHost_fontconfig_direct.h"
#include "SkFontHost_fontconfig_ipc.h"
@@ -36,6 +38,8 @@ using WebKit::WebMimeRegistry;
using WebKit::WebPluginInfo;
using WebKit::WebPluginListBuilder;
using WebKit::WebSandboxSupport;
+using WebKit::WebStorageArea;
+using WebKit::WebStorageNamespace;
using WebKit::WebString;
using WebKit::WebThemeEngine;
using WebKit::WebUChar;
@@ -108,6 +112,10 @@ class SandboxIPCProcess : public WebKitClient {
virtual WebSandboxSupport* sandboxSupport() { return NULL; }
virtual WebThemeEngine* themeEngine() { return NULL; }
+ virtual WebStorageNamespace* createLocalStorageNamespace(
+ const WebString& path) { return 0; }
+ virtual WebStorageNamespace* createSessionStorageNamespace() { return 0; }
+
virtual bool getFileSize(const WebString& path, long long& result) {
return false;
}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 7264983..f2ba135 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -2507,6 +2507,10 @@
'renderer/renderer_sandbox_support_linux.h',
'renderer/renderer_webkitclient_impl.cc',
'renderer/renderer_webkitclient_impl.h',
+ 'renderer/renderer_webstoragearea_impl.cc',
+ 'renderer/renderer_webstoragearea_impl.h',
+ 'renderer/renderer_webstoragenamespace_impl.cc',
+ 'renderer/renderer_webstoragenamespace_impl.h',
'renderer/user_script_slave.cc',
'renderer/user_script_slave.h',
'renderer/visitedlink_slave.cc',
diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc
index 05e56fb..a863971 100644
--- a/chrome/renderer/renderer_webkitclient_impl.cc
+++ b/chrome/renderer/renderer_webkitclient_impl.cc
@@ -10,6 +10,7 @@
#include "chrome/plugin/npobject_util.h"
#include "chrome/renderer/net/render_dns_master.h"
#include "chrome/renderer/render_thread.h"
+#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
#include "chrome/renderer/visitedlink_slave.h"
#include "webkit/api/public/WebString.h"
#include "webkit/api/public/WebURL.h"
@@ -20,6 +21,8 @@
#include "chrome/renderer/renderer_sandbox_support_linux.h"
#endif
+using WebKit::WebStorageArea;
+using WebKit::WebStorageNamespace;
using WebKit::WebString;
using WebKit::WebURL;
@@ -100,6 +103,20 @@ void RendererWebKitClientImpl::suddenTerminationChanged(bool enabled) {
thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled));
}
+WebStorageNamespace* RendererWebKitClientImpl::createLocalStorageNamespace(
+ const WebString& path) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
+ return WebStorageNamespace::createLocalStorageNamespace(path);
+ // The browser process decides the path, so ignore that param.
+ return new RendererWebStorageNamespaceImpl(true);
+}
+
+WebStorageNamespace* RendererWebKitClientImpl::createSessionStorageNamespace() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
+ return WebStorageNamespace::createSessionStorageNamespace();
+ return new RendererWebStorageNamespaceImpl(false);
+}
+
//------------------------------------------------------------------------------
WebString RendererWebKitClientImpl::MimeRegistry::mimeTypeForExtension(
diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h
index 3f4d5cf..0190027 100644
--- a/chrome/renderer/renderer_webkitclient_impl.h
+++ b/chrome/renderer/renderer_webkitclient_impl.h
@@ -36,6 +36,9 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl {
virtual void prefetchHostName(const WebKit::WebString&);
virtual WebKit::WebString defaultLocale();
virtual void suddenTerminationChanged(bool enabled);
+ virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
+ const WebKit::WebString& path);
+ virtual WebKit::WebStorageNamespace* createSessionStorageNamespace();
private:
class MimeRegistry : public webkit_glue::SimpleWebMimeRegistryImpl {
diff --git a/chrome/renderer/renderer_webstoragearea_impl.cc b/chrome/renderer/renderer_webstoragearea_impl.cc
new file mode 100644
index 0000000..c438cdfe
--- /dev/null
+++ b/chrome/renderer/renderer_webstoragearea_impl.cc
@@ -0,0 +1,171 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#include "chrome/renderer/renderer_webstoragearea_impl.h"
+
+#include "chrome/common/render_messages.h"
+#include "chrome/renderer/render_thread.h"
+#include "webkit/api/public/WebString.h"
+
+RendererWebStorageAreaImpl::RendererWebStorageAreaImpl(
+ int64 namespace_id,
+ const WebKit::WebString& origin)
+ : namespace_id_(namespace_id),
+ origin_(origin),
+ storage_area_id_(kUninitializedStorageAreaId),
+ lock_held_(false),
+ bytes_left_in_quota_(0) {
+}
+
+RendererWebStorageAreaImpl::~RendererWebStorageAreaImpl() {
+}
+
+void RendererWebStorageAreaImpl::lock(bool& invalidate_cache,
+ size_t& bytes_left_in_quota) {
+ EnsureInitializedAndLocked();
+}
+
+void RendererWebStorageAreaImpl::unlock() {
+ if (storage_area_id_ != kUninitializedStorageAreaId) {
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageUnlock(storage_area_id_));
+ }
+ lock_held_ = false;
+}
+
+unsigned RendererWebStorageAreaImpl::length() {
+ EnsureInitializedAndLocked();
+ // Right now this is always sync. We could cache it, but I can't think of
+ // too many use cases where you'd repeatedly look up length() and not be
+ // doing so many key() lookups that the length() calls are the problem.
+ unsigned length;
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageLength(storage_area_id_, &length));
+ return length;
+}
+
+WebKit::WebString RendererWebStorageAreaImpl::key(unsigned index,
+ bool& key_exception) {
+ EnsureInitializedAndLocked();
+ // Right now this is always sync. We may want to optimize this by fetching
+ // chunks of keys rather than single keys (and flushing the cache on every
+ // mutation of the storage area) since this will most often be used to fetch
+ // all the keys at once.
+ string16 key;
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageKey(storage_area_id_, index,
+ &key_exception, &key));
+ return key;
+}
+
+WebKit::WebString RendererWebStorageAreaImpl::getItem(
+ const WebKit::WebString& webkit_key) {
+ EnsureInitializedAndLocked();
+ string16 key = webkit_key;
+
+ // Return from our cache if possible.
+ CacheMap::const_iterator iterator = cached_items_.find(key);
+ if (iterator != cached_items_.end())
+ return iterator->second;
+ if (cached_invalid_items_.find(key) != cached_invalid_items_.end())
+ return WebKit::WebString(); // Return a "null" string.
+
+ // The item is not in the cache, so we must do a sync IPC. Afterwards,
+ // add it to the cache.
+ string16 raw_value;
+ bool value_is_null;
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageGetItem(storage_area_id_, key,
+ &raw_value, &value_is_null));
+ WebKit::WebString value = value_is_null ? WebKit::WebString()
+ : WebKit::WebString(raw_value);
+ SetCache(key, value);
+ return value;
+}
+
+void RendererWebStorageAreaImpl::setItem(const WebKit::WebString& key,
+ const WebKit::WebString& value,
+ bool& quota_exception) {
+ EnsureInitializedAndLocked();
+ quota_exception = !UpdateQuota(key, value);
+ if (quota_exception)
+ return;
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageSetItem(storage_area_id_, key, value));
+ SetCache(key, value);
+}
+
+void RendererWebStorageAreaImpl::removeItem(const WebKit::WebString& key) {
+ EnsureInitializedAndLocked();
+ bool update_succeeded = UpdateQuota(key, WebKit::WebString());
+ DCHECK(update_succeeded);
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageRemoveItem(storage_area_id_, key));
+ SetCache(key, WebKit::WebString());
+}
+
+void RendererWebStorageAreaImpl::clear() {
+ EnsureInitializedAndLocked();
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageClear(storage_area_id_,
+ &bytes_left_in_quota_));
+ // A possible optimization is a flag that says our cache is 100% complete.
+ // This could be set here, and then future gets would never require IPC.
+ cached_items_.clear();
+ cached_invalid_items_.clear();
+}
+
+void RendererWebStorageAreaImpl::EnsureInitializedAndLocked() {
+ if (storage_area_id_ == kUninitializedStorageAreaId) {
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageStorageAreaId(namespace_id_, origin_,
+ &storage_area_id_));
+ }
+
+ if (lock_held_)
+ return;
+
+ bool invalidate_cache;
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageLock(storage_area_id_, &invalidate_cache,
+ &bytes_left_in_quota_));
+ lock_held_ = true;
+ if (invalidate_cache) {
+ cached_items_.clear();
+ cached_invalid_items_.clear();
+ }
+}
+
+bool RendererWebStorageAreaImpl::UpdateQuota(const WebKit::WebString& key,
+ const WebKit::WebString& value) {
+ // TODO(jorlow): Remove once the bytes_left_in_quota values we're getting
+ // are accurate.
+ return true;
+
+ size_t existing_bytes = getItem(key).length();
+ size_t new_bytes = value.length();
+
+ if (existing_bytes < new_bytes) {
+ size_t delta = new_bytes - existing_bytes;
+ if (delta > bytes_left_in_quota_)
+ return false;
+ bytes_left_in_quota_ -= delta;
+ } else {
+ size_t delta = existing_bytes - new_bytes;
+ DCHECK(delta + bytes_left_in_quota_ >= bytes_left_in_quota_);
+ bytes_left_in_quota_ += delta;
+ }
+ return true;
+}
+
+void RendererWebStorageAreaImpl::SetCache(const string16& key,
+ const WebKit::WebString& value) {
+ cached_items_.erase(key);
+ cached_invalid_items_.erase(key);
+
+ if (!value.isNull())
+ cached_items_[key] = value;
+ else
+ cached_invalid_items_.insert(key);
+}
diff --git a/chrome/renderer/renderer_webstoragearea_impl.h b/chrome/renderer/renderer_webstoragearea_impl.h
new file mode 100644
index 0000000..0a313c2
--- /dev/null
+++ b/chrome/renderer/renderer_webstoragearea_impl.h
@@ -0,0 +1,76 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#ifndef CHROME_RENDERER_RENDERER_WEBSTORAGEAREA_IMPL_H_
+#define CHROME_RENDERER_RENDERER_WEBSTORAGEAREA_IMPL_H_
+
+#include "base/basictypes.h"
+#include "base/hash_tables.h"
+#include "base/string16.h"
+#include "webkit/api/public/WebStorageArea.h"
+#include "webkit/api/public/WebString.h"
+
+class RendererWebStorageAreaImpl : public WebKit::WebStorageArea {
+ public:
+ RendererWebStorageAreaImpl(int64 namespace_id,
+ const WebKit::WebString& origin);
+ virtual ~RendererWebStorageAreaImpl();
+
+ // See WebStorageArea.h for documentation on these functions.
+ virtual void lock(bool& invalidate_cache, size_t& bytes_left_in_quota);
+ virtual void unlock();
+ virtual unsigned length();
+ virtual WebKit::WebString key(unsigned index, bool& key_exception);
+ virtual WebKit::WebString getItem(const WebKit::WebString& key);
+ virtual void setItem(const WebKit::WebString& key,
+ const WebKit::WebString& value,
+ bool& quota_exception);
+ virtual void removeItem(const WebKit::WebString& key);
+ virtual void clear();
+
+ private:
+ // Calls lock if we haven't already done so, and also gets a storage_area_id
+ // if we haven't done so. Fetches quota and cache invalidation information
+ // while locking. Only call on the WebKit thread.
+ void EnsureInitializedAndLocked();
+
+ // Update our quota calculation. Returns true if we updated the quota.
+ // Returns false if we couldn't update because we would have exceeded the
+ // quota. If an item is not in our cache, it'll require a getItem IPC in
+ // order to determine the existing value's size.
+ bool UpdateQuota(const WebKit::WebString& key,
+ const WebKit::WebString& value);
+
+ // Set a key/value pair in our cache.
+ void SetCache(const string16& key, const WebKit::WebString& value);
+
+ // Used for initialization or storage_area_id_.
+ int64 namespace_id_;
+ string16 origin_;
+
+ // The ID we use for all IPC. Initialized lazily.
+ int64 storage_area_id_;
+
+ // storage_area_id_ should equal this iff its unitialized.
+ static const int64 kUninitializedStorageAreaId = -1;
+
+ // Do we currently hold the lock on this storage area?
+ bool lock_held_;
+
+ // We track how many bytes are left in the quota between lock and unlock
+ // calls. This allows us to avoid sync IPC on setItem.
+ size_t bytes_left_in_quota_;
+
+ // A cache of key/value pairs. If the item exists, it's put in the
+ // cached_items_ map. If not, it's added to the cached_invalid_items_ set.
+ // The lock IPC call tells us when to invalidate these caches.
+ // TODO(jorlow): Instead of a map + a set, use NullableString16 once it's
+ // implemented: http://crbug.com/17343
+ typedef base::hash_map<string16, string16> CacheMap;
+ typedef base::hash_set<string16> CacheSet;
+ CacheMap cached_items_;
+ CacheSet cached_invalid_items_;
+};
+
+#endif // CHROME_RENDERER_WEBSTORAGEAREA_IMPL_H_
diff --git a/chrome/renderer/renderer_webstoragenamespace_impl.cc b/chrome/renderer/renderer_webstoragenamespace_impl.cc
new file mode 100644
index 0000000..453bbcf
--- /dev/null
+++ b/chrome/renderer/renderer_webstoragenamespace_impl.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
+
+#include "chrome/common/render_messages.h"
+#include "chrome/renderer/render_thread.h"
+#include "chrome/renderer/renderer_webstoragearea_impl.h"
+
+RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl(
+ bool is_local_storage)
+ : is_local_storage_(is_local_storage),
+ namespace_id_(kUninitializedNamespaceId) {
+}
+
+RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl(
+ bool is_local_storage, int64 namespace_id)
+ : is_local_storage_(is_local_storage),
+ namespace_id_(namespace_id) {
+ DCHECK(namespace_id_ != kUninitializedNamespaceId);
+}
+
+RendererWebStorageNamespaceImpl::~RendererWebStorageNamespaceImpl() {
+ if (namespace_id_ != kUninitializedNamespaceId)
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageDerefNamespaceId(namespace_id_));
+}
+
+WebKit::WebStorageArea* RendererWebStorageNamespaceImpl::createStorageArea(
+ const WebKit::WebString& origin) {
+ // This could be done async in the background (started when this class is
+ // first instantiated) rather than lazily on first use, but it's unclear
+ // whether it's worth the complexity.
+ if (namespace_id_ == kUninitializedNamespaceId) {
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageNamespaceId(is_local_storage_,
+ &namespace_id_));
+ DCHECK(namespace_id_ != kUninitializedNamespaceId);
+ }
+ // Ideally, we'd keep a hash map of origin to these objects. Unfortunately
+ // this doesn't seem practical because there's no good way to ref-count these
+ // objects, and it'd be unclear who owned them. So, instead, we'll pay a
+ // price for an allocaiton and IPC for each.
+ return new RendererWebStorageAreaImpl(namespace_id_, origin);
+}
+
+WebKit::WebStorageNamespace* RendererWebStorageNamespaceImpl::copy() {
+ // If we haven't been used yet, we might as well start out fresh (and lazy).
+ if (namespace_id_ == kUninitializedNamespaceId)
+ return new RendererWebStorageNamespaceImpl(is_local_storage_);
+
+ // This cannot easily be differed because we need a snapshot in time.
+ int64 new_namespace_id;
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageCloneNamespaceId(namespace_id_,
+ &new_namespace_id));
+ return new RendererWebStorageNamespaceImpl(is_local_storage_,
+ new_namespace_id);
+}
+
+void RendererWebStorageNamespaceImpl::close() {
+ // This is called only on LocalStorage namespaces when WebKit thinks its
+ // shutting down. This has no impact on Chromium.
+}
diff --git a/chrome/renderer/renderer_webstoragenamespace_impl.h b/chrome/renderer/renderer_webstoragenamespace_impl.h
new file mode 100644
index 0000000..7478a67
--- /dev/null
+++ b/chrome/renderer/renderer_webstoragenamespace_impl.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#ifndef CHROME_RENDERER_RENDERER_WEBSTORAGENAMESPACE_IMPL_H_
+#define CHROME_RENDERER_RENDERER_WEBSTORAGENAMESPACE_IMPL_H_
+
+#include "base/basictypes.h"
+#include "webkit/api/public/WebStorageNamespace.h"
+
+class RendererWebStorageNamespaceImpl : public WebKit::WebStorageNamespace {
+ public:
+ explicit RendererWebStorageNamespaceImpl(bool is_local_storage);
+ RendererWebStorageNamespaceImpl(bool is_local_storage, int64 namespace_id);
+
+ // See WebStorageNamespace.h for documentation on these functions.
+ virtual ~RendererWebStorageNamespaceImpl();
+ virtual WebKit::WebStorageArea* createStorageArea(
+ const WebKit::WebString& origin);
+ virtual WebKit::WebStorageNamespace* copy();
+ virtual void close();
+
+ private:
+ // Are we local storage (as opposed to session storage). Used during lazy
+ // initialization of namespace_id_.
+ bool is_local_storage_;
+
+ // Our namespace ID. Lazily initialized.
+ int64 namespace_id_;
+
+ // namespace_id_ should equal this iff its unitialized.
+ static const int64 kUninitializedNamespaceId = -1;
+};
+
+#endif // CHROME_RENDERER_WEBSTORAGENAMESPACE_IMPL_H_
diff --git a/chrome/worker/worker_webkitclient_impl.cc b/chrome/worker/worker_webkitclient_impl.cc
index a159938..21ca49a 100644
--- a/chrome/worker/worker_webkitclient_impl.cc
+++ b/chrome/worker/worker_webkitclient_impl.cc
@@ -62,3 +62,16 @@ WebKit::WebString WorkerWebKitClientImpl::defaultLocale() {
NOTREACHED();
return WebKit::WebString();
}
+
+WebKit::WebStorageNamespace*
+WorkerWebKitClientImpl::createLocalStorageNamespace(
+ const WebKit::WebString& path) {
+ NOTREACHED();
+ return 0;
+}
+
+WebKit::WebStorageNamespace*
+WorkerWebKitClientImpl::createSessionStorageNamespace() {
+ NOTREACHED();
+ return 0;
+}
diff --git a/chrome/worker/worker_webkitclient_impl.h b/chrome/worker/worker_webkitclient_impl.h
index cebe706..ecd3220 100644
--- a/chrome/worker/worker_webkitclient_impl.h
+++ b/chrome/worker/worker_webkitclient_impl.h
@@ -24,6 +24,9 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl {
virtual void prefetchHostName(const WebKit::WebString&);
virtual bool getFileSize(const WebKit::WebString& path, long long& result);
virtual WebKit::WebString defaultLocale();
+ virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
+ const WebKit::WebString& path);
+ virtual WebKit::WebStorageNamespace* createSessionStorageNamespace();
};
#endif // CHROME_WORKER_WORKER_WEBKIT_CLIENT_IMPL_H_
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',