http/tests/preconnect/link-rel-preconnect-https.html is flaky
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Sep 2017 00:35:24 +0000 (00:35 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Sep 2017 00:35:24 +0000 (00:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177673

Reviewed by Alex Christensen.

Source/WebCore:

No new tests, unskipped test that is now passing consistently.

* loader/LinkLoader.cpp:
(WebCore::LinkLoader::loadLink):
* loader/LoaderStrategy.h:

Source/WebKit:

Update PreconnectTask to query the client when a certificate needs to be
validated. This allows WebKitTestRunner to ignore invalid certificates
and this causes http/tests/preconnect/link-rel-preconnect-https.html
to pass consistently.

To avoid duplicating code, PreconnectTask now uses NetworkLoad internally
instead of using a NetworkDataTask directly.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::preconnectTo):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:
* NetworkProcess/NetworkLoad.h:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::generateCanAuthenticateIdentifier):
(WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace):
(WebKit::NetworkProcess::continueCanAuthenticateAgainstProtectionSpace):
(WebKit::NetworkProcess::preconnectTo):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkResourceLoadParameters.cpp:
(WebKit::NetworkResourceLoadParameters::encode const):
(WebKit::NetworkResourceLoadParameters::decode):
* NetworkProcess/PreconnectTask.cpp:
(WebKit::PreconnectTask::PreconnectTask):
(WebKit::PreconnectTask::~PreconnectTask):
(WebKit::PreconnectTask::willSendRedirectedRequest):
(WebKit::PreconnectTask::didReceiveResponse):
(WebKit::PreconnectTask::didReceiveBuffer):
(WebKit::PreconnectTask::didFinishLoading):
(WebKit::PreconnectTask::didFailLoading):
(WebKit::PreconnectTask::didSendData):
(WebKit::PreconnectTask::canAuthenticateAgainstProtectionSpaceAsync):
(WebKit::PreconnectTask::continueCanAuthenticateAgainstProtectionSpace):
(WebKit::PreconnectTask::frameID const):
(WebKit::PreconnectTask::pageID const):
* NetworkProcess/PreconnectTask.h:
* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::preconnectTo):
* WebProcess/Network/WebLoaderStrategy.h:

Source/WebKitLegacy:

* WebCoreSupport/WebResourceLoadScheduler.cpp:
(WebResourceLoadScheduler::preconnectTo):
* WebCoreSupport/WebResourceLoadScheduler.h:

LayoutTests:

* http/tests/preconnect/link-rel-preconnect-https-expected.txt:
Rebaseline test now that it is passing.

* platform/wk2/TestExpectations:
Uskip test as it should no longer be flaky.

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

21 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/preconnect/link-rel-preconnect-https-expected.txt
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/loader/LinkLoader.cpp
Source/WebCore/loader/LoaderStrategy.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in
Source/WebKit/NetworkProcess/NetworkLoad.h
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.cpp
Source/WebKit/NetworkProcess/PreconnectTask.cpp
Source/WebKit/NetworkProcess/PreconnectTask.h
Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
Source/WebKit/WebProcess/Network/WebLoaderStrategy.h
Source/WebKitLegacy/ChangeLog
Source/WebKitLegacy/WebCoreSupport/WebResourceLoadScheduler.cpp
Source/WebKitLegacy/WebCoreSupport/WebResourceLoadScheduler.h

index 3c8f1fb..fe5a59f 100644 (file)
@@ -1,5 +1,18 @@
 2017-09-29  Chris Dumez  <cdumez@apple.com>
 
+        http/tests/preconnect/link-rel-preconnect-https.html is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=177673
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/preconnect/link-rel-preconnect-https-expected.txt:
+        Rebaseline test now that it is passing.
+
+        * platform/wk2/TestExpectations:
+        Uskip test as it should no longer be flaky.
+
+2017-09-29  Chris Dumez  <cdumez@apple.com>
+
         Unreviewed, temporarily mark http/tests/preconnect/link-rel-preconnect-https.html as flaky.
 
         * platform/wk2/TestExpectations:
index 3c14e23..7d1e478 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: Failed to preconnect to https://localhost:8443/. Error: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “localhost” which could put your confidential information at risk.
+CONSOLE MESSAGE: Successfuly preconnected to https://localhost:8443/
 Tests that Link's rel=preconnect works as expected over HTTPS.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
