1 | /*
|
---|
2 | * Copyright (C) 2010-2022 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 "WebPreferences.h"
|
---|
28 |
|
---|
29 | #include "WebPageGroup.h"
|
---|
30 | #include "WebPageProxy.h"
|
---|
31 | #include "WebPreferencesKeys.h"
|
---|
32 | #include "WebProcessPool.h"
|
---|
33 | #include <WebCore/LibWebRTCProvider.h>
|
---|
34 | #include <wtf/NeverDestroyed.h>
|
---|
35 | #include <wtf/ThreadingPrimitives.h>
|
---|
36 |
|
---|
37 | #if !PLATFORM(COCOA)
|
---|
38 | #include <WebCore/NotImplemented.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | namespace WebKit {
|
---|
42 |
|
---|
43 | Ref<WebPreferences> WebPreferences::create(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix)
|
---|
44 | {
|
---|
45 | return adoptRef(*new WebPreferences(identifier, keyPrefix, globalDebugKeyPrefix));
|
---|
46 | }
|
---|
47 |
|
---|
48 | Ref<WebPreferences> WebPreferences::createWithLegacyDefaults(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix)
|
---|
49 | {
|
---|
50 | auto preferences = WebPreferences::create(identifier, keyPrefix, globalDebugKeyPrefix);
|
---|
51 | // FIXME: The registerDefault...ValueForKey machinery is unnecessarily heavyweight and complicated.
|
---|
52 | // We can just compute different defaults for modern and legacy APIs in WebPreferencesDefinitions.h macros.
|
---|
53 | preferences->registerDefaultBoolValueForKey(WebPreferencesKey::pluginsEnabledKey(), true);
|
---|
54 | preferences->registerDefaultUInt32ValueForKey(WebPreferencesKey::storageBlockingPolicyKey(), static_cast<uint32_t>(WebCore::StorageBlockingPolicy::AllowAll));
|
---|
55 | return preferences;
|
---|
56 | }
|
---|
57 |
|
---|
58 | WebPreferences::WebPreferences(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix)
|
---|
59 | : m_identifier(identifier)
|
---|
60 | , m_keyPrefix(keyPrefix)
|
---|
61 | , m_globalDebugKeyPrefix(globalDebugKeyPrefix)
|
---|
62 | {
|
---|
63 | platformInitializeStore();
|
---|
64 | }
|
---|
65 |
|
---|
66 | WebPreferences::WebPreferences(const WebPreferences& other)
|
---|
67 | : m_identifier()
|
---|
68 | , m_keyPrefix(other.m_keyPrefix)
|
---|
69 | , m_globalDebugKeyPrefix(other.m_globalDebugKeyPrefix)
|
---|
70 | , m_store(other.m_store)
|
---|
71 | {
|
---|
72 | platformInitializeStore();
|
---|
73 | }
|
---|
74 |
|
---|
75 | WebPreferences::~WebPreferences()
|
---|
76 | {
|
---|
77 | ASSERT(m_pages.computesEmpty());
|
---|
78 | }
|
---|
79 |
|
---|
80 | Ref<WebPreferences> WebPreferences::copy() const
|
---|
81 | {
|
---|
82 | return adoptRef(*new WebPreferences(*this));
|
---|
83 | }
|
---|
84 |
|
---|
85 | void WebPreferences::addPage(WebPageProxy& webPageProxy)
|
---|
86 | {
|
---|
87 | ASSERT(!m_pages.contains(webPageProxy));
|
---|
88 | m_pages.add(webPageProxy);
|
---|
89 | }
|
---|
90 |
|
---|
91 | void WebPreferences::removePage(WebPageProxy& webPageProxy)
|
---|
92 | {
|
---|
93 | ASSERT(m_pages.contains(webPageProxy));
|
---|
94 | m_pages.remove(webPageProxy);
|
---|
95 | }
|
---|
96 |
|
---|
97 | void WebPreferences::update()
|
---|
98 | {
|
---|
99 | if (m_updateBatchCount) {
|
---|
100 | m_needUpdateAfterBatch = true;
|
---|
101 | return;
|
---|
102 | }
|
---|
103 |
|
---|
104 | for (auto& webPageProxy : m_pages)
|
---|
105 | webPageProxy.preferencesDidChange();
|
---|
106 | }
|
---|
107 |
|
---|
108 | void WebPreferences::startBatchingUpdates()
|
---|
109 | {
|
---|
110 | if (!m_updateBatchCount)
|
---|
111 | m_needUpdateAfterBatch = false;
|
---|
112 |
|
---|
113 | ++m_updateBatchCount;
|
---|
114 | }
|
---|
115 |
|
---|
116 | void WebPreferences::endBatchingUpdates()
|
---|
117 | {
|
---|
118 | ASSERT(m_updateBatchCount > 0);
|
---|
119 | --m_updateBatchCount;
|
---|
120 | if (!m_updateBatchCount && m_needUpdateAfterBatch)
|
---|
121 | update();
|
---|
122 | }
|
---|
123 |
|
---|
124 | void WebPreferences::setBoolValueForKey(const String& key, bool value)
|
---|
125 | {
|
---|
126 | if (!m_store.setBoolValueForKey(key, value))
|
---|
127 | return;
|
---|
128 | updateBoolValueForKey(key, value);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void WebPreferences::setDoubleValueForKey(const String& key, double value)
|
---|
132 | {
|
---|
133 | if (!m_store.setDoubleValueForKey(key, value))
|
---|
134 | return;
|
---|
135 | updateDoubleValueForKey(key, value);
|
---|
136 | }
|
---|
137 |
|
---|
138 | void WebPreferences::setUInt32ValueForKey(const String& key, uint32_t value)
|
---|
139 | {
|
---|
140 | if (!m_store.setUInt32ValueForKey(key, value))
|
---|
141 | return;
|
---|
142 | updateUInt32ValueForKey(key, value);
|
---|
143 | }
|
---|
144 |
|
---|
145 | void WebPreferences::setStringValueForKey(const String& key, const String& value)
|
---|
146 | {
|
---|
147 | if (!m_store.setStringValueForKey(key, value))
|
---|
148 | return;
|
---|
149 | updateStringValueForKey(key, value);
|
---|
150 | }
|
---|
151 |
|
---|
152 | void WebPreferences::updateStringValueForKey(const String& key, const String& value)
|
---|
153 | {
|
---|
154 | platformUpdateStringValueForKey(key, value);
|
---|
155 | update(); // FIXME: Only send over the changed key and value.
|
---|
156 | }
|
---|
157 |
|
---|
158 | void WebPreferences::updateBoolValueForKey(const String& key, bool value)
|
---|
159 | {
|
---|
160 | platformUpdateBoolValueForKey(key, value);
|
---|
161 | update(); // FIXME: Only send over the changed key and value.
|
---|
162 | }
|
---|
163 |
|
---|
164 | void WebPreferences::updateBoolValueForInternalDebugFeatureKey(const String& key, bool value)
|
---|
165 | {
|
---|
166 | if (key == WebPreferencesKey::processSwapOnCrossSiteNavigationEnabledKey()) {
|
---|
167 | for (auto& page : m_pages)
|
---|
168 | page.process().processPool().configuration().setProcessSwapsOnNavigation(value);
|
---|
169 |
|
---|
170 | return;
|
---|
171 | }
|
---|
172 | update(); // FIXME: Only send over the changed key and value.
|
---|
173 | }
|
---|
174 |
|
---|
175 | void WebPreferences::updateBoolValueForExperimentalFeatureKey(const String& key, bool value)
|
---|
176 | {
|
---|
177 | update(); // FIXME: Only send over the changed key and value.
|
---|
178 | }
|
---|
179 |
|
---|
180 | void WebPreferences::updateUInt32ValueForKey(const String& key, uint32_t value)
|
---|
181 | {
|
---|
182 | platformUpdateUInt32ValueForKey(key, value);
|
---|
183 | update(); // FIXME: Only send over the changed key and value.
|
---|
184 | }
|
---|
185 |
|
---|
186 | void WebPreferences::updateDoubleValueForKey(const String& key, double value)
|
---|
187 | {
|
---|
188 | platformUpdateDoubleValueForKey(key, value);
|
---|
189 | update(); // FIXME: Only send over the changed key and value.
|
---|
190 | }
|
---|
191 |
|
---|
192 | void WebPreferences::updateFloatValueForKey(const String& key, float value)
|
---|
193 | {
|
---|
194 | platformUpdateFloatValueForKey(key, value);
|
---|
195 | update(); // FIXME: Only send over the changed key and value.
|
---|
196 | }
|
---|
197 |
|
---|
198 | void WebPreferences::deleteKey(const String& key)
|
---|
199 | {
|
---|
200 | m_store.deleteKey(key);
|
---|
201 | platformDeleteKey(key);
|
---|
202 | update(); // FIXME: Only send over the changed key and value.
|
---|
203 | }
|
---|
204 |
|
---|
205 | void WebPreferences::registerDefaultBoolValueForKey(const String& key, bool value)
|
---|
206 | {
|
---|
207 | m_store.setOverrideDefaultsBoolValueForKey(key, value);
|
---|
208 | bool userValue;
|
---|
209 | if (platformGetBoolUserValueForKey(key, userValue))
|
---|
210 | m_store.setBoolValueForKey(key, userValue);
|
---|
211 | }
|
---|
212 |
|
---|
213 | void WebPreferences::registerDefaultUInt32ValueForKey(const String& key, uint32_t value)
|
---|
214 | {
|
---|
215 | m_store.setOverrideDefaultsUInt32ValueForKey(key, value);
|
---|
216 | uint32_t userValue;
|
---|
217 | if (platformGetUInt32UserValueForKey(key, userValue))
|
---|
218 | m_store.setUInt32ValueForKey(key, userValue);
|
---|
219 | }
|
---|
220 |
|
---|
221 | #if !PLATFORM(COCOA) && !PLATFORM(GTK)
|
---|
222 | void WebPreferences::platformInitializeStore()
|
---|
223 | {
|
---|
224 | notImplemented();
|
---|
225 | }
|
---|
226 | #endif
|
---|
227 |
|
---|
228 | #if !PLATFORM(COCOA)
|
---|
229 | void WebPreferences::platformUpdateStringValueForKey(const String&, const String&)
|
---|
230 | {
|
---|
231 | notImplemented();
|
---|
232 | }
|
---|
233 |
|
---|
234 | void WebPreferences::platformUpdateBoolValueForKey(const String&, bool)
|
---|
235 | {
|
---|
236 | notImplemented();
|
---|
237 | }
|
---|
238 |
|
---|
239 | void WebPreferences::platformUpdateUInt32ValueForKey(const String&, uint32_t)
|
---|
240 | {
|
---|
241 | notImplemented();
|
---|
242 | }
|
---|
243 |
|
---|
244 | void WebPreferences::platformUpdateDoubleValueForKey(const String&, double)
|
---|
245 | {
|
---|
246 | notImplemented();
|
---|
247 | }
|
---|
248 |
|
---|
249 | void WebPreferences::platformUpdateFloatValueForKey(const String&, float)
|
---|
250 | {
|
---|
251 | notImplemented();
|
---|
252 | }
|
---|
253 |
|
---|
254 | void WebPreferences::platformDeleteKey(const String&)
|
---|
255 | {
|
---|
256 | notImplemented();
|
---|
257 | }
|
---|
258 |
|
---|
259 | bool WebPreferences::platformGetStringUserValueForKey(const String&, String&)
|
---|
260 | {
|
---|
261 | notImplemented();
|
---|
262 | return false;
|
---|
263 | }
|
---|
264 |
|
---|
265 | bool WebPreferences::platformGetBoolUserValueForKey(const String&, bool&)
|
---|
266 | {
|
---|
267 | notImplemented();
|
---|
268 | return false;
|
---|
269 | }
|
---|
270 |
|
---|
271 | bool WebPreferences::platformGetUInt32UserValueForKey(const String&, uint32_t&)
|
---|
272 | {
|
---|
273 | notImplemented();
|
---|
274 | return false;
|
---|
275 | }
|
---|
276 |
|
---|
277 | bool WebPreferences::platformGetDoubleUserValueForKey(const String&, double&)
|
---|
278 | {
|
---|
279 | notImplemented();
|
---|
280 | return false;
|
---|
281 | }
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | } // namespace WebKit
|
---|