Title: [150346] trunk/Source
Revision
150346
Author
[email protected]
Date
2013-05-18 17:06:45 -0700 (Sat, 18 May 2013)

Log Message

Simplify the StorageArea setter functions
https://bugs.webkit.org/show_bug.cgi?id=116402

Reviewed by Sam Weinig.

Source/WebCore:

Move more security checking code to Storage so more code can be shared between WebKit1 and WebKit2.

* inspector/InspectorDOMStorageAgent.cpp:
(WebCore::InspectorDOMStorageAgent::setDOMStorageItem):
(WebCore::InspectorDOMStorageAgent::removeDOMStorageItem):
* storage/Storage.cpp:
(WebCore::Storage::setItem):
(WebCore::Storage::removeItem):
(WebCore::Storage::clear):
* storage/StorageArea.h:
(StorageArea):
* storage/StorageAreaImpl.cpp:
(WebCore::StorageAreaImpl::setItem):
(WebCore::StorageAreaImpl::removeItem):
(WebCore::StorageAreaImpl::clear):
* storage/StorageAreaImpl.h:
(StorageAreaImpl):

Source/WebKit2:

Remove security checking code that lives in Storage now.

* WebProcess/Storage/StorageAreaImpl.cpp:
(WebKit::StorageAreaImpl::setItem):
(WebKit::StorageAreaImpl::removeItem):
(WebKit::StorageAreaImpl::clear):
* WebProcess/Storage/StorageAreaImpl.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (150345 => 150346)


--- trunk/Source/WebCore/ChangeLog	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebCore/ChangeLog	2013-05-19 00:06:45 UTC (rev 150346)
@@ -1,5 +1,30 @@
 2013-05-18  Anders Carlsson  <[email protected]>
 
+        Simplify the StorageArea setter functions
+        https://bugs.webkit.org/show_bug.cgi?id=116402
+
+        Reviewed by Sam Weinig.
+
+        Move more security checking code to Storage so more code can be shared between WebKit1 and WebKit2.
+
+        * inspector/InspectorDOMStorageAgent.cpp:
+        (WebCore::InspectorDOMStorageAgent::setDOMStorageItem):
+        (WebCore::InspectorDOMStorageAgent::removeDOMStorageItem):
+        * storage/Storage.cpp:
+        (WebCore::Storage::setItem):
+        (WebCore::Storage::removeItem):
+        (WebCore::Storage::clear):
+        * storage/StorageArea.h:
+        (StorageArea):
+        * storage/StorageAreaImpl.cpp:
+        (WebCore::StorageAreaImpl::setItem):
+        (WebCore::StorageAreaImpl::removeItem):
+        (WebCore::StorageAreaImpl::clear):
+        * storage/StorageAreaImpl.h:
+        (StorageAreaImpl):
+
+2013-05-18  Anders Carlsson  <[email protected]>
+
         Simplify StorageArea getter functions
         https://bugs.webkit.org/show_bug.cgi?id=116399
 

Modified: trunk/Source/WebCore/inspector/InspectorDOMStorageAgent.cpp (150345 => 150346)


--- trunk/Source/WebCore/inspector/InspectorDOMStorageAgent.cpp	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebCore/inspector/InspectorDOMStorageAgent.cpp	2013-05-19 00:06:45 UTC (rev 150346)
@@ -125,15 +125,6 @@
     items = storageItems.release();
 }
 
-static String toErrorString(const ExceptionCode& ec)
-{
-    if (ec) {
-        ExceptionCodeDescription description(ec);
-        return description.name;
-    }
-    return "";
-}
-
 void InspectorDOMStorageAgent::setDOMStorageItem(ErrorString* errorString, const RefPtr<InspectorObject>& storageId, const String& key, const String& value)
 {
     Frame* frame;
@@ -143,9 +134,10 @@
         return;
     }
 
-    ExceptionCode exception = 0;
-    storageArea->setItem(key, value, exception, frame);
-    *errorString = toErrorString(exception);
+    bool quotaException = false;
+    storageArea->setItem(frame, key, value, quotaException);
+    if (quotaException)
+        *errorString = ExceptionCodeDescription(QUOTA_EXCEEDED_ERR).name;
 }
 
 void InspectorDOMStorageAgent::removeDOMStorageItem(ErrorString* errorString, const RefPtr<InspectorObject>& storageId, const String& key)
@@ -157,9 +149,7 @@
         return;
     }
 
-    ExceptionCode exception = 0;
-    storageArea->removeItem(key, exception, frame);
-    *errorString = toErrorString(exception);
+    storageArea->removeItem(frame, key);
 }
 
 String InspectorDOMStorageAgent::storageId(Storage* storage)

