1/*
2 * Copyright (C) 2010-2019 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#pragma once
27
28#include "SandboxExtension.h"
29
30namespace WebKit {
31
32struct WebProcessDataStoreParameters {
33 String applicationCacheDirectory;
34 SandboxExtension::Handle applicationCacheDirectoryExtensionHandle;
35 String applicationCacheFlatFileSubdirectoryName;
36 String webSQLDatabaseDirectory;
37 SandboxExtension::Handle webSQLDatabaseDirectoryExtensionHandle;
38 String mediaCacheDirectory;
39 SandboxExtension::Handle mediaCacheDirectoryExtensionHandle;
40 String mediaKeyStorageDirectory;
41 SandboxExtension::Handle mediaKeyStorageDirectoryExtensionHandle;
42 String javaScriptConfigurationDirectory;
43 SandboxExtension::Handle javaScriptConfigurationDirectoryExtensionHandle;
44 bool resourceLoadStatisticsEnabled { false };
45
46 template<class Encoder> void encode(Encoder&) const;
47 template<class Decoder> static Optional<WebProcessDataStoreParameters> decode(Decoder&);
48};
49
50template<class Encoder>
51void WebProcessDataStoreParameters::encode(Encoder& encoder) const
52{
53 encoder << applicationCacheDirectory;
54 encoder << applicationCacheDirectoryExtensionHandle;
55 encoder << applicationCacheFlatFileSubdirectoryName;
56 encoder << webSQLDatabaseDirectory;
57 encoder << webSQLDatabaseDirectoryExtensionHandle;
58 encoder << mediaCacheDirectory;
59 encoder << mediaCacheDirectoryExtensionHandle;
60 encoder << mediaKeyStorageDirectory;
61 encoder << mediaKeyStorageDirectoryExtensionHandle;
62 encoder << javaScriptConfigurationDirectory;
63 encoder << javaScriptConfigurationDirectoryExtensionHandle;
64 encoder << resourceLoadStatisticsEnabled;
65}
66
67template<class Decoder>
68Optional<WebProcessDataStoreParameters> WebProcessDataStoreParameters::decode(Decoder& decoder)
69{
70 WebProcessDataStoreParameters parameters;
71
72 if (!decoder.decode(parameters.applicationCacheDirectory))
73 return WTF::nullopt;
74
75 Optional<SandboxExtension::Handle> applicationCacheDirectoryExtensionHandle;
76 decoder >> applicationCacheDirectoryExtensionHandle;
77 if (!applicationCacheDirectoryExtensionHandle)
78 return WTF::nullopt;
79 parameters.applicationCacheDirectoryExtensionHandle = WTFMove(*applicationCacheDirectoryExtensionHandle);
80
81 if (!decoder.decode(parameters.applicationCacheFlatFileSubdirectoryName))
82 return WTF::nullopt;
83
84 if (!decoder.decode(parameters.webSQLDatabaseDirectory))
85 return WTF::nullopt;
86
87 Optional<SandboxExtension::Handle> webSQLDatabaseDirectoryExtensionHandle;
88 decoder >> webSQLDatabaseDirectoryExtensionHandle;
89 if (!webSQLDatabaseDirectoryExtensionHandle)
90 return WTF::nullopt;
91 parameters.webSQLDatabaseDirectoryExtensionHandle = WTFMove(*webSQLDatabaseDirectoryExtensionHandle);
92
93 if (!decoder.decode(parameters.mediaCacheDirectory))
94 return WTF::nullopt;
95
96 Optional<SandboxExtension::Handle> mediaCacheDirectoryExtensionHandle;
97 decoder >> mediaCacheDirectoryExtensionHandle;
98 if (!mediaCacheDirectoryExtensionHandle)
99 return WTF::nullopt;
100 parameters.mediaCacheDirectoryExtensionHandle = WTFMove(*mediaCacheDirectoryExtensionHandle);
101
102 if (!decoder.decode(parameters.mediaKeyStorageDirectory))
103 return WTF::nullopt;
104
105 Optional<SandboxExtension::Handle> mediaKeyStorageDirectoryExtensionHandle;
106 decoder >> mediaKeyStorageDirectoryExtensionHandle;
107 if (!mediaKeyStorageDirectoryExtensionHandle)
108 return WTF::nullopt;
109 parameters.mediaKeyStorageDirectoryExtensionHandle = WTFMove(*mediaKeyStorageDirectoryExtensionHandle);
110
111 if (!decoder.decode(parameters.javaScriptConfigurationDirectory))
112 return WTF::nullopt;
113
114 Optional<SandboxExtension::Handle> javaScriptConfigurationDirectoryExtensionHandle;
115 decoder >> javaScriptConfigurationDirectoryExtensionHandle;
116 if (!javaScriptConfigurationDirectoryExtensionHandle)
117 return WTF::nullopt;
118 parameters.javaScriptConfigurationDirectoryExtensionHandle = WTFMove(*javaScriptConfigurationDirectoryExtensionHandle);
119
120 if (!decoder.decode(parameters.resourceLoadStatisticsEnabled))
121 return WTF::nullopt;
122
123 return parameters;
124}
125
126} // namespace WebKit
127