blob: 9ed90909d57434d015cb2008d5781c4d140b1986 [file] [log] [blame]
beidson@apple.comc7fe45f2010-07-21 23:19:55 +00001/*
2 * Copyright (C) 2010 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. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mjs@apple.com92047332014-03-15 04:08:27 +000016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000017 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
commit-queue@webkit.org8bdba9b2012-03-09 00:41:22 +000023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000024 *
25 */
26#include "config.h"
27#include "SchemeRegistry.h"
cdn@chromium.org76966522012-01-26 23:50:31 +000028#include <wtf/MainThread.h>
jpfau@apple.com39bf85f2014-01-30 23:02:39 +000029#include <wtf/NeverDestroyed.h>
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000030
abarth@webkit.org617ecad2012-01-06 00:39:16 +000031namespace WebCore {
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000032
33static URLSchemesMap& localURLSchemes()
34{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +000035 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, localSchemes, ());
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000036
37 if (localSchemes.isEmpty()) {
38 localSchemes.add("file");
mitz@apple.com1a8d7d32014-02-07 23:37:54 +000039#if PLATFORM(COCOA)
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000040 localSchemes.add("applewebdata");
41#endif
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000042 }
43
44 return localSchemes;
45}
46
abarth@webkit.orgc655f682011-01-11 01:02:01 +000047static URLSchemesMap& displayIsolatedURLSchemes()
48{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +000049 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, displayIsolatedSchemes, ());
abarth@webkit.orgc655f682011-01-11 01:02:01 +000050 return displayIsolatedSchemes;
51}
52
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000053static URLSchemesMap& secureSchemes()
54{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +000055 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, secureSchemes, ());
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000056
57 if (secureSchemes.isEmpty()) {
58 secureSchemes.add("https");
59 secureSchemes.add("about");
60 secureSchemes.add("data");
61 }
62
63 return secureSchemes;
64}
65
66static URLSchemesMap& schemesWithUniqueOrigins()
67{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +000068 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, schemesWithUniqueOrigins, ());
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000069
abarth@webkit.orge8643232011-11-17 21:34:36 +000070 if (schemesWithUniqueOrigins.isEmpty()) {
71 schemesWithUniqueOrigins.add("about");
72 schemesWithUniqueOrigins.add("javascript");
73 // This is a willful violation of HTML5.
74 // See https://bugs.webkit.org/show_bug.cgi?id=11885
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000075 schemesWithUniqueOrigins.add("data");
abarth@webkit.orge8643232011-11-17 21:34:36 +000076 }
beidson@apple.comc7fe45f2010-07-21 23:19:55 +000077
78 return schemesWithUniqueOrigins;
79}
80
beidson@apple.com5c1fdf12010-07-26 20:37:56 +000081static URLSchemesMap& emptyDocumentSchemes()
82{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +000083 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, emptyDocumentSchemes, ());
beidson@apple.com5c1fdf12010-07-26 20:37:56 +000084
85 if (emptyDocumentSchemes.isEmpty())
86 emptyDocumentSchemes.add("about");
87
88 return emptyDocumentSchemes;
89}
90
abarth@webkit.org8e056b02011-11-08 01:37:47 +000091static HashSet<String>& schemesForbiddenFromDomainRelaxation()
92{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +000093 DEPRECATED_DEFINE_STATIC_LOCAL(HashSet<String>, schemes, ());
abarth@webkit.org8e056b02011-11-08 01:37:47 +000094 return schemes;
95}
96
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +000097static URLSchemesMap& canDisplayOnlyIfCanRequestSchemes()
98{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +000099 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, canDisplayOnlyIfCanRequestSchemes, ());
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +0000100
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +0000101#if ENABLE(BLOB)
commit-queue@webkit.org8bdba9b2012-03-09 00:41:22 +0000102 if (canDisplayOnlyIfCanRequestSchemes.isEmpty()) {
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +0000103 canDisplayOnlyIfCanRequestSchemes.add("blob");
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +0000104 }
commit-queue@webkit.org8bdba9b2012-03-09 00:41:22 +0000105#endif // ENABLE(BLOB)
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +0000106
107 return canDisplayOnlyIfCanRequestSchemes;
108}
109
commit-queue@webkit.org54a0b042011-08-24 21:06:43 +0000110static URLSchemesMap& notAllowingJavascriptURLsSchemes()
111{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +0000112 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, notAllowingJavascriptURLsSchemes, ());
commit-queue@webkit.org54a0b042011-08-24 21:06:43 +0000113 return notAllowingJavascriptURLsSchemes;
114}
115
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000116void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme)
117{
abarth@webkit.orgc655f682011-01-11 01:02:01 +0000118 localURLSchemes().add(scheme);
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000119}
120
121void SchemeRegistry::removeURLSchemeRegisteredAsLocal(const String& scheme)
122{
123 if (scheme == "file")
124 return;
mitz@apple.com1a8d7d32014-02-07 23:37:54 +0000125#if PLATFORM(COCOA)
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000126 if (scheme == "applewebdata")
127 return;
128#endif
abarth@webkit.orgc655f682011-01-11 01:02:01 +0000129 localURLSchemes().remove(scheme);
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000130}
131
abarth@webkit.orgc655f682011-01-11 01:02:01 +0000132const URLSchemesMap& SchemeRegistry::localSchemes()
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000133{
abarth@webkit.orgc655f682011-01-11 01:02:01 +0000134 return localURLSchemes();
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000135}
136
jberlin@webkit.orgda2af492011-11-07 18:16:33 +0000137static URLSchemesMap& schemesAllowingLocalStorageAccessInPrivateBrowsing()
138{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +0000139 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, schemesAllowingLocalStorageAccessInPrivateBrowsing, ());
jberlin@webkit.orgda2af492011-11-07 18:16:33 +0000140 return schemesAllowingLocalStorageAccessInPrivateBrowsing;
141}
142
143static URLSchemesMap& schemesAllowingDatabaseAccessInPrivateBrowsing()
144{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +0000145 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, schemesAllowingDatabaseAccessInPrivateBrowsing, ());
jberlin@webkit.orgda2af492011-11-07 18:16:33 +0000146 return schemesAllowingDatabaseAccessInPrivateBrowsing;
147}
148
cdn@chromium.org76966522012-01-26 23:50:31 +0000149static URLSchemesMap& CORSEnabledSchemes()
150{
commit-queue@webkit.org8bdba9b2012-03-09 00:41:22 +0000151 // FIXME: http://bugs.webkit.org/show_bug.cgi?id=77160
svillar@igalia.com5b31eef2014-03-14 08:30:55 +0000152 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, CORSEnabledSchemes, ());
cdn@chromium.org76966522012-01-26 23:50:31 +0000153
154 if (CORSEnabledSchemes.isEmpty()) {
155 CORSEnabledSchemes.add("http");
156 CORSEnabledSchemes.add("https");
157 }
158
159 return CORSEnabledSchemes;
160}
161
commit-queue@webkit.org828d2392012-06-19 07:27:33 +0000162static URLSchemesMap& ContentSecurityPolicyBypassingSchemes()
163{
svillar@igalia.com5b31eef2014-03-14 08:30:55 +0000164 DEPRECATED_DEFINE_STATIC_LOCAL(URLSchemesMap, schemes, ());
commit-queue@webkit.org828d2392012-06-19 07:27:33 +0000165 return schemes;
166}
167
jpfau@apple.com39bf85f2014-01-30 23:02:39 +0000168#if ENABLE(CACHE_PARTITIONING)
169static URLSchemesMap& cachePartitioningSchemes()
170{
171 static NeverDestroyed<URLSchemesMap> schemes;
172 return schemes;
173}
174#endif
175
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000176bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme)
177{
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000178 if (scheme.isEmpty())
179 return false;
abarth@webkit.orgc655f682011-01-11 01:02:01 +0000180 return localURLSchemes().contains(scheme);
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000181}
182
183void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme)
184{
185 schemesWithUniqueOrigins().add(scheme);
186}
187
188bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme)
189{
commit-queue@webkit.org051eef42011-02-11 22:03:09 +0000190 if (scheme.isEmpty())
191 return false;
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000192 return schemesWithUniqueOrigins().contains(scheme);
193}
194
abarth@webkit.orgc655f682011-01-11 01:02:01 +0000195void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme)
196{
197 displayIsolatedURLSchemes().add(scheme);
198}
199
200bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(const String& scheme)
201{
abarth@webkit.orgd7652e82011-01-25 21:29:14 +0000202 if (scheme.isEmpty())
203 return false;
abarth@webkit.orgc655f682011-01-11 01:02:01 +0000204 return displayIsolatedURLSchemes().contains(scheme);
205}
206
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000207void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme)
208{
209 secureSchemes().add(scheme);
210}
211
212bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme)
213{
commit-queue@webkit.org051eef42011-02-11 22:03:09 +0000214 if (scheme.isEmpty())
215 return false;
beidson@apple.comc7fe45f2010-07-21 23:19:55 +0000216 return secureSchemes().contains(scheme);
217}
218
beidson@apple.com5c1fdf12010-07-26 20:37:56 +0000219void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme)
220{
221 emptyDocumentSchemes().add(scheme);
222}
223
224bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme)
225{
commit-queue@webkit.org051eef42011-02-11 22:03:09 +0000226 if (scheme.isEmpty())
227 return false;
beidson@apple.com5c1fdf12010-07-26 20:37:56 +0000228 return emptyDocumentSchemes().contains(scheme);
229}
230
abarth@webkit.org8e056b02011-11-08 01:37:47 +0000231void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const String& scheme)
232{
233 if (scheme.isEmpty())
234 return;
235
236 if (forbidden)
237 schemesForbiddenFromDomainRelaxation().add(scheme);
238 else
239 schemesForbiddenFromDomainRelaxation().remove(scheme);
240}
241
242bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(const String& scheme)
243{
244 if (scheme.isEmpty())
245 return false;
246 return schemesForbiddenFromDomainRelaxation().contains(scheme);
247}
248
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +0000249bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme)
250{
251 if (scheme.isEmpty())
252 return false;
253 return canDisplayOnlyIfCanRequestSchemes().contains(scheme);
254}
255
256void SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(const String& scheme)
257{
258 canDisplayOnlyIfCanRequestSchemes().add(scheme);
259}
260
commit-queue@webkit.org8bdba9b2012-03-09 00:41:22 +0000261void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
commit-queue@webkit.org54a0b042011-08-24 21:06:43 +0000262{
263 notAllowingJavascriptURLsSchemes().add(scheme);
264}
265
266bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
267{
268 if (scheme.isEmpty())
269 return false;
270 return notAllowingJavascriptURLsSchemes().contains(scheme);
271}
272
jberlin@webkit.orgda2af492011-11-07 18:16:33 +0000273void SchemeRegistry::registerURLSchemeAsAllowingLocalStorageAccessInPrivateBrowsing(const String& scheme)
274{
275 schemesAllowingLocalStorageAccessInPrivateBrowsing().add(scheme);
276}
277
278bool SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(const String& scheme)
279{
280 if (scheme.isEmpty())
281 return false;
282 return schemesAllowingLocalStorageAccessInPrivateBrowsing().contains(scheme);
283}
284
285void SchemeRegistry::registerURLSchemeAsAllowingDatabaseAccessInPrivateBrowsing(const String& scheme)
286{
287 schemesAllowingDatabaseAccessInPrivateBrowsing().add(scheme);
288}
289
290bool SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(const String& scheme)
291{
292 if (scheme.isEmpty())
293 return false;
294 return schemesAllowingDatabaseAccessInPrivateBrowsing().contains(scheme);
295}
296
cdn@chromium.org76966522012-01-26 23:50:31 +0000297void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme)
298{
299 CORSEnabledSchemes().add(scheme);
300}
301
302bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme)
303{
304 if (scheme.isEmpty())
305 return false;
306 return CORSEnabledSchemes().contains(scheme);
307}
308
commit-queue@webkit.org828d2392012-06-19 07:27:33 +0000309void SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
310{
311 ContentSecurityPolicyBypassingSchemes().add(scheme);
312}
313
314void SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
315{
316 ContentSecurityPolicyBypassingSchemes().remove(scheme);
317}
318
319bool SchemeRegistry::schemeShouldBypassContentSecurityPolicy(const String& scheme)
320{
321 if (scheme.isEmpty())
322 return false;
323 return ContentSecurityPolicyBypassingSchemes().contains(scheme);
324}
325
aestes@apple.comd90a51a2013-05-16 02:54:06 +0000326bool SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely(const String& scheme)
327{
mitz@apple.com1a8d7d32014-02-07 23:37:54 +0000328#if PLATFORM(COCOA)
aestes@apple.comd90a51a2013-05-16 02:54:06 +0000329 if (equalIgnoringCase(scheme, "applewebdata"))
330 return true;
331#endif
aestes@apple.com40add752013-05-16 21:32:31 +0000332 return equalIgnoringCase(scheme, "data");
aestes@apple.comd90a51a2013-05-16 02:54:06 +0000333}
334
jpfau@apple.com39bf85f2014-01-30 23:02:39 +0000335#if ENABLE(CACHE_PARTITIONING)
336void SchemeRegistry::registerURLSchemeAsCachePartitioned(const String& scheme)
337{
338 cachePartitioningSchemes().add(scheme);
339}
340
341bool SchemeRegistry::shouldPartitionCacheForURLScheme(const String& scheme)
342{
343 if (scheme.isEmpty())
344 return false;
345 return cachePartitioningSchemes().contains(scheme);
346}
347#endif
348
abarth@webkit.org617ecad2012-01-06 00:39:16 +0000349} // namespace WebCore