Changeset 148215 in webkit


Ignore:
Timestamp:
Apr 11, 2013 10:44:17 AM (11 years ago)
Author:
andersca@apple.com
Message:

Implement more logic in StorageAreaMap
https://bugs.webkit.org/show_bug.cgi?id=114451

Reviewed by Alexey Proskuryakov.

  • Platform/CoreIPC/HandleMessage.h:

(CoreIPC::callMemberFunction):
Add new overload.

  • UIProcess/Storage/StorageManager.cpp:

(WebKit::StorageManager::StorageArea::addListener):
(WebKit::StorageManager::StorageArea::removeListener):
These take storage map IDs.

(WebKit::StorageManager::StorageArea::setItem):
Rename storageAreaID to sourceStorageAreaID.

(WebKit::StorageManager::StorageArea::dispatchEvents):
Remove the code that would not dispatch to the source connection, there may still be storage areas interested in those events.

(WebKit::StorageManager::setItem):
This now takes the source storage area ID.

(WebKit::StorageManager::findStorageArea):
This takes a storage map ID.

  • UIProcess/Storage/StorageManager.messages.in:

SetItem now takes the source storage area ID as well.

  • WebProcess/Storage/StorageAreaImpl.cpp:

(WebKit::StorageAreaImpl::setItem):
Pass the source frame to StorageAreaMap::setItem.

  • WebProcess/Storage/StorageAreaMap.cpp:

(WebKit::StorageAreaMap::StorageAreaMap):
Send CreateStorageMap and add the object as a message receiver.

(WebKit::StorageAreaMap::~StorageAreaMap):
Send DestroyStorageMap and remove the object as a message receiver.

(WebKit::StorageAreaMap::length):
(WebKit::StorageAreaMap::key):
(WebKit::StorageAreaMap::item):
(WebKit::StorageAreaMap::contains):
Load values and forward calls to the storage map.

(WebKit::StorageAreaMap::setItem):
This now takes the source frame as well. Update the local storage map and send a SetItem message.

(WebKit::StorageAreaMap::loadValuesIfNeeded):
Get the values from the storage manager.

(WebKit::StorageAreaMap::dispatchStorageEvent):
This now takes the source storage area ID.

  • WebProcess/Storage/StorageAreaMap.messages.in:

DispatchStorageEvent now takes the source storage area ID.

