Title: [144675] trunk/Source/WebKit2
Revision
144675
Author
[email protected]
Date
2013-03-04 14:25:57 -0800 (Mon, 04 Mar 2013)

Log Message

Create and destroy storage areas in the UI process
https://bugs.webkit.org/show_bug.cgi?id=111361

Reviewed by Sam Weinig.

* UIProcess/Storage/StorageManager.cpp:
(StorageManager::StorageArea):
Keep track of listener connection and storage area ID pairs.

(WebKit::StorageManager::StorageArea::~StorageArea):
Assert that we don't have any listeners left.

(WebKit::StorageManager::StorageArea::addListener):
Add the pair to the set of listeners.

(WebKit::StorageManager::StorageArea::removeListener):
Remove the pair from the set of listeners.

(WebKit::StorageManager::SessionStorageNamespace::getOrCreateStorageArea):
Given an origin, look up or create the storage area.

(WebKit::StorageManager::createStorageArea):
Create the storage area if it doesn't already exist.

(WebKit::StorageManager::destroyStorageArea):
Look up the storage area and destroy it.

* UIProcess/Storage/StorageManager.h:
Add a map of open storage areas.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (144674 => 144675)


--- trunk/Source/WebKit2/ChangeLog	2013-03-04 22:16:46 UTC (rev 144674)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-04 22:25:57 UTC (rev 144675)
@@ -1,3 +1,35 @@
+2013-03-04  Anders Carlsson  <[email protected]>
+
+        Create and destroy storage areas in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=111361
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/Storage/StorageManager.cpp:
+        (StorageManager::StorageArea):
+        Keep track of listener connection and storage area ID pairs.
+        
+        (WebKit::StorageManager::StorageArea::~StorageArea):
+        Assert that we don't have any listeners left.
+
+        (WebKit::StorageManager::StorageArea::addListener):
+        Add the pair to the set of listeners.
+        
+        (WebKit::StorageManager::StorageArea::removeListener):
+        Remove the pair from the set of listeners.
+        
+        (WebKit::StorageManager::SessionStorageNamespace::getOrCreateStorageArea):
+        Given an origin, look up or create the storage area.
+
+        (WebKit::StorageManager::createStorageArea):
+        Create the storage area if it doesn't already exist.
+
+        (WebKit::StorageManager::destroyStorageArea):
+        Look up the storage area and destroy it.
+
+        * UIProcess/Storage/StorageManager.h:
+        Add a map of open storage areas.
+
 2013-03-04  Jer Noble  <[email protected]>
 
         Add API to allow WK2 clients to query the list of installed plug-ins.

Modified: trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp (144674 => 144675)


--- trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp	2013-03-04 22:16:46 UTC (rev 144674)
+++ trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp	2013-03-04 22:25:57 UTC (rev 144675)
@@ -42,8 +42,13 @@
     static PassRefPtr<StorageArea> create();
     ~StorageArea();
 
+    void addListener(CoreIPC::Connection*, uint64_t storageAreaID);
+    void removeListener(CoreIPC::Connection*, uint64_t storageAreaID);
+
 private:
     StorageArea();
+
+    HashSet<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>> m_eventListeners;
 };
 
 PassRefPtr<StorageManager::StorageArea> StorageManager::StorageArea::create()
@@ -57,8 +62,21 @@
 
 StorageManager::StorageArea::~StorageArea()
 {
+    ASSERT(m_eventListeners.isEmpty());
 }
 
+void StorageManager::StorageArea::addListener(CoreIPC::Connection* connection, uint64_t storageAreaID)
+{
+    ASSERT(!m_eventListeners.contains(std::make_pair(connection, storageAreaID)));
+    m_eventListeners.add(std::make_pair(connection, storageAreaID));
+}
+
+void StorageManager::StorageArea::removeListener(CoreIPC::Connection* connection, uint64_t storageAreaID)
+{
+    ASSERT(m_eventListeners.contains(std::make_pair(connection, storageAreaID)));
+    m_eventListeners.remove(std::make_pair(connection, storageAreaID));
+}
+
 class StorageManager::SessionStorageNamespace : public ThreadSafeRefCounted<SessionStorageNamespace> {
 public:
     static PassRefPtr<SessionStorageNamespace> create(CoreIPC::Connection* allowedConnection);
@@ -69,6 +87,8 @@
     CoreIPC::Connection* allowedConnection() const { return m_allowedConnection.get(); }
     void setAllowedConnection(CoreIPC::Connection*);
 
+    PassRefPtr<StorageArea> getOrCreateStorageArea(PassRefPtr<SecurityOrigin>);
+
     void cloneTo(SessionStorageNamespace& newSessionStorageNamespace);
 
 private:
@@ -99,6 +119,15 @@
     m_allowedConnection = allowedConnection;
 }
 
