2 * Copyright (C) 2010 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * 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
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "platform/weborigin/SchemeRegistry.h"
30 #include "wtf/MainThread.h"
34 static URLSchemesMap& localURLSchemes()
36 DEFINE_STATIC_LOCAL(URLSchemesMap, localSchemes, ());
38 if (localSchemes.isEmpty())
39 localSchemes.add("file");
44 static URLSchemesMap& displayIsolatedURLSchemes()
46 DEFINE_STATIC_LOCAL(URLSchemesMap, displayIsolatedSchemes, ());
47 return displayIsolatedSchemes;
50 static URLSchemesMap& secureSchemes()
52 DEFINE_STATIC_LOCAL(URLSchemesMap, secureSchemes, ());
54 if (secureSchemes.isEmpty()) {
55 secureSchemes.add("https");
56 secureSchemes.add("about");
57 secureSchemes.add("data");
58 secureSchemes.add("wss");
64 static URLSchemesMap& schemesWithUniqueOrigins()
66 DEFINE_STATIC_LOCAL(URLSchemesMap, schemesWithUniqueOrigins, ());
68 if (schemesWithUniqueOrigins.isEmpty()) {
69 schemesWithUniqueOrigins.add("about");
70 schemesWithUniqueOrigins.add("javascript");
71 // This is a willful violation of HTML5.
72 // See https://bugs.webkit.org/show_bug.cgi?id=11885
73 schemesWithUniqueOrigins.add("data");
76 return schemesWithUniqueOrigins;
79 static URLSchemesMap& emptyDocumentSchemes()
81 DEFINE_STATIC_LOCAL(URLSchemesMap, emptyDocumentSchemes, ());
83 if (emptyDocumentSchemes.isEmpty())
84 emptyDocumentSchemes.add("about");
86 return emptyDocumentSchemes;
89 static HashSet<String>& schemesForbiddenFromDomainRelaxation()
91 DEFINE_STATIC_LOCAL(HashSet<String>, schemes, ());
95 static URLSchemesMap& canDisplayOnlyIfCanRequestSchemes()
97 DEFINE_STATIC_LOCAL(URLSchemesMap, canDisplayOnlyIfCanRequestSchemes, ());
99 if (canDisplayOnlyIfCanRequestSchemes.isEmpty()) {
100 canDisplayOnlyIfCanRequestSchemes.add("blob");
101 canDisplayOnlyIfCanRequestSchemes.add("filesystem");
104 return canDisplayOnlyIfCanRequestSchemes;
107 static URLSchemesMap& notAllowingJavascriptURLsSchemes()
109 DEFINE_STATIC_LOCAL(URLSchemesMap, notAllowingJavascriptURLsSchemes, ());
110 return notAllowingJavascriptURLsSchemes;
113 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme)
115 localURLSchemes().add(scheme);
118 void SchemeRegistry::removeURLSchemeRegisteredAsLocal(const String& scheme)
120 if (scheme == "file")
122 localURLSchemes().remove(scheme);
125 const URLSchemesMap& SchemeRegistry::localSchemes()
127 return localURLSchemes();
130 static URLSchemesMap& CORSEnabledSchemes()
132 // FIXME: http://bugs.webkit.org/show_bug.cgi?id=77160
133 DEFINE_STATIC_LOCAL(URLSchemesMap, CORSEnabledSchemes, ());
135 if (CORSEnabledSchemes.isEmpty()) {
136 CORSEnabledSchemes.add("http");
137 CORSEnabledSchemes.add("https");
140 return CORSEnabledSchemes;
143 static URLSchemesMap& ContentSecurityPolicyBypassingSchemes()
145 DEFINE_STATIC_LOCAL(URLSchemesMap, schemes, ());
149 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme)
151 if (scheme.isEmpty())
153 return localURLSchemes().contains(scheme);
156 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme)
158 schemesWithUniqueOrigins().add(scheme);
161 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme)
163 if (scheme.isEmpty())
165 return schemesWithUniqueOrigins().contains(scheme);
168 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme)
170 displayIsolatedURLSchemes().add(scheme);
173 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(const String& scheme)
175 if (scheme.isEmpty())
177 return displayIsolatedURLSchemes().contains(scheme);
180 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme)
182 secureSchemes().add(scheme);
185 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme)
187 if (scheme.isEmpty())
189 return secureSchemes().contains(scheme);
192 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme)
194 emptyDocumentSchemes().add(scheme);
197 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme)
199 if (scheme.isEmpty())
201 return emptyDocumentSchemes().contains(scheme);
204 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const String& scheme)
206 if (scheme.isEmpty())
210 schemesForbiddenFromDomainRelaxation().add(scheme);
212 schemesForbiddenFromDomainRelaxation().remove(scheme);
215 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(const String& scheme)
217 if (scheme.isEmpty())
219 return schemesForbiddenFromDomainRelaxation().contains(scheme);
222 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme)
224 if (scheme.isEmpty())
226 return canDisplayOnlyIfCanRequestSchemes().contains(scheme);
229 void SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(const String& scheme)
231 canDisplayOnlyIfCanRequestSchemes().add(scheme);
234 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
236 notAllowingJavascriptURLsSchemes().add(scheme);
239 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
241 if (scheme.isEmpty())
243 return notAllowingJavascriptURLsSchemes().contains(scheme);
246 void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme)
248 CORSEnabledSchemes().add(scheme);
251 bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme)
253 if (scheme.isEmpty())
255 return CORSEnabledSchemes().contains(scheme);
258 void SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
260 ContentSecurityPolicyBypassingSchemes().add(scheme);
263 void SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
265 ContentSecurityPolicyBypassingSchemes().remove(scheme);
268 bool SchemeRegistry::schemeShouldBypassContentSecurityPolicy(const String& scheme)
270 if (scheme.isEmpty())
272 return ContentSecurityPolicyBypassingSchemes().contains(scheme);
275 } // namespace WebCore