Unreviewed, rolling out r254753.
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Jan 2020 17:52:52 +0000 (17:52 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Jan 2020 17:52:52 +0000 (17:52 +0000)
It turns out this is not dead code

Reverted changeset:

"Drop dead code related to local storage prewarming"
https://bugs.webkit.org/show_bug.cgi?id=206418
https://trac.webkit.org/changeset/254753

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

Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/Frame.cpp
Source/WebCore/page/Frame.h

index 96a3737..5c0c777 100644 (file)
@@ -1,3 +1,15 @@
+2020-01-21  Chris Dumez  <cdumez@apple.com>
+
+        Unreviewed, rolling out r254753.
+
+        It turns out this is not dead code
+
+        Reverted changeset:
+
+        "Drop dead code related to local storage prewarming"
+        https://bugs.webkit.org/show_bug.cgi?id=206418
+        https://trac.webkit.org/changeset/254753
+
 2020-01-21  Sihui Liu  <sihui_liu@apple.com>
 
         Disable WebSQL everywhere by default except in tests
index 78e08c7..2ab2ef5 100644 (file)
@@ -1092,6 +1092,9 @@ void DocumentLoader::commitData(const char* bytes, size_t length)
         if (!isLoading())
             return;
 
+        if (auto* window = m_frame->document()->domWindow())
+            window->prewarmLocalStorageIfNecessary();
+
         bool userChosen;
         String encoding;
         if (overrideEncoding().isNull()) {
index 2c4576f..ad9ad13 100644 (file)
@@ -439,6 +439,28 @@ void DOMWindow::didSecureTransitionTo(Document& document)
     m_performance = nullptr;
 }
 
+void DOMWindow::prewarmLocalStorageIfNecessary()
+{
+    auto* page = this->page();
+
+    // No need to prewarm for ephemeral sessions since the data is in memory only.
+    if (!page || page->usesEphemeralSession())
+        return;
+
+    if (!page->mainFrame().mayPrewarmLocalStorage())
+        return;
+
+    auto localStorageResult = this->localStorage();
+    if (localStorageResult.hasException())
+        return;
+
+    auto* localStorage = localStorageResult.returnValue();
+    if (!localStorage)
+        return;
+
+    page->mainFrame().didPrewarmLocalStorage();
+}
+
 DOMWindow::~DOMWindow()
 {
     if (m_suspendedForDocumentSuspension)
index 024b263..f7e0728 100644 (file)
@@ -203,6 +203,8 @@ public:
 
     void showModalDialog(const String& urlString, const String& dialogFeaturesString, DOMWindow& activeWindow, DOMWindow& firstWindow, const WTF::Function<void(DOMWindow&)>& prepareDialogFunction);
 
+    void prewarmLocalStorageIfNecessary();
+
     void alert(const String& message = emptyString());
     bool confirmForBindings(const String& message);
     String prompt(const String& message, const String& defaultValue);
index dc0266d..6f434d9 100644 (file)
@@ -117,6 +117,9 @@ static const Seconds scrollFrequency { 1000_s / 60. };
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, frameCounter, ("Frame"));
 
+// We prewarm local storage for at most 5 origins in a given page.
+static const unsigned maxlocalStoragePrewarmingCount { 5 };
+
 static inline Frame* parentFromOwnerElement(HTMLFrameOwnerElement* ownerElement)
 {
     if (!ownerElement)
@@ -985,6 +988,19 @@ void Frame::dropChildren()
         tree().removeChild(*child);
 }
 
+void Frame::didPrewarmLocalStorage()
+{
+    ASSERT(isMainFrame());
+    ASSERT(m_localStoragePrewarmingCount < maxlocalStoragePrewarmingCount);
+    ++m_localStoragePrewarmingCount;
+}
+
+bool Frame::mayPrewarmLocalStorage() const
+{
+    ASSERT(isMainFrame());
+    return m_localStoragePrewarmingCount < maxlocalStoragePrewarmingCount;
+}
+
 void Frame::selfOnlyRef()
 {
     ASSERT(isMainFrame());
index 2d8d007..dd9802c 100644 (file)
@@ -291,6 +291,9 @@ public:
 
     WEBCORE_EXPORT bool isAlwaysOnLoggingAllowed() const;
 
+    void didPrewarmLocalStorage();
+    bool mayPrewarmLocalStorage() const;
+
 // ========
 
     void selfOnlyRef();
@@ -353,6 +356,7 @@ private:
     unsigned m_navigationDisableCount { 0 };
     unsigned m_selfOnlyRefCount { 0 };
     bool m_hasHadUserInteraction { false };
+    unsigned m_localStoragePrewarmingCount { 0 };
 
 protected:
     UniqueRef<EventHandler> m_eventHandler;