Modified: trunk/Source/WebCore/storage/Storage.cpp (150345 => 150346)


--- trunk/Source/WebCore/storage/Storage.cpp	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebCore/storage/Storage.cpp	2013-05-19 00:06:45 UTC (rev 150346)
@@ -100,17 +100,47 @@
 
 void Storage::setItem(const String& key, const String& value, ExceptionCode& ec)
 {
-    m_storageArea->setItem(key, value, ec, m_frame);
+    if (!m_storageArea->canAccessStorage(m_frame)) {
+        ec = SECURITY_ERR;
+        return;
+    }
+
+    if (isDisabledByPrivateBrowsing()) {
+        ec = QUOTA_EXCEEDED_ERR;
+        return;
+    }
+
+    bool quotaException = false;
+    m_storageArea->setItem(m_frame, key, value, quotaException);
+
+    if (quotaException)
+        ec = QUOTA_EXCEEDED_ERR;
 }
 
 void Storage::removeItem(const String& key, ExceptionCode& ec)
 {
-    m_storageArea->removeItem(key, ec, m_frame);
+    if (!m_storageArea->canAccessStorage(m_frame)) {
+        ec = SECURITY_ERR;
+        return;
+    }
+
+    if (isDisabledByPrivateBrowsing())
+        return;
+
+    m_storageArea->removeItem(m_frame, key);
 }
 
 void Storage::clear(ExceptionCode& ec)
 {
-    m_storageArea->clear(ec, m_frame);
+    if (!m_storageArea->canAccessStorage(m_frame)) {
+        ec = SECURITY_ERR;
+        return;
+    }
+
+    if (isDisabledByPrivateBrowsing())
+        return;
+
+    m_storageArea->clear(m_frame);
 }
 
 bool Storage::contains(const String& key, ExceptionCode& ec) const

Modified: trunk/Source/WebCore/storage/StorageArea.h (150345 => 150346)


--- trunk/Source/WebCore/storage/StorageArea.h	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebCore/storage/StorageArea.h	2013-05-19 00:06:45 UTC (rev 150346)
@@ -42,14 +42,12 @@
 public:
     virtual ~StorageArea() { }
 
-    // The HTML5 DOM Storage API
-    // FIXME: We should pass Document instead of Frame. Also, that parameter should go first.
     virtual unsigned length() = 0;
     virtual String key(unsigned index) = 0;
     virtual String item(const String& key) = 0;
-    virtual void setItem(const String& key, const String& value, ExceptionCode&, Frame* sourceFrame) = 0;
-    virtual void removeItem(const String& key, ExceptionCode&, Frame* sourceFrame) = 0;
-    virtual void clear(ExceptionCode&, Frame* sourceFrame) = 0;
+    virtual void setItem(Frame* sourceFrame, const String& key, const String& value, bool& quotaException) = 0;
+    virtual void removeItem(Frame* sourceFrame, const String& key) = 0;
+    virtual void clear(Frame* sourceFrame) = 0;
     virtual bool contains(const String& key) = 0;
 
     virtual bool canAccessStorage(Frame*) = 0;

Modified: trunk/Source/WebCore/storage/StorageAreaImpl.cpp (150345 => 150346)


--- trunk/Source/WebCore/storage/StorageAreaImpl.cpp	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebCore/storage/StorageAreaImpl.cpp	2013-05-19 00:06:45 UTC (rev 150346)
@@ -114,15 +114,6 @@
     return m_storageType;
 }
 
-bool StorageAreaImpl::disabledByPrivateBrowsingInFrame(const Frame* frame) const
-{
-    if (!frame->page()->settings()->privateBrowsingEnabled())
-        return false;
-    if (m_storageType != LocalStorage)
-        return true;
-    return !SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(frame->document()->securityOrigin()->protocol());
-}
-
 unsigned StorageAreaImpl::length()
 {
     ASSERT(!m_isShutdown);
@@ -147,33 +138,19 @@
     return m_storageMap->getItem(key);
 }
 
