Resource Load Statistics: Switch NSURLSession on top navigation to prevalent resource...
[WebKit.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, 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 << enableResourceLoadStatisticsLogTestingEvent;
84     encoder << shouldIncludeLocalhostInResourceLoadStatistics;
85     encoder << enableResourceLoadStatisticsDebugMode;
86     encoder << resourceLoadStatisticsManualPrevalentResource;
87     encoder << enableResourceLoadStatisticsNSURLSessionSwitching;
88
89     encoder << localStorageDirectory << localStorageDirectoryExtensionHandle;
90     encoder << networkCacheDirectory << networkCacheDirectoryExtensionHandle;
91
92     encoder << deviceManagementRestrictionsEnabled;
93     encoder << allLoadsBlockedByDeviceManagementRestrictionsForTesting;
94 }
95
96 Optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters::decode(IPC::Decoder& decoder)
97 {
98     PAL::SessionID sessionID;
99     if (!decoder.decode(sessionID))
100         return WTF::nullopt;
101     
102     Optional<String> boundInterfaceIdentifier;
103     decoder >> boundInterfaceIdentifier;
104     if (!boundInterfaceIdentifier)
105         return WTF::nullopt;
106     
107     Optional<AllowsCellularAccess> allowsCellularAccess;
108     decoder >> allowsCellularAccess;
109     if (!allowsCellularAccess)
110         return WTF::nullopt;
111     
112 #if PLATFORM(COCOA)
113     RetainPtr<CFDictionaryRef> proxyConfiguration;
114     if (!IPC::decode(decoder, proxyConfiguration))
115         return WTF::nullopt;
116     
117     Optional<String> sourceApplicationBundleIdentifier;
118     decoder >> sourceApplicationBundleIdentifier;
119     if (!sourceApplicationBundleIdentifier)
120         return WTF::nullopt;
121     
122     Optional<String> sourceApplicationSecondaryIdentifier;
123     decoder >> sourceApplicationSecondaryIdentifier;
124     if (!sourceApplicationSecondaryIdentifier)
125         return WTF::nullopt;
126
127     Optional<AllowsTLSFallback> allowsTLSFallback;
128     decoder >> allowsTLSFallback;
129     if (!allowsTLSFallback)
130         return WTF::nullopt;
131
132     Optional<bool> shouldLogCookieInformation;
133     decoder >> shouldLogCookieInformation;
134     if (!shouldLogCookieInformation)
135         return WTF::nullopt;
136     
137     Optional<Seconds> loadThrottleLatency;
138     decoder >> loadThrottleLatency;
139     if (!loadThrottleLatency)
140         return WTF::nullopt;
141     
142     Optional<URL> httpProxy;
143     decoder >> httpProxy;
144     if (!httpProxy)
145         return WTF::nullopt;
146
147     Optional<URL> httpsProxy;
148     decoder >> httpsProxy;
149     if (!httpsProxy)
150         return WTF::nullopt;
151 #endif
152
153 #if USE(SOUP)
154     Optional<String> cookiePersistentStoragePath;
155     decoder >> cookiePersistentStoragePath;
156     if (!cookiePersistentStoragePath)
157         return WTF::nullopt;
158
159     Optional<SoupCookiePersistentStorageType> cookiePersistentStorageType;
160     decoder >> cookiePersistentStorageType;
161     if (!cookiePersistentStorageType)
162         return WTF::nullopt;
163 #endif
164
165 #if USE(CURL)
166     Optional<String> cookiePersistentStorageFile;
167     decoder >> cookiePersistentStorageFile;
168     if (!cookiePersistentStorageFile)
169         return WTF::nullopt;
170
171     Optional<WebCore::CurlProxySettings> proxySettings;
172     decoder >> proxySettings;
173     if (!proxySettings)
174         return WTF::nullopt;
175 #endif
176
177     Optional<String> resourceLoadStatisticsDirectory;
178     decoder >> resourceLoadStatisticsDirectory;
179     if (!resourceLoadStatisticsDirectory)
180         return WTF::nullopt;
181
182     Optional<SandboxExtension::Handle> resourceLoadStatisticsDirectoryExtensionHandle;
183     decoder >> resourceLoadStatisticsDirectoryExtensionHandle;
184     if (!resourceLoadStatisticsDirectoryExtensionHandle)
185         return WTF::nullopt;
186
187     Optional<bool> enableResourceLoadStatistics;
188     decoder >> enableResourceLoadStatistics;
189     if (!enableResourceLoadStatistics)
190         return WTF::nullopt;
191
192     Optional<bool> enableResourceLoadStatisticsLogTestingEvent;
193     decoder >> enableResourceLoadStatisticsLogTestingEvent;
194     if (!enableResourceLoadStatisticsLogTestingEvent)
195         return WTF::nullopt;
196
197     Optional<bool> shouldIncludeLocalhostInResourceLoadStatistics;
198     decoder >> shouldIncludeLocalhostInResourceLoadStatistics;
199     if (!shouldIncludeLocalhostInResourceLoadStatistics)
200         return WTF::nullopt;
201
202     Optional<bool> enableResourceLoadStatisticsDebugMode;
203     decoder >> enableResourceLoadStatisticsDebugMode;
204     if (!enableResourceLoadStatisticsDebugMode)
205         return WTF::nullopt;
206
207     Optional<WebCore::RegistrableDomain> resourceLoadStatisticsManualPrevalentResource;
208     decoder >> resourceLoadStatisticsManualPrevalentResource;
209     if (!resourceLoadStatisticsManualPrevalentResource)
210         return WTF::nullopt;
211
212     Optional<bool> enableResourceLoadStatisticsNSURLSessionSwitching;
213     decoder >> enableResourceLoadStatisticsNSURLSessionSwitching;
214     if (!enableResourceLoadStatisticsNSURLSessionSwitching)
215         return WTF::nullopt;
216     
217     Optional<String> localStorageDirectory;
218     decoder >> localStorageDirectory;
219     if (!localStorageDirectory)
220         return WTF::nullopt;
221
222     Optional<SandboxExtension::Handle> localStorageDirectoryExtensionHandle;
223     decoder >> localStorageDirectoryExtensionHandle;
224     if (!localStorageDirectoryExtensionHandle)
225         return WTF::nullopt;
226
227     Optional<String> networkCacheDirectory;
228     decoder >> networkCacheDirectory;
229     if (!networkCacheDirectory)
230         return WTF::nullopt;
231     
232     Optional<SandboxExtension::Handle> networkCacheDirectoryExtensionHandle;
233     decoder >> networkCacheDirectoryExtensionHandle;
234     if (!networkCacheDirectoryExtensionHandle)
235         return WTF::nullopt;
236
237     Optional<bool> deviceManagementRestrictionsEnabled;
238     decoder >> deviceManagementRestrictionsEnabled;
239     if (!deviceManagementRestrictionsEnabled)
240         return WTF::nullopt;
241
242     Optional<bool> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
243     decoder >> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
244     if (!allLoadsBlockedByDeviceManagementRestrictionsForTesting)
245         return WTF::nullopt;
246
247     return {{
248         sessionID
249         , WTFMove(*boundInterfaceIdentifier)
250         , WTFMove(*allowsCellularAccess)
251 #if PLATFORM(COCOA)
252         , WTFMove(proxyConfiguration)
253         , WTFMove(*sourceApplicationBundleIdentifier)
254         , WTFMove(*sourceApplicationSecondaryIdentifier)
255         , WTFMove(*allowsTLSFallback)
256         , WTFMove(*shouldLogCookieInformation)
257         , WTFMove(*loadThrottleLatency)
258         , WTFMove(*httpProxy)
259         , WTFMove(*httpsProxy)
260 #endif
261 #if USE(SOUP)
262         , WTFMove(*cookiePersistentStoragePath)
263         , WTFMove(*cookiePersistentStorageType)
264 #endif
265 #if USE(CURL)
266         , WTFMove(*cookiePersistentStorageFile)
267         , WTFMove(*proxySettings)
268 #endif
269         , WTFMove(*resourceLoadStatisticsDirectory)
270         , WTFMove(*resourceLoadStatisticsDirectoryExtensionHandle)
271         , WTFMove(*enableResourceLoadStatistics)
272         , WTFMove(*enableResourceLoadStatisticsLogTestingEvent)
273         , WTFMove(*shouldIncludeLocalhostInResourceLoadStatistics)
274         , WTFMove(*enableResourceLoadStatisticsDebugMode)
275         , WTFMove(*enableResourceLoadStatisticsNSURLSessionSwitching)
276         , WTFMove(*deviceManagementRestrictionsEnabled)
277         , WTFMove(*allLoadsBlockedByDeviceManagementRestrictionsForTesting)
278         , WTFMove(*resourceLoadStatisticsManualPrevalentResource)
279         , WTFMove(*localStorageDirectory)
280         , WTFMove(*localStorageDirectoryExtensionHandle)
281         , WTFMove(*networkCacheDirectory)
282         , WTFMove(*networkCacheDirectoryExtensionHandle)
283     }};
284 }
285
286 } // namespace WebKit