From ee2be5b38100f85155ab667d9979350f3a51e3fc Mon Sep 17 00:00:00 2001 From: "jorlow@chromium.org" Date: Thu, 5 Nov 2009 09:13:12 +0000 Subject: Enable the URL portion of storage events. This is mostly just plumbing + a hack for making them work in test shell and single process mode. This replaces http://codereview.chromium.org/335034/show TEST=none BUG=24581 Review URL: http://codereview.chromium.org/363014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31081 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/api/src/StorageAreaProxy.cpp | 16 +++++++------- webkit/api/src/StorageEventDispatcherChromium.cpp | 3 ++- webkit/api/src/StorageEventDispatcherImpl.cpp | 7 +++--- webkit/api/src/StorageEventDispatcherImpl.h | 5 +++-- webkit/api/src/WebStorageAreaImpl.cpp | 18 ++++++++++----- webkit/api/src/WebStorageAreaImpl.h | 27 ++++++++++++++++++++--- webkit/api/src/WebStorageEventDispatcherImpl.cpp | 12 ++++++++-- webkit/api/src/WebStorageEventDispatcherImpl.h | 2 +- 8 files changed, 64 insertions(+), 26 deletions(-) (limited to 'webkit/api/src') diff --git a/webkit/api/src/StorageAreaProxy.cpp b/webkit/api/src/StorageAreaProxy.cpp index 736f97a..551507f 100644 --- a/webkit/api/src/StorageAreaProxy.cpp +++ b/webkit/api/src/StorageAreaProxy.cpp @@ -28,12 +28,15 @@ #if ENABLE(DOM_STORAGE) +#include "Document.h" #include "ExceptionCode.h" #include "Frame.h" #include "SecurityOrigin.h" #include "StorageAreaImpl.h" + #include "WebStorageArea.h" #include "WebString.h" +#include "WebURL.h" namespace WebCore { @@ -61,24 +64,21 @@ String StorageAreaProxy::getItem(const String& key) const return m_storageArea->getItem(key); } -void StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame*) +void StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame) { - // FIXME: Is frame any use to us? Probably not. bool quotaException = false; - m_storageArea->setItem(key, value, quotaException); + m_storageArea->setItem(key, value, frame->document()->url(), quotaException); ec = quotaException ? QUOTA_EXCEEDED_ERR : 0; } -void StorageAreaProxy::removeItem(const String& key, Frame*) +void StorageAreaProxy::removeItem(const String& key, Frame* frame) { - // FIXME: Is frame any use to us? Probably not. - m_storageArea->removeItem(key); + m_storageArea->removeItem(key, frame->document()->url()); } void StorageAreaProxy::clear(Frame* frame) { - // FIXME: Is frame any use to us? Probably not. - m_storageArea->clear(); + m_storageArea->clear(frame->document()->url()); } bool StorageAreaProxy::contains(const String& key) const diff --git a/webkit/api/src/StorageEventDispatcherChromium.cpp b/webkit/api/src/StorageEventDispatcherChromium.cpp index 9c283cd..3286929 100644 --- a/webkit/api/src/StorageEventDispatcherChromium.cpp +++ b/webkit/api/src/StorageEventDispatcherChromium.cpp @@ -39,6 +39,7 @@ #include "WebKit.h" #include "WebKitClient.h" #include "WebString.h" +#include "WebURL.h" namespace WebCore { @@ -47,7 +48,7 @@ void StorageEventDispatcher::dispatch(const String& key, const String& oldValue, SecurityOrigin* origin, Frame* sourceFrame) { ASSERT(!sourceFrame); // Sad, but true. - WebKit::webKitClient()->dispatchStorageEvent(key, oldValue, newValue, origin->toString(), storageType == LocalStorage); + WebKit::webKitClient()->dispatchStorageEvent(key, oldValue, newValue, origin->toString(), WebKit::WebURL(), storageType == LocalStorage); } } // namespace WebCore diff --git a/webkit/api/src/StorageEventDispatcherImpl.cpp b/webkit/api/src/StorageEventDispatcherImpl.cpp index 6dc6357..f07a5e0 100644 --- a/webkit/api/src/StorageEventDispatcherImpl.cpp +++ b/webkit/api/src/StorageEventDispatcherImpl.cpp @@ -36,6 +36,7 @@ #include "DOMWindow.h" #include "EventNames.h" #include "Frame.h" +#include "KURL.h" #include "Page.h" #include "PageGroup.h" #include "SecurityOrigin.h" @@ -50,8 +51,8 @@ StorageEventDispatcherImpl::StorageEventDispatcherImpl(const String& groupName) } void StorageEventDispatcherImpl::dispatchStorageEvent(const String& key, const String& oldValue, - const String& newValue, StorageType storageType, - SecurityOrigin* securityOrigin) + const String& newValue, SecurityOrigin* securityOrigin, + const KURL& url, StorageType storageType) { // FIXME: Implement if (storageType == SessionStorage) @@ -73,7 +74,7 @@ void StorageEventDispatcherImpl::dispatchStorageEvent(const String& key, const S // FIXME: Figure out how to pass in the document URI. for (unsigned i = 0; i < frames.size(); ++i) { frames[i]->document()->dispatchWindowEvent(StorageEvent::create(eventNames().storageEvent, key,oldValue, newValue, - String(), frames[i]->domWindow()->localStorage())); + url, frames[i]->domWindow()->localStorage())); } } diff --git a/webkit/api/src/StorageEventDispatcherImpl.h b/webkit/api/src/StorageEventDispatcherImpl.h index e0f57e2..08700ed 100644 --- a/webkit/api/src/StorageEventDispatcherImpl.h +++ b/webkit/api/src/StorageEventDispatcherImpl.h @@ -38,6 +38,7 @@ namespace WebCore { + class KURL; class PageGroup; class SecurityOrigin; @@ -46,8 +47,8 @@ namespace WebCore { StorageEventDispatcherImpl(const String& groupName); void dispatchStorageEvent(const String& key, const String& oldValue, - const String& newValue, StorageType, - SecurityOrigin*); + const String& newValue, SecurityOrigin*, + const KURL&, StorageType); private: PageGroup* m_pageGroup; diff --git a/webkit/api/src/WebStorageAreaImpl.cpp b/webkit/api/src/WebStorageAreaImpl.cpp index c835424..4e46f54 100644 --- a/webkit/api/src/WebStorageAreaImpl.cpp +++ b/webkit/api/src/WebStorageAreaImpl.cpp @@ -34,10 +34,14 @@ #if ENABLE(DOM_STORAGE) #include "ExceptionCode.h" + #include "WebString.h" +#include "WebURL.h" namespace WebKit { +const WebURL* WebStorageAreaImpl::storageEventURL = NULL; + WebStorageAreaImpl::WebStorageAreaImpl(PassRefPtr storageArea) : m_storageArea(storageArea) { @@ -62,11 +66,13 @@ WebString WebStorageAreaImpl::getItem(const WebString& key) return m_storageArea->getItem(key); } -void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, bool& quotaException) +void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException) { int exceptionCode = 0; - // FIXME: Can we do any better than just passing 0 for the frame? + + ScopedStorageEventURL scope(url); m_storageArea->setItem(key, value, exceptionCode, 0); + if (exceptionCode != 0) { ASSERT(exceptionCode == WebCore::QUOTA_EXCEEDED_ERR); quotaException = true; @@ -75,15 +81,15 @@ void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, b } } -void WebStorageAreaImpl::removeItem(const WebString& key) +void WebStorageAreaImpl::removeItem(const WebString& key, const WebURL& url) { - // FIXME: Can we do any better than just passing 0 for the frame? + ScopedStorageEventURL scope(url); m_storageArea->removeItem(key, 0); } -void WebStorageAreaImpl::clear() +void WebStorageAreaImpl::clear(const WebURL& url) { - // FIXME: Can we do any better than just passing 0 for the frame? + ScopedStorageEventURL scope(url); m_storageArea->clear(0); } diff --git a/webkit/api/src/WebStorageAreaImpl.h b/webkit/api/src/WebStorageAreaImpl.h index 5c57ae2..2a88af3 100644 --- a/webkit/api/src/WebStorageAreaImpl.h +++ b/webkit/api/src/WebStorageAreaImpl.h @@ -45,11 +45,32 @@ namespace WebKit { virtual unsigned length(); virtual WebString key(unsigned index); virtual WebString getItem(const WebString& key); - virtual void setItem(const WebString& key, const WebString& value, bool& quotaException); - virtual void removeItem(const WebString& key); - virtual void clear(); + virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException); + virtual void removeItem(const WebString& key, const WebURL& url); + virtual void clear(const WebURL& url); + + // For storage events in single-process mode and test shell. + static const WebURL* currentStorageEventURL() { return storageEventURL; } private: + class ScopedStorageEventURL { + public: + ScopedStorageEventURL(const WebURL& url) { + // FIXME: Once storage events are fired async in WebKit (as they should + // be) this can be ASSERTed to be NULL rather than saved. + m_existingStorageEventURL = storageEventURL; + storageEventURL = &url; + } + ~ScopedStorageEventURL() { + storageEventURL = m_existingStorageEventURL; + } + + private: + const WebURL* m_existingStorageEventURL; + }; + + static const WebURL* storageEventURL; + RefPtr m_storageArea; }; diff --git a/webkit/api/src/WebStorageEventDispatcherImpl.cpp b/webkit/api/src/WebStorageEventDispatcherImpl.cpp index 2e6df47..515a423 100644 --- a/webkit/api/src/WebStorageEventDispatcherImpl.cpp +++ b/webkit/api/src/WebStorageEventDispatcherImpl.cpp @@ -33,8 +33,12 @@ #if ENABLE(DOM_STORAGE) +#include "KURL.h" #include "SecurityOrigin.h" +#include "WebStorageAreaImpl.h" +#include "WebURL.h" + namespace WebKit { extern const char* pageGroupName; @@ -52,11 +56,15 @@ WebStorageEventDispatcherImpl::WebStorageEventDispatcherImpl() void WebStorageEventDispatcherImpl::dispatchStorageEvent(const WebString& key, const WebString& oldValue, const WebString& newValue, const WebString& origin, - bool isLocalStorage) + const WebURL& passedInURL, bool isLocalStorage) { + // Hack for single-process mode and test shell. + const WebURL* storageAreaImplURL = WebStorageAreaImpl::currentStorageEventURL(); + const WebURL& url = storageAreaImplURL ? *storageAreaImplURL : passedInURL; + WebCore::StorageType storageType = isLocalStorage ? WebCore::LocalStorage : WebCore::SessionStorage; RefPtr securityOrigin = WebCore::SecurityOrigin::createFromString(origin); - m_eventDispatcher->dispatchStorageEvent(key, oldValue, newValue, storageType, securityOrigin.get()); + m_eventDispatcher->dispatchStorageEvent(key, oldValue, newValue, securityOrigin.get(), url, storageType); } } // namespace WebKit diff --git a/webkit/api/src/WebStorageEventDispatcherImpl.h b/webkit/api/src/WebStorageEventDispatcherImpl.h index 464c4f3..aa3f066 100644 --- a/webkit/api/src/WebStorageEventDispatcherImpl.h +++ b/webkit/api/src/WebStorageEventDispatcherImpl.h @@ -46,7 +46,7 @@ namespace WebKit { virtual void dispatchStorageEvent(const WebString& key, const WebString& oldValue, const WebString& newValue, const WebString& origin, - bool isLocalStorage); + const WebURL& url, bool isLocalStorage); private: OwnPtr m_eventDispatcher; -- cgit v1.1