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