Do domain prewarming for processes for new tabs
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Oct 2018 17:41:55 +0000 (17:41 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Oct 2018 17:41:55 +0000 (17:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190425

Reviewed by Chris Dumez.

We currently only do domain prewarming for navigation process swaps.

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::processForNavigationInternal):

Do domain prewarming when using an existing but so far unused process.

(WebKit::WebProcessPool::tryPrewarmWithDomainInformation):

Factor into a function.

* UIProcess/WebProcessPool.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::close):

This didn't usually get invoked.

(WebKit::WebPage::didReceivePolicyDecision):
(WebKit::WebPage::didFinishLoad):

Update prewarm information when a top level load finishes.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::sendPrewarmInformation):
* WebProcess/WebProcess.h:

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h

index 6ef050a..b3c017f 100644 (file)
@@ -1,3 +1,36 @@
+2018-10-10  Antti Koivisto  <antti@apple.com>
+
+        Do domain prewarming for processes for new tabs
+        https://bugs.webkit.org/show_bug.cgi?id=190425
+
+        Reviewed by Chris Dumez.
+
+        We currently only do domain prewarming for navigation process swaps.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::processForNavigationInternal):
+
+        Do domain prewarming when using an existing but so far unused process.
+
+        (WebKit::WebProcessPool::tryPrewarmWithDomainInformation):
+
+        Factor into a function.
+
+        * UIProcess/WebProcessPool.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::close):
+
+        This didn't usually get invoked.
+
+        (WebKit::WebPage::didReceivePolicyDecision):
+        (WebKit::WebPage::didFinishLoad):
+
+        Update prewarm information when a top level load finishes.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::sendPrewarmInformation):
+        * WebProcess/WebProcess.h:
+
 2018-10-09  Antoine Quint  <graouts@apple.com>
 
         Remove the frames() timing function