-void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)
+void StorageAreaImpl::setItem(Frame* sourceFrame, const String& key, const String& value, bool& quotaException)
 {
-    ec = 0;
-    if (!canAccessStorage(frame)) {
-        ec = SECURITY_ERR;
-        return;
-    }
-
     ASSERT(!m_isShutdown);
     ASSERT(!value.isNull());
     blockUntilImportComplete();
 
-    if (disabledByPrivateBrowsingInFrame(frame)) {
-        ec = QUOTA_EXCEEDED_ERR;
-        return;
-    }
-
     String oldValue;
-    bool quotaException;
     RefPtr<StorageMap> newMap = m_storageMap->setItem(key, value, oldValue, quotaException);
     if (newMap)
         m_storageMap = newMap.release();
 
-    if (quotaException) {
-        ec = QUOTA_EXCEEDED_ERR;
+    if (quotaException)
         return;
-    }
 
     if (oldValue == value)
         return;
@@ -181,23 +158,14 @@
     if (m_storageAreaSync)
         m_storageAreaSync->scheduleItemForSync(key, value);
 
-    dispatchStorageEvent(key, oldValue, value, frame);
+    dispatchStorageEvent(key, oldValue, value, sourceFrame);
 }
 
-void StorageAreaImpl::removeItem(const String& key, ExceptionCode& ec, Frame* frame)
+void StorageAreaImpl::removeItem(Frame* sourceFrame, const String& key)
 {
-    ec = 0;
-    if (!canAccessStorage(frame)) {
-        ec = SECURITY_ERR;
-        return;
-    }
-
     ASSERT(!m_isShutdown);
     blockUntilImportComplete();
 
-    if (disabledByPrivateBrowsingInFrame(frame))
-        return;
-
     String oldValue;
     RefPtr<StorageMap> newMap = m_storageMap->removeItem(key, oldValue);
     if (newMap)
@@ -208,23 +176,15 @@
 
     if (m_storageAreaSync)
         m_storageAreaSync->scheduleItemForSync(key, String());
-    dispatchStorageEvent(key, oldValue, String(), frame);
+
+    dispatchStorageEvent(key, oldValue, String(), sourceFrame);
 }
 
-void StorageAreaImpl::clear(ExceptionCode& ec, Frame* frame)
+void StorageAreaImpl::clear(Frame* sourceFrame)
 {
-    ec = 0;
-    if (!canAccessStorage(frame)) {
-        ec = SECURITY_ERR;
-        return;
-    }
-
     ASSERT(!m_isShutdown);
     blockUntilImportComplete();
 
-    if (disabledByPrivateBrowsingInFrame(frame))
-        return;
-
     if (!m_storageMap->length())
         return;
 
@@ -233,7 +193,8 @@
 
     if (m_storageAreaSync)
         m_storageAreaSync->scheduleClear();
-    dispatchStorageEvent(String(), String(), String(), frame);
+
+    dispatchStorageEvent(String(), String(), String(), sourceFrame);
 }
 
 bool StorageAreaImpl::contains(const String& key)

Modified: trunk/Source/WebCore/storage/StorageAreaImpl.h (150345 => 150346)


--- trunk/Source/WebCore/storage/StorageAreaImpl.h	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebCore/storage/StorageAreaImpl.h	2013-05-19 00:06:45 UTC (rev 150346)
@@ -47,9 +47,9 @@
     virtual unsigned length() OVERRIDE;
     virtual String key(unsigned index) OVERRIDE;
     virtual String item(const String& key) OVERRIDE;
-    virtual void setItem(const String& key, const String& value, ExceptionCode&, Frame* sourceFrame) OVERRIDE;
-    virtual void removeItem(const String& key, ExceptionCode&, Frame* sourceFrame) OVERRIDE;
-    virtual void clear(ExceptionCode&, Frame* sourceFrame) OVERRIDE;
+    virtual void setItem(Frame* sourceFrame, const String& key, const String& value, bool& quotaException) OVERRIDE;
+    virtual void removeItem(Frame* sourceFrame, const String& key) OVERRIDE;
+    virtual void clear(Frame* sourceFrame) OVERRIDE;
     virtual bool contains(const String& key) OVERRIDE;
 
     virtual bool canAccessStorage(Frame* sourceFrame) OVERRIDE;
@@ -78,7 +78,6 @@
 
     void blockUntilImportComplete() const;
     void closeDatabaseTimerFired(Timer<StorageAreaImpl>*);
-    bool disabledByPrivateBrowsingInFrame(const Frame* sourceFrame) const;
 
     void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
 

Modified: trunk/Source/WebKit2/ChangeLog (150345 => 150346)


--- trunk/Source/WebKit2/ChangeLog	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebKit2/ChangeLog	2013-05-19 00:06:45 UTC (rev 150346)
@@ -1,3 +1,18 @@
+2013-05-18  Anders Carlsson  <[email protected]>
+
+        Simplify the StorageArea setter functions
+        https://bugs.webkit.org/show_bug.cgi?id=116402
+
+        Reviewed by Sam Weinig.
+
+        Remove security checking code that lives in Storage now.
+
+        * WebProcess/Storage/StorageAreaImpl.cpp:
+        (WebKit::StorageAreaImpl::setItem):
+        (WebKit::StorageAreaImpl::removeItem):
+        (WebKit::StorageAreaImpl::clear):
+        * WebProcess/Storage/StorageAreaImpl.h:
+
 2013-05-18  Sam Weinig  <[email protected]>
 
         Fix some builds.

