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