index efbc22b..56ff98d 100644 (file)
@@ -2073,6 +2073,8 @@ Ref<WebProcessProxy> WebProcessPool::processForNavigation(WebPageProxy& page, co
 
 Ref<WebProcessProxy> WebProcessPool::processForNavigationInternal(WebPageProxy& page, const API::Navigation& navigation, ProcessSwapRequestedByClient processSwapRequestedByClient, PolicyAction& action, String& reason)
 {
+    auto& targetURL = navigation.currentRequest().url();
+
     if (!m_configuration->processSwapsOnNavigation() && processSwapRequestedByClient == ProcessSwapRequestedByClient::No) {
         reason = "Feature is disabled"_s;
         return page.process();
@@ -2090,6 +2092,7 @@ Ref<WebProcessProxy> WebProcessPool::processForNavigationInternal(WebPageProxy&
 
     if (!page.process().hasCommittedAnyProvisionalLoads()) {
         reason = "Process has not yet committed any provisional loads"_s;
+        tryPrewarmWithDomainInformation(page.process(), targetURL);
         return page.process();
     }
 
@@ -2130,7 +2133,6 @@ Ref<WebProcessProxy> WebProcessPool::processForNavigationInternal(WebPageProxy&
         }
     }
 
-    auto targetURL = navigation.currentRequest().url();
     if (processSwapRequestedByClient == ProcessSwapRequestedByClient::No) {
         if (navigation.treatAsSameOriginNavigation()) {
             reason = "The treatAsSameOriginNavigation flag is set"_s;
@@ -2182,9 +2184,7 @@ Ref<WebProcessProxy> WebProcessPool::processForNavigationInternal(WebPageProxy&
     action = PolicyAction::Suspend;
 
     if (RefPtr<WebProcessProxy> process = tryTakePrewarmedProcess(page.websiteDataStore())) {
-        if (auto* prewarmInformation = m_prewarmInformationPerRegistrableDomain.get(toRegistrableDomain(targetURL)))
-            process->send(Messages::WebProcess::PrewarmWithDomainInformation(*prewarmInformation), 0);
-
+        tryPrewarmWithDomainInformation(*process, targetURL);
         return process.releaseNonNull();
     }
 
@@ -2274,4 +2274,12 @@ void WebProcessPool::didCollectPrewarmInformation(const String& registrableDomai
     *value = prewarmInformation;
 }
 
+void WebProcessPool::tryPrewarmWithDomainInformation(WebProcessProxy& process, const WebCore::URL& url)
+{
+    auto* prewarmInformation = m_prewarmInformationPerRegistrableDomain.get(toRegistrableDomain(url));
+    if (!prewarmInformation)
+        return;
+    process.send(Messages::WebProcess::PrewarmWithDomainInformation(*prewarmInformation), 0);
+}
+
 } // namespace WebKit
index a239ea0..ff8eb15 100644 (file)
@@ -523,6 +523,8 @@ private:
     void addProcessToOriginCacheSet(WebPageProxy&);
     void removeProcessFromOriginCacheSet(WebProcessProxy&);
 
+    void tryPrewarmWithDomainInformation(WebProcessProxy&, const WebCore::URL&);
+
     Ref<API::ProcessPoolConfiguration> m_configuration;
 
     IPC::MessageReceiverMap m_messageReceiverMap;
index 2981ffd..a4e46cb 100644 (file)
@@ -1173,12 +1173,9 @@ void WebPage::close()
     m_isClosed = true;
 
     // If there is still no URL, then we never loaded anything in this page, so nothing to report.
-    if (!mainWebFrame()->url().isEmpty()) {
+    if (!mainWebFrame()->url().isEmpty())
         reportUsedFeatures();
 
-        WebProcess::singleton().sendPrewarmInformation(toRegistrableDomain(mainWebFrame()->url()));
-    }
-
     if (pageGroup()->isVisibleToInjectedBundle() && WebProcess::singleton().injectedBundle())
         WebProcess::singleton().injectedBundle()->willDestroyPage(this);
 
@@ -2877,7 +2874,7 @@ void WebPage::didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, Po
         ASSERT(frame == m_mainFrame);
         setIsSuspended(true);
 
-        WebProcess::singleton().sendPrewarmInformation(toRegistrableDomain(mainWebFrame()->url()));
+        WebProcess::singleton().sendPrewarmInformation(mainWebFrame()->url());
     }
     frame->didReceivePolicyDecision(listenerID, policyAction, navigationID, downloadID, WTFMove(websitePolicies));
 }
@@ -5385,10 +5382,12 @@ void WebPage::didCommitLoad(WebFrame* frame)
 
 void WebPage::didFinishLoad(WebFrame* frame)
 {
-#if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
     if (!frame->isMainFrame())
         return;
 
+    WebProcess::singleton().sendPrewarmInformation(frame->url());
+
+#if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
     m_readyToFindPrimarySnapshottedPlugin = true;
     LOG(Plugins, "Primary Plug-In Detection: triggering detection from didFinishLoad (marking as ready to detect).");
     m_determinePrimarySnapshottedPlugInTimer.startOneShot(0_s);
index 66fd2fc..69c2335 100644 (file)
@@ -1473,8 +1473,9 @@ void WebProcess::processDidResume()
 #endif
 }
 
-void WebProcess::sendPrewarmInformation(const String& registrableDomain)
+void WebProcess::sendPrewarmInformation(const WebCore::URL& url)
 {
+    auto registrableDomain = toRegistrableDomain(url);
     if (registrableDomain.isEmpty())
         return;
     parentProcessConnection()->send(Messages::WebProcessProxy::DidCollectPrewarmInformation(registrableDomain, WebCore::ProcessWarming::collectPrewarmInformation()), 0);
index 5a451d2..3d21cc8 100644 (file)
@@ -201,7 +201,7 @@ public:
     void cancelPrepareToSuspend();
     void processDidResume();
 
-    void sendPrewarmInformation(const String& registrableDomain);
+    void sendPrewarmInformation(const WebCore::URL&);
 
 #if PLATFORM(IOS)
     void resetAllGeolocationPermissions();