Changeset 53710 in webkit
- Timestamp:
- Jan 22, 2010 12:33:41 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r53709 r53710 1 2010-01-21 Jeremy Orlow <jorlow@chromium.org> 2 3 Reviewed by Darin Fisher. 4 5 The Chromium WebKit API needs to expose storage event related data 6 https://bugs.webkit.org/show_bug.cgi?id=33985 7 8 This change is not visible to layoutTests/web pages. 9 10 * storage/StorageArea.h: 11 * storage/StorageAreaImpl.cpp: 12 (WebCore::StorageAreaImpl::setItem): return the old value 13 (WebCore::StorageAreaImpl::removeItem): return the old value 14 (WebCore::StorageAreaImpl::clear): return whether there was anything to clear 15 * storage/StorageAreaImpl.h: 16 1 17 2010-01-22 Adele Peterson <adele@apple.com> 2 18 -
trunk/WebCore/storage/StorageArea.h
r48939 r53710 51 51 virtual String key(unsigned index) const = 0; 52 52 virtual String getItem(const String& key) const = 0; 53 virtual voidsetItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame) = 0;54 virtual voidremoveItem(const String& key, Frame* sourceFrame) = 0;55 virtual voidclear(Frame* sourceFrame) = 0;53 virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame) = 0; 54 virtual String removeItem(const String& key, Frame* sourceFrame) = 0; 55 virtual bool clear(Frame* sourceFrame) = 0; 56 56 virtual bool contains(const String& key) const = 0; 57 57 }; -
trunk/WebCore/storage/StorageAreaImpl.cpp
r50581 r53710 129 129 } 130 130 131 voidStorageAreaImpl::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)131 String StorageAreaImpl::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame) 132 132 { 133 133 ASSERT(!m_isShutdown); … … 137 137 if (privateBrowsingEnabled(frame)) { 138 138 ec = QUOTA_EXCEEDED_ERR; 139 return ;139 return String(); 140 140 } 141 141 … … 148 148 if (quotaException) { 149 149 ec = QUOTA_EXCEEDED_ERR; 150 return ;150 return oldValue; 151 151 } 152 152 153 153 if (oldValue == value) 154 return ;154 return oldValue; 155 155 156 156 if (m_storageAreaSync) 157 157 m_storageAreaSync->scheduleItemForSync(key, value); 158 158 StorageEventDispatcher::dispatch(key, oldValue, value, m_storageType, m_securityOrigin.get(), frame); 159 } 160 161 void StorageAreaImpl::removeItem(const String& key, Frame* frame) 159 return oldValue; 160 } 161 162 String StorageAreaImpl::removeItem(const String& key, Frame* frame) 162 163 { 163 164 ASSERT(!m_isShutdown); … … 165 166 166 167 if (privateBrowsingEnabled(frame)) 167 return ;168 return String(); 168 169 169 170 String oldValue; … … 173 174 174 175 if (oldValue.isNull()) 175 return ;176 return oldValue; 176 177 177 178 if (m_storageAreaSync) 178 179 m_storageAreaSync->scheduleItemForSync(key, String()); 179 180 StorageEventDispatcher::dispatch(key, oldValue, String(), m_storageType, m_securityOrigin.get(), frame); 180 } 181 182 void StorageAreaImpl::clear(Frame* frame) 181 return oldValue; 182 } 183 184 bool StorageAreaImpl::clear(Frame* frame) 183 185 { 184 186 ASSERT(!m_isShutdown); … … 186 188 187 189 if (privateBrowsingEnabled(frame)) 188 return ;190 return false; 189 191 190 192 if (!m_storageMap->length()) 191 return ;193 return false; 192 194 193 195 unsigned quota = m_storageMap->quota(); … … 197 199 m_storageAreaSync->scheduleClear(); 198 200 StorageEventDispatcher::dispatch(String(), String(), String(), m_storageType, m_securityOrigin.get(), frame); 201 return true; 199 202 } 200 203 -
trunk/WebCore/storage/StorageAreaImpl.h
r50581 r53710 49 49 virtual String key(unsigned index) const; 50 50 virtual String getItem(const String& key) const; 51 virtual voidsetItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);52 virtual voidremoveItem(const String& key, Frame* sourceFrame);53 virtual voidclear(Frame* sourceFrame);51 virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame); 52 virtual String removeItem(const String& key, Frame* sourceFrame); 53 virtual bool clear(Frame* sourceFrame); 54 54 virtual bool contains(const String& key) const; 55 55 -
trunk/WebKit/chromium/ChangeLog
r53705 r53710 1 2010-01-21 Jeremy Orlow <jorlow@chromium.org> 2 3 Reviewed by Darin Fisher. 4 5 The Chromium WebKit API needs to expose storage event related data 6 https://bugs.webkit.org/show_bug.cgi?id=33985 7 8 setItem and removeItem on WebStorageArea need to expose what the previous 9 value was for the key being modified. Clear needs to return whether it 10 actually cleared anything. 11 12 * public/WebStorageArea.h: 13 (WebKit::WebStorageArea::setItem): 14 (WebKit::WebStorageArea::removeItem): 15 (WebKit::WebStorageArea::clear): 16 * src/StorageAreaProxy.cpp: 17 (WebCore::StorageAreaProxy::StorageAreaProxy): 18 (WebCore::StorageAreaProxy::setItem): 19 (WebCore::StorageAreaProxy::removeItem): 20 (WebCore::StorageAreaProxy::clear): 21 (WebCore::StorageAreaProxy::storageEvent): 22 * src/StorageAreaProxy.h: 23 * src/StorageNamespaceProxy.cpp: 24 (WebCore::StorageNamespace::localStorageNamespace): 25 (WebCore::StorageNamespace::sessionStorageNamespace): 26 (WebCore::StorageNamespaceProxy::StorageNamespaceProxy): 27 (WebCore::StorageNamespaceProxy::copy): 28 (WebCore::StorageNamespaceProxy::storageArea): 29 * src/StorageNamespaceProxy.h: 30 * src/WebStorageAreaImpl.cpp: 31 (WebKit::WebStorageAreaImpl::setItem): 32 (WebKit::WebStorageAreaImpl::removeItem): 33 (WebKit::WebStorageAreaImpl::clear): 34 * src/WebStorageAreaImpl.h: 35 1 36 2010-01-21 Darin Fisher <darin@chromium.org> 2 37 -
trunk/WebKit/chromium/public/WebStorageArea.h
r50688 r53710 33 33 34 34 #include "WebCommon.h" 35 #include "WebString.h" 35 36 36 37 namespace WebKit { 37 38 38 class WebString;39 39 class WebURL; 40 40 … … 61 61 // the StorageArea would have exceeded its quota. The value is NOT set when there's 62 62 // an exception. url is the url that should be used if a storage event fires. 63 virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException) = 0; 63 // FIXME: The following is a hack to keep Chromium compiling until the other half is landed. Remove soon. 64 virtual void setItem(const WebString& key, const WebString& newValue, const WebURL& url, bool& quotaException) // Deprecated. 65 { 66 WebString oldValue; 67 setItem(key, newValue, url, quotaException, oldValue); 68 } 69 virtual void setItem(const WebString& key, const WebString& newValue, const WebURL& url, bool& quotaException, WebString& oldValue) 70 { 71 setItem(key, newValue, url, quotaException); 72 } 64 73 65 74 // Remove the value associated with a particular key. url is the url that should be used 66 75 // if a storage event fires. 67 virtual void removeItem(const WebString& key, const WebURL& url) = 0; 76 // FIXME: The following is a hack to keep Chromium compiling until the other half is landed. Remove soon. 77 virtual void removeItem(const WebString& key, const WebURL& url) // Deprecated. 78 { 79 WebString oldValue; 80 removeItem(key, url, oldValue); 81 } 82 virtual void removeItem(const WebString& key, const WebURL& url, WebString& oldValue) 83 { 84 removeItem(key, url); 85 } 68 86 69 87 // Clear all key/value pairs. url is the url that should be used if a storage event fires. 70 virtual void clear(const WebURL& url) = 0; 88 // FIXME: The following is a hack to keep Chromium compiling until the other half is landed. Remove soon. 89 virtual void clear(const WebURL& url) // Deprecated. 90 { 91 bool somethingCleared; 92 clear(url, somethingCleared); 93 } 94 virtual void clear(const WebURL& url, bool& somethingCleared) 95 { 96 clear(url); 97 } 71 98 }; 72 99 -
trunk/WebKit/chromium/src/StorageAreaProxy.cpp
r50746 r53710 1 1 /* 2 2 * Copyright (C) 2009 Google Inc. All Rights Reserved. 3 * (C) 2008 Apple Inc. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 29 30 #if ENABLE(DOM_STORAGE) 30 31 32 #include "DOMWindow.h" 31 33 #include "Document.h" 34 #include "EventNames.h" 32 35 #include "ExceptionCode.h" 33 36 #include "Frame.h" 37 #include "Page.h" 38 #include "PageGroup.h" 34 39 #include "SecurityOrigin.h" 35 40 #include "StorageAreaImpl.h" 41 #include "StorageEvent.h" 36 42 37 43 #include "WebStorageArea.h" … … 41 47 namespace WebCore { 42 48 43 StorageAreaProxy::StorageAreaProxy(WebKit::WebStorageArea* storageArea )49 StorageAreaProxy::StorageAreaProxy(WebKit::WebStorageArea* storageArea, StorageType storageType) 44 50 : m_storageArea(storageArea) 51 , m_storageType(storageType) 45 52 { 46 53 } … … 65 72 } 66 73 67 voidStorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)74 String StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame) 68 75 { 69 76 bool quotaException = false; 70 m_storageArea->setItem(key, value, frame->document()->url(), quotaException); 77 WebKit::WebString oldValue; 78 m_storageArea->setItem(key, value, frame->document()->url(), quotaException, oldValue); 71 79 ec = quotaException ? QUOTA_EXCEEDED_ERR : 0; 80 String oldValueString = oldValue; 81 if (oldValueString != value) 82 storageEvent(key, oldValue, value, m_storageType, frame->document()->securityOrigin(), frame); 83 return oldValue; 72 84 } 73 85 74 voidStorageAreaProxy::removeItem(const String& key, Frame* frame)86 String StorageAreaProxy::removeItem(const String& key, Frame* frame) 75 87 { 76 m_storageArea->removeItem(key, frame->document()->url()); 88 WebKit::WebString oldValue; 89 m_storageArea->removeItem(key, frame->document()->url(), oldValue); 90 if (!oldValue.isNull()) 91 storageEvent(key, oldValue, String(), m_storageType, frame->document()->securityOrigin(), frame); 92 return oldValue; 77 93 } 78 94 79 voidStorageAreaProxy::clear(Frame* frame)95 bool StorageAreaProxy::clear(Frame* frame) 80 96 { 81 m_storageArea->clear(frame->document()->url()); 97 bool clearedSomething; 98 m_storageArea->clear(frame->document()->url(), clearedSomething); 99 if (clearedSomething) 100 storageEvent(String(), String(), String(), m_storageType, frame->document()->securityOrigin(), frame); 101 return clearedSomething; 82 102 } 83 103 … … 87 107 } 88 108 109 // Copied from WebCore/storage/StorageEventDispatcher.cpp out of necessity. It's probably best to keep it current. 110 void StorageAreaProxy::storageEvent(const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Frame* sourceFrame) 111 { 112 Page* page = sourceFrame->page(); 113 if (!page) 114 return; 115 116 // We need to copy all relevant frames from every page to a vector since sending the event to one frame might mutate the frame tree 117 // of any given page in the group or mutate the page group itself. 118 Vector<RefPtr<Frame> > frames; 119 if (storageType == SessionStorage) { 120 // Send events only to our page. 121 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) { 122 if (frame->document()->securityOrigin()->equal(securityOrigin)) 123 frames.append(frame); 124 } 125 126 for (unsigned i = 0; i < frames.size(); ++i) 127 frames[i]->document()->dispatchWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->sessionStorage())); 128 } else { 129 // Send events to every page. 130 const HashSet<Page*>& pages = page->group().pages(); 131 HashSet<Page*>::const_iterator end = pages.end(); 132 for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) { 133 for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree()->traverseNext()) { 134 if (frame->document()->securityOrigin()->equal(securityOrigin)) 135 frames.append(frame); 136 } 137 } 138 139 for (unsigned i = 0; i < frames.size(); ++i) 140 frames[i]->document()->dispatchWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->localStorage())); 141 } 142 } 143 89 144 } // namespace WebCore 90 145 -
trunk/WebKit/chromium/src/StorageAreaProxy.h
r50746 r53710 35 35 namespace WebCore { 36 36 37 class Frame; 38 class SecurityOrigin; 39 37 40 class StorageAreaProxy : public StorageArea { 38 41 public: 39 StorageAreaProxy(WebKit::WebStorageArea* storageArea);42 StorageAreaProxy(WebKit::WebStorageArea*, StorageType); 40 43 virtual ~StorageAreaProxy(); 41 44 … … 44 47 virtual String key(unsigned index) const; 45 48 virtual String getItem(const String& key) const; 46 virtual voidsetItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);47 virtual voidremoveItem(const String& key, Frame* sourceFrame);48 virtual voidclear(Frame* sourceFrame);49 virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame); 50 virtual String removeItem(const String& key, Frame* sourceFrame); 51 virtual bool clear(Frame* sourceFrame); 49 52 virtual bool contains(const String& key) const; 50 53 51 54 private: 55 void storageEvent(const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*, Frame* sourceFrame); 56 52 57 OwnPtr<WebKit::WebStorageArea> m_storageArea; 58 StorageType m_storageType; 53 59 }; 54 60 -
trunk/WebKit/chromium/src/StorageNamespaceProxy.cpp
r53321 r53710 45 45 PassRefPtr<StorageNamespace> StorageNamespace::localStorageNamespace(const String& path, unsigned quota) 46 46 { 47 return adoptRef(new StorageNamespaceProxy(WebKit::webKitClient()->createLocalStorageNamespace(path, quota) ));47 return adoptRef(new StorageNamespaceProxy(WebKit::webKitClient()->createLocalStorageNamespace(path, quota), LocalStorage)); 48 48 } 49 49 … … 52 52 WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClientImpl*>(page->chrome()->client()); 53 53 WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client(); 54 return adoptRef(new StorageNamespaceProxy(webViewClient->createSessionStorageNamespace() ));54 return adoptRef(new StorageNamespaceProxy(webViewClient->createSessionStorageNamespace(), SessionStorage)); 55 55 } 56 56 57 StorageNamespaceProxy::StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace )57 StorageNamespaceProxy::StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace, StorageType storageType) 58 58 : m_storageNamespace(storageNamespace) 59 , m_storageType(storageType) 59 60 { 60 61 } … … 66 67 PassRefPtr<StorageNamespace> StorageNamespaceProxy::copy() 67 68 { 68 return adoptRef(new StorageNamespaceProxy(m_storageNamespace->copy() ));69 return adoptRef(new StorageNamespaceProxy(m_storageNamespace->copy(), m_storageType)); 69 70 } 70 71 71 72 PassRefPtr<StorageArea> StorageNamespaceProxy::storageArea(PassRefPtr<SecurityOrigin> origin) 72 73 { 73 return adoptRef(new StorageAreaProxy(m_storageNamespace->createStorageArea(origin->toString()) ));74 return adoptRef(new StorageAreaProxy(m_storageNamespace->createStorageArea(origin->toString()), m_storageType)); 74 75 } 75 76 -
trunk/WebKit/chromium/src/StorageNamespaceProxy.h
r50746 r53710 29 29 #if ENABLE(DOM_STORAGE) 30 30 31 #include "StorageArea.h" 31 32 #include "StorageNamespace.h" 32 33 … … 37 38 class StorageNamespaceProxy : public StorageNamespace { 38 39 public: 39 StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace);40 StorageNamespaceProxy(WebKit::WebStorageNamespace*, StorageType); 40 41 virtual ~StorageNamespaceProxy(); 41 42 virtual PassRefPtr<StorageArea> storageArea(PassRefPtr<SecurityOrigin>); … … 46 47 private: 47 48 OwnPtr<WebKit::WebStorageNamespace> m_storageNamespace; 49 StorageType m_storageType; 48 50 }; 49 51 -
trunk/WebKit/chromium/src/WebStorageAreaImpl.cpp
r50723 r53710 67 67 } 68 68 69 void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException )69 void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException, WebString& oldValue) 70 70 { 71 71 int exceptionCode = 0; 72 72 73 73 ScopedStorageEventURL scope(url); 74 m_storageArea->setItem(key, value, exceptionCode, 0);74 oldValue = m_storageArea->setItem(key, value, exceptionCode, 0); 75 75 76 76 if (exceptionCode) { … … 81 81 } 82 82 83 void WebStorageAreaImpl::removeItem(const WebString& key, const WebURL& url )83 void WebStorageAreaImpl::removeItem(const WebString& key, const WebURL& url, WebString& oldValue) 84 84 { 85 85 ScopedStorageEventURL scope(url); 86 m_storageArea->removeItem(key, 0);86 oldValue = m_storageArea->removeItem(key, 0); 87 87 } 88 88 89 void WebStorageAreaImpl::clear(const WebURL& url )89 void WebStorageAreaImpl::clear(const WebURL& url, bool& somethingCleared) 90 90 { 91 91 ScopedStorageEventURL scope(url); 92 m_storageArea->clear(0);92 somethingCleared = m_storageArea->clear(0); 93 93 } 94 94 -
trunk/WebKit/chromium/src/WebStorageAreaImpl.h
r50723 r53710 46 46 virtual WebString key(unsigned index); 47 47 virtual WebString getItem(const WebString& key); 48 virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException );49 virtual void removeItem(const WebString& key, const WebURL& url );50 virtual void clear(const WebURL& url );48 virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException, WebString& oldValue); 49 virtual void removeItem(const WebString& key, const WebURL& url, WebString& oldValue); 50 virtual void clear(const WebURL& url, bool& somethingCleared); 51 51 52 52 // For storage events in single-process mode and test shell.
Note: See TracChangeset
for help on using the changeset viewer.