index 238e86e..c6350ef 100644 (file)
@@ -712,7 +712,5 @@ webkit.org/b/174471 webrtc/filtering-ice-candidate-after-reload.html [ Pass Time
 
 webkit.org/b/175678 media/W3C/video/events/event_progress.html [ Pass Failure ]
 
-webkit.org/b/177673 http/tests/preconnect/link-rel-preconnect-https.html [ Pass Failure ]
-
 webkit.org/b/177440 imported/w3c/web-platform-tests/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain_setter_null.tentative.html [ Pass Failure ]
 
index 0c3c5b8..8923495 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-29  Chris Dumez  <cdumez@apple.com>
+
+        http/tests/preconnect/link-rel-preconnect-https.html is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=177673
+
+        Reviewed by Alex Christensen.
+
+        No new tests, unskipped test that is now passing consistently.
+
+        * loader/LinkLoader.cpp:
+        (WebCore::LinkLoader::loadLink):
+        * loader/LoaderStrategy.h:
+
 2017-09-29  Daniel Bates  <dabates@apple.com>
 
         Extract logic to compute text to render into common function
index 9e3f2aa..f7cc579 100644 (file)
@@ -253,12 +253,13 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href,
             document.frame()->loader().client().prefetchDNS(href.host());
     }
 