+PassRefPtr<StorageManager::StorageArea> StorageManager::SessionStorageNamespace::getOrCreateStorageArea(PassRefPtr<SecurityOrigin> securityOrigin)
+{
+    HashMap<RefPtr<SecurityOrigin>, RefPtr<StorageArea> >::AddResult result = m_storageAreaMap.add(securityOrigin, 0);
+    if (result.isNewEntry)
+        result.iterator->value = StorageArea::create();
+
+    return result.iterator->value;
+}
+
 void StorageManager::SessionStorageNamespace::cloneTo(SessionStorageNamespace& newSessionStorageNamespace)
 {
     ASSERT(newSessionStorageNamespace.isEmpty());
@@ -152,17 +181,49 @@
 
 void StorageManager::createStorageArea(CoreIPC::Connection* connection, uint64_t storageAreaID, uint64_t storageNamespaceID, const SecurityOriginData& securityOriginData)
 {
-    UNUSED_PARAM(storageAreaID);
-    UNUSED_PARAM(storageNamespaceID);
+    std::pair<RefPtr<CoreIPC::Connection>, uint64_t> connectionAndStorageAreaIDPair(connection, storageAreaID);
 
+    // FIXME: This should be a message check.
+    ASSERT((HashMap<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>, RefPtr<StorageArea> >::isValidKey(connectionAndStorageAreaIDPair)));
+
+    HashMap<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>, RefPtr<StorageArea> >::AddResult result = m_storageAreas.add(connectionAndStorageAreaIDPair, 0);
+
+    // FIXME: This should be a message check.
+    ASSERT(result.isNewEntry);
+
     if (!storageNamespaceID) {
         // FIXME: This is a local storage namespace. Do something.
         ASSERT_NOT_REACHED();
     }
+
+    ASSERT((HashMap<uint64_t, RefPtr<SessionStorageNamespace> >::isValidKey(storageNamespaceID)));
+    SessionStorageNamespace* sessionStorageNamespace = m_sessionStorageNamespaces.get(storageNamespaceID).get();
+
+    // FIXME: These should be message checks.
+    ASSERT(sessionStorageNamespace);
+    ASSERT(connection == sessionStorageNamespace->allowedConnection());
+
+    RefPtr<StorageArea> storageArea = sessionStorageNamespace->getOrCreateStorageArea(securityOriginData.securityOrigin());
+    storageArea->addListener(connection, storageAreaID);
+
+    result.iterator->value = storageArea.release();
 }
 
-void StorageManager::destroyStorageArea(CoreIPC::Connection*, uint64_t)
+void StorageManager::destroyStorageArea(CoreIPC::Connection* connection, uint64_t storageAreaID)
 {
+    std::pair<RefPtr<CoreIPC::Connection>, uint64_t> connectionAndStorageAreaIDPair(connection, storageAreaID);
+
+    // FIXME: This should be a message check.
+    ASSERT((HashMap<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>, RefPtr<StorageArea> >::isValidKey(connectionAndStorageAreaIDPair)));
+
+    HashMap<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>, RefPtr<StorageArea> >::iterator it = m_storageAreas.find(connectionAndStorageAreaIDPair);
+
+    // FIXME: This should be a message check.
+    ASSERT(it != m_storageAreas.end());
+
+    it->value->removeListener(connection, storageAreaID);
+
+    m_storageAreas.remove(connectionAndStorageAreaIDPair);
 }
 
 void StorageManager::getValues(CoreIPC::Connection*, uint64_t, HashMap<String, String>&)

Modified: trunk/Source/WebKit2/UIProcess/Storage/StorageManager.h (144674 => 144675)


--- trunk/Source/WebKit2/UIProcess/Storage/StorageManager.h	2013-03-04 22:16:46 UTC (rev 144674)
+++ trunk/Source/WebKit2/UIProcess/Storage/StorageManager.h	2013-03-04 22:25:57 UTC (rev 144675)
@@ -75,6 +75,7 @@
     HashMap<uint64_t, RefPtr<SessionStorageNamespace> > m_sessionStorageNamespaces;
 
     class StorageArea;
+    HashMap<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>, RefPtr<StorageArea> > m_storageAreas;
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to