Changeset 290223 in webkit


Ignore:
Timestamp:
Feb 19, 2022 11:12:29 PM (5 months ago)
Author:
Chris Dumez
Message:

Optimize DOM storage event dispatch
https://bugs.webkit.org/show_bug.cgi?id=236871

Reviewed by Sihui Liu.

Made the following optimization to DOM storage event dispatch:

  1. Pass a SecurityOrigin around instead of a SecurityOriginData. Otherwise, dispatchLocalStorageEvents() / dispatchSessionStorageEvents() just keep reconstructing the SecurityOrigin from the SecurityOriginData for every frame.
  2. When gathering the list of frames where we need to dispatch the storage event, discard the ones that do not have a "storage" event listener.

Source/WebCore:

  • inspector/InspectorInstrumentation.cpp:

(WebCore::InspectorInstrumentation::didDispatchDOMStorageEventImpl):

  • inspector/InspectorInstrumentation.h:

(WebCore::InspectorInstrumentation::didDispatchDOMStorageEvent):

  • inspector/agents/InspectorDOMStorageAgent.cpp:

(WebCore::InspectorDOMStorageAgent::storageId):
(WebCore::InspectorDOMStorageAgent::didDispatchDOMStorageEvent):
(WebCore::InspectorDOMStorageAgent::findStorageArea):

  • inspector/agents/InspectorDOMStorageAgent.h:
  • loader/EmptyClients.cpp:
  • page/DOMWindow.cpp:
  • storage/StorageEventDispatcher.cpp:

(WebCore::StorageEventDispatcher::dispatchSessionStorageEvents):
(WebCore::StorageEventDispatcher::dispatchLocalStorageEvents):
(WebCore::StorageEventDispatcher::dispatchSessionStorageEventsToFrames):
(WebCore::StorageEventDispatcher::dispatchLocalStorageEventsToFrames):

  • storage/StorageEventDispatcher.h:
  • storage/StorageNamespace.h:
  • storage/StorageNamespaceProvider.cpp:

(WebCore::StorageNamespaceProvider::localStorageArea):

Source/WebKit:

  • WebProcess/WebStorage/StorageAreaMap.cpp:

(WebKit::StorageAreaMap::StorageAreaMap):
(WebKit::framesForEventDispatching):
(WebKit::StorageAreaMap::dispatchSessionStorageEvent):
(WebKit::StorageAreaMap::dispatchLocalStorageEvent):

  • WebProcess/WebStorage/StorageAreaMap.h:
  • WebProcess/WebStorage/StorageNamespaceImpl.cpp:

(WebKit::StorageNamespaceImpl::storageArea):

  • WebProcess/WebStorage/StorageNamespaceImpl.h:

Source/WebKitLegacy:

  • Storage/StorageAreaImpl.cpp:

(WebKit::StorageAreaImpl::StorageAreaImpl):
(WebKit::StorageAreaImpl::create):
(WebKit::StorageAreaImpl::clearForOriginDeletion):
(WebKit::StorageAreaImpl::sync):
(WebKit::StorageAreaImpl::sessionChanged):

  • Storage/StorageAreaImpl.h:
  • Storage/StorageNamespaceImpl.cpp:

(WebKit::StorageNamespaceImpl::storageArea):

  • Storage/StorageNamespaceImpl.h:
Location:
trunk/Source
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r290217 r290223  
     12022-02-19  Chris Dumez  <cdumez@apple.com>
     2
     3        Optimize DOM storage event dispatch
     4        https://bugs.webkit.org/show_bug.cgi?id=236871
     5
     6        Reviewed by Sihui Liu.
     7
     8        Made the following optimization to DOM storage event dispatch:
     9        1. Pass a SecurityOrigin around instead of a SecurityOriginData. Otherwise,
     10           dispatchLocalStorageEvents() / dispatchSessionStorageEvents() just keep
     11           reconstructing the SecurityOrigin from the SecurityOriginData for every
     12           frame.
     13        2. When gathering the list of frames where we need to dispatch the storage
     14           event, discard the ones that do not have a "storage" event listener.
     15
     16        * inspector/InspectorInstrumentation.cpp:
     17        (WebCore::InspectorInstrumentation::didDispatchDOMStorageEventImpl):
     18        * inspector/InspectorInstrumentation.h:
     19        (WebCore::InspectorInstrumentation::didDispatchDOMStorageEvent):
     20        * inspector/agents/InspectorDOMStorageAgent.cpp:
     21        (WebCore::InspectorDOMStorageAgent::storageId):
     22        (WebCore::InspectorDOMStorageAgent::didDispatchDOMStorageEvent):
     23        (WebCore::InspectorDOMStorageAgent::findStorageArea):
     24        * inspector/agents/InspectorDOMStorageAgent.h:
     25        * loader/EmptyClients.cpp:
     26        * page/DOMWindow.cpp:
     27        * storage/StorageEventDispatcher.cpp:
     28        (WebCore::StorageEventDispatcher::dispatchSessionStorageEvents):
     29        (WebCore::StorageEventDispatcher::dispatchLocalStorageEvents):
     30        (WebCore::StorageEventDispatcher::dispatchSessionStorageEventsToFrames):
     31        (WebCore::StorageEventDispatcher::dispatchLocalStorageEventsToFrames):
     32        * storage/StorageEventDispatcher.h:
     33        * storage/StorageNamespace.h:
     34        * storage/StorageNamespaceProvider.cpp:
     35        (WebCore::StorageNamespaceProvider::localStorageArea):
     36
    1372022-02-19  Mark Lam  <mark.lam@apple.com>
    238
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r289698 r290223  
    10081008}
    10091009
    1010 void InspectorInstrumentation::didDispatchDOMStorageEventImpl(InstrumentingAgents& instrumentingAgents, const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin)
     1010void InspectorInstrumentation::didDispatchDOMStorageEventImpl(InstrumentingAgents& instrumentingAgents, const String& key, const String& oldValue, const String& newValue, StorageType storageType, const SecurityOrigin& securityOrigin)
    10111011{
    10121012    if (auto* domStorageAgent = instrumentingAgents.enabledDOMStorageAgent())
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r289698 r290223  
    275275    static void didOpenDatabase(Database&);
    276276
    277     static void didDispatchDOMStorageEvent(Page&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
     277    static void didDispatchDOMStorageEvent(Page&, const String& key, const String& oldValue, const String& newValue, StorageType, const SecurityOrigin&);
    278278
    279279    static bool shouldWaitForDebuggerOnStart(ScriptExecutionContext&);
     
    478478    static void didOpenDatabaseImpl(InstrumentingAgents&, Database&);
    479479
    480     static void didDispatchDOMStorageEventImpl(InstrumentingAgents&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
     480    static void didDispatchDOMStorageEventImpl(InstrumentingAgents&, const String& key, const String& oldValue, const String& newValue, StorageType, const SecurityOrigin&);
    481481
    482482    static bool shouldWaitForDebuggerOnStartImpl(InstrumentingAgents&);
     
    13261326}
    13271327
    1328 inline void InspectorInstrumentation::didDispatchDOMStorageEvent(Page& page, const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin)
     1328inline void InspectorInstrumentation::didDispatchDOMStorageEvent(Page& page, const String& key, const String& oldValue, const String& newValue, StorageType storageType, const SecurityOrigin& securityOrigin)
    13291329{
    13301330    FAST_RETURN_IF_NO_FRONTENDS(void());
  • trunk/Source/WebCore/inspector/agents/InspectorDOMStorageAgent.cpp

    r266902 r290223  
    169169    Ref<SecurityOrigin> securityOrigin = document->securityOrigin();
    170170    bool isLocalStorage = window->optionalLocalStorage() == &storage;
    171     return InspectorDOMStorageAgent::storageId(securityOrigin.ptr(), isLocalStorage)->toJSONString();
    172 }
    173 
    174 Ref<Protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::storageId(SecurityOrigin* securityOrigin, bool isLocalStorage)
     171    return InspectorDOMStorageAgent::storageId(securityOrigin, isLocalStorage)->toJSONString();
     172}
     173
     174Ref<Protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::storageId(const SecurityOrigin& securityOrigin, bool isLocalStorage)
    175175{
    176176    return Protocol::DOMStorage::StorageId::create()
    177         .setSecurityOrigin(securityOrigin->toRawString())
     177        .setSecurityOrigin(securityOrigin.toRawString())
    178178        .setIsLocalStorage(isLocalStorage)
    179179        .release();
    180180}
    181181
    182 void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin)
     182void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, const String& oldValue, const String& newValue, StorageType storageType, const SecurityOrigin& securityOrigin)
    183183{
    184184    auto id = InspectorDOMStorageAgent::storageId(securityOrigin, storageType == StorageType::Local);
     
    215215
    216216    if (!*isLocalStorage)
    217         return m_inspectedPage.sessionStorage()->storageArea(targetFrame->document()->securityOrigin().data());
     217        return m_inspectedPage.sessionStorage()->storageArea(targetFrame->document()->securityOrigin());
    218218    return m_inspectedPage.storageNamespaceProvider().localStorageArea(*targetFrame->document());
    219219}
  • trunk/Source/WebCore/inspector/agents/InspectorDOMStorageAgent.h

    r266885 r290223  
    6666
    6767    // InspectorInstrumentation
    68     void didDispatchDOMStorageEvent(const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
     68    void didDispatchDOMStorageEvent(const String& key, const String& oldValue, const String& newValue, StorageType, const SecurityOrigin&);
    6969
    7070    // CommandLineAPI
    7171    static String storageId(Storage&);
    72     static Ref<Inspector::Protocol::DOMStorage::StorageId> storageId(SecurityOrigin*, bool isLocalStorage);
     72    static Ref<Inspector::Protocol::DOMStorage::StorageId> storageId(const SecurityOrigin&, bool isLocalStorage);
    7373
    7474private:
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r289994 r290223  
    499499        }
    500500    private:
    501         Ref<StorageArea> storageArea(const SecurityOriginData&) final { return adoptRef(*new EmptyStorageArea); }
     501        Ref<StorageArea> storageArea(const SecurityOrigin&) final { return adoptRef(*new EmptyStorageArea); }
    502502        Ref<StorageNamespace> copy(Page&) final { return adoptRef(*new EmptyStorageNamespace { m_sessionID }); }
    503503        PAL::SessionID sessionID() const final { return m_sessionID; }
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r290026 r290223  
    831831        return nullptr;
    832832
    833     auto storageArea = page->sessionStorage()->storageArea(document->securityOrigin().data());
     833    auto storageArea = page->sessionStorage()->storageArea(document->securityOrigin());
    834834    m_sessionStorage = Storage::create(*this, WTFMove(storageArea));
    835835    return m_sessionStorage.get();
  • trunk/Source/WebCore/storage/StorageEventDispatcher.cpp

    r282799 r290223  
    4141namespace WebCore {
    4242
    43 void StorageEventDispatcher::dispatchSessionStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOriginData& securityOrigin, Frame* sourceFrame)
     43void StorageEventDispatcher::dispatchSessionStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOrigin& securityOrigin, Frame* sourceFrame)
    4444{
    4545    Page* page = sourceFrame->page();
     
    4747        return;
    4848
    49     Vector<RefPtr<Frame>> frames;
     49    Vector<Ref<Frame>> frames;
    5050
    5151    // Send events only to our page.
    5252    for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
    53         if (!frame->document())
     53        if (auto* window = frame->window(); !window || !window->hasEventListeners(eventNames().storageEvent))
    5454            continue;
    55         if (sourceFrame != frame && frame->document()->securityOrigin().equal(securityOrigin.securityOrigin().ptr()))
    56             frames.append(frame);
     55        if (sourceFrame != frame && frame->document()->securityOrigin().equal(&securityOrigin))
     56            frames.append(*frame);
    5757    }
    5858
     
    6060}
    6161
    62 void StorageEventDispatcher::dispatchLocalStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOriginData& securityOrigin, Frame* sourceFrame)
     62void StorageEventDispatcher::dispatchLocalStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOrigin& securityOrigin, Frame* sourceFrame)
    6363{
    6464    Page* page = sourceFrame->page();
     
    6666        return;
    6767
    68     Vector<RefPtr<Frame>> frames;
     68    Vector<Ref<Frame>> frames;
    6969
    7070    // Send events to every page.
    7171    for (auto& pageInGroup : page->group().pages()) {
    7272        for (auto* frame = &pageInGroup.mainFrame(); frame; frame = frame->tree().traverseNext()) {
    73             if (!frame->document())
     73            if (auto* window = frame->window(); !window || !window->hasEventListeners(eventNames().storageEvent))
    7474                continue;
    75             if (sourceFrame != frame && frame->document()->securityOrigin().equal(securityOrigin.securityOrigin().ptr()))
    76                 frames.append(frame);
     75            if (sourceFrame != frame && frame->document()->securityOrigin().equal(&securityOrigin))
     76                frames.append(*frame);
    7777        }
    7878    }
     
    8181}
    8282
    83 void StorageEventDispatcher::dispatchSessionStorageEventsToFrames(Page& page, const Vector<RefPtr<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOriginData& securityOrigin)
     83void StorageEventDispatcher::dispatchSessionStorageEventsToFrames(Page& page, const Vector<Ref<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOrigin& securityOrigin)
    8484{
    85     InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Session, securityOrigin.securityOrigin().ptr());
     85    InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Session, securityOrigin);
    8686
    8787    for (auto& frame : frames) {
     
    9393}
    9494
    95 void StorageEventDispatcher::dispatchLocalStorageEventsToFrames(PageGroup& pageGroup, const Vector<RefPtr<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOriginData& securityOrigin)
     95void StorageEventDispatcher::dispatchLocalStorageEventsToFrames(PageGroup& pageGroup, const Vector<Ref<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOrigin& securityOrigin)
    9696{
    9797    for (auto& page : pageGroup.pages())
    98         InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Local, securityOrigin.securityOrigin().ptr());
     98        InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Local, securityOrigin);
    9999
    100100    for (auto& frame : frames) {
  • trunk/Source/WebCore/storage/StorageEventDispatcher.h

    r222113 r290223  
    3737class Page;
    3838class PageGroup;
    39 struct SecurityOriginData;
     39class SecurityOrigin;
    4040
    4141class StorageEventDispatcher {
    4242public:
    43     WEBCORE_EXPORT static void dispatchSessionStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOriginData&, Frame* sourceFrame);
    44     WEBCORE_EXPORT static void dispatchLocalStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOriginData&, Frame* sourceFrame);
     43    WEBCORE_EXPORT static void dispatchSessionStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOrigin&, Frame* sourceFrame);
     44    WEBCORE_EXPORT static void dispatchLocalStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOrigin&, Frame* sourceFrame);
    4545
    46     WEBCORE_EXPORT static void dispatchSessionStorageEventsToFrames(Page&, const Vector<RefPtr<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOriginData&);
    47     WEBCORE_EXPORT static void dispatchLocalStorageEventsToFrames(PageGroup&, const Vector<RefPtr<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOriginData&);
     46    WEBCORE_EXPORT static void dispatchSessionStorageEventsToFrames(Page&, const Vector<Ref<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOrigin&);
     47    WEBCORE_EXPORT static void dispatchLocalStorageEventsToFrames(PageGroup&, const Vector<Ref<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOrigin&);
    4848private:
    4949    // Do not instantiate.
  • trunk/Source/WebCore/storage/StorageNamespace.h

    r255875 r290223  
    3636
    3737class Page;
     38class SecurityOrigin;
    3839class StorageArea;
    39 struct SecurityOriginData;
    4040
    4141class StorageNamespace : public RefCounted<StorageNamespace> {
    4242public:
    4343    virtual ~StorageNamespace() = default;
    44     virtual Ref<StorageArea> storageArea(const SecurityOriginData&) = 0;
     44    virtual Ref<StorageArea> storageArea(const SecurityOrigin&) = 0;
    4545
    4646    // FIXME: This is only valid for session storage and should probably be moved to a subclass.
  • trunk/Source/WebCore/storage/StorageNamespaceProvider.cpp

    r278849 r290223  
    6161        storageNamespace = &localStorageNamespace(document.page()->sessionID());
    6262
    63     return storageNamespace->storageArea(document.securityOrigin().data());
     63    return storageNamespace->storageArea(document.securityOrigin());
    6464}
    6565
  • trunk/Source/WebKit/ChangeLog

    r290219 r290223  
     12022-02-19  Chris Dumez  <cdumez@apple.com>
     2
     3        Optimize DOM storage event dispatch
     4        https://bugs.webkit.org/show_bug.cgi?id=236871
     5
     6        Reviewed by Sihui Liu.
     7
     8        Made the following optimization to DOM storage event dispatch:
     9        1. Pass a SecurityOrigin around instead of a SecurityOriginData. Otherwise,
     10           dispatchLocalStorageEvents() / dispatchSessionStorageEvents() just keep
     11           reconstructing the SecurityOrigin from the SecurityOriginData for every
     12           frame.
     13        2. When gathering the list of frames where we need to dispatch the storage
     14           event, discard the ones that do not have a "storage" event listener.
     15
     16        * WebProcess/WebStorage/StorageAreaMap.cpp:
     17        (WebKit::StorageAreaMap::StorageAreaMap):
     18        (WebKit::framesForEventDispatching):
     19        (WebKit::StorageAreaMap::dispatchSessionStorageEvent):
     20        (WebKit::StorageAreaMap::dispatchLocalStorageEvent):
     21        * WebProcess/WebStorage/StorageAreaMap.h:
     22        * WebProcess/WebStorage/StorageNamespaceImpl.cpp:
     23        (WebKit::StorageNamespaceImpl::storageArea):
     24        * WebProcess/WebStorage/StorageNamespaceImpl.h:
     25
    1262022-02-19  Tim Horton  <timothy_horton@apple.com>
    227
  • trunk/Source/WebKit/WebProcess/WebStorage/StorageAreaMap.cpp

    r288551 r290223  
    3939#include <WebCore/DOMWindow.h>
    4040#include <WebCore/Document.h>
     41#include <WebCore/EventNames.h>
    4142#include <WebCore/Frame.h>
    4243#include <WebCore/Page.h>
     
    5152using namespace WebCore;
    5253
    53 StorageAreaMap::StorageAreaMap(StorageNamespaceImpl& storageNamespace, Ref<WebCore::SecurityOrigin>&& securityOrigin)
     54StorageAreaMap::StorageAreaMap(StorageNamespaceImpl& storageNamespace, Ref<const WebCore::SecurityOrigin>&& securityOrigin)
    5455    : m_identifier(StorageAreaMapIdentifier::generate())
    5556    , m_namespace(storageNamespace)
     
    296297}
    297298
    298 static Vector<RefPtr<Frame>> framesForEventDispatching(Page& page, SecurityOrigin& origin, StorageType storageType, const std::optional<StorageAreaImplIdentifier>& storageAreaImplID)
    299 {
    300     Vector<RefPtr<Frame>> frames;
     299static Vector<Ref<Frame>> framesForEventDispatching(Page& page, const SecurityOrigin& origin, StorageType storageType, const std::optional<StorageAreaImplIdentifier>& storageAreaImplID)
     300{
     301    Vector<Ref<Frame>> frames;
    301302    page.forEachDocument([&](auto& document) {
    302303        if (!document.securityOrigin().equal(&origin))
     
    304305
    305306        auto* window = document.domWindow();
    306         if (!window)
     307        if (!window || !window->hasEventListeners(eventNames().storageEvent))
    307308            return;
    308309       
     
    328329       
    329330        if (auto* frame = document.frame())
    330             frames.append(frame);
     331            frames.append(*frame);
    331332    });
    332333    return frames;
     
    346347
    347348    auto frames = framesForEventDispatching(*page, m_securityOrigin, StorageType::Session, storageAreaImplID);
    348     StorageEventDispatcher::dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, urlString, m_securityOrigin->data());
     349    StorageEventDispatcher::dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, urlString, m_securityOrigin);
    349350}
    350351
     
    353354    ASSERT(isLocalStorage(type()));
    354355
    355     Vector<RefPtr<Frame>> frames;
     356    Vector<Ref<Frame>> frames;
    356357
    357358    // Namespace IDs for local storage namespaces are currently equivalent to web page group IDs.
     
    360361        frames.appendVector(framesForEventDispatching(page, m_securityOrigin, StorageType::Local, storageAreaImplID));
    361362
    362     StorageEventDispatcher::dispatchLocalStorageEventsToFrames(pageGroup, frames, key, oldValue, newValue, urlString, m_securityOrigin->data());
     363    StorageEventDispatcher::dispatchLocalStorageEventsToFrames(pageGroup, frames, key, oldValue, newValue, urlString, m_securityOrigin);
    363364}
    364365
  • trunk/Source/WebKit/WebProcess/WebStorage/StorageAreaMap.h

    r288551 r290223  
    5151    WTF_MAKE_FAST_ALLOCATED;
    5252public:
    53     StorageAreaMap(StorageNamespaceImpl&, Ref<WebCore::SecurityOrigin>&&);
     53    StorageAreaMap(StorageNamespaceImpl&, Ref<const WebCore::SecurityOrigin>&&);
    5454    ~StorageAreaMap();
    5555
     
    101101    uint64_t m_lastHandledMessageIdentifier { 0 };
    102102    StorageNamespaceImpl& m_namespace;
    103     Ref<WebCore::SecurityOrigin> m_securityOrigin;
     103    Ref<const WebCore::SecurityOrigin> m_securityOrigin;
    104104    std::unique_ptr<WebCore::StorageMap> m_map;
    105105    std::optional<StorageAreaIdentifier> m_remoteAreaIdentifier;
  • trunk/Source/WebKit/WebProcess/WebStorage/StorageNamespaceImpl.cpp

    r286936 r290223  
    101101}
    102102
    103 Ref<StorageArea> StorageNamespaceImpl::storageArea(const SecurityOriginData& securityOriginData)
     103Ref<StorageArea> StorageNamespaceImpl::storageArea(const SecurityOrigin& securityOrigin)
    104104{
    105     auto& map = m_storageAreaMaps.ensure(securityOriginData, [&] {
    106         return makeUnique<StorageAreaMap>(*this, securityOriginData.securityOrigin());
     105    auto& map = m_storageAreaMaps.ensure(securityOrigin.data(), [&] {
     106        return makeUnique<StorageAreaMap>(*this, securityOrigin);
    107107    }).iterator->value;
    108108    return StorageAreaImpl::create(*map);
  • trunk/Source/WebKit/WebProcess/WebStorage/StorageNamespaceImpl.h

    r281398 r290223  
    6868    StorageNamespaceImpl(WebCore::StorageType, Identifier, const std::optional<WebCore::PageIdentifier>&, WebCore::SecurityOrigin* topLevelOrigin, unsigned quotaInBytes);
    6969
    70     Ref<WebCore::StorageArea> storageArea(const WebCore::SecurityOriginData&) override;
     70    Ref<WebCore::StorageArea> storageArea(const WebCore::SecurityOrigin&) final;
    7171    uint64_t storageAreaMapCountForTesting() const final { return m_storageAreaMaps.size(); }
    7272
  • trunk/Source/WebKitLegacy/ChangeLog

    r289474 r290223  
     12022-02-19  Chris Dumez  <cdumez@apple.com>
     2
     3        Optimize DOM storage event dispatch
     4        https://bugs.webkit.org/show_bug.cgi?id=236871
     5
     6        Reviewed by Sihui Liu.
     7
     8        Made the following optimization to DOM storage event dispatch:
     9        1. Pass a SecurityOrigin around instead of a SecurityOriginData. Otherwise,
     10           dispatchLocalStorageEvents() / dispatchSessionStorageEvents() just keep
     11           reconstructing the SecurityOrigin from the SecurityOriginData for every
     12           frame.
     13        2. When gathering the list of frames where we need to dispatch the storage
     14           event, discard the ones that do not have a "storage" event listener.
     15
     16        * Storage/StorageAreaImpl.cpp:
     17        (WebKit::StorageAreaImpl::StorageAreaImpl):
     18        (WebKit::StorageAreaImpl::create):
     19        (WebKit::StorageAreaImpl::clearForOriginDeletion):
     20        (WebKit::StorageAreaImpl::sync):
     21        (WebKit::StorageAreaImpl::sessionChanged):
     22        * Storage/StorageAreaImpl.h:
     23        * Storage/StorageNamespaceImpl.cpp:
     24        (WebKit::StorageNamespaceImpl::storageArea):
     25        * Storage/StorageNamespaceImpl.h:
     26
    1272022-02-09  Sihui Liu  <sihui_liu@apple.com>
    228
  • trunk/Source/WebKitLegacy/Storage/StorageAreaImpl.cpp

    r276659 r290223  
    4545}
    4646
    47 inline StorageAreaImpl::StorageAreaImpl(StorageType storageType, const SecurityOriginData& origin, RefPtr<StorageSyncManager>&& syncManager, unsigned quota)
     47inline StorageAreaImpl::StorageAreaImpl(StorageType storageType, const SecurityOrigin& origin, RefPtr<StorageSyncManager>&& syncManager, unsigned quota)
    4848    : m_storageType(storageType)
    4949    , m_securityOrigin(origin)
     
    5454{
    5555    ASSERT(isMainThread());
    56    
    57     // Accessing the shared global StorageTracker when a StorageArea is created 
     56
     57    // Accessing the shared global StorageTracker when a StorageArea is created
    5858    // ensures that the tracker is properly initialized before anyone actually needs to use it.
    5959    StorageTracker::tracker();
    6060}
    6161
    62 Ref<StorageAreaImpl> StorageAreaImpl::create(StorageType storageType, const SecurityOriginData& origin, RefPtr<StorageSyncManager>&& syncManager, unsigned quota)
     62Ref<StorageAreaImpl> StorageAreaImpl::create(StorageType storageType, const SecurityOrigin& origin, RefPtr<StorageSyncManager>&& syncManager, unsigned quota)
    6363{
    6464    Ref<StorageAreaImpl> area = adoptRef(*new StorageAreaImpl(storageType, origin, WTFMove(syncManager), quota));
     
    6666    // not silently ignoring it. https://bugs.webkit.org/show_bug.cgi?id=25894
    6767    if (area->m_storageSyncManager) {
    68         area->m_storageAreaSync = StorageAreaSync::create(area->m_storageSyncManager.get(), area.copyRef(), area->m_securityOrigin.databaseIdentifier());
     68        area->m_storageAreaSync = StorageAreaSync::create(area->m_storageSyncManager.get(), area.copyRef(), area->m_securityOrigin->data().databaseIdentifier());
    6969        ASSERT(area->m_storageAreaSync);
    7070    }
     
    204204    ASSERT(!m_isShutdown);
    205205    blockUntilImportComplete();
    206    
     206
    207207    m_storageMap.clear();
    208208
     
    212212    }
    213213}
    214    
     214
    215215void StorageAreaImpl::sync()
    216216{
    217217    ASSERT(!m_isShutdown);
    218218    blockUntilImportComplete();
    219    
     219
    220220    if (m_storageAreaSync)
    221221        m_storageAreaSync->scheduleSync();
     
    288288
    289289    if (isNewSessionPersistent && !m_storageAreaSync && m_storageSyncManager) {
    290         m_storageAreaSync = StorageAreaSync::create(m_storageSyncManager.get(), *this, m_securityOrigin.databaseIdentifier());
     290        m_storageAreaSync = StorageAreaSync::create(m_storageSyncManager.get(), *this, m_securityOrigin->data().databaseIdentifier());
    291291        return;
    292292    }
  • trunk/Source/WebKitLegacy/Storage/StorageAreaImpl.h

    r276659 r290223  
    4444class StorageAreaImpl : public WebCore::StorageArea {
    4545public:
    46     static Ref<StorageAreaImpl> create(WebCore::StorageType, const WebCore::SecurityOriginData&, RefPtr<WebCore::StorageSyncManager>&&, unsigned quota);
     46    static Ref<StorageAreaImpl> create(WebCore::StorageType, const WebCore::SecurityOrigin&, RefPtr<WebCore::StorageSyncManager>&&, unsigned quota);
    4747    virtual ~StorageAreaImpl();
    4848
     
    7777
    7878private:
    79     StorageAreaImpl(WebCore::StorageType, const WebCore::SecurityOriginData&, RefPtr<WebCore::StorageSyncManager>&&, unsigned quota);
     79    StorageAreaImpl(WebCore::StorageType, const WebCore::SecurityOrigin&, RefPtr<WebCore::StorageSyncManager>&&, unsigned quota);
    8080    explicit StorageAreaImpl(const StorageAreaImpl&);
    8181
     
    8686
    8787    WebCore::StorageType m_storageType;
    88     WebCore::SecurityOriginData m_securityOrigin;
     88    Ref<const WebCore::SecurityOrigin> m_securityOrigin;
    8989    WebCore::StorageMap m_storageMap;
    9090
  • trunk/Source/WebKitLegacy/Storage/StorageNamespaceImpl.cpp

    r283237 r290223  
    2929#include "StorageSyncManager.h"
    3030#include "StorageTracker.h"
     31#include <WebCore/SecurityOrigin.h>
    3132#include <WebCore/StorageMap.h>
    3233#include <WebCore/StorageType.h>
     
    103104}
    104105
    105 Ref<StorageArea> StorageNamespaceImpl::storageArea(const SecurityOriginData& origin)
     106Ref<StorageArea> StorageNamespaceImpl::storageArea(const SecurityOrigin& origin)
    106107{
    107108    ASSERT(isMainThread());
    108109    ASSERT(!m_isShutdown);
    109110
    110     if (RefPtr<StorageAreaImpl> storageArea = m_storageAreaMap.get(origin))
    111         return storageArea.releaseNonNull();
    112 
    113     auto storageArea = StorageAreaImpl::create(m_storageType, origin, m_syncManager.get(), m_quota);
    114     m_storageAreaMap.set(origin, storageArea.ptr());
    115     return WTFMove(storageArea);
     111    return *m_storageAreaMap.ensure(origin.data(), [&] {
     112        return StorageAreaImpl::create(m_storageType, origin, m_syncManager.get(), m_quota);
     113    }).iterator->value;
    116114}
    117115
  • trunk/Source/WebKitLegacy/Storage/StorageNamespaceImpl.h

    r249354 r290223  
    3838class StorageAreaImpl;
    3939
    40 class StorageNamespaceImpl : public WebCore::StorageNamespace {
     40class StorageNamespaceImpl final : public WebCore::StorageNamespace {
    4141public:
    4242    static Ref<StorageNamespaceImpl> createSessionStorageNamespace(unsigned quota, PAL::SessionID);
     
    5555    void closeIdleLocalStorageDatabases();
    5656
    57     PAL::SessionID sessionID() const override { return m_sessionID; }
    58     void setSessionIDForTesting(PAL::SessionID) override;
     57    PAL::SessionID sessionID() const final { return m_sessionID; }
     58    void setSessionIDForTesting(PAL::SessionID) final;
    5959
    6060private:
    6161    StorageNamespaceImpl(WebCore::StorageType, const String& path, unsigned quota, PAL::SessionID);
    6262
    63     Ref<WebCore::StorageArea> storageArea(const WebCore::SecurityOriginData&) override;
    64     Ref<StorageNamespace> copy(WebCore::Page& newPage) override;
     63    Ref<WebCore::StorageArea> storageArea(const WebCore::SecurityOrigin&) final;
     64    Ref<StorageNamespace> copy(WebCore::Page& newPage) final;
    6565
    6666    typedef HashMap<WebCore::SecurityOriginData, RefPtr<StorageAreaImpl>> StorageAreaMap;
Note: See TracChangeset for help on using the changeset viewer.