-    if (relAttribute.isLinkPreconnect && href.isValid() && href.protocolIsInHTTPFamily()) {
+    if (relAttribute.isLinkPreconnect && href.isValid() && href.protocolIsInHTTPFamily() && document.frame()) {
         ASSERT(document.settings().linkPreconnectEnabled());
         StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
         if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
             storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
-        platformStrategies()->loaderStrategy()->preconnectTo(document.sessionID(), href, storageCredentialsPolicy, [weakDocument = document.createWeakPtr(), href](ResourceError error) {
+        ASSERT(document.frame()->loader().networkingContext());
+        platformStrategies()->loaderStrategy()->preconnectTo(*document.frame()->loader().networkingContext(), href, storageCredentialsPolicy, [weakDocument = document.createWeakPtr(), href](ResourceError error) {
             if (!weakDocument)
                 return;
 
index 98bed84..b57cf95 100644 (file)
@@ -69,7 +69,7 @@ public:
     virtual void startPingLoad(Frame&, ResourceRequest&, const HTTPHeaderMap& originalRequestHeaders, const FetchOptions&, PingLoadCompletionHandler&& = { }) = 0;
 
     using PreconnectCompletionHandler = WTF::Function<void(const ResourceError&)>;
-    virtual void preconnectTo(PAL::SessionID, const URL&, StoredCredentialsPolicy, PreconnectCompletionHandler&&) = 0;
+    virtual void preconnectTo(NetworkingContext&, const URL&, StoredCredentialsPolicy, PreconnectCompletionHandler&&) = 0;
 
     virtual void storeDerivedDataToCache(const SHA1::Digest& bodyKey, const String& type, const String& partition, WebCore::SharedBuffer&) = 0;
 
index 3907b48..398eebb 100644 (file)
@@ -1,3 +1,50 @@
+2017-09-29  Chris Dumez  <cdumez@apple.com>
+
+        http/tests/preconnect/link-rel-preconnect-https.html is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=177673
+
+        Reviewed by Alex Christensen.
+
+        Update PreconnectTask to query the client when a certificate needs to be
+        validated. This allows WebKitTestRunner to ignore invalid certificates
+        and this causes http/tests/preconnect/link-rel-preconnect-https.html
+        to pass consistently.
+
+        To avoid duplicating code, PreconnectTask now uses NetworkLoad internally
+        instead of using a NetworkDataTask directly.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::preconnectTo):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+        * NetworkProcess/NetworkLoad.h:
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::generateCanAuthenticateIdentifier):
+        (WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace):
+        (WebKit::NetworkProcess::continueCanAuthenticateAgainstProtectionSpace):
+        (WebKit::NetworkProcess::preconnectTo):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkResourceLoadParameters.cpp:
+        (WebKit::NetworkResourceLoadParameters::encode const):
+        (WebKit::NetworkResourceLoadParameters::decode):
+        * NetworkProcess/PreconnectTask.cpp:
+        (WebKit::PreconnectTask::PreconnectTask):
+        (WebKit::PreconnectTask::~PreconnectTask):
+        (WebKit::PreconnectTask::willSendRedirectedRequest):
+        (WebKit::PreconnectTask::didReceiveResponse):
+        (WebKit::PreconnectTask::didReceiveBuffer):
+        (WebKit::PreconnectTask::didFinishLoading):
+        (WebKit::PreconnectTask::didFailLoading):
+        (WebKit::PreconnectTask::didSendData):
+        (WebKit::PreconnectTask::canAuthenticateAgainstProtectionSpaceAsync):
+        (WebKit::PreconnectTask::continueCanAuthenticateAgainstProtectionSpace):
+        (WebKit::PreconnectTask::frameID const):
+        (WebKit::PreconnectTask::pageID const):
+        * NetworkProcess/PreconnectTask.h:
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::WebLoaderStrategy::preconnectTo):
+        * WebProcess/Network/WebLoaderStrategy.h:
+
 2017-09-29  Alex Christensen  <achristensen@webkit.org>
 
         Expose WebPreferences::webGLEnabled through WKPreferences
index 94ec00f..4eaecf7 100644 (file)
@@ -291,15 +291,15 @@ void NetworkConnectionToWebProcess::prefetchDNS(const String& hostname)
     NetworkProcess::singleton().prefetchDNS(hostname);
 }
 
-void NetworkConnectionToWebProcess::preconnectTo(PAL::SessionID sessionID, uint64_t preconnectionIdentifier, const URL& url, WebCore::StoredCredentialsPolicy storedCredentialsPolicy)
+void NetworkConnectionToWebProcess::preconnectTo(uint64_t preconnectionIdentifier, NetworkLoadParameters&& parameters)
 {
 #if ENABLE(SERVER_PRECONNECT)
-    new PreconnectTask(sessionID, url, storedCredentialsPolicy, [this, protectedThis = makeRef(*this), identifier = preconnectionIdentifier] (const ResourceError& error) {
+    new PreconnectTask(WTFMove(parameters), [this, protectedThis = makeRef(*this), identifier = preconnectionIdentifier] (const ResourceError& error) {
         didFinishPreconnection(identifier, error);
     });
 #else
-    UNUSED_PARAM(storedCredentialsPolicy);
-    didFinishPreconnection(preconnectionIdentifier, internalError(url));
+    UNUSED_PARAM(parameters);
+    didFinishPreconnection(preconnectionIdentifier, internalError(parameters.request.url()));
 #endif
 }
 
index b10df58..3aed7eb 100644 (file)
@@ -47,6 +47,7 @@ enum class IncludeSecureCookies;
 namespace WebKit {
 
 class NetworkConnectionToWebProcess;
+class NetworkLoadParameters;
 class NetworkResourceLoader;
 class NetworkSocketStream;
 class SyncNetworkResourceLoader;
@@ -92,7 +93,7 @@ private:
     void performSynchronousLoad(const NetworkResourceLoadParameters&, Ref<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
     void loadPing(NetworkResourceLoadParameters&&, WebCore::HTTPHeaderMap&& originalRequestHeaders);
     void prefetchDNS(const String&);
-    void preconnectTo(PAL::SessionID, uint64_t preconnectionIdentifier, const WebCore::URL&, WebCore::StoredCredentialsPolicy);
+    void preconnectTo(uint64_t preconnectionIdentifier, NetworkLoadParameters&&);
 
     void removeLoadIdentifier(ResourceLoadIdentifier);
     void setDefersLoading(ResourceLoadIdentifier, bool);
index e85e973..abfb30f 100644 (file)
@@ -28,7 +28,7 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
     RemoveLoadIdentifier(uint64_t resourceLoadIdentifier)
     SetDefersLoading(uint64_t resourceLoadIdentifier, bool defers)
     PrefetchDNS(String hostname)
-    PreconnectTo(PAL::SessionID sessionID, uint64_t preconnectionIdentifier, WebCore::URL url, enum WebCore::StoredCredentialsPolicy storedCredentialsPolicy);
+    PreconnectTo(uint64_t preconnectionIdentifier, WebKit::NetworkResourceLoadParameters loadParameters);
 
     StartDownload(PAL::SessionID sessionID, WebKit::DownloadID downloadID, WebCore::ResourceRequest request, String suggestedName)
     ConvertMainResourceLoadToDownload(PAL::SessionID sessionID, uint64_t mainResourceLoadIdentifier, WebKit::DownloadID downloadID, WebCore::ResourceRequest request, WebCore::ResourceResponse response)
index 62873e4..d697298 100644 (file)
@@ -67,6 +67,8 @@ public:
     const WebCore::ResourceRequest& currentRequest() const { return m_currentRequest; }
     void clearCurrentRequest() { m_currentRequest = WebCore::ResourceRequest(); }
 
+    const NetworkLoadParameters& parameters() const { return m_parameters; }
+
     void continueWillSendRequest(WebCore::ResourceRequest&&);
     void continueDidReceiveResponse();
 
index d46c6f3..5a21c13 100644 (file)
@@ -505,18 +505,42 @@ void NetworkProcess::cancelDownload(DownloadID downloadID)
 }
     
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-void NetworkProcess::canAuthenticateAgainstProtectionSpace(NetworkResourceLoader& loader, const WebCore::ProtectionSpace& protectionSpace)
+static uint64_t generateCanAuthenticateIdentifier()
 {
     static uint64_t lastLoaderID = 0;
-    uint64_t loaderID = ++lastLoaderID;
-    m_waitingNetworkResourceLoaders.set(lastLoaderID, loader);
+    return ++lastLoaderID;
+}
+
+void NetworkProcess::canAuthenticateAgainstProtectionSpace(NetworkResourceLoader& loader, const WebCore::ProtectionSpace& protectionSpace)
+{
+    uint64_t loaderID = generateCanAuthenticateIdentifier();
+    m_waitingNetworkResourceLoaders.set(loaderID, loader);
     parentProcessConnection()->send(Messages::NetworkProcessProxy::CanAuthenticateAgainstProtectionSpace(loaderID, loader.pageID(), loader.frameID(), protectionSpace), 0);
 }
 
+#if ENABLE(SERVER_PRECONNECT)
+void NetworkProcess::canAuthenticateAgainstProtectionSpace(PreconnectTask& preconnectTask, const WebCore::ProtectionSpace& protectionSpace)
+{
+    uint64_t loaderID = generateCanAuthenticateIdentifier();
+    m_waitingPreconnectTasks.set(loaderID, preconnectTask.createWeakPtr());
+    parentProcessConnection()->send(Messages::NetworkProcessProxy::CanAuthenticateAgainstProtectionSpace(loaderID, preconnectTask.pageID(), preconnectTask.frameID(), protectionSpace), 0);
+}
+#endif
+
 void NetworkProcess::continueCanAuthenticateAgainstProtectionSpace(uint64_t loaderID, bool canAuthenticate)
 {
-    m_waitingNetworkResourceLoaders.take(loaderID).value()->continueCanAuthenticateAgainstProtectionSpace(canAuthenticate);
+    if (auto resourceLoader = m_waitingNetworkResourceLoaders.take(loaderID)) {
+        resourceLoader.value()->continueCanAuthenticateAgainstProtectionSpace(canAuthenticate);
+        return;
+    }
+#if ENABLE(SERVER_PRECONNECT)
+    if (auto preconnectTask = m_waitingPreconnectTasks.take(loaderID)) {
+        preconnectTask->continueCanAuthenticateAgainstProtectionSpace(canAuthenticate);
+        return;
+    }
+#endif
 }
+
 #endif
 
 #if USE(NETWORK_SESSION)
@@ -729,7 +753,13 @@ String NetworkProcess::cacheStorageDirectory(PAL::SessionID sessionID) const
 void NetworkProcess::preconnectTo(const WebCore::URL& url, WebCore::StoredCredentialsPolicy storedCredentialsPolicy)
 {
 #if ENABLE(SERVER_PRECONNECT)
-    new PreconnectTask(PAL::SessionID::defaultSessionID(), url, storedCredentialsPolicy);
+    NetworkLoadParameters parameters;
+    parameters.request = ResourceRequest { url };
+    parameters.sessionID = PAL::SessionID::defaultSessionID();
+    parameters.storedCredentialsPolicy = storedCredentialsPolicy;
+    parameters.shouldPreconnectOnly = PreconnectOnly::Yes;
+
+    new PreconnectTask(WTFMove(parameters));
 #else
     UNUSED_PARAM(url);
     UNUSED_PARAM(storedCredentialsPolicy);
index b9fa720..24f4a0e 100644 (file)
@@ -37,6 +37,7 @@
 #include <wtf/MemoryPressureHandler.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
 
 #if PLATFORM(IOS)
 #include "WebSQLiteDatabaseTracker.h"
@@ -60,6 +61,9 @@ class URL;
 
 namespace WebKit {
 class AuthenticationManager;
+#if ENABLE(SERVER_PRECONNECT)
+class PreconnectTask;
+#endif
 class NetworkConnectionToWebProcess;
 class NetworkProcessSupplement;
 class NetworkResourceLoader;
@@ -123,6 +127,9 @@ public:
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
     void canAuthenticateAgainstProtectionSpace(NetworkResourceLoader&, const WebCore::ProtectionSpace&);
+#if ENABLE(SERVER_PRECONNECT)
+    void canAuthenticateAgainstProtectionSpace(PreconnectTask&, const WebCore::ProtectionSpace&);
+#endif
 #endif
 
     void prefetchDNS(const String&);
@@ -248,6 +255,9 @@ private:
 
     HashMap<uint64_t, Function<void ()>> m_sandboxExtensionForBlobsCompletionHandlers;
     HashMap<uint64_t, Ref<NetworkResourceLoader>> m_waitingNetworkResourceLoaders;
+#if ENABLE(SERVER_PRECONNECT)
+    HashMap<uint64_t, WeakPtr<PreconnectTask>> m_waitingPreconnectTasks;
+#endif
 
 #if PLATFORM(COCOA)
     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
index 717bf88..e963576 100644 (file)
@@ -76,6 +76,7 @@ void NetworkResourceLoadParameters::encode(IPC::Encoder& encoder) const
     encoder.encodeEnum(contentSniffingPolicy);
     encoder.encodeEnum(storedCredentialsPolicy);
     encoder.encodeEnum(clientCredentialPolicy);
+    encoder.encodeEnum(shouldPreconnectOnly);
     encoder << shouldFollowRedirects;
     encoder << shouldClearReferrerOnHTTPSToHTTPRedirect;
     encoder << defersLoading;
@@ -144,6 +145,8 @@ bool NetworkResourceLoadParameters::decode(IPC::Decoder& decoder, NetworkResourc
         return false;
     if (!decoder.decodeEnum(result.clientCredentialPolicy))
         return false;
+    if (!decoder.decodeEnum(result.shouldPreconnectOnly))
+        return false;
     if (!decoder.decode(result.shouldFollowRedirects))
         return false;
     if (!decoder.decode(result.shouldClearReferrerOnHTTPSToHTTPRedirect))
index 8683c90..2e10b87 100644 (file)
 
 #if ENABLE(SERVER_PRECONNECT)
 
-#include "AuthenticationManager.h"
 #include "Logging.h"
+#include "NetworkLoad.h"
 #include "NetworkLoadParameters.h"
-#include "NetworkSession.h"
+#include "NetworkProcess.h"
 #include "SessionTracker.h"
-#include "WebErrors.h"
-#include <WebCore/AuthenticationChallenge.h>
 #include <WebCore/ResourceError.h>
 
-#if PLATFORM(COCOA)
-#include "NetworkDataTaskCocoa.h"
-#endif
-
 namespace WebKit {
 
 using namespace WebCore;
 
-PreconnectTask::PreconnectTask(PAL::SessionID sessionID, const URL& url, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, WTF::CompletionHandler<void(const WebCore::ResourceError&)>&& completionHandler)
+PreconnectTask::PreconnectTask(NetworkLoadParameters&& parameters, WTF::CompletionHandler<void(const ResourceError&)>&& completionHandler)
     : m_completionHandler(WTFMove(completionHandler))
-    , m_timeoutTimer([this] { didFinish(ResourceError { String(), 0, m_task->firstRequest().url(), ASCIILiteral("Preconnection timed out"), ResourceError::Type::Timeout }); })
+    , m_timeoutTimer([this] { didFinish(ResourceError { String(), 0, m_networkLoad->parameters().request.url(), ASCIILiteral("Preconnection timed out"), ResourceError::Type::Timeout }); })
 {
-    auto* networkSession = SessionTracker::networkSession(sessionID);
+    RELEASE_LOG(Network, "%p - PreconnectTask::PreconnectTask()", this);
+
+    auto* networkSession = SessionTracker::networkSession(parameters.sessionID);
     ASSERT(networkSession);
 
-    RELEASE_LOG(Network, "%p - PreconnectTask::PreconnectTask()", this);
-    NetworkLoadParameters parameters;
-    parameters.request = ResourceRequest(url);
-    parameters.shouldPreconnectOnly = PreconnectOnly::Yes;
-    parameters.storedCredentialsPolicy = storedCredentialsPolicy;
-    m_task = NetworkDataTask::create(*networkSession, *this, parameters);
-    m_task->resume();
+    ASSERT(parameters.shouldPreconnectOnly == PreconnectOnly::Yes);
+    m_networkLoad = std::make_unique<NetworkLoad>(*this, WTFMove(parameters), *networkSession);
 
     m_timeoutTimer.startOneShot(60000_s);
 }
 
 PreconnectTask::~PreconnectTask()
 {
-    ASSERT(m_task->client() == this);
-    m_task->clearClient();
-    m_task->cancel();
 }
 
-void PreconnectTask::willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&)
+void PreconnectTask::willSendRedirectedRequest(ResourceRequest&&, ResourceRequest&& redirectRequest, ResourceResponse&& redirectResponse)
 {
     ASSERT_NOT_REACHED();
 }
 
-void PreconnectTask::didReceiveChallenge(const WebCore::AuthenticationChallenge& challenge, ChallengeCompletionHandler&& completionHandler)
+auto PreconnectTask::didReceiveResponse(ResourceResponse&&) -> ShouldContinueDidReceiveResponse
 {
     ASSERT_NOT_REACHED();
+    return ShouldContinueDidReceiveResponse::No;
 }
 
-void PreconnectTask::didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&)
+void PreconnectTask::didReceiveBuffer(Ref<SharedBuffer>&&, int reportedEncodedDataLength)
 {
     ASSERT_NOT_REACHED();
 }
 
-void PreconnectTask::didReceiveData(Ref<WebCore::SharedBuffer>&&)
+void PreconnectTask::didFinishLoading(const NetworkLoadMetrics&)
 {
-    ASSERT_NOT_REACHED();
+    RELEASE_LOG(Network, "%p - PreconnectTask::didFinishLoading", this);
+    didFinish({ });
 }
 
-void PreconnectTask::didCompleteWithError(const WebCore::ResourceError& error, const WebCore::NetworkLoadMetrics&)
+void PreconnectTask::didFailLoading(const ResourceError& error)
 {
-    if (error.isNull())
-        RELEASE_LOG(Network, "%p - PreconnectTask::didComplete", this);
-    else
-        RELEASE_LOG(Network, "%p - PreconnectTask::didCompleteWithError, error_code: %d", this, error.errorCode());
-
+    RELEASE_LOG(Network, "%p - PreconnectTask::didFailLoading, error_code: %d", this, error.errorCode());
     didFinish(error);
 }
 
-void PreconnectTask::didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend)
+void PreconnectTask::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
 {
     ASSERT_NOT_REACHED();
 }
 
-void PreconnectTask::wasBlocked()
+void PreconnectTask::canAuthenticateAgainstProtectionSpaceAsync(const ProtectionSpace& protectionSpace)
 {
-    RELEASE_LOG(Network, "%p - PreconnectTask::wasBlocked()", this);
-    didFinish(blockedError(m_task->firstRequest()));
+    if (!pageID()) {
+        // The preconnect was started by the UIProcess.
+        continueCanAuthenticateAgainstProtectionSpace(false);
+        return;
+    }
+    NetworkProcess::singleton().canAuthenticateAgainstProtectionSpace(*this, protectionSpace);
 }
 
-void PreconnectTask::cannotShowURL()
+void PreconnectTask::continueCanAuthenticateAgainstProtectionSpace(bool result)
 {
-    RELEASE_LOG(Network, "%p - PreconnectTask::cannotShowURL()", this);
-    didFinish(cannotShowURLError(m_task->firstRequest()));
+    m_networkLoad->continueCanAuthenticateAgainstProtectionSpace(result);
 }
 
 void PreconnectTask::didFinish(const ResourceError& error)
@@ -124,6 +113,16 @@ void PreconnectTask::didFinish(const ResourceError& error)
     delete this;
 }
 
+uint64_t PreconnectTask::frameID() const
+{
+    return m_networkLoad->parameters().webFrameID;
+}
+
+uint64_t PreconnectTask::pageID() const
+{
+    return m_networkLoad->parameters().webPageID;
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(SERVER_PRECONNECT)
index bf9e395..89eabab 100644 (file)
 
 #if ENABLE(SERVER_PRECONNECT)
 
-#include "NetworkDataTask.h"
+#include "NetworkLoadClient.h"
 #include <WebCore/Timer.h>
 #include <wtf/CompletionHandler.h>
-
-namespace PAL {
-class SessionID;
-}
+#include <wtf/WeakPtr.h>
 
 namespace WebKit {
 
-class PreconnectTask final : private NetworkDataTaskClient {
+class NetworkLoad;
+class NetworkLoadParameters;
+
+class PreconnectTask final : public NetworkLoadClient {
 public:
-    explicit PreconnectTask(PAL::SessionID, const WebCore::URL&, WebCore::StoredCredentialsPolicy, WTF::CompletionHandler<void(const WebCore::ResourceError&)>&& completionHandler = { });
+    explicit PreconnectTask(NetworkLoadParameters&&, WTF::CompletionHandler<void(const WebCore::ResourceError&)>&& completionHandler = { });
     ~PreconnectTask();
 
+    uint64_t frameID() const;
+    uint64_t pageID() const;
+
+    void continueCanAuthenticateAgainstProtectionSpace(bool);
+
+    WeakPtr<PreconnectTask> createWeakPtr() { return m_weakFactory.createWeakPtr(*this); }
+
 private:
-    // NetworkDataTaskClient.
-    void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) final;
-    void didReceiveChallenge(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&) final;
-    void didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
-    void didReceiveData(Ref<WebCore::SharedBuffer>&&) final;
-    void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&) final;
-    void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) final;
-    void wasBlocked() final;
-    void cannotShowURL() final;
+    // NetworkLoadClient.
+    bool isSynchronous() const final { return false; }
+    void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) final;
+    void canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace&) final;
+    void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse) final;
+    ShouldContinueDidReceiveResponse didReceiveResponse(WebCore::ResourceResponse&&) final;
+    void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) final;
+    void didFinishLoading(const WebCore::NetworkLoadMetrics&) final;
+    void didFailLoading(const WebCore::ResourceError&) final;
 
     void didFinish(const WebCore::ResourceError&);
 
-    RefPtr<NetworkDataTask> m_task;
+    std::unique_ptr<NetworkLoad> m_networkLoad;
     WTF::CompletionHandler<void(const WebCore::ResourceError&)> m_completionHandler;
     WebCore::Timer m_timeoutTimer;
+    WeakPtrFactory<PreconnectTask> m_weakFactory;
 };
 
 } // namespace WebKit
