Implement DownloadMonitor to prevent long-running slow downloads from background...
[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.encodeEnum(cacheModel);
45     encoder << canHandleHTTPSServerTrustEvaluation;
46     encoder << diskCacheDirectory;
47     encoder << diskCacheDirectoryExtensionHandle;
48     encoder << shouldEnableNetworkCacheEfficacyLogging;
49 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
50     encoder << shouldEnableNetworkCacheSpeculativeRevalidation;
51 #endif
52 #if PLATFORM(MAC)
53     encoder << uiProcessCookieStorageIdentifier;
54 #endif
55 #if PLATFORM(IOS_FAMILY)
56     encoder << cookieStorageDirectoryExtensionHandle;
57     encoder << containerCachesDirectoryExtensionHandle;
58     encoder << parentBundleDirectoryExtensionHandle;
59 #endif
60     encoder << shouldSuppressMemoryPressureHandler;
61     encoder << shouldUseTestingNetworkSession;
62     encoder << urlSchemesRegisteredForCustomProtocols;
63 #if PLATFORM(COCOA)
64     encoder << uiProcessBundleIdentifier;
65     encoder << uiProcessSDKVersion;
66 #if PLATFORM(IOS_FAMILY)
67     encoder << ctDataConnectionServiceType;
68 #endif
69     IPC::encode(encoder, networkATSContext.get());
70     encoder << storageAccessAPIEnabled;
71     encoder << suppressesConnectionTerminationOnSystemChange;
72 #endif
73     encoder << defaultDataStoreParameters;
74 #if USE(SOUP)
75     encoder.encodeEnum(cookieAcceptPolicy);
76     encoder << ignoreTLSErrors;
77     encoder << languages;
78     encoder << proxySettings;
79 #endif
80
81     encoder << urlSchemesRegisteredAsSecure;
82     encoder << urlSchemesRegisteredAsBypassingContentSecurityPolicy;
83     encoder << urlSchemesRegisteredAsLocal;
84     encoder << urlSchemesRegisteredAsNoAccess;
85     encoder << urlSchemesRegisteredAsDisplayIsolated;
86     encoder << urlSchemesRegisteredAsCORSEnabled;
87     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
88
89 #if ENABLE(PROXIMITY_NETWORKING)
90     encoder << wirelessContextIdentifier;
91 #endif
92
93 #if ENABLE(SERVICE_WORKER)
94     encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle << urlSchemesServiceWorkersCanHandle << shouldDisableServiceWorkerProcessTerminationDelay;
95 #endif
96     encoder << shouldEnableITPDatabase;
97     encoder << downloadMonitorSpeedMultiplier;
98 }
99
100 bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProcessCreationParameters& result)
101 {
102     if (!decoder.decodeEnum(result.cacheModel))
103         return false;
104     if (!decoder.decode(result.canHandleHTTPSServerTrustEvaluation))
105         return false;
106
107     if (!decoder.decode(result.diskCacheDirectory))
108         return false;
109     
110     Optional<SandboxExtension::Handle> diskCacheDirectoryExtensionHandle;
111     decoder >> diskCacheDirectoryExtensionHandle;
112     if (!diskCacheDirectoryExtensionHandle)
113         return false;
114     result.diskCacheDirectoryExtensionHandle = WTFMove(*diskCacheDirectoryExtensionHandle);
115
116     if (!decoder.decode(result.shouldEnableNetworkCacheEfficacyLogging))
117         return false;
118 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
119     if (!decoder.decode(result.shouldEnableNetworkCacheSpeculativeRevalidation))
120         return false;
121 #endif
122 #if PLATFORM(MAC)
123     if (!decoder.decode(result.uiProcessCookieStorageIdentifier))
124         return false;
125 #endif
126 #if PLATFORM(IOS_FAMILY)
127     Optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
128     decoder >> cookieStorageDirectoryExtensionHandle;
129     if (!cookieStorageDirectoryExtensionHandle)
130         return false;
131     result.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
132
133     Optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
134     decoder >> containerCachesDirectoryExtensionHandle;
135     if (!containerCachesDirectoryExtensionHandle)
136         return false;
137     result.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
138
139     Optional<SandboxExtension::Handle> parentBundleDirectoryExtensionHandle;
140     decoder >> parentBundleDirectoryExtensionHandle;
141     if (!parentBundleDirectoryExtensionHandle)
142         return false;
143     result.parentBundleDirectoryExtensionHandle = WTFMove(*parentBundleDirectoryExtensionHandle);
144 #endif
145     if (!decoder.decode(result.shouldSuppressMemoryPressureHandler))
146         return false;
147     if (!decoder.decode(result.shouldUseTestingNetworkSession))
148         return false;
149     if (!decoder.decode(result.urlSchemesRegisteredForCustomProtocols))
150         return false;
151 #if PLATFORM(COCOA)
152     if (!decoder.decode(result.uiProcessBundleIdentifier))
153         return false;
154     if (!decoder.decode(result.uiProcessSDKVersion))
155         return false;
156 #if PLATFORM(IOS_FAMILY)
157     if (!decoder.decode(result.ctDataConnectionServiceType))
158         return false;
159 #endif
160     if (!IPC::decode(decoder, result.networkATSContext))
161         return false;
162     if (!decoder.decode(result.storageAccessAPIEnabled))
163         return false;
164     if (!decoder.decode(result.suppressesConnectionTerminationOnSystemChange))
165         return false;
166 #endif
167
168     Optional<WebsiteDataStoreParameters> defaultDataStoreParameters;
169     decoder >> defaultDataStoreParameters;
170     if (!defaultDataStoreParameters)
171         return false;
172     result.defaultDataStoreParameters = WTFMove(*defaultDataStoreParameters);
173
174 #if USE(SOUP)
175     if (!decoder.decodeEnum(result.cookieAcceptPolicy))
176         return false;
177     if (!decoder.decode(result.ignoreTLSErrors))
178         return false;
179     if (!decoder.decode(result.languages))
180         return false;
181     if (!decoder.decode(result.proxySettings))
182         return false;
183 #endif
184
185     if (!decoder.decode(result.urlSchemesRegisteredAsSecure))
186         return false;
187     if (!decoder.decode(result.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
188         return false;
189     if (!decoder.decode(result.urlSchemesRegisteredAsLocal))
190         return false;
191     if (!decoder.decode(result.urlSchemesRegisteredAsNoAccess))
192         return false;
193     if (!decoder.decode(result.urlSchemesRegisteredAsDisplayIsolated))
194         return false;
195     if (!decoder.decode(result.urlSchemesRegisteredAsCORSEnabled))
196         return false;
197     if (!decoder.decode(result.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
198         return false;
199
200 #if ENABLE(PROXIMITY_NETWORKING)
201     if (!decoder.decode(result.wirelessContextIdentifier))
202         return false;
203 #endif
204
205 #if ENABLE(SERVICE_WORKER)
206     if (!decoder.decode(result.serviceWorkerRegistrationDirectory))
207         return false;
208     
209     Optional<SandboxExtension::Handle> serviceWorkerRegistrationDirectoryExtensionHandle;
210     decoder >> serviceWorkerRegistrationDirectoryExtensionHandle;
211     if (!serviceWorkerRegistrationDirectoryExtensionHandle)
212         return false;
213     result.serviceWorkerRegistrationDirectoryExtensionHandle = WTFMove(*serviceWorkerRegistrationDirectoryExtensionHandle);
214     
215     if (!decoder.decode(result.urlSchemesServiceWorkersCanHandle))
216         return false;
217     
218     if (!decoder.decode(result.shouldDisableServiceWorkerProcessTerminationDelay))
219         return false;
220 #endif
221
222     if (!decoder.decode(result.shouldEnableITPDatabase))
223         return false;
224
225     Optional<uint32_t> downloadMonitorSpeedMultiplier;
226     decoder >> downloadMonitorSpeedMultiplier;
227     if (!downloadMonitorSpeedMultiplier)
228         return false;
229     result.downloadMonitorSpeedMultiplier = *downloadMonitorSpeedMultiplier;
230     
231     return true;
232 }
233
234 } // namespace WebKit