Remove FrameLoader::addExtraFieldsToMainResourceRequest
https://bugs.webkit.org/show_bug.cgi?id=209853

Patch by Rob Buis <rbuis@igalia.com> on 2020-04-02
Reviewed by Darin Adler.

Remove FrameLoader::addExtraFieldsToMainResourceRequest since the call is
not needed in DocumentLoader and can be inlined in FrameLoader. The call
in DocumentLoader is no longer needed since adding the User-Agent header
is decoupled from addExtraFields functionality and the User-Agent header
will be added in CachedResourceLoader after any custom setting of the
user agent (setCustomUserAgent API).

Test: http/tests/navigation/useragent-reload.php

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::startLoadingMainResource):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::load):
(WebCore::FrameLoader::addExtraFieldsToMainResourceRequest): Deleted.
* loader/FrameLoader.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259379 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 573982f..8446a9b 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,26 @@
+2020-04-02  Rob Buis  <rbuis@igalia.com>
+
+        Remove FrameLoader::addExtraFieldsToMainResourceRequest
+        https://bugs.webkit.org/show_bug.cgi?id=209853
+
+        Reviewed by Darin Adler.
+
+        Remove FrameLoader::addExtraFieldsToMainResourceRequest since the call is
+        not needed in DocumentLoader and can be inlined in FrameLoader. The call
+        in DocumentLoader is no longer needed since adding the User-Agent header
+        is decoupled from addExtraFields functionality and the User-Agent header
+        will be added in CachedResourceLoader after any custom setting of the
+        user agent (setCustomUserAgent API).
+
+        Test: http/tests/navigation/useragent-reload.php
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::startLoadingMainResource):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::load):
+        (WebCore::FrameLoader::addExtraFieldsToMainResourceRequest): Deleted.
+        * loader/FrameLoader.h:
+
 2020-04-01  Ryosuke Niwa  <rniwa@webkit.org>
 
         Crash in WebCore::HTMLDocumentParser::insert
diff --git a/Source/WebCore/loader/DocumentLoader.cpp b/Source/WebCore/loader/DocumentLoader.cpp
index decd7d7..796513c 100644
--- a/Source/WebCore/loader/DocumentLoader.cpp
+++ b/Source/WebCore/loader/DocumentLoader.cpp
@@ -1819,9 +1819,8 @@
 #endif
 
     // Make sure we re-apply the user agent to the Document's ResourceRequest upon reload in case the embedding
-    // application has changed it.
+    // application has changed it, by clearing the previous user agent value here and applying the new value in CachedResourceLoader.
     m_request.clearHTTPUserAgent();
-    frameLoader()->addExtraFieldsToMainResourceRequest(m_request);
 
     ASSERT(timing().startTime());
     ASSERT(timing().fetchStart());
diff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cpp
index 56827ff..c94c914 100644
--- a/Source/WebCore/loader/FrameLoader.cpp
+++ b/Source/WebCore/loader/FrameLoader.cpp
@@ -1521,7 +1521,9 @@
     FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "load (DocumentLoader): frame load started");
 
     ResourceRequest& r = newDocumentLoader.request();
-    addExtraFieldsToMainResourceRequest(r);
+    // FIXME: Using m_loadType seems wrong here.
+    // If we are only preparing to load the main resource, that is previous load's load type!
+    addExtraFieldsToRequest(r, m_loadType, true);
     FrameLoadType type;
 
     if (shouldTreatURLAsSameAsCurrent(newDocumentLoader.originalRequest().url())) {
@@ -2874,19 +2876,12 @@
     setDocumentLoader(nullptr);
     m_client->detachedFromParent3();
 }
-    
+
 void FrameLoader::addExtraFieldsToSubresourceRequest(ResourceRequest& request)
 {
     addExtraFieldsToRequest(request, m_loadType, false);
 }
 
-void FrameLoader::addExtraFieldsToMainResourceRequest(ResourceRequest& request)
-{
-    // FIXME: Using m_loadType seems wrong for some callers.
-    // If we are only preparing to load the main resource, that is previous load's load type!
-    addExtraFieldsToRequest(request, m_loadType, true);
-}
-
 ResourceRequestCachePolicy FrameLoader::defaultRequestCachingPolicy(const ResourceRequest& request, FrameLoadType loadType, bool isMainResource)
 {
     if (m_overrideCachePolicyForTesting)
diff --git a/Source/WebCore/loader/FrameLoader.h b/Source/WebCore/loader/FrameLoader.h
index 25b7959..0e648cc 100644
--- a/Source/WebCore/loader/FrameLoader.h
+++ b/Source/WebCore/loader/FrameLoader.h
@@ -222,7 +222,6 @@
     void detachViewsAndDocumentLoader();
 
     void addExtraFieldsToSubresourceRequest(ResourceRequest&);
-    void addExtraFieldsToMainResourceRequest(ResourceRequest&);
     
     static void addSameSiteInfoToRequestIfNeeded(ResourceRequest&, const Document* initiator = nullptr);