Move NetworkCache ownership from NetworkProcess to NetworkSession
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkSessionCreationParameters.cpp
1 /*
2  * Copyright (C) 2018 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 #include "config.h"
27 #include "NetworkSessionCreationParameters.h"
28
29 #include "ArgumentCoders.h"
30
31 #if PLATFORM(COCOA)
32 #include "ArgumentCodersCF.h"
33 #endif
34
35 #if USE(CURL)
36 #include "WebCoreArgumentCoders.h"
37 #endif
38
39 namespace WebKit {
40
41 NetworkSessionCreationParameters NetworkSessionCreationParameters::privateSessionParameters(const PAL::SessionID& sessionID)
42 {
43     return { sessionID, { }, AllowsCellularAccess::Yes
44 #if PLATFORM(COCOA)
45         , { }, { }, { }, AllowsTLSFallback::Yes, false, { }, { }, { }
46 #endif
47 #if USE(SOUP)
48         , { }, SoupCookiePersistentStorageType::Text
49 #endif
50 #if USE(CURL)
51         , { }, { }
52 #endif
53         , { }, { }, false, { }, { }, { }, { }, { }, { }, { }, { }, { }
54     };
55 }
56
57 void NetworkSessionCreationParameters::encode(IPC::Encoder& encoder) const
58 {
59     encoder << sessionID;
60     encoder << boundInterfaceIdentifier;
61     encoder << allowsCellularAccess;
62 #if PLATFORM(COCOA)
63     IPC::encode(encoder, proxyConfiguration.get());
64     encoder << sourceApplicationBundleIdentifier;
65     encoder << sourceApplicationSecondaryIdentifier;
66     encoder << allowsTLSFallback;
67     encoder << shouldLogCookieInformation;
68     encoder << loadThrottleLatency;
69     encoder << httpProxy;
70     encoder << httpsProxy;
71 #endif
72 #if USE(SOUP)
73     encoder << cookiePersistentStoragePath;
74     encoder << cookiePersistentStorageType;
75 #endif
76 #if USE(CURL)
77     encoder << cookiePersistentStorageFile;
78     encoder << proxySettings;
79 #endif
80     encoder << resourceLoadStatisticsDirectory;
81     encoder << resourceLoadStatisticsDirectoryExtensionHandle;
82     encoder << enableResourceLoadStatistics;
83     encoder << shouldIncludeLocalhostInResourceLoadStatistics;
84     encoder << enableResourceLoadStatisticsDebugMode;
85     encoder << resourceLoadStatisticsManualPrevalentResource;
86
87     encoder << localStorageDirectory << localStorageDirectoryExtensionHandle;
88     encoder << networkCacheDirectory << networkCacheDirectoryExtensionHandle;
89
90     encoder << deviceManagementRestrictionsEnabled;
91     encoder << allLoadsBlockedByDeviceManagementRestrictionsForTesting;
92 }
93
94 Optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters::decode(IPC::Decoder& decoder)
95 {
96     PAL::SessionID sessionID;
97     if (!decoder.decode(sessionID))
98         return WTF::nullopt;
99     
100     Optional<String> boundInterfaceIdentifier;
101     decoder >> boundInterfaceIdentifier;
102     if (!boundInterfaceIdentifier)
103         return WTF::nullopt;
104     
105     Optional<AllowsCellularAccess> allowsCellularAccess;
106     decoder >> allowsCellularAccess;
107     if (!allowsCellularAccess)
108         return WTF::nullopt;
109     
110 #if PLATFORM(COCOA)
111     RetainPtr<CFDictionaryRef> proxyConfiguration;
112     if (!IPC::decode(decoder, proxyConfiguration))
113         return WTF::nullopt;
114     
115     Optional<String> sourceApplicationBundleIdentifier;
116     decoder >> sourceApplicationBundleIdentifier;
117     if (!sourceApplicationBundleIdentifier)
118         return WTF::nullopt;
119     
120     Optional<String> sourceApplicationSecondaryIdentifier;
121     decoder >> sourceApplicationSecondaryIdentifier;
122     if (!sourceApplicationSecondaryIdentifier)
123         return WTF::nullopt;
124
125     Optional<AllowsTLSFallback> allowsTLSFallback;
126     decoder >> allowsTLSFallback;
127     if (!allowsTLSFallback)
128         return WTF::nullopt;
129
130     Optional<bool> shouldLogCookieInformation;
131     decoder >> shouldLogCookieInformation;
132     if (!shouldLogCookieInformation)
133         return WTF::nullopt;
134     
135     Optional<Seconds> loadThrottleLatency;
136     decoder >> loadThrottleLatency;
137     if (!loadThrottleLatency)
138         return WTF::nullopt;
139     
140     Optional<URL> httpProxy;
141     decoder >> httpProxy;
142     if (!httpProxy)
143         return WTF::nullopt;
144
145     Optional<URL> httpsProxy;
146     decoder >> httpsProxy;
147     if (!httpsProxy)
148         return WTF::nullopt;
149 #endif
150
151 #if USE(SOUP)
152     Optional<String> cookiePersistentStoragePath;
153     decoder >> cookiePersistentStoragePath;
154     if (!cookiePersistentStoragePath)
155         return WTF::nullopt;
156
157     Optional<SoupCookiePersistentStorageType> cookiePersistentStorageType;
158     decoder >> cookiePersistentStorageType;
159     if (!cookiePersistentStorageType)
160         return WTF::nullopt;
161 #endif
162
163 #if USE(CURL)
164     Optional<String> cookiePersistentStorageFile;
165     decoder >> cookiePersistentStorageFile;
166     if (!cookiePersistentStorageFile)
167         return WTF::nullopt;
168
169     Optional<WebCore::CurlProxySettings> proxySettings;
170     decoder >> proxySettings;
171     if (!proxySettings)
172         return WTF::nullopt;
173 #endif
174
175     Optional<String> resourceLoadStatisticsDirectory;
176     decoder >> resourceLoadStatisticsDirectory;
177     if (!resourceLoadStatisticsDirectory)
178         return WTF::nullopt;
179
180     Optional<SandboxExtension::Handle> resourceLoadStatisticsDirectoryExtensionHandle;
181     decoder >> resourceLoadStatisticsDirectoryExtensionHandle;
182     if (!resourceLoadStatisticsDirectoryExtensionHandle)
183         return WTF::nullopt;
184
185     Optional<bool> enableResourceLoadStatistics;
186     decoder >> enableResourceLoadStatistics;
187     if (!enableResourceLoadStatistics)
188         return WTF::nullopt;
189
190     Optional<bool> shouldIncludeLocalhostInResourceLoadStatistics;
191     decoder >> shouldIncludeLocalhostInResourceLoadStatistics;
192     if (!shouldIncludeLocalhostInResourceLoadStatistics)
193         return WTF::nullopt;
194
195     Optional<bool> enableResourceLoadStatisticsDebugMode;
196     decoder >> enableResourceLoadStatisticsDebugMode;
197     if (!enableResourceLoadStatisticsDebugMode)
198         return WTF::nullopt;
199
200     Optional<WebCore::RegistrableDomain> resourceLoadStatisticsManualPrevalentResource;
201     decoder >> resourceLoadStatisticsManualPrevalentResource;
202     if (!resourceLoadStatisticsManualPrevalentResource)
203         return WTF::nullopt;
204
205     Optional<String> localStorageDirectory;
206     decoder >> localStorageDirectory;
207     if (!localStorageDirectory)
208         return WTF::nullopt;
209
210     Optional<SandboxExtension::Handle> localStorageDirectoryExtensionHandle;
211     decoder >> localStorageDirectoryExtensionHandle;
212     if (!localStorageDirectoryExtensionHandle)
213         return WTF::nullopt;
214
215     Optional<String> networkCacheDirectory;
216     decoder >> networkCacheDirectory;
217     if (!networkCacheDirectory)
218         return WTF::nullopt;
219     
220     Optional<SandboxExtension::Handle> networkCacheDirectoryExtensionHandle;
221     decoder >> networkCacheDirectoryExtensionHandle;
222     if (!networkCacheDirectoryExtensionHandle)
223         return WTF::nullopt;
224
225     Optional<bool> deviceManagementRestrictionsEnabled;
226     decoder >> deviceManagementRestrictionsEnabled;
227     if (!deviceManagementRestrictionsEnabled)
228         return WTF::nullopt;
229
230     Optional<bool> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
231     decoder >> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
232     if (!allLoadsBlockedByDeviceManagementRestrictionsForTesting)
233         return WTF::nullopt;
234
235     return {{
236         sessionID
237         , WTFMove(*boundInterfaceIdentifier)
238         , WTFMove(*allowsCellularAccess)
239 #if PLATFORM(COCOA)
240         , WTFMove(proxyConfiguration)
241         , WTFMove(*sourceApplicationBundleIdentifier)
242         , WTFMove(*sourceApplicationSecondaryIdentifier)
243         , WTFMove(*allowsTLSFallback)
244         , WTFMove(*shouldLogCookieInformation)
245         , WTFMove(*loadThrottleLatency)
246         , WTFMove(*httpProxy)
247         , WTFMove(*httpsProxy)
248 #endif
249 #if USE(SOUP)
250         , WTFMove(*cookiePersistentStoragePath)
251         , WTFMove(*cookiePersistentStorageType)
252 #endif
253 #if USE(CURL)
254         , WTFMove(*cookiePersistentStorageFile)
255         , WTFMove(*proxySettings)
256 #endif
257         , WTFMove(*resourceLoadStatisticsDirectory)
258         , WTFMove(*resourceLoadStatisticsDirectoryExtensionHandle)
259         , WTFMove(*enableResourceLoadStatistics)
260         , WTFMove(*shouldIncludeLocalhostInResourceLoadStatistics)
261         , WTFMove(*enableResourceLoadStatisticsDebugMode)
262         , WTFMove(*deviceManagementRestrictionsEnabled)
263         , WTFMove(*allLoadsBlockedByDeviceManagementRestrictionsForTesting)
264         , WTFMove(*resourceLoadStatisticsManualPrevalentResource)
265         , WTFMove(*localStorageDirectory)
266         , WTFMove(*localStorageDirectoryExtensionHandle)
267         , WTFMove(*networkCacheDirectory)
268         , WTFMove(*networkCacheDirectoryExtensionHandle)
269     }};
270 }
271
272 } // namespace WebKit