Use NetworkSession for pings
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2016 18:01:37 +0000 (18:01 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2016 18:01:37 +0000 (18:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154984

Reviewed by Antti Koivisto.

Before this patch, we were using NSURLConnection for pings when the rest of the loading was being
done with NSURLSession.  To fix this, I implemented PingLoad, which is the NetworkSession equivalent
of PingHandle.

This fixes http/tests/security/contentSecurityPolicy/report-status-code-zero-when-using-https.html

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::loadPing):
(WebKit::NetworkConnectionToWebProcess::removeLoadIdentifier):
* NetworkProcess/PingLoad.h: Added.
(WebKit::PingLoad::PingLoad):
(WebKit::PingLoad::willPerformHTTPRedirection):
(WebKit::PingLoad::didReceiveChallenge):
(WebKit::PingLoad::didReceiveResponseNetworkSession):
(WebKit::PingLoad::didReceiveData):
(WebKit::PingLoad::didCompleteWithError):
(WebKit::PingLoad::didBecomeDownload):
(WebKit::PingLoad::didSendData):
(WebKit::PingLoad::wasBlocked):
(WebKit::PingLoad::cannotShowURL):
(WebKit::PingLoad::timeoutTimerFired):
(WebKit::PingLoad::~PingLoad):
* WebKit2.xcodeproj/project.pbxproj:

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

Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit2/NetworkProcess/PingLoad.h [new file with mode: 0644]
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index a9c878f..2e9e132 100644 (file)
@@ -1,3 +1,34 @@
+2016-03-04  Alex Christensen  <achristensen@webkit.org>
+
+        Use NetworkSession for pings
+        https://bugs.webkit.org/show_bug.cgi?id=154984
+
+        Reviewed by Antti Koivisto.
+
+        Before this patch, we were using NSURLConnection for pings when the rest of the loading was being 
+        done with NSURLSession.  To fix this, I implemented PingLoad, which is the NetworkSession equivalent
+        of PingHandle.
+
+        This fixes http/tests/security/contentSecurityPolicy/report-status-code-zero-when-using-https.html
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::loadPing):
+        (WebKit::NetworkConnectionToWebProcess::removeLoadIdentifier):
+        * NetworkProcess/PingLoad.h: Added.
+        (WebKit::PingLoad::PingLoad):
+        (WebKit::PingLoad::willPerformHTTPRedirection):
+        (WebKit::PingLoad::didReceiveChallenge):
+        (WebKit::PingLoad::didReceiveResponseNetworkSession):
+        (WebKit::PingLoad::didReceiveData):
+        (WebKit::PingLoad::didCompleteWithError):
+        (WebKit::PingLoad::didBecomeDownload):
+        (WebKit::PingLoad::didSendData):
+        (WebKit::PingLoad::wasBlocked):
+        (WebKit::PingLoad::cannotShowURL):
+        (WebKit::PingLoad::timeoutTimerFired):
+        (WebKit::PingLoad::~PingLoad):
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2016-03-04  Timothy Hatcher  <timothy@apple.com>
 
         Inform WebKit and WebCore if a page is controlled by automation.
index 330d457..bc0626f 100644 (file)
 #include <WebCore/SessionID.h>
 #include <wtf/RunLoop.h>
 
+#if USE(NETWORK_SESSION)
+#include "PingLoad.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -130,10 +134,15 @@ void NetworkConnectionToWebProcess::performSynchronousLoad(const NetworkResource
 
 void NetworkConnectionToWebProcess::loadPing(const NetworkResourceLoadParameters& loadParameters)
 {
+#if USE(NETWORK_SESSION)
+    // PingLoad manages its own lifetime, deleting itself when its purpose has been fulfilled.
+    new PingLoad(loadParameters);
+#else
     RefPtr<NetworkingContext> context = RemoteNetworkingContext::create(loadParameters.sessionID, loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect);
 
     // PingHandle manages its own lifetime, deleting itself when its purpose has been fulfilled.
     new PingHandle(context.get(), loadParameters.request, loadParameters.allowStoredCredentials == AllowStoredCredentials, PingHandle::UsesAsyncCallbacks::Yes);
+#endif
 }
 
 void NetworkConnectionToWebProcess::removeLoadIdentifier(ResourceLoadIdentifier identifier)
