REGRESSION (r231850): Cookie file cannot be read or written by network process
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkProcessCreationParameters.cpp
1 /*
2  * Copyright (C) 2012-2017 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 "NetworkProcessCreationParameters.h"
28
29 #include "ArgumentCoders.h"
30 #include "WebCoreArgumentCoders.h"
31
32 #if PLATFORM(COCOA)
33 #include "ArgumentCodersCF.h"
34 #endif
35
36 namespace WebKit {
37
38 NetworkProcessCreationParameters::NetworkProcessCreationParameters()
39 {
40 }
41
42 void NetworkProcessCreationParameters::encode(IPC::Encoder& encoder) const
43 {
44     encoder << defaultSessionParameters;
45     encoder << privateBrowsingEnabled;
46     encoder.encodeEnum(cacheModel);
47     encoder << diskCacheSizeOverride;
48     encoder << canHandleHTTPSServerTrustEvaluation;
49     encoder << diskCacheDirectory;
50     encoder << diskCacheDirectoryExtensionHandle;
51     encoder << shouldEnableNetworkCacheEfficacyLogging;
52 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
53     encoder << shouldEnableNetworkCacheSpeculativeRevalidation;
54 #endif
55 #if PLATFORM(COCOA)
56     encoder << uiProcessCookieStorageIdentifier;
57 #endif
58     encoder << defaultSessionPendingCookies;
59 #if PLATFORM(IOS)
60     encoder << cookieStorageDirectoryExtensionHandle;
61     encoder << containerCachesDirectoryExtensionHandle;
62     encoder << parentBundleDirectoryExtensionHandle;
63 #endif
64     encoder << shouldSuppressMemoryPressureHandler;
65     encoder << shouldUseTestingNetworkSession;
66     encoder << loadThrottleLatency;
67     encoder << urlSchemesRegisteredForCustomProtocols;
68     encoder << presentingApplicationPID;
69 #if PLATFORM(COCOA)
70     encoder << parentProcessName;
71     encoder << uiProcessBundleIdentifier;
72     encoder << sourceApplicationBundleIdentifier;
73     encoder << sourceApplicationSecondaryIdentifier;
74 #if PLATFORM(IOS)
75     encoder << ctDataConnectionServiceType;
76 #endif
77     encoder << httpProxy;
78     encoder << httpsProxy;
79     IPC::encode(encoder, networkATSContext.get());
80     encoder << cookieStoragePartitioningEnabled;
81     encoder << storageAccessAPIEnabled;
82     encoder << suppressesConnectionTerminationOnSystemChange;
83 #endif
84 #if USE(SOUP)
85     encoder << cookiePersistentStoragePath;
86     encoder << cookiePersistentStorageType;
87     encoder.encodeEnum(cookieAcceptPolicy);
88     encoder << ignoreTLSErrors;
89     encoder << languages;
90     encoder << proxySettings;
91 #elif USE(CURL)
92     encoder << cookiePersistentStorageFile;
93 #endif
94 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
95     encoder << logCookieInformation;
96 #endif
97 #if ENABLE(NETWORK_CAPTURE)
98     encoder << recordReplayMode;
99     encoder << recordReplayCacheLocation;
100 #endif
101
102     encoder << urlSchemesRegisteredAsSecure;
103     encoder << urlSchemesRegisteredAsBypassingContentSecurityPolicy;
104     encoder << urlSchemesRegisteredAsLocal;
105     encoder << urlSchemesRegisteredAsNoAccess;
106     encoder << urlSchemesRegisteredAsDisplayIsolated;
107     encoder << urlSchemesRegisteredAsCORSEnabled;
108     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
109
110 #if ENABLE(WIFI_ASSERTIONS)
111     encoder << wirelessContextIdentifier;
112 #endif
113 }
114
115 bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProcessCreationParameters& result)
116 {
117     std::optional<NetworkSessionCreationParameters> defaultSessionParameters;
118     decoder >> defaultSessionParameters;
119     if (!defaultSessionParameters)
120         return false;
121     result.defaultSessionParameters = WTFMove(*defaultSessionParameters);
122
123     if (!decoder.decode(result.privateBrowsingEnabled))
124         return false;
125     if (!decoder.decodeEnum(result.cacheModel))
126         return false;
127     if (!decoder.decode(result.diskCacheSizeOverride))
128         return false;
129     if (!decoder.decode(result.canHandleHTTPSServerTrustEvaluation))
130         return false;
131
132     if (!decoder.decode(result.diskCacheDirectory))
133         return false;
134     
135     std::optional<SandboxExtension::Handle> diskCacheDirectoryExtensionHandle;
136     decoder >> diskCacheDirectoryExtensionHandle;
137     if (!diskCacheDirectoryExtensionHandle)
138         return false;
139     result.diskCacheDirectoryExtensionHandle = WTFMove(*diskCacheDirectoryExtensionHandle);
140
141     if (!decoder.decode(result.shouldEnableNetworkCacheEfficacyLogging))
142         return false;
143 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
144     if (!decoder.decode(result.shouldEnableNetworkCacheSpeculativeRevalidation))
145         return false;
146 #endif
147 #if PLATFORM(COCOA)
148     if (!decoder.decode(result.uiProcessCookieStorageIdentifier))
149         return false;
150 #endif
151     if (!decoder.decode(result.defaultSessionPendingCookies))
152         return false;
153 #if PLATFORM(IOS)
154     std::optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
155     decoder >> cookieStorageDirectoryExtensionHandle;
156     if (!cookieStorageDirectoryExtensionHandle)
157         return false;
158     result.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
159
160     std::optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
161     decoder >> containerCachesDirectoryExtensionHandle;
162     if (!containerCachesDirectoryExtensionHandle)
163         return false;
164     result.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
165
166     std::optional<SandboxExtension::Handle> parentBundleDirectoryExtensionHandle;
167     decoder >> parentBundleDirectoryExtensionHandle;
168     if (!parentBundleDirectoryExtensionHandle)
169         return false;
170     result.parentBundleDirectoryExtensionHandle = WTFMove(*parentBundleDirectoryExtensionHandle);
171 #endif
172     if (!decoder.decode(result.shouldSuppressMemoryPressureHandler))
173         return false;
174     if (!decoder.decode(result.shouldUseTestingNetworkSession))
175         return false;
176     if (!decoder.decode(result.loadThrottleLatency))
177         return false;
178     if (!decoder.decode(result.urlSchemesRegisteredForCustomProtocols))
179         return false;
180     if (!decoder.decode(result.presentingApplicationPID))
181         return false;
182 #if PLATFORM(COCOA)
183     if (!decoder.decode(result.parentProcessName))
184         return false;
185     if (!decoder.decode(result.uiProcessBundleIdentifier))
186         return false;
187     if (!decoder.decode(result.sourceApplicationBundleIdentifier))
188         return false;
189     if (!decoder.decode(result.sourceApplicationSecondaryIdentifier))
190         return false;
191 #if PLATFORM(IOS)
192     if (!decoder.decode(result.ctDataConnectionServiceType))
193         return false;
194 #endif
195     if (!decoder.decode(result.httpProxy))
196         return false;
197     if (!decoder.decode(result.httpsProxy))
198         return false;
199     if (!IPC::decode(decoder, result.networkATSContext))
200         return false;
201     if (!decoder.decode(result.cookieStoragePartitioningEnabled))
202         return false;
203     if (!decoder.decode(result.storageAccessAPIEnabled))
204         return false;
205     if (!decoder.decode(result.suppressesConnectionTerminationOnSystemChange))
206         return false;
207 #endif
208
209 #if USE(SOUP)
210     if (!decoder.decode(result.cookiePersistentStoragePath))
211         return false;
212     if (!decoder.decode(result.cookiePersistentStorageType))
213         return false;
214     if (!decoder.decodeEnum(result.cookieAcceptPolicy))
215         return false;
216     if (!decoder.decode(result.ignoreTLSErrors))
217         return false;
218     if (!decoder.decode(result.languages))
219         return false;
220     if (!decoder.decode(result.proxySettings))
221         return false;
222 #elif USE(CURL)
223     if (!decoder.decode(result.cookiePersistentStorageFile))
224         return false;
225 #endif
226
227 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
228     if (!decoder.decode(result.logCookieInformation))
229         return false;
230 #endif
231
232 #if ENABLE(NETWORK_CAPTURE)
233     if (!decoder.decode(result.recordReplayMode))
234         return false;
235     if (!decoder.decode(result.recordReplayCacheLocation))
236         return false;
237 #endif
238
239     if (!decoder.decode(result.urlSchemesRegisteredAsSecure))
240         return false;
241     if (!decoder.decode(result.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
242         return false;
243     if (!decoder.decode(result.urlSchemesRegisteredAsLocal))
244         return false;
245     if (!decoder.decode(result.urlSchemesRegisteredAsNoAccess))
246         return false;
247     if (!decoder.decode(result.urlSchemesRegisteredAsDisplayIsolated))
248         return false;
249     if (!decoder.decode(result.urlSchemesRegisteredAsCORSEnabled))
250         return false;
251     if (!decoder.decode(result.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
252         return false;
253
254 #if ENABLE(WIFI_ASSERTIONS)
255     if (!decoder.decode(result.wirelessContextIdentifier))
256         return false;
257 #endif
258
259     return true;
260 }
261
262 } // namespace WebKit