1 | /* |
2 | * Copyright (C) 2014-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 "APIWebsiteDataStore.h" |
28 | |
29 | #include "WebKit2Initialize.h" |
30 | #include "WebsiteDataStore.h" |
31 | |
32 | namespace API { |
33 | |
34 | static RefPtr<WebsiteDataStore>& globalDefaultDataStore() |
35 | { |
36 | static NeverDestroyed<RefPtr<WebsiteDataStore>> globalDefaultDataStore; |
37 | return globalDefaultDataStore.get(); |
38 | } |
39 | |
40 | |
41 | Ref<WebsiteDataStore> WebsiteDataStore::defaultDataStore() |
42 | { |
43 | WebKit::InitializeWebKit2(); |
44 | |
45 | auto& store = globalDefaultDataStore(); |
46 | if (!store) |
47 | store = adoptRef(new WebsiteDataStore(defaultDataStoreConfiguration(), PAL::SessionID::defaultSessionID())); |
48 | |
49 | return *store; |
50 | } |
51 | |
52 | void WebsiteDataStore::deleteDefaultDataStoreForTesting() |
53 | { |
54 | globalDefaultDataStore() = nullptr; |
55 | } |
56 | |
57 | bool WebsiteDataStore::defaultDataStoreExists() |
58 | { |
59 | return !!globalDefaultDataStore(); |
60 | } |
61 | |
62 | Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistentDataStore() |
63 | { |
64 | return adoptRef(*new WebsiteDataStore); |
65 | } |
66 | |
67 | Ref<WebsiteDataStore> WebsiteDataStore::createLegacy(Ref<WebKit::WebsiteDataStoreConfiguration>&& configuration) |
68 | { |
69 | configuration->setIndexedDBDatabaseDirectory(legacyDefaultIndexedDBDatabaseDirectory()); |
70 | return adoptRef(*new WebsiteDataStore(WTFMove(configuration), PAL::SessionID::defaultSessionID())); |
71 | } |
72 | |
73 | WebsiteDataStore::WebsiteDataStore() |
74 | : m_websiteDataStore(WebKit::WebsiteDataStore::createNonPersistent()) |
75 | { |
76 | } |
77 | |
78 | WebsiteDataStore::WebsiteDataStore(Ref<WebKit::WebsiteDataStoreConfiguration>&& configuration, PAL::SessionID sessionID) |
79 | : m_websiteDataStore(WebKit::WebsiteDataStore::create(WTFMove(configuration), sessionID)) |
80 | { |
81 | } |
82 | |
83 | WebsiteDataStore::~WebsiteDataStore() |
84 | { |
85 | } |
86 | |
87 | HTTPCookieStore& WebsiteDataStore::httpCookieStore() |
88 | { |
89 | return m_websiteDataStore->cookieStore(); |
90 | } |
91 | |
92 | WTF::String WebsiteDataStore:: indexedDBDatabaseDirectory() |
93 | { |
94 | return m_websiteDataStore->configuration().indexedDBDatabaseDirectory(); |
95 | } |
96 | |
97 | bool WebsiteDataStore::isPersistent() |
98 | { |
99 | return m_websiteDataStore->isPersistent(); |
100 | } |
101 | |
102 | bool WebsiteDataStore::resourceLoadStatisticsEnabled() const |
103 | { |
104 | return m_websiteDataStore->resourceLoadStatisticsEnabled(); |
105 | } |
106 | |
107 | void WebsiteDataStore::setResourceLoadStatisticsEnabled(bool enabled) |
108 | { |
109 | m_websiteDataStore->setResourceLoadStatisticsEnabled(enabled); |
110 | } |
111 | |
112 | bool WebsiteDataStore::resourceLoadStatisticsDebugMode() const |
113 | { |
114 | return m_websiteDataStore->resourceLoadStatisticsDebugMode(); |
115 | } |
116 | |
117 | void WebsiteDataStore::setResourceLoadStatisticsDebugMode(bool enabled) |
118 | { |
119 | m_websiteDataStore->setResourceLoadStatisticsDebugMode(enabled); |
120 | } |
121 | |
122 | #if !PLATFORM(COCOA) |
123 | WTF::String WebsiteDataStore::defaultMediaCacheDirectory() |
124 | { |
125 | // FIXME: Implement. https://bugs.webkit.org/show_bug.cgi?id=156369 and https://bugs.webkit.org/show_bug.cgi?id=156370 |
126 | return WTF::String(); |
127 | } |
128 | |
129 | WTF::String WebsiteDataStore::defaultJavaScriptConfigurationDirectory() |
130 | { |
131 | // FIXME: Implement. |
132 | return WTF::String(); |
133 | } |
134 | #endif |
135 | |
136 | #if !USE(GLIB) |
137 | WTF::String WebsiteDataStore::defaultDeviceIdHashSaltsStorageDirectory() |
138 | { |
139 | // Not implemented. |
140 | return WTF::String(); |
141 | } |
142 | #endif |
143 | |
144 | Ref<WebKit::WebsiteDataStoreConfiguration> WebsiteDataStore::defaultDataStoreConfiguration() |
145 | { |
146 | auto configuration = WebKit::WebsiteDataStoreConfiguration::create(); |
147 | |
148 | configuration->setPersistent(true); |
149 | |
150 | configuration->setApplicationCacheDirectory(defaultApplicationCacheDirectory()); |
151 | configuration->setApplicationCacheFlatFileSubdirectoryName("Files" ); |
152 | configuration->setCacheStorageDirectory(defaultCacheStorageDirectory()); |
153 | configuration->setNetworkCacheDirectory(defaultNetworkCacheDirectory()); |
154 | configuration->setMediaCacheDirectory(defaultMediaCacheDirectory()); |
155 | |
156 | configuration->setIndexedDBDatabaseDirectory(defaultIndexedDBDatabaseDirectory()); |
157 | configuration->setServiceWorkerRegistrationDirectory(defaultServiceWorkerRegistrationDirectory()); |
158 | configuration->setWebSQLDatabaseDirectory(defaultWebSQLDatabaseDirectory()); |
159 | configuration->setLocalStorageDirectory(defaultLocalStorageDirectory()); |
160 | configuration->setMediaKeysStorageDirectory(defaultMediaKeysStorageDirectory()); |
161 | configuration->setResourceLoadStatisticsDirectory(defaultResourceLoadStatisticsDirectory()); |
162 | configuration->setDeviceIdHashSaltsStorageDirectory(defaultDeviceIdHashSaltsStorageDirectory()); |
163 | |
164 | configuration->setJavaScriptConfigurationDirectory(defaultJavaScriptConfigurationDirectory()); |
165 | |
166 | return configuration; |
167 | } |
168 | |
169 | Ref<WebKit::WebsiteDataStoreConfiguration> WebsiteDataStore::legacyDefaultDataStoreConfiguration() |
170 | { |
171 | auto configuration = defaultDataStoreConfiguration(); |
172 | |
173 | configuration->setApplicationCacheDirectory(legacyDefaultApplicationCacheDirectory()); |
174 | configuration->setApplicationCacheFlatFileSubdirectoryName("ApplicationCache" ); |
175 | configuration->setNetworkCacheDirectory(legacyDefaultNetworkCacheDirectory()); |
176 | configuration->setMediaCacheDirectory(legacyDefaultMediaCacheDirectory()); |
177 | configuration->setMediaKeysStorageDirectory(legacyDefaultMediaKeysStorageDirectory()); |
178 | configuration->setDeviceIdHashSaltsStorageDirectory(legacyDefaultDeviceIdHashSaltsStorageDirectory()); |
179 | configuration->setIndexedDBDatabaseDirectory(legacyDefaultIndexedDBDatabaseDirectory()); |
180 | configuration->setWebSQLDatabaseDirectory(legacyDefaultWebSQLDatabaseDirectory()); |
181 | configuration->setLocalStorageDirectory(legacyDefaultLocalStorageDirectory()); |
182 | configuration->setJavaScriptConfigurationDirectory(legacyDefaultJavaScriptConfigurationDirectory()); |
183 | |
184 | return configuration; |
185 | } |
186 | |
187 | } // namespace API |
188 | |