diff --git a/Source/WebKit2/NetworkProcess/PingLoad.h b/Source/WebKit2/NetworkProcess/PingLoad.h
new file mode 100644 (file)
index 0000000..1ec1331
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PingLoad_h
+#define PingLoad_h
+
+#include "NetworkDataTask.h"
+#include "SessionTracker.h"
+
+namespace WebKit {
+
+class PingLoad : public NetworkDataTaskClient {
+public:
+    PingLoad(const NetworkResourceLoadParameters& parameters)
+        : m_timeoutTimer(*this, &PingLoad::timeoutTimerFired)
+    {
+        if (auto* networkSession = SessionTracker::networkSession(parameters.sessionID)) {
+            m_task = NetworkDataTask::create(*networkSession, *this, parameters.request, parameters.allowStoredCredentials, parameters.contentSniffingPolicy, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect);
+            m_task->resume();
+        } else
+            ASSERT_NOT_REACHED();
+
+        // If the server never responds, this object will hang around forever.
+        // Set a very generous timeout, just in case.
+        m_timeoutTimer.startOneShot(60000);
+    }
+    
+private:
+    void willPerformHTTPRedirection(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, RedirectCompletionHandler completionHandler) override
+    {
+        completionHandler({ });
+        delete this;
+    }
+    void didReceiveChallenge(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler completionHandler) override
+    {
+        completionHandler(AuthenticationChallengeDisposition::Cancel, { });
+        delete this;
+    }
+    void didReceiveResponseNetworkSession(const WebCore::ResourceResponse&, ResponseCompletionHandler completionHandler) override
+    {
+        completionHandler(WebCore::PolicyAction::PolicyIgnore);
+        delete this;
+    }
+    void didReceiveData(RefPtr<WebCore::SharedBuffer>&&)  override { ASSERT_NOT_REACHED(); }
+    void didCompleteWithError(const WebCore::ResourceError&) override { delete this; }
+    void didBecomeDownload() override { ASSERT_NOT_REACHED(); }
+    void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) override { }
+    void wasBlocked() override { delete this; }
+    void cannotShowURL() override { delete this; }
+
+    void timeoutTimerFired() { delete this; }
+    
+    virtual ~PingLoad()
+    {
+        if (m_task)
+            m_task->cancel();
+    }
+    
+    RefPtr<NetworkDataTask> m_task;
+    WebCore::Timer m_timeoutTimer;
+};
+
+}
+
+#endif
index 48be95e..5f571fe 100644 (file)
                5C85C7881C3F23CE0061A4FA /* PendingDownload.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C85C7861C3F23C50061A4FA /* PendingDownload.cpp */; };
                5CBC9B8D1C65279C00A8FDCF /* NetworkDataTaskCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CBC9B8B1C65257300A8FDCF /* NetworkDataTaskCocoa.mm */; };
                5CBC9B8E1C652CA000A8FDCF /* NetworkDataTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CBC9B891C6524A500A8FDCF /* NetworkDataTask.h */; };
+               5CE85B201C88E64B0070BFCE /* PingLoad.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CE85B1F1C88E6430070BFCE /* PingLoad.h */; };
                6501BD1A12F1243400E9F248 /* WKBundleInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65B86F1712F11D7B00B7DD8A /* WKBundleInspector.cpp */; };
                659C551E130006410025C0C2 /* InjectedBundlePageResourceLoadClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */; };
                65B86F1E12F11DE300B7DD8A /* WKBundleInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 65B86F1812F11D7B00B7DD8A /* WKBundleInspector.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5C85C7861C3F23C50061A4FA /* PendingDownload.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PendingDownload.cpp; path = NetworkProcess/Downloads/PendingDownload.cpp; sourceTree = "<group>"; };
                5CBC9B891C6524A500A8FDCF /* NetworkDataTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkDataTask.h; path = NetworkProcess/NetworkDataTask.h; sourceTree = "<group>"; };
                5CBC9B8B1C65257300A8FDCF /* NetworkDataTaskCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkDataTaskCocoa.mm; path = NetworkProcess/cocoa/NetworkDataTaskCocoa.mm; sourceTree = "<group>"; };
+               5CE85B1F1C88E6430070BFCE /* PingLoad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PingLoad.h; path = NetworkProcess/PingLoad.h; sourceTree = "<group>"; };
                5D442A5516D5856700AC3331 /* PluginService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PluginService.entitlements; sourceTree = "<group>"; };
                5DAD73F1116FF90C00EE5396 /* BaseTarget.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = BaseTarget.xcconfig; sourceTree = "<group>"; };
                6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageResourceLoadClient.cpp; sourceTree = "<group>"; };
                510CC7DA16138E0100D03ED3 /* NetworkProcess */ = {
                        isa = PBXGroup;
                        children = (
+                               5CE85B1F1C88E6430070BFCE /* PingLoad.h */,
                                5CBC9B891C6524A500A8FDCF /* NetworkDataTask.h */,
                                5C1426F21C23F82D00D41183 /* CustomProtocols */,
                                5C1426F11C23F81700D41183 /* Downloads */,
                                2DEAC5CF1AC368BB00A195D8 /* _WKFindOptions.h in Headers */,
                                2E7A944A1BBD97C300945547 /* _WKFocusedElementInfo.h in Headers */,
                                2E0B8A7A1BC59A590044B32D /* _WKFormDelegate.h in Headers */,
+                               5CE85B201C88E64B0070BFCE /* PingLoad.h in Headers */,
                                37A64E5718F38F4600EB30F1 /* _WKFormInputSession.h in Headers */,
                                373D122318A473010066D9CC /* _WKFrameHandle.h in Headers */,
                                373D122718A473F60066D9CC /* _WKFrameHandleInternal.h in Headers */,