Source/WebCore/ChangeLog

 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 NOBODY (OOPS!).
 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 Alan Bujtas <zalan@apple.com>
238
339 [LFC][IFC] Add support for ideographic baseline with font fallback

Source/WebKit/ChangeLog

 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 NOBODY (OOPS!).
 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 Wenson Hsieh <wenson_hsieh@apple.com>
227
328 [macOS] Hovering over "Copy Cropped Image" context menu item should reveal the cropped image

Source/WebKitLegacy/ChangeLog

 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 NOBODY (OOPS!).
 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
329 Manage IndexedDB storage by origin

Source/WebCore/inspector/InspectorInstrumentation.cpp

@@void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents& instrume
10071007 databaseAgent->didOpenDatabase(database);
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())
10131013 domStorageAgent->didDispatchDOMStorageEvent(key, oldValue, newValue, storageType, securityOrigin);

Source/WebCore/inspector/InspectorInstrumentation.h

@@public:
274274
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&);
280280 static void workerStarted(WorkerInspectorProxy&);

@@private:
477477
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&);
483483 static void workerStartedImpl(InstrumentingAgents&, WorkerInspectorProxy&);

@@inline void InspectorInstrumentation::didOpenDatabase(Database& database)
13251325 didOpenDatabaseImpl(*agents, database);
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());
13311331 didDispatchDOMStorageEventImpl(instrumentingAgents(page), key, oldValue, newValue, storageType, securityOrigin);

Source/WebCore/inspector/agents/InspectorDOMStorageAgent.cpp

@@String InspectorDOMStorageAgent::storageId(Storage& storage)
168168 ASSERT(window);
169169 Ref<SecurityOrigin> securityOrigin = document->securityOrigin();
170170 bool isLocalStorage = window->optionalLocalStorage() == &storage;
171  return InspectorDOMStorageAgent::storageId(securityOrigin.ptr(), isLocalStorage)->toJSONString();
 171 return InspectorDOMStorageAgent::storageId(securityOrigin, isLocalStorage)->toJSONString();
172172}
173173
174 Ref<Protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::storageId(SecurityOrigin* securityOrigin, bool isLocalStorage)
 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);
185185

@@RefPtr<StorageArea> InspectorDOMStorageAgent::findStorageArea(Protocol::ErrorStr
214214 }
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}
220220

Source/WebCore/inspector/agents/InspectorDOMStorageAgent.h

@@public:
6565 Inspector::Protocol::ErrorStringOr<void> clearDOMStorageItems(Ref<JSON::Object>&& storageId);
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:
7575 RefPtr<StorageArea> findStorageArea(Inspector::Protocol::ErrorString&, Ref<JSON::Object>&& storageId, Frame*&);

Source/WebCore/loader/EmptyClients.cpp

@@class EmptyStorageNamespaceProvider final : public StorageNamespaceProvider {
498498 {
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; }
504504 void setSessionIDForTesting(PAL::SessionID sessionID) final { m_sessionID = sessionID; };

Source/WebCore/page/DOMWindow.cpp

@@ExceptionOr<Storage*> DOMWindow::sessionStorage()
830830 if (!page)
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();
836836}

Source/WebCore/storage/StorageEventDispatcher.cpp

4040
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();
4646 if (!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 (!frame->document() || !frame->window())
5454 continue;
55  if (sourceFrame != frame && frame->document()->securityOrigin().equal(securityOrigin.securityOrigin().ptr()))
56  frames.append(frame);
 55 if (!frame->window()->hasEventListeners(eventNames().storageEvent))
 56 continue;
 57 if (sourceFrame != frame && frame->document()->securityOrigin().equal(&securityOrigin))
 58 frames.append(*frame);
5759 }
5860
5961 dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, sourceFrame->document()->url().string(), securityOrigin);
6062}
6163
62 void StorageEventDispatcher::dispatchLocalStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOriginData& securityOrigin, Frame* sourceFrame)
 64void StorageEventDispatcher::dispatchLocalStorageEvents(const String& key, const String& oldValue, const String& newValue, const SecurityOrigin& securityOrigin, Frame* sourceFrame)
6365{
6466 Page* page = sourceFrame->page();
6567 if (!page)
6668 return;
6769
68  Vector<RefPtr<Frame>> frames;
 70 Vector<Ref<Frame>> frames;
6971
7072 // Send events to every page.
7173 for (auto& pageInGroup : page->group().pages()) {
7274 for (auto* frame = &pageInGroup.mainFrame(); frame; frame = frame->tree().traverseNext()) {
73  if (!frame->document())
 75 if (!frame->document() || !frame->window())
 76 continue;
 77 if (!frame->window()->hasEventListeners(eventNames().storageEvent))
7478 continue;
75  if (sourceFrame != frame && frame->document()->securityOrigin().equal(securityOrigin.securityOrigin().ptr()))
76  frames.append(frame);
 79 if (sourceFrame != frame && frame->document()->securityOrigin().equal(&securityOrigin))
 80 frames.append(*frame);
7781 }
7882 }
7983
8084 dispatchLocalStorageEventsToFrames(page->group(), frames, key, oldValue, newValue, sourceFrame->document()->url().string(), securityOrigin);
8185}
8286
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)
 87void StorageEventDispatcher::dispatchSessionStorageEventsToFrames(Page& page, const Vector<Ref<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOrigin& securityOrigin)
