WebCore:
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Apr 2008 03:14:28 +0000 (03:14 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Apr 2008 03:14:28 +0000 (03:14 +0000)
2008-04-28  Brady Eidson <beidson@apple.com>

        Reviewed by Sam Weinig

        Add Storage.clear(), per updates to HTML5

        Tests: storage/domstorage/localstorage/clear.html
               storage/domstorage/sessionstorage/clear.html

        * storage/LocalStorageArea.cpp:
        (WebCore::LocalStorageArea::areaCleared):
        * storage/LocalStorageArea.h:

        * storage/SessionStorageArea.cpp:
        (WebCore::SessionStorageArea::areaCleared):
        * storage/SessionStorageArea.h:

        * storage/Storage.cpp:
        (WebCore::Storage::clear):
        * storage/Storage.h:
        * storage/Storage.idl:

        * storage/StorageArea.cpp:
        (WebCore::StorageArea::internalClear):
        * storage/StorageArea.h:
        (WebCore::StorageArea::clear):

LayoutTests:

2008-04-28  Brady Eidson  <beidson@apple.com>

        Reviewed by Sam Weinig

        Add Storage.clear(), per updates to HTML5

        * storage/domstorage/localstorage/clear-expected.txt: Added.
        * storage/domstorage/localstorage/clear.html: Added.
        * storage/domstorage/sessionstorage/clear-expected.txt: Added.
        * storage/domstorage/sessionstorage/clear.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@32668 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/storage/domstorage/localstorage/clear-expected.txt [new file with mode: 0644]
LayoutTests/storage/domstorage/localstorage/clear.html [new file with mode: 0644]
LayoutTests/storage/domstorage/sessionstorage/clear-expected.txt [new file with mode: 0644]
LayoutTests/storage/domstorage/sessionstorage/clear.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/storage/LocalStorageArea.cpp
WebCore/storage/LocalStorageArea.h
WebCore/storage/SessionStorageArea.cpp
WebCore/storage/SessionStorageArea.h
WebCore/storage/Storage.cpp
WebCore/storage/Storage.h
WebCore/storage/Storage.idl
WebCore/storage/StorageArea.cpp
WebCore/storage/StorageArea.h

index 6ea1a55..4ae554f 100644 (file)
@@ -1,3 +1,14 @@
+2008-04-28  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Sam Weinig
+
+        Add Storage.clear(), per updates to HTML5
+
+        * storage/domstorage/localstorage/clear-expected.txt: Added.
+        * storage/domstorage/localstorage/clear.html: Added.
+        * storage/domstorage/sessionstorage/clear-expected.txt: Added.
+        * storage/domstorage/sessionstorage/clear.html: Added.
+
 2008-04-28  Alice Liu  <alice.liu@apple.com>
 
         Reviewed by Sam Weinig.
diff --git a/LayoutTests/storage/domstorage/localstorage/clear-expected.txt b/LayoutTests/storage/domstorage/localstorage/clear-expected.txt
new file mode 100644 (file)
index 0000000..7029325
--- /dev/null
@@ -0,0 +1,11 @@
+This test exercises storage.clear() on the local storage area.
+Length is 0
+Clearing an empty storage area didn't crash
+Length is 2
+Value for FOO is MyFOO
+Value for BAR is MyBar
+Cleared the storage area
+Length is 0
+Value for FOO is undefined
+Value for BAR is undefined
+
diff --git a/LayoutTests/storage/domstorage/localstorage/clear.html b/LayoutTests/storage/domstorage/localstorage/clear.html
new file mode 100644 (file)
index 0000000..55907f8
--- /dev/null
@@ -0,0 +1,45 @@
+<html>
+<head>
+<script src="resources/clearLocalStorage.js"></script>
+<script>
+
+if (layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(a)
+{
+    document.getElementById("logger").innerHTML += a + "<br>";
+}
+
+function runTest()
+{
+    if (!window.localStorage) {
+        log("window.localStorage DOES NOT exist");
+        return;
+    }
+    
+    log("Length is " + localStorage.length);
+
+    localStorage.clear();
+    log("Clearing an empty storage area didn't crash");
+
+    localStorage['FOO'] = 'MyFOO';
+    localStorage['BAR'] = 'MyBar';
+    log("Length is " + localStorage.length);
+    log("Value for FOO is " + localStorage['FOO']);
+    log("Value for BAR is " + localStorage['BAR']);
+
+    localStorage.clear();    
+    log("Cleared the storage area");
+    log("Length is " + localStorage.length);
+    log("Value for FOO is " + localStorage['FOO']);
+    log("Value for BAR is " + localStorage['BAR']);    
+}
+
+</script>
+</head>
+<body onload="runTest();">
+This test exercises storage.clear() on the local storage area.
+<div id="logger"></div>
+</body>
+</html>
diff --git a/LayoutTests/storage/domstorage/sessionstorage/clear-expected.txt b/LayoutTests/storage/domstorage/sessionstorage/clear-expected.txt
new file mode 100644 (file)
index 0000000..f121675
--- /dev/null
@@ -0,0 +1,11 @@
+This test exercises storage.clear() on the session storage area.
+Length is 0
+Clearing an empty storage area didn't crash
+Length is 2
+Value for FOO is MyFOO
+Value for BAR is MyBar
+Cleared the storage area
+Length is 0
+Value for FOO is undefined
+Value for BAR is undefined
+
diff --git a/LayoutTests/storage/domstorage/sessionstorage/clear.html b/LayoutTests/storage/domstorage/sessionstorage/clear.html
new file mode 100644 (file)
index 0000000..13f228a
--- /dev/null
@@ -0,0 +1,45 @@
+<html>
+<head>
+<script src="resources/clearSessionStorage.js"></script>
+<script>
+
+if (layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(a)
+{
+    document.getElementById("logger").innerHTML += a + "<br>";
+}
+
+function runTest()
+{
+    if (!window.sessionStorage) {
+        log("window.sessionStorage DOES NOT exist");
+        return;
+    }
+    
+    log("Length is " + sessionStorage.length);
+
+    sessionStorage.clear();
+    log("Clearing an empty storage area didn't crash");
+
+    sessionStorage['FOO'] = 'MyFOO';
+    sessionStorage['BAR'] = 'MyBar';
+    log("Length is " + sessionStorage.length);
+    log("Value for FOO is " + sessionStorage['FOO']);
+    log("Value for BAR is " + sessionStorage['BAR']);
+
+    sessionStorage.clear();    
+    log("Cleared the storage area");
+    log("Length is " + sessionStorage.length);
+    log("Value for FOO is " + sessionStorage['FOO']);
+    log("Value for BAR is " + sessionStorage['BAR']);    
+}
+
+</script>
+</head>
+<body onload="runTest();">
+This test exercises storage.clear() on the session storage area.
+<div id="logger"></div>
+</body>
+</html>
index 702572d..32e9a36 100644 (file)
@@ -1,3 +1,30 @@
+2008-04-28  Brady Eidson <beidson@apple.com>
+
+        Reviewed by Sam Weinig
+
+        Add Storage.clear(), per updates to HTML5
+
+        Tests: storage/domstorage/localstorage/clear.html
+               storage/domstorage/sessionstorage/clear.html
+
+        * storage/LocalStorageArea.cpp:
+        (WebCore::LocalStorageArea::areaCleared):
+        * storage/LocalStorageArea.h:
+
+        * storage/SessionStorageArea.cpp:
+        (WebCore::SessionStorageArea::areaCleared):
+        * storage/SessionStorageArea.h:
+
+        * storage/Storage.cpp:
+        (WebCore::Storage::clear):
+        * storage/Storage.h:
+        * storage/Storage.idl:
+
+        * storage/StorageArea.cpp:
+        (WebCore::StorageArea::internalClear):
+        * storage/StorageArea.h:
+        (WebCore::StorageArea::clear):
+
 2008-04-28  Adele Peterson  <adele@apple.com>
 
         Reviewed by Dan Bernstein, Tim Hatcher, Anders Carlsson, and Darin Adler.
index 9e10153..e16d972 100644 (file)
@@ -56,6 +56,13 @@ void LocalStorageArea::itemRemoved(const String& key, const String& oldValue, Fr
     dispatchStorageEvent(key, oldValue, String(), sourceFrame);
 }
 
+void LocalStorageArea::areaCleared(Frame* sourceFrame)
+{
+    // FIXME: Flag this clearing to be written out to the persistent store
+
+    dispatchStorageEvent(String(), String(), String(), sourceFrame);
+}
+
 void LocalStorageArea::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame)
 {
     Page* page = sourceFrame->page();
index 2dbf4c4..f92ee29 100644 (file)
@@ -43,6 +43,7 @@ namespace WebCore {
 
         virtual void itemChanged(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
         virtual void itemRemoved(const String& key, const String& oldValue, Frame* sourceFrame);
+        virtual void areaCleared(Frame* sourceFrame);
 
         void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
         
index 9b3702f..bee3bf3 100644 (file)
@@ -65,6 +65,11 @@ void SessionStorageArea::itemRemoved(const String& key, const String& oldValue,
     dispatchStorageEvent(key, oldValue, String(), sourceFrame);
 }
 
+void SessionStorageArea::areaCleared(Frame* sourceFrame)
+{
+    dispatchStorageEvent(String(), String(), String(), sourceFrame);
+}
+
 void SessionStorageArea::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame)
 {
     // For SessionStorage events, each frame in the page's frametree with the same origin as this StorageArea needs to be notified of the change
index 87c86bb..3dad1af 100644 (file)
@@ -45,6 +45,7 @@ namespace WebCore {
 
         virtual void itemChanged(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
         virtual void itemRemoved(const String& key, const String& oldValue, Frame* sourceFrame);
+        virtual void areaCleared(Frame* sourceFrame);
 
         void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
         
index 3f1fe38..cf4413a 100644 (file)
@@ -87,6 +87,14 @@ void Storage::removeItem(const String& key)
     m_storageArea->removeItem(key, m_frame);
 }
 
+void Storage::clear()
+{
+    if (!m_frame)
+        return;
+
+    m_storageArea->clear(m_frame);
+}
+
 bool Storage::contains(const String& key) const
 {
     if (!m_frame)
index 9596a91..061f7c4 100644 (file)
@@ -47,7 +47,8 @@ namespace WebCore {
         String getItem(const String&) const;
         void setItem(const String& key, const String& value, ExceptionCode&);
         void removeItem(const String&);
-        
+        void clear();
+
         bool contains(const String& key) const;
 
         void disconnectFrame() { m_frame = 0; }
index 4d9c6cf..7bc4ead 100644 (file)
@@ -38,6 +38,7 @@ module storage {
         [DontEnum] void setItem(in DOMString key, in DOMString data) 
             raises(DOMException);
         [DontEnum] void removeItem(in DOMString key);
+        [DontEnum] void clear();
     };
 
 }
index 315dff0..1ff18bf 100644 (file)
@@ -105,6 +105,13 @@ void StorageArea::internalRemoveItem(const String& key, Frame* frame)
         itemRemoved(key, oldValue, frame);
 }
 
+void StorageArea::internalClear(Frame* frame)
+{
+    m_storageMap = StorageMap::create();
+    
+    areaCleared(frame);
+}
+
 bool StorageArea::internalContains(const String& key) const
 {
     return m_storageMap->contains(key);
index fd5366f..5fb7e62 100644 (file)
@@ -49,6 +49,7 @@ namespace WebCore {
         virtual String getItem(const String& key) const { return internalGetItem(key); }
         virtual void setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame) { internalSetItem(key, value, ec, sourceFrame); }
         virtual void removeItem(const String& key, Frame* sourceFrame) { internalRemoveItem(key, sourceFrame); }
+        virtual void clear(Frame* sourceFrame) { internalClear(sourceFrame); }
         virtual bool contains(const String& key) const { return internalContains(key); }
         
         SecurityOrigin* securityOrigin() { return m_securityOrigin.get(); }
@@ -62,11 +63,13 @@ namespace WebCore {
         String internalGetItem(const String&) const;
         void internalSetItem(const String& key, const String& value, ExceptionCode&, Frame* sourceFrame);
         void internalRemoveItem(const String&, Frame* sourceFrame);
+        void internalClear(Frame* sourceFrame);
         bool internalContains(const String& key) const;
 
     private:
         virtual void itemChanged(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame) = 0;
         virtual void itemRemoved(const String& key, const String& oldValue, Frame* sourceFrame) = 0;
+        virtual void areaCleared(Frame* sourceFrame) = 0;
 
         RefPtr<SecurityOrigin> m_securityOrigin;
         RefPtr<StorageMap> m_storageMap;