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 // This is a willful violation of HTML5.
72 // See https://bugs.webkit.org/show_bug.cgi?id=11885
73 if (schemesWithUniqueOrigins.isEmpty())
74 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 URLSchemesMap& canDisplayOnlyIfCanRequestSchemes()
91 DEFINE_STATIC_LOCAL(URLSchemesMap, canDisplayOnlyIfCanRequestSchemes, ());
93 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
94 if (canDisplayOnlyIfCanRequestSchemes.isEmpty()) {
96 canDisplayOnlyIfCanRequestSchemes.add("blob");
98 #if ENABLE(FILE_SYSTEM)
99 canDisplayOnlyIfCanRequestSchemes.add("filesystem");
102 #endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
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")
123 if (scheme == "applewebdata")
126 localURLSchemes().remove(scheme);
129 const URLSchemesMap& SchemeRegistry::localSchemes()
131 return localURLSchemes();
134 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme)
136 if (scheme.isEmpty())
138 return localURLSchemes().contains(scheme);
141 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme)
143 schemesWithUniqueOrigins().add(scheme);
146 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme)
148 if (scheme.isEmpty())
150 return schemesWithUniqueOrigins().contains(scheme);
153 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme)
155 displayIsolatedURLSchemes().add(scheme);
158 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(const String& scheme)
160 if (scheme.isEmpty())
162 return displayIsolatedURLSchemes().contains(scheme);
165 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme)
167 secureSchemes().add(scheme);
170 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme)
172 if (scheme.isEmpty())
174 return secureSchemes().contains(scheme);
177 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme)
179 emptyDocumentSchemes().add(scheme);
182 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme)
184 if (scheme.isEmpty())
186 return emptyDocumentSchemes().contains(scheme);
189 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme)
191 if (scheme.isEmpty())
193 return canDisplayOnlyIfCanRequestSchemes().contains(scheme);
196 void SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(const String& scheme)
198 canDisplayOnlyIfCanRequestSchemes().add(scheme);
201 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
203 notAllowingJavascriptURLsSchemes().add(scheme);
206 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
208 if (scheme.isEmpty())
210 return notAllowingJavascriptURLsSchemes().contains(scheme);
213 } // namespace WebCore