Location:
trunk/Source/WebKit2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r148214 r148215  
     12013-04-11  Anders Carlsson  <andersca@apple.com>
     2
     3        Implement more logic in StorageAreaMap
     4        https://bugs.webkit.org/show_bug.cgi?id=114451
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        * Platform/CoreIPC/HandleMessage.h:
     9        (CoreIPC::callMemberFunction):
     10        Add new overload.
     11
     12        * UIProcess/Storage/StorageManager.cpp:
     13        (WebKit::StorageManager::StorageArea::addListener):
     14        (WebKit::StorageManager::StorageArea::removeListener):
     15        These take storage map IDs.
     16
     17        (WebKit::StorageManager::StorageArea::setItem):
     18        Rename storageAreaID to sourceStorageAreaID.
     19
     20        (WebKit::StorageManager::StorageArea::dispatchEvents):
     21        Remove the code that would not dispatch to the source connection, there may still be storage areas interested in those events.
     22
     23        (WebKit::StorageManager::setItem):
     24        This now takes the source storage area ID.
     25
     26        (WebKit::StorageManager::findStorageArea):
     27        This takes a storage map ID.
     28
     29        * UIProcess/Storage/StorageManager.messages.in:
     30        SetItem now takes the source storage area ID as well.
     31
     32        * WebProcess/Storage/StorageAreaImpl.cpp:
     33        (WebKit::StorageAreaImpl::setItem):
     34        Pass the source frame to StorageAreaMap::setItem.
     35
     36        * WebProcess/Storage/StorageAreaMap.cpp:
     37        (WebKit::StorageAreaMap::StorageAreaMap):
     38        Send CreateStorageMap and add the object as a message receiver.
     39
     40        (WebKit::StorageAreaMap::~StorageAreaMap):
     41        Send DestroyStorageMap and remove the object as a message receiver.
     42
     43        (WebKit::StorageAreaMap::length):
     44        (WebKit::StorageAreaMap::key):
     45        (WebKit::StorageAreaMap::item):
     46        (WebKit::StorageAreaMap::contains):
     47        Load values and forward calls to the storage map.
     48
     49        (WebKit::StorageAreaMap::setItem):
     50        This now takes the source frame as well. Update the local storage map and send a SetItem message.
     51       
     52        (WebKit::StorageAreaMap::loadValuesIfNeeded):
     53        Get the values from the storage manager.
     54
     55        (WebKit::StorageAreaMap::dispatchStorageEvent):
     56        This now takes the source storage area ID.
     57
     58        * WebProcess/Storage/StorageAreaMap.messages.in:
     59        DispatchStorageEvent now takes the source storage area ID.
     60
    1612013-04-10  Brady Eidson  <beidson@apple.com>
    262
  • trunk/Source/WebKit2/Platform/CoreIPC/HandleMessage.h

    r145164 r148215  
    254254}
    255255
     256template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5>
     257void callMemberFunction(Connection* connection, const Arguments5<P1, P2, P3, P4, P5>& args, C* object, MF function)
     258{
     259    (object->*function)(connection, args.argument1, args.argument2, args.argument3, args.argument4, args.argument5);
     260}
     261
    256262template<typename C, typename MF, typename P1, typename R1>
    257263void callMemberFunction(Connection* connection, const Arguments1<P1>& args, Arguments1<R1>& replyArgs, C* object, MF function)
  • trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp

    r148160 r148215  
    4444    ~StorageArea();
    4545
    46     void addListener(CoreIPC::Connection*, uint64_t storageAreaID);
    47     void removeListener(CoreIPC::Connection*, uint64_t storageAreaID);
    48 
    49     void setItem(CoreIPC::Connection*, uint64_t storageAreaID, const String& key, const String& value, const String& urlString, bool& quotaException);
     46    void addListener(CoreIPC::Connection*, uint64_t storageMapID);
     47    void removeListener(CoreIPC::Connection*, uint64_t storageMapID);
     48
     49    void setItem(CoreIPC::Connection*, uint64_t sourceStorageAreaID, const String& key, const String& value, const String& urlString, bool& quotaException);
    5050
    5151private:
    5252    explicit StorageArea(unsigned quotaInBytes);
    5353
    54     void dispatchEvents(CoreIPC::Connection*, uint64_t storageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString) const;
     54    void dispatchEvents(CoreIPC::Connection* sourceConnection, uint64_t sourceStorageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString) const;
    5555
    5656    RefPtr<StorageMap> m_storageMap;
     
    7373}
    7474
    75 void StorageManager::StorageArea::addListener(CoreIPC::Connection* connection, uint64_t storageAreaID)
    76 {
    77     ASSERT(!m_eventListeners.contains(std::make_pair(connection, storageAreaID)));
    78     m_eventListeners.add(std::make_pair(connection, storageAreaID));
    79 }
    80 
    81 void StorageManager::StorageArea::removeListener(CoreIPC::Connection* connection, uint64_t storageAreaID)
    82 {
    83     ASSERT(m_eventListeners.contains(std::make_pair(connection, storageAreaID)));
    84     m_eventListeners.remove(std::make_pair(connection, storageAreaID));
    85 }
    86 
    87 void StorageManager::StorageArea::setItem(CoreIPC::Connection* connection, uint64_t storageAreaID, const String& key, const String& value, const String& urlString, bool& quotaException)
     75void StorageManager::StorageArea::addListener(CoreIPC::Connection* connection, uint64_t storageMapID)
     76{
     77    ASSERT(!m_eventListeners.contains(std::make_pair(connection, storageMapID)));
     78    m_eventListeners.add(std::make_pair(connection, storageMapID));
     79}
     80
     81void StorageManager::StorageArea::removeListener(CoreIPC::Connection* connection, uint64_t storageMapID)
     82{
     83    ASSERT(m_eventListeners.contains(std::make_pair(connection, storageMapID)));
     84    m_eventListeners.remove(std::make_pair(connection, storageMapID));
     85}
     86
     87void StorageManager::StorageArea::setItem(CoreIPC::Connection* connection, uint64_t sourceStorageAreaID, const String& key, const String& value, const String& urlString, bool& quotaException)
    8888{
    8989    ASSERT(m_storageMap->hasOneRef());
     
    9393
    9494    if (!quotaException)
    95         dispatchEvents(connection, storageAreaID, key, oldValue, value, urlString);
    96 }
    97 
    98 void StorageManager::StorageArea::dispatchEvents(CoreIPC::Connection* connection, uint64_t storageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString) const
     95        dispatchEvents(connection, sourceStorageAreaID, key, oldValue, value, urlString);
     96}
     97
     98void StorageManager::StorageArea::dispatchEvents(CoreIPC::Connection* sourceConnection, uint64_t sourceStorageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString) const
    9999{
    100100    for (HashSet<std::pair<RefPtr<CoreIPC::Connection>, uint64_t> >::const_iterator it = m_eventListeners.begin(), end = m_eventListeners.end(); it != end; ++it) {
    101         if (it->first == connection && it->second == storageAreaID) {
    102             // We don't want to dispatch events to the storage area that originated the event.
    103             continue;
    104         }
    105 
    106         it->first->send(Messages::StorageAreaMap::DispatchStorageEvent(key, oldValue, newValue, urlString), it->second);
     101        // FIXME: If this is sent to another process, the source storage area ID will be bogus, since storage are IDs are per process.
     102        it->first->send(Messages::StorageAreaMap::DispatchStorageEvent(sourceStorageAreaID, key, oldValue, newValue, urlString), it->second);
    107103    }
    108104}
     
    265261}
    266262
    267 void StorageManager::setItem(CoreIPC::Connection* connection, uint64_t storageMapID, const String& key, const String& value, const String& urlString)
     263void StorageManager::setItem(CoreIPC::Connection* connection, uint64_t storageMapID, uint64_t sourceStorageAreaID, const String& key, const String& value, const String& urlString)
    268264{
    269265    StorageArea* storageArea = findStorageArea(connection, storageMapID);
     
    273269
    274270    bool quotaError;
    275     storageArea->setItem(connection, storageMapID, key, value, urlString, quotaError);
     271    storageArea->setItem(connection, sourceStorageAreaID, key, value, urlString, quotaError);
    276272    connection->send(Messages::StorageAreaMap::DidSetItem(key, quotaError), storageMapID);
    277273}
     
    309305}
    310306
    311 StorageManager::StorageArea* StorageManager::findStorageArea(CoreIPC::Connection* connection, uint64_t storageAreaID) const
    312 {
    313     std::pair<CoreIPC::Connection*, uint64_t> connectionAndStorageAreaIDPair(connection, storageAreaID);
    314     if (!HashMap<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>, RefPtr<StorageArea> >::isValidKey(connectionAndStorageAreaIDPair))
     307StorageManager::StorageArea* StorageManager::findStorageArea(CoreIPC::Connection* connection, uint64_t storageMapID) const
     308{
     309    std::pair<CoreIPC::Connection*, uint64_t> connectionAndStorageMapIDPair(connection, storageMapID);
     310    if (!HashMap<std::pair<RefPtr<CoreIPC::Connection>, uint64_t>, RefPtr<StorageArea> >::isValidKey(connectionAndStorageMapIDPair))
    315311        return 0;
    316312
    317     return m_storageAreas.get(connectionAndStorageAreaIDPair).get();
     313    return m_storageAreas.get(connectionAndStorageMapIDPair).get();
    318314}
    319315
  • trunk/Source/WebKit2/UIProcess/Storage/StorageManager.h

    r148160 r148215  
    6363    void destroyStorageMap(CoreIPC::Connection*, uint64_t storageMapID);
    6464    void getValues(CoreIPC::Connection*, uint64_t storageMapID, HashMap<String, String>& values);
    65     void setItem(CoreIPC::Connection*, uint64_t storageAreaID, const String& key, const String& value, const String& urlString);
     65    void setItem(CoreIPC::Connection*, uint64_t storageAreaID, uint64_t sourceStorageAreaID, const String& key, const String& value, const String& urlString);
    6666
    6767    void createSessionStorageNamespaceInternal(uint64_t storageNamespaceID, CoreIPC::Connection* allowedConnection, unsigned quotaInBytes);
  • trunk/Source/WebKit2/UIProcess/Storage/StorageManager.messages.in

    r148160 r148215  
    2727    GetValues(uint64_t storageMapID) -> (WTF::HashMap<WTF::String, WTF::String> values) WantsConnection
    2828
    29     SetItem(uint64_t storageMapID, WTF::String key, WTF::String value, WTF::String urlString) WantsConnection
     29    SetItem(uint64_t storageMapID, uint64_t sourceStorageAreaID, WTF::String key, WTF::String value, WTF::String urlString) WantsConnection
    3030}
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.cpp

    r148161 r148215  
    122122
    123123    bool quotaException;
    124     m_storageAreaMap->setItem(this, key, value, quotaException);
     124    m_storageAreaMap->setItem(sourceFrame, this, key, value, quotaException);
    125125
    126126    if (quotaException)
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp

    r148161 r148215  
    2727#include "StorageAreaMap.h"
    2828
     29#include "SecurityOriginData.h"
     30#include "StorageAreaImpl.h"
     31#include "StorageAreaMapMessages.h"
     32#include "StorageManagerMessages.h"
    2933#include "StorageNamespaceImpl.h"
     34#include "WebProcess.h"
     35#include <WebCore/Frame.h>
    3036#include <WebCore/StorageMap.h>
    3137
     
    5157    , m_securityOrigin(securityOrigin)
    5258{
     59    WebProcess::shared().connection()->send(Messages::StorageManager::CreateStorageMap(m_storageMapID, storageNamespace->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin.get())), 0);
     60    WebProcess::shared().addMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageMapID, this);
    5361}
    5462
    5563StorageAreaMap::~StorageAreaMap()
    5664{
     65    WebProcess::shared().connection()->send(Messages::StorageManager::DestroyStorageMap(m_storageMapID), 0);
     66    WebProcess::shared().removeMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageMapID);
    5767}
    5868
     
    6878unsigned StorageAreaMap::length()
    6979{
    70     // FIXME: Implement.
    71     return 0;
     80    loadValuesIfNeeded();
     81
     82    return m_storageMap->length();
    7283}
    7384
    7485String StorageAreaMap::key(unsigned index)
    7586{
    76     // FIXME: Implement.
    77     return String();
     87    loadValuesIfNeeded();
     88
     89    return m_storageMap->key(index);
    7890}
    7991
    8092String StorageAreaMap::item(const String& key)
    8193{
    82     // FIXME: Implement.
    83     return String();
     94    loadValuesIfNeeded();
     95
     96    return m_storageMap->getItem(key);
    8497}
    8598
    86 void StorageAreaMap::setItem(StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException)
     99void StorageAreaMap::setItem(Frame* sourceFrame, StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException)
    87100{
    88     // FIXME: Implement.
     101    loadValuesIfNeeded();
     102
     103    ASSERT(m_storageMap->hasOneRef());
     104
     105    String oldValue;
     106    quotaException = false;
     107    m_storageMap->setItem(key, value, oldValue, quotaException);
     108    if (quotaException)
     109        return;
     110
     111    if (oldValue == value)
     112        return;
     113
     114    m_pendingValueChanges.add(key);
     115
     116    WebProcess::shared().connection()->send(Messages::StorageManager::SetItem(m_storageMapID, sourceArea->storageAreaID(), key, value, sourceFrame->document()->url()), 0);
    89117}
    90118
    91119bool StorageAreaMap::contains(const String& key)
    92120{
    93     // FIXME: Implement.
    94     return false;
     121    loadValuesIfNeeded();
     122
     123    return m_storageMap->contains(key);
     124}
     125
     126void StorageAreaMap::loadValuesIfNeeded()
     127{
     128    if (m_storageMap)
     129        return;
     130
     131    HashMap<String, String> values;
     132    // FIXME: This should use a special sendSync flag to indicate that we don't want to process incoming messages while waiting for a reply.
     133    // (This flag does not yet exist). Since loadValuesIfNeeded() ends up being called from within JavaScript code, processing incoming synchronous messages
     134    // could lead to weird reentrency bugs otherwise.
     135    WebProcess::shared().connection()->sendSync(Messages::StorageManager::GetValues(m_storageMapID), Messages::StorageManager::GetValues::Reply(values), 0);
     136
     137    m_storageMap = StorageMap::create(m_quotaInBytes);
     138    m_storageMap->importItems(values);
    95139}
    96140
     
    100144}
    101145
    102 void StorageAreaMap::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)
     146void StorageAreaMap::dispatchStorageEvent(uint64_t sourceStorageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString)
    103147{
    104148    // FIXME: Implement.
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaMap.h

    r148161 r148215  
    3131#include <WebCore/StorageArea.h>
    3232#include <wtf/Forward.h>
     33#include <wtf/HashCountedSet.h>
    3334#include <wtf/PassRefPtr.h>
    3435#include <wtf/RefCounted.h>
     
    5455    String key(unsigned index);
    5556    String item(const String& key);
    56     void setItem(StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException);
     57    void setItem(WebCore::Frame* sourceFrame, StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException);
    5758    bool contains(const String& key);
    5859
     
    6465
    6566    void didSetItem(const String& key, bool quotaError);
    66     void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);
     67    void dispatchStorageEvent(uint64_t sourceStorageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString);
    6768
    6869    void loadValuesIfNeeded();
     
    7374    RefPtr<WebCore::SecurityOrigin> m_securityOrigin;
    7475
    75 
    7676    RefPtr<WebCore::StorageMap> m_storageMap;
     77    HashCountedSet<String> m_pendingValueChanges;
    7778};
    7879
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaMap.messages.in

    r148154 r148215  
    2424    DidSetItem(WTF::String key, bool quotaException)
    2525
    26     DispatchStorageEvent(WTF::String key, WTF::String oldValue, WTF::String newValue, WTF::String urlString)
     26    DispatchStorageEvent(uint64_t sourceStorageAreaID, WTF::String key, WTF::String oldValue, WTF::String newValue, WTF::String urlString)
    2727}
Note: See TracChangeset for help on using the changeset viewer.