ceb5963ed7980585406b3ba9ef64c47be8fca3d9
[WebKit-https.git] / Source / WebKit / NetworkProcess / cocoa / NetworkDataTaskCocoa.h
1 /*
2  * Copyright (C) 2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #pragma once
27
28 #if USE(NETWORK_SESSION)
29
30 #include "NetworkDataTask.h"
31 #include <WebCore/NetworkLoadMetrics.h>
32 #include <wtf/RetainPtr.h>
33
34 OBJC_CLASS NSURLSessionDataTask;
35
36 namespace WebKit {
37
38 class NetworkSessionCocoa;
39
40 class NetworkDataTaskCocoa final : public NetworkDataTask {
41     friend class NetworkSessionCocoa;
42 public:
43     static Ref<NetworkDataTask> create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, WebCore::StoredCredentials storedCredentials, WebCore::ContentSniffingPolicy shouldContentSniff, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
44     {
45         return adoptRef(*new NetworkDataTaskCocoa(session, client, request, storedCredentials, shouldContentSniff, shouldClearReferrerOnHTTPSToHTTPRedirect));
46     }
47
48     ~NetworkDataTaskCocoa();
49
50     typedef uint64_t TaskIdentifier;
51
52     void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend);
53     void didReceiveChallenge(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&&);
54     void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&);
55     void didReceiveData(Ref<WebCore::SharedBuffer>&&);
56
57     void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&);
58     void transferSandboxExtensionToDownload(Download&);
59
60     void suspend() override;
61     void cancel() override;
62     void resume() override;
63     void invalidateAndCancel() override { }
64     NetworkDataTask::State state() const override;
65
66     void setPendingDownloadLocation(const String&, const SandboxExtension::Handle&, bool /*allowOverwrite*/) override;
67     String suggestedFilename() const override;
68
69     bool allowsSpecificHTTPSCertificateForHost(const WebCore::AuthenticationChallenge&) override;
70
71     WebCore::NetworkLoadMetrics& networkLoadMetrics() { return m_networkLoadMetrics; }
72
73 private:
74     NetworkDataTaskCocoa(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::StoredCredentials, WebCore::ContentSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
75
76     bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, const ChallengeCompletionHandler&);
77
78     RefPtr<SandboxExtension> m_sandboxExtension;
79     RetainPtr<NSURLSessionDataTask> m_task;
80     WebCore::NetworkLoadMetrics m_networkLoadMetrics;
81 };
82
83 WebCore::Credential serverTrustCredential(const WebCore::AuthenticationChallenge&);
84
85 } // namespace WebKit
86
87 #endif // USE(NETWORK_SESSION)