8488{
85  InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Session, securityOrigin.securityOrigin().ptr());
 89 InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Session, securityOrigin);
8690
8791 for (auto& frame : frames) {
8892 RefPtr document = frame->document();

@@void StorageEventDispatcher::dispatchSessionStorageEventsToFrames(Page& page, co
9296 }
9397}
9498
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)
 99void StorageEventDispatcher::dispatchLocalStorageEventsToFrames(PageGroup& pageGroup, const Vector<Ref<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, const SecurityOrigin& securityOrigin)
96100{
97101 for (auto& page : pageGroup.pages())
98  InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Local, securityOrigin.securityOrigin().ptr());
 102 InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, newValue, StorageType::Local, securityOrigin);
99103
100104 for (auto& frame : frames) {
101105 RefPtr document = frame->document();

Source/WebCore/storage/StorageEventDispatcher.h

@@namespace WebCore {
3636class Frame;
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.
5050 StorageEventDispatcher();

Source/WebCore/storage/StorageNamespace.h

@@class SessionID;
3535namespace WebCore {
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.
4747 virtual Ref<StorageNamespace> copy(Page& newPage) = 0;

Source/WebCore/storage/StorageNamespaceProvider.cpp

@@Ref<StorageArea> StorageNamespaceProvider::localStorageArea(Document& document)
6060 else
6161 storageNamespace = &localStorageNamespace(document.page()->sessionID());
6262
63  return storageNamespace->storageArea(document.securityOrigin().data());
 63 return storageNamespace->storageArea(document.securityOrigin());
6464}
6565
6666StorageNamespace& StorageNamespaceProvider::localStorageNamespace(PAL::SessionID sessionID)

Source/WebKit/WebProcess/WebStorage/StorageAreaMap.cpp

3838#include "WebProcess.h"
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>
4344#include <WebCore/PageGroup.h>

5051namespace WebKit {
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)
5657 , m_securityOrigin(WTFMove(securityOrigin))

@@void StorageAreaMap::clearCache(uint64_t messageIdentifier)
295296 resetValues();
296297}
297298
298 static Vector<RefPtr<Frame>> framesForEventDispatching(Page& page, SecurityOrigin& origin, StorageType storageType, const std::optional<StorageAreaImplIdentifier>& storageAreaImplID)
 299static Vector<Ref<Frame>> framesForEventDispatching(Page& page, const SecurityOrigin& origin, StorageType storageType, const std::optional<StorageAreaImplIdentifier>& storageAreaImplID)
299300{
300  Vector<RefPtr<Frame>> frames;
 301 Vector<Ref<Frame>> frames;
301302 page.forEachDocument([&](auto& document) {
302303 if (!document.securityOrigin().equal(&origin))
303304 return;

@@static Vector<RefPtr<Frame>> framesForEventDispatching(Page& page, SecurityOrigi
305306 auto* window = document.domWindow();
306307 if (!window)
307308 return;
 309
 310 if (!window->hasEventListeners(eventNames().storageEvent))
 311 return;
308312
309313 Storage* storage = nullptr;
310314 switch (storageType) {

@@static Vector<RefPtr<Frame>> framesForEventDispatching(Page& page, SecurityOrigi
327331 }
328332
329333 if (auto* frame = document.frame())
330  frames.append(frame);
 334 frames.append(*frame);
331335 });
332336 return frames;
333337}

@@void StorageAreaMap::dispatchSessionStorageEvent(const std::optional<StorageArea
345349 return;
346350
347351 auto frames = framesForEventDispatching(*page, m_securityOrigin, StorageType::Session, storageAreaImplID);
348  StorageEventDispatcher::dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, urlString, m_securityOrigin->data());
 352 StorageEventDispatcher::dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, urlString, m_securityOrigin);
349353}
350354
351355void StorageAreaMap::dispatchLocalStorageEvent(const std::optional<StorageAreaImplIdentifier>& storageAreaImplID, const String& key, const String& oldValue, const String& newValue, const String& urlString)
352356{
353357 ASSERT(isLocalStorage(type()));
354358
355  Vector<RefPtr<Frame>> frames;
 359 Vector<Ref<Frame>> frames;
356360
357361 // Namespace IDs for local storage namespaces are currently equivalent to web page group IDs.
358362 auto& pageGroup = *WebProcess::singleton().webPageGroup(m_namespace.pageGroupID())->corePageGroup();
359363 for (auto& page : pageGroup.pages())
360364 frames.appendVector(framesForEventDispatching(page, m_securityOrigin, StorageType::Local, storageAreaImplID));
361365
362  StorageEventDispatcher::dispatchLocalStorageEventsToFrames(pageGroup, frames, key, oldValue, newValue, urlString, m_securityOrigin->data());
 366 StorageEventDispatcher::dispatchLocalStorageEventsToFrames(pageGroup, frames, key, oldValue, newValue, urlString, m_securityOrigin);
363367}
364368
365369void StorageAreaMap::sendConnectMessage(SendMode mode)

Source/WebKit/WebProcess/WebStorage/StorageAreaMap.h

@@class StorageNamespaceImpl;
5050class StorageAreaMap final : public IPC::MessageReceiver {
5151 WTF_MAKE_FAST_ALLOCATED;
5252public:
53  StorageAreaMap(StorageNamespaceImpl&, Ref<WebCore::SecurityOrigin>&&);
 53 StorageAreaMap(StorageNamespaceImpl&, Ref<const WebCore::SecurityOrigin>&&);
5454 ~StorageAreaMap();
5555
5656 WebCore::StorageType type() const { return m_type; }

@@private:
100100 StorageAreaMapIdentifier m_identifier;
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;
106106 HashCountedSet<String> m_pendingValueChanges;

Source/WebKit/WebProcess/WebStorage/StorageNamespaceImpl.cpp

@@void StorageNamespaceImpl::destroyStorageAreaMap(StorageAreaMap& map)
100100 m_storageAreaMaps.remove(map.securityOrigin().data());
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);
109109}