index 76f1866..2f15b3d 100644 (file)
@@ -463,12 +463,38 @@ void WebLoaderStrategy::didFinishPingLoad(uint64_t pingLoadIdentifier, ResourceE
         completionHandler(WTFMove(error));
 }
 
-void WebLoaderStrategy::preconnectTo(PAL::SessionID sessionID, const WebCore::URL& url, StoredCredentialsPolicy storedCredentialsPolicy, PreconnectCompletionHandler&& completionHandler)
+void WebLoaderStrategy::preconnectTo(NetworkingContext& context, const WebCore::URL& url, StoredCredentialsPolicy storedCredentialsPolicy, PreconnectCompletionHandler&& completionHandler)
 {
     uint64_t preconnectionIdentifier = generateLoadIdentifier();
     auto addResult = m_preconnectCompletionHandlers.add(preconnectionIdentifier, WTFMove(completionHandler));
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
-    WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::PreconnectTo(sessionID, preconnectionIdentifier, url, storedCredentialsPolicy), 0);
+
+    auto& webContext = static_cast<WebFrameNetworkingContext&>(context);
+    auto* webFrameLoaderClient = webContext.webFrameLoaderClient();
+    if (!webFrameLoaderClient) {
+        completionHandler(internalError(url));
+        return;
+    }
+    auto* webFrame = webFrameLoaderClient->webFrame();
+    if (!webFrame) {
+        completionHandler(internalError(url));
+        return;
+    }
+    auto* webPage = webFrame->page();
+    if (!webPage) {
+        completionHandler(internalError(url));
+        return;
+    }
+
+    NetworkResourceLoadParameters parameters;
+    parameters.request = ResourceRequest { url };
+    parameters.webPageID = webPage ? webPage->pageID() : 0;
+    parameters.webFrameID = webFrame ? webFrame->frameID() : 0;
+    parameters.sessionID = webPage ? webPage->sessionID() : PAL::SessionID::defaultSessionID();
+    parameters.storedCredentialsPolicy = storedCredentialsPolicy;
+    parameters.shouldPreconnectOnly = PreconnectOnly::Yes;
+
+    WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::PreconnectTo(preconnectionIdentifier, WTFMove(parameters)), 0);
 }
 
 void WebLoaderStrategy::didFinishPreconnection(uint64_t preconnectionIdentifier, ResourceError&& error)
