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