Remove "virtual" from all lines that have both "virtual" and "override".
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / NetworkResourceLoader.h
1 /*
2  * Copyright (C) 2012-2015 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 #ifndef NetworkResourceLoader_h
27 #define NetworkResourceLoader_h
28
29 #include "MessageSender.h"
30 #include "NetworkConnectionToWebProcessMessages.h"
31 #include "NetworkLoadClient.h"
32 #include "NetworkResourceLoadParameters.h"
33 #include "ShareableResource.h"
34 #include <WebCore/Timer.h>
35 #include <wtf/Optional.h>
36
37 namespace WebCore {
38 class BlobDataFileReference;
39 class ResourceRequest;
40 }
41
42 namespace WebKit {
43
44 class NetworkConnectionToWebProcess;
45 class NetworkLoad;
46 class SandboxExtension;
47
48 namespace NetworkCache {
49 class Entry;
50 }
51
52 class NetworkResourceLoader final : public RefCounted<NetworkResourceLoader>, public NetworkLoadClient, public IPC::MessageSender {
53 public:
54     static Ref<NetworkResourceLoader> create(const NetworkResourceLoadParameters& parameters, NetworkConnectionToWebProcess& connection, RefPtr<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&& reply = nullptr)
55     {
56         return adoptRef(*new NetworkResourceLoader(parameters, connection, WTFMove(reply)));
57     }
58     virtual ~NetworkResourceLoader();
59
60     const WebCore::ResourceRequest& originalRequest() const { return m_parameters.request; }
61
62     NetworkLoad* networkLoad() const { return m_networkLoad.get(); }
63
64     void start();
65     void abort();
66
67     void setDefersLoading(bool);
68
69     // Message handlers.
70     void didReceiveNetworkResourceLoaderMessage(IPC::Connection&, IPC::MessageDecoder&);
71
72 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
73     void continueCanAuthenticateAgainstProtectionSpace(bool);
74 #endif
75     void continueWillSendRequest(const WebCore::ResourceRequest& newRequest);
76
77     WebCore::SharedBuffer* bufferedData() { return m_bufferedData.get(); }
78     const WebCore::ResourceResponse& response() const { return m_response; }
79
80     NetworkConnectionToWebProcess& connectionToWebProcess() { return m_connection; }
81     WebCore::SessionID sessionID() const { return m_parameters.sessionID; }
82     ResourceLoadIdentifier identifier() const { return m_parameters.identifier; }
83
84     struct SynchronousLoadData;
85
86     // NetworkLoadClient.
87     void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
88     void canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace&) override;
89     bool isSynchronous() const override;
90     void willSendRedirectedRequest(const WebCore::ResourceRequest&, const WebCore::ResourceRequest& redirectRequest, const WebCore::ResourceResponse& redirectResponse) override;
91     ShouldContinueDidReceiveResponse didReceiveResponse(const WebCore::ResourceResponse&) override;
92     void didReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
93     void didFinishLoading(double finishTime) override;
94     void didFailLoading(const WebCore::ResourceError&) override;
95 #if USE(NETWORK_SESSION)
96     void didBecomeDownload() override;
97 #endif
98     
99     void didConvertToDownload();
100
101 private:
102     NetworkResourceLoader(const NetworkResourceLoadParameters&, NetworkConnectionToWebProcess&, RefPtr<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
103
104     // IPC::MessageSender
105     IPC::Connection* messageSenderConnection() override;
106     uint64_t messageSenderDestinationID() override { return m_parameters.identifier; }
107
108 #if ENABLE(NETWORK_CACHE)
109     bool canUseCache(const WebCore::ResourceRequest&) const;
110     bool canUseCachedRedirect(const WebCore::ResourceRequest&) const;
111
112     void tryStoreAsCacheEntry();
113     void retrieveCacheEntry(const WebCore::ResourceRequest&);
114     void didRetrieveCacheEntry(std::unique_ptr<NetworkCache::Entry>);
115     void validateCacheEntry(std::unique_ptr<NetworkCache::Entry>);
116     void dispatchWillSendRequestForCacheEntry(std::unique_ptr<NetworkCache::Entry>);
117 #endif
118
119     void startNetworkLoad(const WebCore::ResourceRequest&);
120     void continueDidReceiveResponse();
121
122     void cleanup();
123     
124     void platformDidReceiveResponse(const WebCore::ResourceResponse&);
125
126     void startBufferingTimerIfNeeded();
127     void bufferingTimerFired();
128     bool sendBufferMaybeAborting(WebCore::SharedBuffer&, size_t encodedDataLength);
129
130     void consumeSandboxExtensions();
131     void invalidateSandboxExtensions();
132
133     template<typename T> bool sendAbortingOnFailure(T&& message, unsigned messageSendFlags = 0);
134
135     const NetworkResourceLoadParameters m_parameters;
136
137     Ref<NetworkConnectionToWebProcess> m_connection;
138
139     std::unique_ptr<NetworkLoad> m_networkLoad;
140
141     WebCore::ResourceResponse m_response;
142
143     size_t m_bytesReceived { 0 };
144     size_t m_bufferedDataEncodedDataLength { 0 };
145     RefPtr<WebCore::SharedBuffer> m_bufferedData;
146     unsigned m_redirectCount { 0 };
147
148     std::unique_ptr<SynchronousLoadData> m_synchronousLoadData;
149     Vector<RefPtr<WebCore::BlobDataFileReference>> m_fileReferences;
150
151     bool m_didConvertToDownload { false };
152     bool m_didConsumeSandboxExtensions { false };
153     bool m_defersLoading { false };
154
155     WebCore::Timer m_bufferingTimer;
156 #if ENABLE(NETWORK_CACHE)
157     RefPtr<WebCore::SharedBuffer> m_bufferedDataForCache;
158     std::unique_ptr<NetworkCache::Entry> m_cacheEntryForValidation;
159     bool m_isWaitingContinueWillSendRequestForCachedRedirect { false };
160 #endif
161 };
162
163 } // namespace WebKit
164
165 #endif // NetworkResourceLoader_h