Modified: trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.cpp (150345 => 150346)


--- trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.cpp	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.cpp	2013-05-19 00:06:45 UTC (rev 150346)
@@ -74,53 +74,20 @@
     return m_storageAreaMap->item(key);
 }
 
-void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame)
+void StorageAreaImpl::setItem(Frame* sourceFrame, const String& key, const String& value, bool& quotaException)
 {
-    ec = 0;
-    if (!canAccessStorage(sourceFrame)) {
-        ec = SECURITY_ERR;
-        return;
-    }
-
     ASSERT(!value.isNull());
 
-    if (disabledByPrivateBrowsingInFrame(sourceFrame)) {
-        ec = QUOTA_EXCEEDED_ERR;
-        return;
-    }
-
-    bool quotaException;
     m_storageAreaMap->setItem(sourceFrame, this, key, value, quotaException);
-
-    if (quotaException)
-        ec = QUOTA_EXCEEDED_ERR;
 }
 
-void StorageAreaImpl::removeItem(const String& key, ExceptionCode& ec, Frame* sourceFrame)
+void StorageAreaImpl::removeItem(Frame* sourceFrame, const String& key)
 {
-    ec = 0;
-    if (!canAccessStorage(sourceFrame)) {
-        ec = SECURITY_ERR;
-        return;
-    }
-
-    if (disabledByPrivateBrowsingInFrame(sourceFrame))
-        return;
-
     m_storageAreaMap->removeItem(sourceFrame, this, key);
 }
 
-void StorageAreaImpl::clear(ExceptionCode& ec, Frame* sourceFrame)
+void StorageAreaImpl::clear(Frame* sourceFrame)
 {
-    ec = 0;
-    if (!canAccessStorage(sourceFrame)) {
-        ec = SECURITY_ERR;
-        return;
-    }
-
-    if (disabledByPrivateBrowsingInFrame(sourceFrame))
-        return;
-
     m_storageAreaMap->clear(sourceFrame, this);
 }
 
@@ -160,15 +127,4 @@
     ASSERT_NOT_REACHED();
 }
 
-bool StorageAreaImpl::disabledByPrivateBrowsingInFrame(const Frame* sourceFrame) const
-{
-    if (!sourceFrame->page()->settings()->privateBrowsingEnabled())
-        return false;
-
-    if (storageType() != LocalStorage)
-        return true;
-
-    return !SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(sourceFrame->document()->securityOrigin()->protocol());
-}
-
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.h (150345 => 150346)


--- trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.h	2013-05-18 23:40:12 UTC (rev 150345)
+++ trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.h	2013-05-19 00:06:45 UTC (rev 150346)
@@ -49,9 +49,9 @@
     virtual unsigned length() OVERRIDE;
     virtual String key(unsigned index) OVERRIDE;
     virtual String item(const String& key) OVERRIDE;
-    virtual void setItem(const String& key, const String& value, WebCore::ExceptionCode&, WebCore::Frame* sourceFrame) OVERRIDE;
-    virtual void removeItem(const String& key, WebCore::ExceptionCode&, WebCore::Frame* sourceFrame) OVERRIDE;
-    virtual void clear(WebCore::ExceptionCode&, WebCore::Frame* sourceFrame) OVERRIDE;
+    virtual void setItem(WebCore::Frame* sourceFrame, const String& key, const String& value, bool& quotaException) OVERRIDE;
+    virtual void removeItem(WebCore::Frame* sourceFrame, const String& key) OVERRIDE;
+    virtual void clear(WebCore::Frame* sourceFrame) OVERRIDE;
     virtual bool contains(const String& key) OVERRIDE;
     virtual bool canAccessStorage(WebCore::Frame*) OVERRIDE;
     virtual WebCore::StorageType storageType() const OVERRIDE;
@@ -60,8 +60,6 @@
     virtual void decrementAccessCount() OVERRIDE;
     virtual void closeDatabaseIfIdle() OVERRIDE;
 
-    bool disabledByPrivateBrowsingInFrame(const WebCore::Frame* sourceFrame) const;
-
     uint64_t m_storageAreaID;
     RefPtr<StorageAreaMap> m_storageAreaMap;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to