Title: [257045] trunk/Source/WebKit
Revision
257045
Author
cdu...@apple.com
Date
2020-02-19 22:25:44 -0800 (Wed, 19 Feb 2020)

Log Message

Regression(r246188) WebProcess is launched too eagerly when [WKWebView _restoreSessionState] is called
https://bugs.webkit.org/show_bug.cgi?id=207908

Reviewed by Darin Adler.

Since r246188, the WebProcess is launched eagerly when [WKWebView _restoreSessionState] is called. This is bad
for performance because we are unable to leverage the process cache at this point (since we don't know which
domain will be loaded).

This patch thus reverts r246188 and fixes what r246188 was trying to address in a different way. If the process
was not launched yet when restoreSessionState() is called, the session state properly gets sent to the WebProcess
after launch, via the WebPageCreationParameters. What was missing at that point was that the session state was
restore by an API Request. To fix this, we now pass an extra itemStatesWereRestoredByAPIRequest flag in
WebPageCreationParameters.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::restoreFromSessionState):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_overriddenMediaType):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (257044 => 257045)


--- trunk/Source/WebKit/ChangeLog	2020-02-20 06:24:43 UTC (rev 257044)
+++ trunk/Source/WebKit/ChangeLog	2020-02-20 06:25:44 UTC (rev 257045)
@@ -1,3 +1,30 @@
+2020-02-19  Chris Dumez  <cdu...@apple.com>
+
+        Regression(r246188) WebProcess is launched too eagerly when [WKWebView _restoreSessionState] is called
+        https://bugs.webkit.org/show_bug.cgi?id=207908
+
+        Reviewed by Darin Adler.
+
+        Since r246188, the WebProcess is launched eagerly when [WKWebView _restoreSessionState] is called. This is bad
+        for performance because we are unable to leverage the process cache at this point (since we don't know which
+        domain will be loaded).
+
+        This patch thus reverts r246188 and fixes what r246188 was trying to address in a different way. If the process
+        was not launched yet when restoreSessionState() is called, the session state properly gets sent to the WebProcess
+        after launch, via the WebPageCreationParameters. What was missing at that point was that the session state was
+        restore by an API Request. To fix this, we now pass an extra itemStatesWereRestoredByAPIRequest flag in
+        WebPageCreationParameters.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::restoreFromSessionState):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_overriddenMediaType):
+
 2020-02-19  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r257029.

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp (257044 => 257045)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2020-02-20 06:24:43 UTC (rev 257044)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2020-02-20 06:25:44 UTC (rev 257045)
@@ -52,6 +52,7 @@
     encoder << gapBetweenPages;
     encoder << paginationLineGridEnabled;
     encoder << userAgent;
+    encoder << itemStatesWereRestoredByAPIRequest;
     encoder << itemStates;
     encoder << userContentControllerID;
     encoder << visitedLinkTableID;
@@ -206,6 +207,12 @@
         return WTF::nullopt;
     parameters.userAgent = WTFMove(*userAgent);
 
+    Optional<bool> itemStatesWereRestoredByAPIRequest;
+    decoder >> itemStatesWereRestoredByAPIRequest;
+    if (!itemStatesWereRestoredByAPIRequest)
+        return WTF::nullopt;
+    parameters.itemStatesWereRestoredByAPIRequest = *itemStatesWereRestoredByAPIRequest;
+
     Optional<Vector<BackForwardListItemState>> itemStates;
     decoder >> itemStates;
     if (!itemStates)

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.h (257044 => 257045)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2020-02-20 06:24:43 UTC (rev 257044)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2020-02-20 06:25:44 UTC (rev 257045)
@@ -97,6 +97,7 @@
     
     String userAgent;
 
+    bool itemStatesWereRestoredByAPIRequest { false };
     Vector<BackForwardListItemState> itemStates;
 
     UserContentControllerIdentifier userContentControllerID;

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (257044 => 257045)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-02-20 06:24:43 UTC (rev 257044)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-02-20 06:25:44 UTC (rev 257045)
@@ -3400,16 +3400,14 @@
     bool hasBackForwardList = !!sessionState.backForwardListState.currentIndex;
 
     if (hasBackForwardList) {
-        // If there isn't a running process yet the RestoreSession message below is just ignored, and
-        // session is restored when the web process is created via creation parameters which is not
-        // considered an API request. So, we launch the initial process here before restoring the
-        // session to ensure the session is restored in the web process via RestoreSession IPC message
-        // which is considered an API request. See https://bugs.webkit.org/show_bug.cgi?id=198561.
-        launchInitialProcessIfNecessary();
+        m_sessionStateWasRestoredByAPIRequest = true;
 
         m_backForwardList->restoreFromState(WTFMove(sessionState.backForwardListState));
-        send(Messages::WebPage::RestoreSession(m_backForwardList->itemStates()));
 
+        // If the process is not launched yet, the session will be restored when sending the WebPageCreationParameters;
+        if (hasRunningProcess())
+            send(Messages::WebPage::RestoreSession(m_backForwardList->itemStates()));
+
         auto transaction = m_pageLoadState.transaction();
         m_pageLoadState.setCanGoBack(transaction, m_backForwardList->backItem());
         m_pageLoadState.setCanGoForward(transaction, m_backForwardList->forwardItem());
@@ -7585,6 +7583,7 @@
     parameters.gapBetweenPages = m_gapBetweenPages;
     parameters.paginationLineGridEnabled = m_paginationLineGridEnabled;
     parameters.userAgent = userAgent();
+    parameters.itemStatesWereRestoredByAPIRequest = m_sessionStateWasRestoredByAPIRequest;
     parameters.itemStates = m_backForwardList->itemStates();
     parameters.userContentControllerID = m_userContentController->identifier();
     parameters.visitedLinkTableID = m_visitedLinkStore->identifier();

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (257044 => 257045)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-02-20 06:24:43 UTC (rev 257044)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-02-20 06:25:44 UTC (rev 257045)
@@ -2720,6 +2720,7 @@
 #if USE(DIRECT2D)
     COMPtr<ID3D11Device1> m_device;
 #endif
+    bool m_sessionStateWasRestoredByAPIRequest { false };
     bool m_isQuotaIncreaseDenied { false };
     bool m_isLayerTreeFrozenDueToSwipeAnimation { false };
     

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (257044 => 257045)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-02-20 06:24:43 UTC (rev 257044)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-02-20 06:25:44 UTC (rev 257045)
@@ -635,7 +635,7 @@
     m_userAgent = parameters.userAgent;
     
     if (!parameters.itemStates.isEmpty())
-        restoreSessionInternal(parameters.itemStates, WasRestoredByAPIRequest::No, WebBackForwardListProxy::OverwriteExistingItem::Yes);
+        restoreSessionInternal(parameters.itemStates, parameters.itemStatesWereRestoredByAPIRequest ? WasRestoredByAPIRequest::Yes : WasRestoredByAPIRequest::No, WebBackForwardListProxy::OverwriteExistingItem::Yes);
 
     m_drawingArea->enablePainting();
     
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to