index 7256b5d..8030e69 100644 (file)
@@ -62,7 +62,7 @@ public:
     void startPingLoad(WebCore::Frame&, WebCore::ResourceRequest&, const WebCore::HTTPHeaderMap& originalRequestHeaders, const WebCore::FetchOptions&, PingLoadCompletionHandler&&) final;
     void didFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError&&);
 
-    void preconnectTo(PAL::SessionID, const WebCore::URL&, WebCore::StoredCredentialsPolicy, PreconnectCompletionHandler&&) final;
+    void preconnectTo(WebCore::NetworkingContext&, const WebCore::URL&, WebCore::StoredCredentialsPolicy, PreconnectCompletionHandler&&) final;
     void didFinishPreconnection(uint64_t preconnectionIdentifier, WebCore::ResourceError&&);
 
     void storeDerivedDataToCache(const SHA1::Digest& bodyHash, const String& type, const String& partition, WebCore::SharedBuffer&) final;
index c8180f3..4e8f3b8 100644 (file)
@@ -1,3 +1,14 @@
+2017-09-29  Chris Dumez  <cdumez@apple.com>
+
+        http/tests/preconnect/link-rel-preconnect-https.html is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=177673
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/WebResourceLoadScheduler.cpp:
+        (WebResourceLoadScheduler::preconnectTo):
+        * WebCoreSupport/WebResourceLoadScheduler.h:
+
 2017-09-28  Chris Dumez  <cdumez@apple.com>
 
         Add support for <link rel=preconnect>
