1/*
2 * Copyright (C) 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 "WebsiteDataStoreParameters.h"
28
29#include "WebCoreArgumentCoders.h"
30#include "WebsiteDataStore.h"
31
32namespace WebKit {
33
34WebsiteDataStoreParameters::~WebsiteDataStoreParameters()
35{
36}
37
38void WebsiteDataStoreParameters::encode(IPC::Encoder& encoder) const
39{
40 encoder << networkSessionParameters;
41 encoder << uiProcessCookieStorageIdentifier;
42 encoder << cookieStoragePathExtensionHandle;
43 encoder << pendingCookies;
44
45#if ENABLE(INDEXED_DATABASE)
46 encoder << indexedDatabaseDirectory << indexedDatabaseDirectoryExtensionHandle;
47#if PLATFORM(IOS_FAMILY)
48 encoder << indexedDatabaseTempBlobDirectoryExtensionHandle;
49#endif
50#endif
51
52#if ENABLE(SERVICE_WORKER)
53 encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle;
54#endif
55
56 encoder << perOriginStorageQuota;
57 encoder << perThirdPartyOriginStorageQuota;
58}
59
60Optional<WebsiteDataStoreParameters> WebsiteDataStoreParameters::decode(IPC::Decoder& decoder)
61{
62 WebsiteDataStoreParameters parameters;
63
64 Optional<NetworkSessionCreationParameters> networkSessionParameters;
65 decoder >> networkSessionParameters;
66 if (!networkSessionParameters)
67 return WTF::nullopt;
68 parameters.networkSessionParameters = WTFMove(*networkSessionParameters);
69
70 Optional<Vector<uint8_t>> uiProcessCookieStorageIdentifier;
71 decoder >> uiProcessCookieStorageIdentifier;
72 if (!uiProcessCookieStorageIdentifier)
73 return WTF::nullopt;
74 parameters.uiProcessCookieStorageIdentifier = WTFMove(*uiProcessCookieStorageIdentifier);
75
76 Optional<SandboxExtension::Handle> cookieStoragePathExtensionHandle;
77 decoder >> cookieStoragePathExtensionHandle;
78 if (!cookieStoragePathExtensionHandle)
79 return WTF::nullopt;
80 parameters.cookieStoragePathExtensionHandle = WTFMove(*cookieStoragePathExtensionHandle);
81
82 Optional<Vector<WebCore::Cookie>> pendingCookies;
83 decoder >> pendingCookies;
84 if (!pendingCookies)
85 return WTF::nullopt;
86 parameters.pendingCookies = WTFMove(*pendingCookies);
87
88#if ENABLE(INDEXED_DATABASE)
89 Optional<String> indexedDatabaseDirectory;
90 decoder >> indexedDatabaseDirectory;
91 if (!indexedDatabaseDirectory)
92 return WTF::nullopt;
93 parameters.indexedDatabaseDirectory = WTFMove(*indexedDatabaseDirectory);
94
95 Optional<SandboxExtension::Handle> indexedDatabaseDirectoryExtensionHandle;
96 decoder >> indexedDatabaseDirectoryExtensionHandle;
97 if (!indexedDatabaseDirectoryExtensionHandle)
98 return WTF::nullopt;
99 parameters.indexedDatabaseDirectoryExtensionHandle = WTFMove(*indexedDatabaseDirectoryExtensionHandle);
100
101#if PLATFORM(IOS_FAMILY)
102 Optional<SandboxExtension::Handle> indexedDatabaseTempBlobDirectoryExtensionHandle;
103 decoder >> indexedDatabaseTempBlobDirectoryExtensionHandle;
104 if (!indexedDatabaseTempBlobDirectoryExtensionHandle)
105 return WTF::nullopt;
106 parameters.indexedDatabaseTempBlobDirectoryExtensionHandle = WTFMove(*indexedDatabaseTempBlobDirectoryExtensionHandle);
107#endif
108#endif
109
110#if ENABLE(SERVICE_WORKER)
111 Optional<String> serviceWorkerRegistrationDirectory;
112 decoder >> serviceWorkerRegistrationDirectory;
113 if (!serviceWorkerRegistrationDirectory)
114 return WTF::nullopt;
115 parameters.serviceWorkerRegistrationDirectory = WTFMove(*serviceWorkerRegistrationDirectory);
116
117 Optional<SandboxExtension::Handle> serviceWorkerRegistrationDirectoryExtensionHandle;
118 decoder >> serviceWorkerRegistrationDirectoryExtensionHandle;
119 if (!serviceWorkerRegistrationDirectoryExtensionHandle)
120 return WTF::nullopt;
121 parameters.serviceWorkerRegistrationDirectoryExtensionHandle = WTFMove(*serviceWorkerRegistrationDirectoryExtensionHandle);
122#endif
123
124 Optional<uint64_t> perOriginStorageQuota;
125 decoder >> perOriginStorageQuota;
126 if (!perOriginStorageQuota)
127 return WTF::nullopt;
128 parameters.perOriginStorageQuota = *perOriginStorageQuota;
129
130 Optional<uint64_t> perThirdPartyOriginStorageQuota;
131 decoder >> perThirdPartyOriginStorageQuota;
132 if (!perThirdPartyOriginStorageQuota)
133 return WTF::nullopt;
134 parameters.perThirdPartyOriginStorageQuota = *perThirdPartyOriginStorageQuota;
135
136 return parameters;
137}
138
139WebsiteDataStoreParameters WebsiteDataStoreParameters::privateSessionParameters(PAL::SessionID sessionID)
140{
141 ASSERT(sessionID.isEphemeral());
142 return { { }, { }, { }, NetworkSessionCreationParameters::privateSessionParameters(sessionID)
143#if ENABLE(INDEXED_DATABASE)
144 , { }, { }
145#if PLATFORM(IOS_FAMILY)
146 , { }
147#endif
148#endif
149#if ENABLE(SERVICE_WORKER)
150 , { }, { }
151#endif
152 };
153}
154
155} // namespace WebKit
156