b126d3cd6c2a245bfc1f78567dc44c2ba4192588
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkConnectionToWebProcess.h
1 /*
2  * Copyright (C) 2012-2017 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 #include "BlockingResponseMap.h"
29 #include "CacheStorageEngineConnection.h"
30 #include "Connection.h"
31 #include "DownloadID.h"
32 #include "NetworkConnectionToWebProcessMessages.h"
33 #include "NetworkRTCProvider.h"
34
35 #include <WebCore/ResourceLoadPriority.h>
36 #include <wtf/RefCounted.h>
37
38 namespace WebCore {
39 class BlobDataFileReference;
40 class HTTPHeaderMap;
41 class ResourceError;
42 class ResourceRequest;
43
44 enum class IncludeSecureCookies;
45 }
46
47 namespace WebKit {
48
49 class NetworkConnectionToWebProcess;
50 class NetworkLoadParameters;
51 class NetworkResourceLoader;
52 class NetworkSocketStream;
53 class SyncNetworkResourceLoader;
54 typedef uint64_t ResourceLoadIdentifier;
55
56 namespace NetworkCache {
57 struct DataKey;
58 }
59
60 class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, IPC::Connection::Client {
61 public:
62     static Ref<NetworkConnectionToWebProcess> create(IPC::Connection::Identifier);
63     virtual ~NetworkConnectionToWebProcess();
64
65     IPC::Connection& connection() { return m_connection.get(); }
66
67     void didCleanupResourceLoader(NetworkResourceLoader&);
68     void didFinishPingLoad(uint64_t pingLoadIdentifier, const WebCore::ResourceError&, const WebCore::ResourceResponse&);
69
70     bool captureExtraNetworkLoadMetricsEnabled() const { return m_captureExtraNetworkLoadMetricsEnabled; }
71
72     RefPtr<WebCore::BlobDataFileReference> getBlobDataFileReferenceForPath(const String& path);
73
74     void cleanupForSuspension(Function<void()>&&);
75     void endSuspension();
76
77 private:
78     NetworkConnectionToWebProcess(IPC::Connection::Identifier);
79
80     void didFinishPreconnection(uint64_t preconnectionIdentifier, const WebCore::ResourceError&);
81
82     // IPC::Connection::Client
83     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
84     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
85     void didClose(IPC::Connection&) override;
86     void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
87
88     // Message handlers.
89     void didReceiveNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&);
90     void didReceiveSyncNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
91
92     void scheduleResourceLoad(const NetworkResourceLoadParameters&);
93     void performSynchronousLoad(const NetworkResourceLoadParameters&, Ref<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
94     void loadPing(NetworkResourceLoadParameters&&, WebCore::HTTPHeaderMap&& originalRequestHeaders);
95     void prefetchDNS(const String&);
96     void preconnectTo(uint64_t preconnectionIdentifier, NetworkLoadParameters&&);
97
98     void removeLoadIdentifier(ResourceLoadIdentifier);
99     void setDefersLoading(ResourceLoadIdentifier, bool);
100     void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::URL& redirectURL);
101     void startDownload(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedName = { });
102     void convertMainResourceLoadToDownload(PAL::SessionID, uint64_t mainResourceLoadIdentifier, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
103
104     void cookiesForDOM(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, WebCore::IncludeSecureCookies, String& cookieString, bool& secureCookiesAccessed);
105     void setCookiesFromDOM(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String&);
106     void cookiesEnabled(PAL::SessionID, bool& result);
107     void cookieRequestHeaderFieldValue(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, WebCore::IncludeSecureCookies, String& cookieString, bool& secureCookiesAccessed);
108     void getRawCookies(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<WebCore::Cookie>&);
109     void deleteCookie(PAL::SessionID, const WebCore::URL&, const String& cookieName);
110
111     void registerFileBlobURL(const WebCore::URL&, const String& path, SandboxExtension::Handle&&, const String& contentType);
112     void registerBlobURL(const WebCore::URL&, Vector<WebCore::BlobPart>&&, const String& contentType);
113     void registerBlobURLFromURL(const WebCore::URL&, const WebCore::URL& srcURL, bool shouldBypassConnectionCheck);
114     void preregisterSandboxExtensionsForOptionallyFileBackedBlob(const Vector<String>& fileBackedPath, SandboxExtension::HandleArray&&);
115     void registerBlobURLOptionallyFileBacked(const WebCore::URL&, const WebCore::URL& srcURL, const String& fileBackedPath, const String& contentType);
116     void registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end);
117     void blobSize(const WebCore::URL&, uint64_t& resultSize);
118     void unregisterBlobURL(const WebCore::URL&);
119     void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, uint64_t requestIdentifier);
120
121     void storeDerivedDataToCache(const WebKit::NetworkCache::DataKey&, const IPC::DataReference&);
122
123     void setCaptureExtraNetworkLoadMetricsEnabled(bool);
124
125     void createSocketStream(WebCore::URL&&, PAL::SessionID, String cachePartition, uint64_t);
126     void destroySocketStream(uint64_t);
127     
128     void ensureLegacyPrivateBrowsingSession();
129
130 #if USE(LIBWEBRTC)
131     NetworkRTCProvider& rtcProvider();
132 #endif
133
134     CacheStorageEngineConnection& cacheStorageConnection();
135
136     void removeStorageAccessForFrame(PAL::SessionID, uint64_t frameID, uint64_t pageID);
137
138     Ref<IPC::Connection> m_connection;
139
140     HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
141     HashMap<ResourceLoadIdentifier, RefPtr<NetworkResourceLoader>> m_networkResourceLoaders;
142     HashMap<String, RefPtr<WebCore::BlobDataFileReference>> m_blobDataFileReferences;
143
144 #if USE(LIBWEBRTC)
145     RefPtr<NetworkRTCProvider> m_rtcProvider;
146 #endif
147
148     bool m_captureExtraNetworkLoadMetricsEnabled { false };
149
150     RefPtr<CacheStorageEngineConnection> m_cacheStorageConnection;
151 };
152
153 } // namespace WebKit