summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/dom_storage/dom_storage_message_filter.cc1
-rw-r--r--content/common/dom_storage_messages.h4
-rw-r--r--content/renderer/render_thread_impl.cc57
-rw-r--r--content/renderer/render_thread_impl.h2
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.cc3
-rw-r--r--content/renderer/renderer_webstoragenamespace_impl.cc11
-rw-r--r--content/renderer/renderer_webstoragenamespace_impl.h3
-rw-r--r--webkit/dom_storage/dom_storage_context.h2
-rw-r--r--webkit/dom_storage/dom_storage_host.cc10
-rw-r--r--webkit/tools/test_shell/simple_dom_storage_system.cc92
-rw-r--r--webkit/tools/test_shell/simple_dom_storage_system.h33
11 files changed, 160 insertions, 58 deletions
diff --git a/content/browser/dom_storage/dom_storage_message_filter.cc b/content/browser/dom_storage/dom_storage_message_filter.cc
index 8175123..15d19b3 100644
--- a/content/browser/dom_storage/dom_storage_message_filter.cc
+++ b/content/browser/dom_storage/dom_storage_message_filter.cc
@@ -245,5 +245,6 @@ void DOMStorageMessageFilter::SendDomStorageEvent(
params.key = key;
params.new_value = new_value;
params.old_value = old_value;
+ params.namespace_id = area->namespace_id();
Send(new DOMStorageMsg_Event(params));
}
diff --git a/content/common/dom_storage_messages.h b/content/common/dom_storage_messages.h
index 2417ab8..3a1affa 100644
--- a/content/common/dom_storage_messages.h
+++ b/content/common/dom_storage_messages.h
@@ -32,6 +32,10 @@ IPC_STRUCT_BEGIN(DOMStorageMsg_Event_Params)
// The non-zero connection_id which caused the event or 0 if the event
// was not caused by the target renderer process.
IPC_STRUCT_MEMBER(int, connection_id)
+
+ // The non-zero session namespace_id associated with the event or 0 if
+ // this is a local storage event.
+ IPC_STRUCT_MEMBER(int64, namespace_id)
IPC_STRUCT_END()
IPC_ENUM_TRAITS(WebKit::WebStorageArea::Result)
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 1edd2ca..dc7a040 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -57,6 +57,7 @@
#include "content/renderer/render_view_impl.h"
#include "content/renderer/renderer_webkitplatformsupport_impl.h"
#include "content/renderer/renderer_webstoragearea_impl.h"
+#include "content/renderer/renderer_webstoragenamespace_impl.h"
#include "grit/content_resources.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_platform_file.h"
@@ -813,32 +814,40 @@ void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& host,
void RenderThreadImpl::OnDOMStorageEvent(
const DOMStorageMsg_Event_Params& params) {
- if (!dom_storage_event_dispatcher_.get()) {
- EnsureWebKitInitialized();
- dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
- }
+ EnsureWebKitInitialized();
- // TODO(michaeln): Return early until webkit/webcore is modified to not
- // raise LocalStorage events internally. Looks like i have some multi-side
- // patch engineering in front of me todo.
- if (params.connection_id)
- return;
+ bool originated_in_process = params.connection_id != 0;
+ RendererWebStorageAreaImpl* originating_area = NULL;
+ if (originated_in_process) {
+ originating_area = RendererWebStorageAreaImpl::FromConnectionId(
+ params.connection_id);
+ }
- // TODO(michaeln): fix the webkit api so we don't need to convert from
- // string types to url types and to pass in the 'area' which
- // caused this event to occur and to get rid of the is_local param.
- // RendererWebStorageAreaImpl* originating_area =
- // RendererWebStorageAreaImpl::FromConnectionId(params.connection_id);
-
- // SessionStorage events are always raised internally by webkit/webcore.
- const bool kIsLocalStorage = true;
- dom_storage_event_dispatcher_->dispatchStorageEvent(
- params.key,
- params.old_value,
- params.new_value,
- UTF8ToUTF16(params.origin.spec()),
- params.page_url,
- kIsLocalStorage);
+ if (params.namespace_id == dom_storage::kLocalStorageNamespaceId) {
+ WebStorageEventDispatcher::dispatchLocalStorageEvent(
+ params.key,
+ params.old_value,
+ params.new_value,
+ params.origin,
+ params.page_url,
+ originating_area,
+ originated_in_process);
+ } else if (originated_in_process) {
+ // TODO(michaeln): For now, we only raise session storage events into the
+ // process which caused the event to occur. However there are cases where
+ // sessions can span process boundaries, so there are correctness issues.
+ RendererWebStorageNamespaceImpl
+ session_namespace_for_event_dispatch(params.namespace_id);
+ WebStorageEventDispatcher::dispatchSessionStorageEvent(
+ params.key,
+ params.old_value,
+ params.new_value,
+ params.origin,
+ params.page_url,
+ session_namespace_for_event_dispatch,
+ originating_area,
+ originated_in_process);
+ }
}
bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h
index 1c1219e..a747b91 100644
--- a/content/renderer/render_thread_impl.h
+++ b/content/renderer/render_thread_impl.h
@@ -42,7 +42,6 @@ class WebDatabaseObserverImpl;
namespace WebKit {
class WebMediaStreamCenter;
class WebMediaStreamCenterClient;
-class WebStorageEventDispatcher;
}
namespace base {
@@ -222,7 +221,6 @@ class CONTENT_EXPORT RenderThreadImpl : public content::RenderThread,
scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
scoped_ptr<IndexedDBDispatcher> main_thread_indexed_db_dispatcher_;
scoped_ptr<RendererWebKitPlatformSupportImpl> webkit_platform_support_;
- scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_;
// Used on the render thread and deleted by WebKit at shutdown.
content::MediaStreamCenter* media_stream_center_;
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index 2281ad3..03b7444 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -45,7 +45,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
#include "webkit/glue/simple_webmimeregistry_impl.h"
@@ -94,8 +93,6 @@ using WebKit::WebPeerConnection00HandlerClient;
using WebKit::WebPeerConnectionHandler;
using WebKit::WebPeerConnectionHandlerClient;
using WebKit::WebSerializedScriptValue;
-using WebKit::WebStorageArea;
-using WebKit::WebStorageEventDispatcher;
using WebKit::WebStorageNamespace;
using WebKit::WebString;
using WebKit::WebURL;
diff --git a/content/renderer/renderer_webstoragenamespace_impl.cc b/content/renderer/renderer_webstoragenamespace_impl.cc
index 2b12496..de6c10a 100644
--- a/content/renderer/renderer_webstoragenamespace_impl.cc
+++ b/content/renderer/renderer_webstoragenamespace_impl.cc
@@ -27,10 +27,6 @@ RendererWebStorageNamespaceImpl::~RendererWebStorageNamespaceImpl() {
WebStorageArea* RendererWebStorageNamespaceImpl::createStorageArea(
const WebString& origin) {
- // 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 the
- // price in terms of wasted memory.
return new RendererWebStorageAreaImpl(namespace_id_, origin);
}
@@ -42,6 +38,9 @@ WebStorageNamespace* RendererWebStorageNamespaceImpl::copy() {
return NULL;
}
-void RendererWebStorageNamespaceImpl::close() {
- // TOOD(michaeln): remove this deprecated method.
+bool RendererWebStorageNamespaceImpl::isSameNamespace(
+ const WebStorageNamespace& other) const {
+ const RendererWebStorageNamespaceImpl* other_impl =
+ static_cast<const RendererWebStorageNamespaceImpl*>(&other);
+ return namespace_id_ == other_impl->namespace_id_;
}
diff --git a/content/renderer/renderer_webstoragenamespace_impl.h b/content/renderer/renderer_webstoragenamespace_impl.h
index 680e307..e8aa204 100644
--- a/content/renderer/renderer_webstoragenamespace_impl.h
+++ b/content/renderer/renderer_webstoragenamespace_impl.h
@@ -21,7 +21,8 @@ class RendererWebStorageNamespaceImpl : public WebKit::WebStorageNamespace {
virtual WebKit::WebStorageArea* createStorageArea(
const WebKit::WebString& origin);
virtual WebKit::WebStorageNamespace* copy();
- virtual void close();
+ virtual bool isSameNamespace(const WebStorageNamespace&) const;
+
private:
int64 namespace_id_;
diff --git a/webkit/dom_storage/dom_storage_context.h b/webkit/dom_storage/dom_storage_context.h
index 3bcc6ca..ca2b570 100644
--- a/webkit/dom_storage/dom_storage_context.h
+++ b/webkit/dom_storage/dom_storage_context.h
@@ -67,7 +67,7 @@ class DomStorageContext
~UsageInfo();
};
- // An interface for observing LocalStorage events on the
+ // An interface for observing Local and Session Storage events on the
// background thread.
class EventObserver {
public:
diff --git a/webkit/dom_storage/dom_storage_host.cc b/webkit/dom_storage/dom_storage_host.cc
index 1b468c8..b97c02c 100644
--- a/webkit/dom_storage/dom_storage_host.cc
+++ b/webkit/dom_storage/dom_storage_host.cc
@@ -88,10 +88,8 @@ bool DomStorageHost::SetAreaItem(
return false;
if (!area->SetItem(key, value, old_value))
return false;
- if ((area->namespace_id() == kLocalStorageNamespaceId) &&
- (old_value->is_null() || old_value->string() != value)) {
+ if (old_value->is_null() || old_value->string() != value)
context_->NotifyItemSet(area, key, value, *old_value, page_url);
- }
return true;
}
@@ -103,8 +101,7 @@ bool DomStorageHost::RemoveAreaItem(
return false;
if (!area->RemoveItem(key, old_value))
return false;
- if (area->namespace_id() == kLocalStorageNamespaceId)
- context_->NotifyItemRemoved(area, key, *old_value, page_url);
+ context_->NotifyItemRemoved(area, key, *old_value, page_url);
return true;
}
@@ -114,8 +111,7 @@ bool DomStorageHost::ClearArea(int connection_id, const GURL& page_url) {
return false;
if (!area->Clear())
return false;
- if (area->namespace_id() == kLocalStorageNamespaceId)
- context_->NotifyAreaCleared(area, page_url);
+ context_->NotifyAreaCleared(area, page_url);
return true;
}
diff --git a/webkit/tools/test_shell/simple_dom_storage_system.cc b/webkit/tools/test_shell/simple_dom_storage_system.cc
index 897ccbd..320491d 100644
--- a/webkit/tools/test_shell/simple_dom_storage_system.cc
+++ b/webkit/tools/test_shell/simple_dom_storage_system.cc
@@ -4,21 +4,23 @@
#include "webkit/tools/test_shell/simple_dom_storage_system.h"
+#include "base/auto_reset.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
#include "webkit/database/database_util.h"
-#include "webkit/dom_storage/dom_storage_context.h"
+#include "webkit/dom_storage/dom_storage_area.h"
#include "webkit/dom_storage/dom_storage_host.h"
-#include "webkit/dom_storage/dom_storage_session.h"
using dom_storage::DomStorageContext;
using dom_storage::DomStorageHost;
using dom_storage::DomStorageSession;
using webkit_database::DatabaseUtil;
-using WebKit::WebStorageNamespace;
using WebKit::WebStorageArea;
+using WebKit::WebStorageNamespace;
+using WebKit::WebStorageEventDispatcher;
using WebKit::WebString;
using WebKit::WebURL;
@@ -34,7 +36,7 @@ class SimpleDomStorageSystem::NamespaceImpl : public WebStorageNamespace {
virtual ~NamespaceImpl();
virtual WebStorageArea* createStorageArea(const WebString& origin) OVERRIDE;
virtual WebStorageNamespace* copy() OVERRIDE;
- virtual void close() OVERRIDE;
+ virtual bool isSameNamespace(const WebStorageNamespace&) const OVERRIDE;
private:
DomStorageContext* Context() {
@@ -110,8 +112,10 @@ WebStorageNamespace* SimpleDomStorageSystem::NamespaceImpl::copy() {
return new NamespaceImpl(parent_, new_id);
}
-void SimpleDomStorageSystem::NamespaceImpl::close() {
- // TODO(michaeln): remove this deprecated method.
+bool SimpleDomStorageSystem::NamespaceImpl::isSameNamespace(
+ const WebStorageNamespace& other) const {
+ const NamespaceImpl* other_impl = static_cast<const NamespaceImpl*>(&other);
+ return namespace_id_ == other_impl->namespace_id_;
}
// AreaImpl -----------------------------
@@ -158,6 +162,7 @@ void SimpleDomStorageSystem::AreaImpl::setItem(
if (!Host())
return;
+ AutoReset<AreaImpl*> auto_reset(&parent_->area_being_processed_, this);
NullableString16 old_value;
if (!Host()->SetAreaItem(connection_id_, key, newValue, pageUrl,
&old_value))
@@ -173,6 +178,7 @@ void SimpleDomStorageSystem::AreaImpl::removeItem(
if (!Host())
return;
+ AutoReset<AreaImpl*> auto_reset(&parent_->area_being_processed_, this);
string16 old_value;
if (!Host()->RemoveAreaItem(connection_id_, key, pageUrl, &old_value))
return;
@@ -182,10 +188,12 @@ void SimpleDomStorageSystem::AreaImpl::removeItem(
void SimpleDomStorageSystem::AreaImpl::clear(
const WebURL& pageUrl, bool& somethingCleared) {
- if (Host())
+ if (Host()) {
+ AutoReset<AreaImpl*> auto_reset(&parent_->area_being_processed_, this);
somethingCleared = Host()->ClearArea(connection_id_, pageUrl);
- else
- somethingCleared = false;
+ return;
+ }
+ somethingCleared = false;
}
// SimpleDomStorageSystem -----------------------------
@@ -196,14 +204,17 @@ SimpleDomStorageSystem::SimpleDomStorageSystem()
: weak_factory_(this),
context_(new DomStorageContext(FilePath(), FilePath(), NULL, NULL)),
host_(new DomStorageHost(context_)),
+ area_being_processed_(NULL),
next_connection_id_(1) {
DCHECK(!g_instance_);
g_instance_ = this;
+ context_->AddEventObserver(this);
}
SimpleDomStorageSystem::~SimpleDomStorageSystem() {
g_instance_ = NULL;
host_.reset();
+ context_->RemoveEventObserver(this);
}
WebStorageNamespace* SimpleDomStorageSystem::CreateLocalStorageNamespace() {
@@ -215,3 +226,66 @@ WebStorageNamespace* SimpleDomStorageSystem::CreateSessionStorageNamespace() {
context_->CreateSessionNamespace(id);
return new NamespaceImpl(weak_factory_.GetWeakPtr(), id);
}
+
+void SimpleDomStorageSystem::OnDomStorageItemSet(
+ const dom_storage::DomStorageArea* area,
+ const string16& key,
+ const string16& new_value,
+ const NullableString16& old_value,
+ const GURL& page_url) {
+ DispatchDomStorageEvent(area, page_url,
+ NullableString16(key, false),
+ NullableString16(new_value, false),
+ old_value);
+}
+
+void SimpleDomStorageSystem::OnDomStorageItemRemoved(
+ const dom_storage::DomStorageArea* area,
+ const string16& key,
+ const string16& old_value,
+ const GURL& page_url) {
+ DispatchDomStorageEvent(area, page_url,
+ NullableString16(key, false),
+ NullableString16(true),
+ NullableString16(old_value, false));
+}
+
+void SimpleDomStorageSystem::OnDomStorageAreaCleared(
+ const dom_storage::DomStorageArea* area,
+ const GURL& page_url) {
+ DispatchDomStorageEvent(area, page_url,
+ NullableString16(true),
+ NullableString16(true),
+ NullableString16(true));
+}
+
+void SimpleDomStorageSystem::DispatchDomStorageEvent(
+ const dom_storage::DomStorageArea* area,
+ const GURL& page_url,
+ const NullableString16& key,
+ const NullableString16& new_value,
+ const NullableString16& old_value) {
+ DCHECK(area_being_processed_);
+ if (area->namespace_id() == dom_storage::kLocalStorageNamespaceId) {
+ WebStorageEventDispatcher::dispatchLocalStorageEvent(
+ key,
+ old_value,
+ new_value,
+ area->origin(),
+ page_url,
+ area_being_processed_,
+ true /* originatedInProcess */);
+ } else {
+ NamespaceImpl session_namespace_for_event_dispatch(
+ base::WeakPtr<SimpleDomStorageSystem>(), area->namespace_id());
+ WebStorageEventDispatcher::dispatchSessionStorageEvent(
+ key,
+ old_value,
+ new_value,
+ area->origin(),
+ page_url,
+ session_namespace_for_event_dispatch,
+ area_being_processed_,
+ true /* originatedInProcess */);
+ }
+}
diff --git a/webkit/tools/test_shell/simple_dom_storage_system.h b/webkit/tools/test_shell/simple_dom_storage_system.h
index fd03554..0c7863e 100644
--- a/webkit/tools/test_shell/simple_dom_storage_system.h
+++ b/webkit/tools/test_shell/simple_dom_storage_system.h
@@ -9,11 +9,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "webkit/dom_storage/dom_storage_context.h"
-#include "webkit/dom_storage/dom_storage_host.h"
-#include "webkit/dom_storage/dom_storage_types.h" // For the ENABLE flag.
namespace dom_storage {
-class DomStorageContext;
class DomStorageHost;
}
namespace WebKit {
@@ -22,12 +19,13 @@ class WebStorageNamespace;
// Class that composes dom_storage classes together for use
// in simple single process environments like test_shell and DRT.
-class SimpleDomStorageSystem {
+class SimpleDomStorageSystem
+ : public dom_storage::DomStorageContext::EventObserver {
public:
static SimpleDomStorageSystem& instance() { return *g_instance_; }
SimpleDomStorageSystem();
- ~SimpleDomStorageSystem();
+ virtual ~SimpleDomStorageSystem();
// The Create<<>> calls are bound to WebKit api that the embedder
// is responsible for implementing. These factories are called strictly
@@ -46,9 +44,34 @@ class SimpleDomStorageSystem {
class NamespaceImpl;
class AreaImpl;
+ // DomStorageContext::EventObserver implementation which
+ // calls into webkit/webcore to dispatch events.
+ virtual void OnDomStorageItemSet(
+ const dom_storage::DomStorageArea* area,
+ const string16& key,
+ const string16& new_value,
+ const NullableString16& old_value,
+ const GURL& page_url) OVERRIDE;
+ virtual void OnDomStorageItemRemoved(
+ const dom_storage::DomStorageArea* area,
+ const string16& key,
+ const string16& old_value,
+ const GURL& page_url) OVERRIDE;
+ virtual void OnDomStorageAreaCleared(
+ const dom_storage::DomStorageArea* area,
+ const GURL& page_url) OVERRIDE;
+
+ void DispatchDomStorageEvent(
+ const dom_storage::DomStorageArea* area,
+ const GURL& page_url,
+ const NullableString16& key,
+ const NullableString16& new_value,
+ const NullableString16& old_value);
+
base::WeakPtrFactory<SimpleDomStorageSystem> weak_factory_;
scoped_refptr<dom_storage::DomStorageContext> context_;
scoped_ptr<dom_storage::DomStorageHost> host_;
+ AreaImpl* area_being_processed_;
int next_connection_id_;
static SimpleDomStorageSystem* g_instance_;