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 NSHTTPCookieStorage;
36 OBJC_CLASS NSURLSessionDataTask;
40 class NetworkSessionCocoa;
42 class NetworkDataTaskCocoa final : public NetworkDataTask {
43 friend class NetworkSessionCocoa;
45 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)
47 return adoptRef(*new NetworkDataTaskCocoa(session, client, request, frameID, pageID, storedCredentialsPolicy, shouldContentSniff, shouldContentEncodingSniff, shouldClearReferrerOnHTTPSToHTTPRedirect, shouldPreconnectOnly));
50 ~NetworkDataTaskCocoa();
52 typedef uint64_t TaskIdentifier;
54 void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend);
55 void didReceiveChallenge(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
56 void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&);
57 void didReceiveData(Ref<WebCore::SharedBuffer>&&);
59 void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&);
60 void transferSandboxExtensionToDownload(Download&);
62 void suspend() override;
63 void cancel() override;
64 void resume() override;
65 void invalidateAndCancel() override { }
66 NetworkDataTask::State state() const override;
68 void setPendingDownloadLocation(const String&, SandboxExtension::Handle&&, bool /*allowOverwrite*/) override;
69 String suggestedFilename() const override;
71 WebCore::NetworkLoadMetrics& networkLoadMetrics() { return m_networkLoadMetrics; }
73 uint64_t frameID() const { return m_frameID; };
74 uint64_t pageID() const { return m_pageID; };
77 NetworkDataTaskCocoa(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy, WebCore::ContentSniffingPolicy, WebCore::ContentEncodingSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly);
79 bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&);
80 void applySniffingPoliciesAndBindRequestToInferfaceIfNeeded(NSURLRequest*&, bool shouldContentSniff, bool shouldContentEncodingSniff);
82 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
83 static NSHTTPCookieStorage *statelessCookieStorage();
84 void applyCookieBlockingPolicy(bool shouldBlock);
85 void applyCookiePartitioningPolicy(const String& requiredStoragePartition, const String& currentStoragePartition);
88 RefPtr<SandboxExtension> m_sandboxExtension;
89 RetainPtr<NSURLSessionDataTask> m_task;
90 WebCore::NetworkLoadMetrics m_networkLoadMetrics;
94 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
95 bool m_hasBeenSetToUseStatelessCookieStorage { false };
99 WebCore::Credential serverTrustCredential(const WebCore::AuthenticationChallenge&);
101 } // namespace WebKit
103 #endif // USE(NETWORK_SESSION)