index 7975bd3..1a7e1af 100644 (file)
@@ -369,7 +369,7 @@ void WebResourceLoadScheduler::startPingLoad(Frame& frame, ResourceRequest& requ
     new PingHandle(frame.loader().networkingContext(), request, options.credentials != FetchOptions::Credentials::Omit, PingHandle::UsesAsyncCallbacks::No, options.redirect == FetchOptions::Redirect::Follow, WTFMove(completionHandler));
 }
 
-void WebResourceLoadScheduler::preconnectTo(PAL::SessionID, const URL&, StoredCredentialsPolicy, PreconnectCompletionHandler&&)
+void WebResourceLoadScheduler::preconnectTo(NetworkingContext&, const URL&, StoredCredentialsPolicy, PreconnectCompletionHandler&&)
 {
 }
 
index ecfc1cf..a0bc167 100644 (file)
@@ -61,7 +61,7 @@ public:
 
     void startPingLoad(WebCore::Frame&, WebCore::ResourceRequest&, const WebCore::HTTPHeaderMap&, const WebCore::FetchOptions&, PingLoadCompletionHandler&&) final;
 
-    void preconnectTo(PAL::SessionID, const WebCore::URL&, WebCore::StoredCredentialsPolicy, PreconnectCompletionHandler&&) final;
+    void preconnectTo(WebCore::NetworkingContext&, const WebCore::URL&, WebCore::StoredCredentialsPolicy, PreconnectCompletionHandler&&) final;
 
     void storeDerivedDataToCache(const SHA1::Digest&, const String&, const String&, WebCore::SharedBuffer&) final { }