Title: [283147] branches/safari-612-branch/Source/WebKit
Revision
283147
Author
[email protected]
Date
2021-09-27 15:49:38 -0700 (Mon, 27 Sep 2021)

Log Message

Cherry-pick r283081. rdar://problem/83584464

    Pending preconnect key should include User-Agent
    https://bugs.webkit.org/show_bug.cgi?id=230565

    Reviewed by Chris Dumez.

    When using an HTTPS proxy, the HTTP connection cache key used for connection coalescing in
    CFNetwork includes the User-Agent (<rdar://problem/59434166>). This means we should also
    include it in the preconnect cache key. Otherwise, we might delay the main resource load on
    preconnect unnecessarily in cases where the User-Agent mismatches and the preconnect gets
    thrown away. This can happen if (for instance) a page is force-loaded into desktop or mobile
    mode on iOS, which causes a UA change after the call to decidePolicyForNavigationAction.

    * NetworkProcess/NetworkLoadScheduler.cpp:
    (WebKit::mainResourceLoadKey):
    (WebKit::NetworkLoadScheduler::scheduleMainResourceLoad):
    (WebKit::NetworkLoadScheduler::unscheduleMainResourceLoad):
    (WebKit::NetworkLoadScheduler::startedPreconnectForMainResource):
    (WebKit::NetworkLoadScheduler::finishedPreconnectForMainResource):
    * NetworkProcess/NetworkLoadScheduler.h:
    * NetworkProcess/NetworkProcess.cpp:
    (WebKit::NetworkProcess::preconnectTo):

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

Modified Paths

Diff

Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (283146 => 283147)


--- branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-27 22:49:35 UTC (rev 283146)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-27 22:49:38 UTC (rev 283147)
@@ -1,5 +1,58 @@
 2021-09-27  Alan Coon  <[email protected]>
 
+        Cherry-pick r283081. rdar://problem/83584464
+
+    Pending preconnect key should include User-Agent
+    https://bugs.webkit.org/show_bug.cgi?id=230565
+    
+    Reviewed by Chris Dumez.
+    
+    When using an HTTPS proxy, the HTTP connection cache key used for connection coalescing in
+    CFNetwork includes the User-Agent (<rdar://problem/59434166>). This means we should also
+    include it in the preconnect cache key. Otherwise, we might delay the main resource load on
+    preconnect unnecessarily in cases where the User-Agent mismatches and the preconnect gets
+    thrown away. This can happen if (for instance) a page is force-loaded into desktop or mobile
+    mode on iOS, which causes a UA change after the call to decidePolicyForNavigationAction.
+    
+    * NetworkProcess/NetworkLoadScheduler.cpp:
+    (WebKit::mainResourceLoadKey):
+    (WebKit::NetworkLoadScheduler::scheduleMainResourceLoad):
+    (WebKit::NetworkLoadScheduler::unscheduleMainResourceLoad):
+    (WebKit::NetworkLoadScheduler::startedPreconnectForMainResource):
+    (WebKit::NetworkLoadScheduler::finishedPreconnectForMainResource):
+    * NetworkProcess/NetworkLoadScheduler.h:
+    * NetworkProcess/NetworkProcess.cpp:
+    (WebKit::NetworkProcess::preconnectTo):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283081 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-25  Ben Nham  <[email protected]>
+
+            Pending preconnect key should include User-Agent
+            https://bugs.webkit.org/show_bug.cgi?id=230565
+
+            Reviewed by Chris Dumez.
+
+            When using an HTTPS proxy, the HTTP connection cache key used for connection coalescing in
+            CFNetwork includes the User-Agent (<rdar://problem/59434166>). This means we should also
+            include it in the preconnect cache key. Otherwise, we might delay the main resource load on
+            preconnect unnecessarily in cases where the User-Agent mismatches and the preconnect gets
+            thrown away. This can happen if (for instance) a page is force-loaded into desktop or mobile
+            mode on iOS, which causes a UA change after the call to decidePolicyForNavigationAction.
+
+            * NetworkProcess/NetworkLoadScheduler.cpp:
+            (WebKit::mainResourceLoadKey):
+            (WebKit::NetworkLoadScheduler::scheduleMainResourceLoad):
+            (WebKit::NetworkLoadScheduler::unscheduleMainResourceLoad):
+            (WebKit::NetworkLoadScheduler::startedPreconnectForMainResource):
+            (WebKit::NetworkLoadScheduler::finishedPreconnectForMainResource):
+            * NetworkProcess/NetworkLoadScheduler.h:
+            * NetworkProcess/NetworkProcess.cpp:
+            (WebKit::NetworkProcess::preconnectTo):
+
+2021-09-27  Alan Coon  <[email protected]>
+
         Cherry-pick r283035. rdar://problem/83584492
 
     <video> element rendered incorrectly when provided with a portrait orientation stream in Safari 15

Modified: branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkLoadScheduler.cpp (283146 => 283147)


--- branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkLoadScheduler.cpp	2021-09-27 22:49:35 UTC (rev 283146)
+++ branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkLoadScheduler.cpp	2021-09-27 22:49:38 UTC (rev 283147)
@@ -153,6 +153,13 @@
         context->unschedule(load);
 }
 
+// We add User-Agent to the preconnect key since it part of the HTTP connection cache key used for
+// coalescing sockets in CFNetwork when using an HTTPS proxy (<rdar://problem/59434166>).
+static std::tuple<String, String> mainResourceLoadKey(const String& protocolHostAndPort, const String& userAgent)
+{
+    return std::make_tuple(protocolHostAndPort.isNull() ? emptyString() : protocolHostAndPort, userAgent.isNull() ? emptyString() : userAgent);
+}
+
 void NetworkLoadScheduler::scheduleMainResourceLoad(NetworkLoad& load)
 {
     String protocolHostAndPort = load.url().protocolHostAndPort();
@@ -161,7 +168,7 @@
         return;
     }
 
-    auto iter = m_pendingMainResourcePreconnects.find(protocolHostAndPort);
+    auto iter = m_pendingMainResourcePreconnects.find(mainResourceLoadKey(protocolHostAndPort, load.parameters().request.httpUserAgent()));
     if (iter == m_pendingMainResourcePreconnects.end()) {
         load.start();
         return;
@@ -185,7 +192,7 @@
     if (metrics)
         updateOriginProtocolInfo(protocolHostAndPort, metrics->protocol);
 
-    auto iter = m_pendingMainResourcePreconnects.find(protocolHostAndPort);
+    auto iter = m_pendingMainResourcePreconnects.find(mainResourceLoadKey(protocolHostAndPort, load.parameters().request.httpUserAgent()));
     if (iter == m_pendingMainResourcePreconnects.end())
         return;
 
@@ -194,9 +201,10 @@
         maybePrunePreconnectInfo(iter);
 }
 
-void NetworkLoadScheduler::startedPreconnectForMainResource(const URL& url)
+void NetworkLoadScheduler::startedPreconnectForMainResource(const URL& url, const String& userAgent)
 {
-    auto iter = m_pendingMainResourcePreconnects.find(url.protocolHostAndPort());
+    auto key = mainResourceLoadKey(url.protocolHostAndPort(), userAgent);
+    auto iter = m_pendingMainResourcePreconnects.find(key);
     if (iter != m_pendingMainResourcePreconnects.end()) {
         PendingMainResourcePreconnectInfo& info = iter->value;
         info.pendingPreconnects++;
@@ -204,12 +212,12 @@
     }
 
     PendingMainResourcePreconnectInfo info;
-    m_pendingMainResourcePreconnects.add(url.protocolHostAndPort(), WTFMove(info));
+    m_pendingMainResourcePreconnects.add(key, WTFMove(info));
 }
 
-void NetworkLoadScheduler::finishedPreconnectForMainResource(const URL& url, const WebCore::ResourceError& error)
+void NetworkLoadScheduler::finishedPreconnectForMainResource(const URL& url, const String& userAgent, const WebCore::ResourceError& error)
 {
-    auto iter = m_pendingMainResourcePreconnects.find(url.protocolHostAndPort());
+    auto iter = m_pendingMainResourcePreconnects.find(mainResourceLoadKey(url.protocolHostAndPort(), userAgent));
     if (iter == m_pendingMainResourcePreconnects.end())
         return;
 

Modified: branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkLoadScheduler.h (283146 => 283147)


--- branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkLoadScheduler.h	2021-09-27 22:49:35 UTC (rev 283146)
+++ branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkLoadScheduler.h	2021-09-27 22:49:38 UTC (rev 283147)
@@ -28,6 +28,7 @@
 #include <WebCore/LoadSchedulingMode.h>
 #include <WebCore/NetworkLoadMetrics.h>
 #include <WebCore/PageIdentifier.h>
+#include <tuple>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/ListHashSet.h>
@@ -50,8 +51,8 @@
     void schedule(NetworkLoad&);
     void unschedule(NetworkLoad&, const WebCore::NetworkLoadMetrics* = nullptr);
 
-    void startedPreconnectForMainResource(const URL&);
-    void finishedPreconnectForMainResource(const URL&, const WebCore::ResourceError&);
+    void startedPreconnectForMainResource(const URL&, const String& userAgent);
+    void finishedPreconnectForMainResource(const URL&, const String& userAgent, const WebCore::ResourceError&);
 
     void setResourceLoadSchedulingMode(WebCore::PageIdentifier, WebCore::LoadSchedulingMode);
     void prioritizeLoads(const Vector<NetworkLoad*>&);
@@ -77,7 +78,8 @@
         unsigned pendingPreconnects {1};
         ListHashSet<NetworkLoad *> pendingLoads;
     };
-    using PendingPreconnectMap = HashMap<String, PendingMainResourcePreconnectInfo>;
+    // Maps (protocolHostAndPort, userAgent) => PendingMainResourcePreconnectInfo.
+    using PendingPreconnectMap = HashMap<std::tuple<String, String>, PendingMainResourcePreconnectInfo>;
     PendingPreconnectMap m_pendingMainResourcePreconnects;
 
     void maybePrunePreconnectInfo(PendingPreconnectMap::iterator&);

Modified: branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp (283146 => 283147)


--- branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2021-09-27 22:49:35 UTC (rev 283146)
+++ branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2021-09-27 22:49:38 UTC (rev 283147)
@@ -1394,9 +1394,9 @@
     parameters.storedCredentialsPolicy = storedCredentialsPolicy;
     parameters.shouldPreconnectOnly = PreconnectOnly::Yes;
 
-    networkSession->networkLoadScheduler().startedPreconnectForMainResource(url);
-    auto task = new PreconnectTask(*networkSession, WTFMove(parameters), [networkSession, url](const WebCore::ResourceError& error) {
-        networkSession->networkLoadScheduler().finishedPreconnectForMainResource(url, error);
+    networkSession->networkLoadScheduler().startedPreconnectForMainResource(url, userAgent);
+    auto task = new PreconnectTask(*networkSession, WTFMove(parameters), [networkSession, url, userAgent](const WebCore::ResourceError& error) {
+        networkSession->networkLoadScheduler().finishedPreconnectForMainResource(url, userAgent, error);
     });
     task->setTimeout(10_s);
     task->start();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to