2 * Copyright (C) 2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if USE(NETWORK_SESSION)
30 #include "NetworkDataTask.h"
31 #include "NetworkLoadParameters.h"
32 #include <WebCore/NetworkLoadMetrics.h>
33 #include <wtf/RetainPtr.h>
35 OBJC_CLASS NSURLSessionDataTask;
39 class NetworkSessionCocoa;
41 class NetworkDataTaskCocoa final : public NetworkDataTask {
42 friend class NetworkSessionCocoa;
44 static Ref<NetworkDataTask> create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, WebCore::ContentSniffingPolicy shouldContentSniff, WebCore::ContentEncodingSniffingPolicy shouldContentEncodingSniff, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly shouldPreconnectOnly)
46 return adoptRef(*new NetworkDataTaskCocoa(session, client, request, frameID, pageID, storedCredentialsPolicy, shouldContentSniff, shouldContentEncodingSniff, shouldClearReferrerOnHTTPSToHTTPRedirect, shouldPreconnectOnly));
49 ~NetworkDataTaskCocoa();
51 typedef uint64_t TaskIdentifier;
53 void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend);
54 void didReceiveChallenge(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
55 void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&);
56 void didReceiveData(Ref<WebCore::SharedBuffer>&&);
58 void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&);
59 void transferSandboxExtensionToDownload(Download&);
61 void suspend() override;
62 void cancel() override;
63 void resume() override;
64 void invalidateAndCancel() override { }
65 NetworkDataTask::State state() const override;
67 void setPendingDownloadLocation(const String&, SandboxExtension::Handle&&, bool /*allowOverwrite*/) override;
68 String suggestedFilename() const override;
70 WebCore::NetworkLoadMetrics& networkLoadMetrics() { return m_networkLoadMetrics; }
72 uint64_t frameID() const { return m_frameID; };
73 uint64_t pageID() const { return m_pageID; };
76 NetworkDataTaskCocoa(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy, WebCore::ContentSniffingPolicy, WebCore::ContentEncodingSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly);
78 bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&);
79 void applySniffingPoliciesAndBindRequestToInferfaceIfNeeded(NSURLRequest*&, bool shouldContentSniff, bool shouldContentEncodingSniff);
81 RefPtr<SandboxExtension> m_sandboxExtension;
82 RetainPtr<NSURLSessionDataTask> m_task;
83 WebCore::NetworkLoadMetrics m_networkLoadMetrics;
88 WebCore::Credential serverTrustCredential(const WebCore::AuthenticationChallenge&);
92 #endif // USE(NETWORK_SESSION)