Source/WebKit/WebProcess/WebStorage/StorageNamespaceImpl.h

@@public:
6767private:
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
7373 // FIXME: This is only valid for session storage and should probably be moved to a subclass.

Source/WebKitLegacy/Storage/StorageAreaImpl.cpp

@@StorageAreaImpl::~StorageAreaImpl()
4444 ASSERT(isMainThread());
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)
5050 , m_storageMap(quota)

@@inline StorageAreaImpl::StorageAreaImpl(StorageType storageType, const SecurityO
5353 , m_closeDatabaseTimer(*this, &StorageAreaImpl::closeDatabaseTimerFired)
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));
6565 // FIXME: If there's no backing storage for LocalStorage, the default WebKit behavior should be that of private browsing,
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 }
7171 return area;

@@void StorageAreaImpl::clearForOriginDeletion()
203203{
204204 ASSERT(!m_isShutdown);
205205 blockUntilImportComplete();
206 
 206
207207 m_storageMap.clear();
208208
209209 if (m_storageAreaSync) {

@@void StorageAreaImpl::clearForOriginDeletion()
211211 m_storageAreaSync->scheduleCloseDatabase();
212212 }
213213}
214 
 214
215215void StorageAreaImpl::sync()
216216{
217217 ASSERT(!m_isShutdown);
218218 blockUntilImportComplete();
219 
 219
220220 if (m_storageAreaSync)
221221 m_storageAreaSync->scheduleSync();
222222}

@@void StorageAreaImpl::sessionChanged(bool isNewSessionPersistent)
287287 m_storageMap.clear();
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 }
293293

Source/WebKitLegacy/Storage/StorageAreaImpl.h

@@class StorageAreaSync;
4343
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
4949 unsigned length() override;

@@public:
7676 void sessionChanged(bool isNewSessionPersistent);
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
8282 void blockUntilImportComplete() const;

@@private:
8585 void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, WebCore::Frame* sourceFrame);
8686
8787 WebCore::StorageType m_storageType;
88  WebCore::SecurityOriginData m_securityOrigin;
 88 Ref<const WebCore::SecurityOrigin> m_securityOrigin;
8989 WebCore::StorageMap m_storageMap;
9090
9191 RefPtr<StorageAreaSync> m_storageAreaSync;

Source/WebKitLegacy/Storage/StorageNamespaceImpl.cpp

2828#include "StorageAreaImpl.h"
2929#include "StorageSyncManager.h"
3030#include "StorageTracker.h"
 31#include <WebCore/SecurityOrigin.h>
3132#include <WebCore/StorageMap.h>
3233#include <WebCore/StorageType.h>
3334#include <wtf/MainThread.h>

@@Ref<StorageNamespace> StorageNamespaceImpl::copy(Page&)
102103 return WTFMove(newNamespace);
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
118116void StorageNamespaceImpl::close()

Source/WebKitLegacy/Storage/StorageNamespaceImpl.h

@@namespace WebKit {
3737
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);
4343 static Ref<StorageNamespaceImpl> getOrCreateLocalStorageNamespace(const String& databasePath, unsigned quota, PAL::SessionID);

@@public:
5454 void sync();
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;
6767 StorageAreaMap m_storageAreaMap;