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.
27 #include "SchemeRegistry.h"
31 static URLSchemesMap& localURLSchemes()
33 DEFINE_STATIC_LOCAL(URLSchemesMap, localSchemes, ());
35 if (localSchemes.isEmpty()) {
36 localSchemes.add("file");
38 localSchemes.add("applewebdata");
41 localSchemes.add("qrc");
48 static URLSchemesMap& displayIsolatedURLSchemes()
50 DEFINE_STATIC_LOCAL(URLSchemesMap, displayIsolatedSchemes, ());
51 return displayIsolatedSchemes;
54 static URLSchemesMap& secureSchemes()
56 DEFINE_STATIC_LOCAL(URLSchemesMap, secureSchemes, ());
58 if (secureSchemes.isEmpty()) {
59 secureSchemes.add("https");
60 secureSchemes.add("about");
61 secureSchemes.add("data");
67 static URLSchemesMap& schemesWithUniqueOrigins()
69 DEFINE_STATIC_LOCAL(URLSchemesMap, schemesWithUniqueOrigins, ());
71 if (schemesWithUniqueOrigins.isEmpty()) {
72 schemesWithUniqueOrigins.add("about");
73 schemesWithUniqueOrigins.add("javascript");
74 // This is a willful violation of HTML5.
75 // See https://bugs.webkit.org/show_bug.cgi?id=11885
76 schemesWithUniqueOrigins.add("data");
79 return schemesWithUniqueOrigins;
82 static URLSchemesMap& emptyDocumentSchemes()
84 DEFINE_STATIC_LOCAL(URLSchemesMap, emptyDocumentSchemes, ());
86 if (emptyDocumentSchemes.isEmpty())
87 emptyDocumentSchemes.add("about");
89 return emptyDocumentSchemes;
92 static HashSet<String>& schemesForbiddenFromDomainRelaxation()
94 DEFINE_STATIC_LOCAL(HashSet<String>, schemes, ());
98 static URLSchemesMap& canDisplayOnlyIfCanRequestSchemes()
100 DEFINE_STATIC_LOCAL(URLSchemesMap, canDisplayOnlyIfCanRequestSchemes, ());
102 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
103 if (canDisplayOnlyIfCanRequestSchemes.isEmpty()) {
105 canDisplayOnlyIfCanRequestSchemes.add("blob");
107 #if ENABLE(FILE_SYSTEM)
108 canDisplayOnlyIfCanRequestSchemes.add("filesystem");
111 #endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
113 return canDisplayOnlyIfCanRequestSchemes;
116 static URLSchemesMap& notAllowingJavascriptURLsSchemes()
118 DEFINE_STATIC_LOCAL(URLSchemesMap, notAllowingJavascriptURLsSchemes, ());
119 return notAllowingJavascriptURLsSchemes;
122 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme)
124 localURLSchemes().add(scheme);
127 void SchemeRegistry::removeURLSchemeRegisteredAsLocal(const String& scheme)
129 if (scheme == "file")
132 if (scheme == "applewebdata")
135 localURLSchemes().remove(scheme);
138 const URLSchemesMap& SchemeRegistry::localSchemes()
140 return localURLSchemes();
143 static URLSchemesMap& schemesAllowingLocalStorageAccessInPrivateBrowsing()
145 DEFINE_STATIC_LOCAL(URLSchemesMap, schemesAllowingLocalStorageAccessInPrivateBrowsing, ());
146 return schemesAllowingLocalStorageAccessInPrivateBrowsing;
149 static URLSchemesMap& schemesAllowingDatabaseAccessInPrivateBrowsing()
151 DEFINE_STATIC_LOCAL(URLSchemesMap, schemesAllowingDatabaseAccessInPrivateBrowsing, ());
152 return schemesAllowingDatabaseAccessInPrivateBrowsing;
155 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme)
157 if (scheme.isEmpty())
159 return localURLSchemes().contains(scheme);
162 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme)
164 schemesWithUniqueOrigins().add(scheme);
167 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme)
169 if (scheme.isEmpty())
171 return schemesWithUniqueOrigins().contains(scheme);
174 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme)
176 displayIsolatedURLSchemes().add(scheme);
179 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(const String& scheme)
181 if (scheme.isEmpty())
183 return displayIsolatedURLSchemes().contains(scheme);
186 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme)
188 secureSchemes().add(scheme);
191 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme)
193 if (scheme.isEmpty())
195 return secureSchemes().contains(scheme);
198 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme)
200 emptyDocumentSchemes().add(scheme);
203 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme)
205 if (scheme.isEmpty())
207 return emptyDocumentSchemes().contains(scheme);
210 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const String& scheme)
212 if (scheme.isEmpty())
216 schemesForbiddenFromDomainRelaxation().add(scheme);
218 schemesForbiddenFromDomainRelaxation().remove(scheme);
221 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(const String& scheme)
223 if (scheme.isEmpty())
225 return schemesForbiddenFromDomainRelaxation().contains(scheme);
228 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme)
230 if (scheme.isEmpty())
232 return canDisplayOnlyIfCanRequestSchemes().contains(scheme);
235 void SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(const String& scheme)
237 canDisplayOnlyIfCanRequestSchemes().add(scheme);
240 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
242 notAllowingJavascriptURLsSchemes().add(scheme);
245 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
247 if (scheme.isEmpty())
249 return notAllowingJavascriptURLsSchemes().contains(scheme);
252 void SchemeRegistry::registerURLSchemeAsAllowingLocalStorageAccessInPrivateBrowsing(const String& scheme)
254 schemesAllowingLocalStorageAccessInPrivateBrowsing().add(scheme);
257 bool SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(const String& scheme)
259 if (scheme.isEmpty())
261 return schemesAllowingLocalStorageAccessInPrivateBrowsing().contains(scheme);
264 void SchemeRegistry::registerURLSchemeAsAllowingDatabaseAccessInPrivateBrowsing(const String& scheme)
266 schemesAllowingDatabaseAccessInPrivateBrowsing().add(scheme);
269 bool SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(const String& scheme)
271 if (scheme.isEmpty())
273 return schemesAllowingDatabaseAccessInPrivateBrowsing().contains(scheme);
276 } // namespace WebCore