Create a WebResourceLoadStatisticsStore attached to the NetworkSession
[WebKit-https.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         , { }, { }, { }, false, { }, { }, { }
46 #endif
47 #if USE(CURL)
48         , { }, { }
49 #endif
50         , { }, { }, false
51     };
52 }
53
54 void NetworkSessionCreationParameters::encode(IPC::Encoder& encoder) const
55 {
56     encoder << sessionID;
57     encoder << boundInterfaceIdentifier;
58     encoder << allowsCellularAccess;
59 #if PLATFORM(COCOA)
60     IPC::encode(encoder, proxyConfiguration.get());
61     encoder << sourceApplicationBundleIdentifier;
62     encoder << sourceApplicationSecondaryIdentifier;
63     encoder << shouldLogCookieInformation;
64     encoder << loadThrottleLatency;
65     encoder << httpProxy;
66     encoder << httpsProxy;
67 #endif
68 #if USE(CURL)
69     encoder << cookiePersistentStorageFile;
70     encoder << proxySettings;
71 #endif
72     encoder << resourceLoadStatisticsDirectory;
73     encoder << resourceLoadStatisticsDirectoryExtensionHandle;
74     encoder << enableResourceLoadStatistics;
75 }
76
77 Optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters::decode(IPC::Decoder& decoder)
78 {
79     PAL::SessionID sessionID;
80     if (!decoder.decode(sessionID))
81         return WTF::nullopt;
82     
83     Optional<String> boundInterfaceIdentifier;
84     decoder >> boundInterfaceIdentifier;
85     if (!boundInterfaceIdentifier)
86         return WTF::nullopt;
87     
88     Optional<AllowsCellularAccess> allowsCellularAccess;
89     decoder >> allowsCellularAccess;
90     if (!allowsCellularAccess)
91         return WTF::nullopt;
92     
93 #if PLATFORM(COCOA)
94     RetainPtr<CFDictionaryRef> proxyConfiguration;
95     if (!IPC::decode(decoder, proxyConfiguration))
96         return WTF::nullopt;
97     
98     Optional<String> sourceApplicationBundleIdentifier;
99     decoder >> sourceApplicationBundleIdentifier;
100     if (!sourceApplicationBundleIdentifier)
101         return WTF::nullopt;
102     
103     Optional<String> sourceApplicationSecondaryIdentifier;
104     decoder >> sourceApplicationSecondaryIdentifier;
105     if (!sourceApplicationSecondaryIdentifier)
106         return WTF::nullopt;
107     
108     Optional<bool> shouldLogCookieInformation;
109     decoder >> shouldLogCookieInformation;
110     if (!shouldLogCookieInformation)
111         return WTF::nullopt;
112     
113     Optional<Seconds> loadThrottleLatency;
114     decoder >> loadThrottleLatency;
115     if (!loadThrottleLatency)
116         return WTF::nullopt;
117     
118     Optional<URL> httpProxy;
119     decoder >> httpProxy;
120     if (!httpProxy)
121         return WTF::nullopt;
122
123     Optional<URL> httpsProxy;
124     decoder >> httpsProxy;
125     if (!httpsProxy)
126         return WTF::nullopt;
127 #endif
128     
129 #if USE(CURL)
130     Optional<String> cookiePersistentStorageFile;
131     decoder >> cookiePersistentStorageFile;
132     if (!cookiePersistentStorageFile)
133         return WTF::nullopt;
134
135     Optional<WebCore::CurlProxySettings> proxySettings;
136     decoder >> proxySettings;
137     if (!proxySettings)
138         return WTF::nullopt;
139 #endif
140
141     Optional<String> resourceLoadStatisticsDirectory;
142     decoder >> resourceLoadStatisticsDirectory;
143     if (!resourceLoadStatisticsDirectory)
144         return WTF::nullopt;
145
146     Optional<SandboxExtension::Handle> resourceLoadStatisticsDirectoryExtensionHandle;
147     decoder >> resourceLoadStatisticsDirectoryExtensionHandle;
148     if (!resourceLoadStatisticsDirectoryExtensionHandle)
149         return WTF::nullopt;
150
151     Optional<bool> enableResourceLoadStatistics;
152     decoder >> enableResourceLoadStatistics;
153     if (!enableResourceLoadStatistics)
154         return WTF::nullopt;
155
156     return {{
157         sessionID
158         , WTFMove(*boundInterfaceIdentifier)
159         , WTFMove(*allowsCellularAccess)
160 #if PLATFORM(COCOA)
161         , WTFMove(proxyConfiguration)
162         , WTFMove(*sourceApplicationBundleIdentifier)
163         , WTFMove(*sourceApplicationSecondaryIdentifier)
164         , WTFMove(*shouldLogCookieInformation)
165         , WTFMove(*loadThrottleLatency)
166         , WTFMove(*httpProxy)
167         , WTFMove(*httpsProxy)
168 #endif
169 #if USE(CURL)
170         , WTFMove(*cookiePersistentStorageFile)
171         , WTFMove(*proxySettings)
172 #endif
173         , WTFMove(*resourceLoadStatisticsDirectory)
174         , WTFMove(*resourceLoadStatisticsDirectoryExtensionHandle)
175         , WTFMove(*enableResourceLoadStatistics)
176     }};
177 }
178
179 } // namespace WebKit