1 /*
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
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.
24  *
25  */
26 #include "config.h"
27 #include "SchemeRegistry.h"
28 
29 namespace WebCore {
30 
localURLSchemes()31 static URLSchemesMap& localURLSchemes()
32 {
33     DEFINE_STATIC_LOCAL(URLSchemesMap, localSchemes, ());
34 
35     if (localSchemes.isEmpty()) {
36         localSchemes.add("file");
37 #if PLATFORM(MAC)
38         localSchemes.add("applewebdata");
39 #endif
40 #if PLATFORM(QT)
41         localSchemes.add("qrc");
42 #endif
43     }
44 
45     return localSchemes;
46 }
47 
displayIsolatedURLSchemes()48 static URLSchemesMap& displayIsolatedURLSchemes()
49 {
50     DEFINE_STATIC_LOCAL(URLSchemesMap, displayIsolatedSchemes, ());
51     return displayIsolatedSchemes;
52 }
53 
secureSchemes()54 static URLSchemesMap& secureSchemes()
55 {
56     DEFINE_STATIC_LOCAL(URLSchemesMap, secureSchemes, ());
57 
58     if (secureSchemes.isEmpty()) {
59         secureSchemes.add("https");
60         secureSchemes.add("about");
61         secureSchemes.add("data");
62     }
63 
64     return secureSchemes;
65 }
66 
schemesWithUniqueOrigins()67 static URLSchemesMap& schemesWithUniqueOrigins()
68 {
69     DEFINE_STATIC_LOCAL(URLSchemesMap, schemesWithUniqueOrigins, ());
70 
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");
75 
76     return schemesWithUniqueOrigins;
77 }
78 
emptyDocumentSchemes()79 static URLSchemesMap& emptyDocumentSchemes()
80 {
81     DEFINE_STATIC_LOCAL(URLSchemesMap, emptyDocumentSchemes, ());
82 
83     if (emptyDocumentSchemes.isEmpty())
84         emptyDocumentSchemes.add("about");
85 
86     return emptyDocumentSchemes;
87 }
88 
canDisplayOnlyIfCanRequestSchemes()89 static URLSchemesMap& canDisplayOnlyIfCanRequestSchemes()
90 {
91     DEFINE_STATIC_LOCAL(URLSchemesMap, canDisplayOnlyIfCanRequestSchemes, ());
92 
93 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
94     if (canDisplayOnlyIfCanRequestSchemes.isEmpty()) {
95 #if ENABLE(BLOB)
96         canDisplayOnlyIfCanRequestSchemes.add("blob");
97 #endif
98 #if ENABLE(FILE_SYSTEM)
99         canDisplayOnlyIfCanRequestSchemes.add("filesystem");
100 #endif
101     }
102 #endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
103 
104     return canDisplayOnlyIfCanRequestSchemes;
105 }
106 
registerURLSchemeAsLocal(const String & scheme)107 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme)
108 {
109     localURLSchemes().add(scheme);
110 }
111 
removeURLSchemeRegisteredAsLocal(const String & scheme)112 void SchemeRegistry::removeURLSchemeRegisteredAsLocal(const String& scheme)
113 {
114     if (scheme == "file")
115         return;
116 #if PLATFORM(MAC)
117     if (scheme == "applewebdata")
118         return;
119 #endif
120     localURLSchemes().remove(scheme);
121 }
122 
localSchemes()123 const URLSchemesMap& SchemeRegistry::localSchemes()
124 {
125     return localURLSchemes();
126 }
127 
shouldTreatURLSchemeAsLocal(const String & scheme)128 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme)
129 {
130     if (scheme.isEmpty())
131         return false;
132     return localURLSchemes().contains(scheme);
133 }
134 
registerURLSchemeAsNoAccess(const String & scheme)135 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme)
136 {
137     schemesWithUniqueOrigins().add(scheme);
138 }
139 
shouldTreatURLSchemeAsNoAccess(const String & scheme)140 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme)
141 {
142     if (scheme.isEmpty())
143         return false;
144     return schemesWithUniqueOrigins().contains(scheme);
145 }
146 
registerURLSchemeAsDisplayIsolated(const String & scheme)147 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme)
148 {
149     displayIsolatedURLSchemes().add(scheme);
150 }
151 
shouldTreatURLSchemeAsDisplayIsolated(const String & scheme)152 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(const String& scheme)
153 {
154     if (scheme.isEmpty())
155         return false;
156     return displayIsolatedURLSchemes().contains(scheme);
157 }
158 
registerURLSchemeAsSecure(const String & scheme)159 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme)
160 {
161     secureSchemes().add(scheme);
162 }
163 
shouldTreatURLSchemeAsSecure(const String & scheme)164 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme)
165 {
166     if (scheme.isEmpty())
167         return false;
168     return secureSchemes().contains(scheme);
169 }
170 
registerURLSchemeAsEmptyDocument(const String & scheme)171 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme)
172 {
173     emptyDocumentSchemes().add(scheme);
174 }
175 
shouldLoadURLSchemeAsEmptyDocument(const String & scheme)176 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme)
177 {
178     if (scheme.isEmpty())
179         return false;
180     return emptyDocumentSchemes().contains(scheme);
181 }
182 
canDisplayOnlyIfCanRequest(const String & scheme)183 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme)
184 {
185     if (scheme.isEmpty())
186         return false;
187     return canDisplayOnlyIfCanRequestSchemes().contains(scheme);
188 }
189 
registerAsCanDisplayOnlyIfCanRequest(const String & scheme)190 void SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(const String& scheme)
191 {
192     canDisplayOnlyIfCanRequestSchemes().add(scheme);
193 }
194 
195 } // namespace WebCore
196