tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / platform / SchemeRegistry.cpp
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
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
48 static URLSchemesMap& displayIsolatedURLSchemes()
49 {
50     DEFINE_STATIC_LOCAL(URLSchemesMap, displayIsolatedSchemes, ());
51     return displayIsolatedSchemes;
52 }
53
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
67 static URLSchemesMap& schemesWithUniqueOrigins()
68 {
69     DEFINE_STATIC_LOCAL(URLSchemesMap, schemesWithUniqueOrigins, ());
70
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");
77     }
78
79     return schemesWithUniqueOrigins;
80 }
81
82 static URLSchemesMap& emptyDocumentSchemes()
83 {
84     DEFINE_STATIC_LOCAL(URLSchemesMap, emptyDocumentSchemes, ());
85
86     if (emptyDocumentSchemes.isEmpty())
87         emptyDocumentSchemes.add("about");
88
89     return emptyDocumentSchemes;
90 }
91
92 static HashSet<String>& schemesForbiddenFromDomainRelaxation()
93 {
94     DEFINE_STATIC_LOCAL(HashSet<String>, schemes, ());
95     return schemes;
96 }
97
98 static URLSchemesMap& canDisplayOnlyIfCanRequestSchemes()
99 {
100     DEFINE_STATIC_LOCAL(URLSchemesMap, canDisplayOnlyIfCanRequestSchemes, ());
101
102 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
103     if (canDisplayOnlyIfCanRequestSchemes.isEmpty()) {
104 #if ENABLE(BLOB)
105         canDisplayOnlyIfCanRequestSchemes.add("blob");
106 #endif
107 #if ENABLE(FILE_SYSTEM)
108         canDisplayOnlyIfCanRequestSchemes.add("filesystem");
109 #endif
110     }
111 #endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
112
113     return canDisplayOnlyIfCanRequestSchemes;
114 }
115
116 static URLSchemesMap& notAllowingJavascriptURLsSchemes()
117 {
118     DEFINE_STATIC_LOCAL(URLSchemesMap, notAllowingJavascriptURLsSchemes, ());
119     return notAllowingJavascriptURLsSchemes;
120 }
121
122 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme)
123 {
124     localURLSchemes().add(scheme);
125 }
126
127 void SchemeRegistry::removeURLSchemeRegisteredAsLocal(const String& scheme)
128 {
129     if (scheme == "file")
130         return;
131 #if PLATFORM(MAC)
132     if (scheme == "applewebdata")
133         return;
134 #endif
135     localURLSchemes().remove(scheme);
136 }
137
138 const URLSchemesMap& SchemeRegistry::localSchemes()
139 {
140     return localURLSchemes();
141 }
142
143 static URLSchemesMap& schemesAllowingLocalStorageAccessInPrivateBrowsing()
144 {
145     DEFINE_STATIC_LOCAL(URLSchemesMap, schemesAllowingLocalStorageAccessInPrivateBrowsing, ());
146     return schemesAllowingLocalStorageAccessInPrivateBrowsing;
147 }
148
149 static URLSchemesMap& schemesAllowingDatabaseAccessInPrivateBrowsing()
150 {
151     DEFINE_STATIC_LOCAL(URLSchemesMap, schemesAllowingDatabaseAccessInPrivateBrowsing, ());
152     return schemesAllowingDatabaseAccessInPrivateBrowsing;
153 }
154
155 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme)
156 {
157     if (scheme.isEmpty())
158         return false;
159     return localURLSchemes().contains(scheme);
160 }
161
162 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme)
163 {
164     schemesWithUniqueOrigins().add(scheme);
165 }
166
167 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme)
168 {
169     if (scheme.isEmpty())
170         return false;
171     return schemesWithUniqueOrigins().contains(scheme);
172 }
173
174 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme)
175 {
176     displayIsolatedURLSchemes().add(scheme);
177 }
178
179 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(const String& scheme)
180 {
181     if (scheme.isEmpty())
182         return false;
183     return displayIsolatedURLSchemes().contains(scheme);
184 }
185
186 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme)
187 {
188     secureSchemes().add(scheme);
189 }
190
191 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme)
192 {
193     if (scheme.isEmpty())
194         return false;
195     return secureSchemes().contains(scheme);
196 }
197
198 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme)
199 {
200     emptyDocumentSchemes().add(scheme);
201 }
202
203 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme)
204 {
205     if (scheme.isEmpty())
206         return false;
207     return emptyDocumentSchemes().contains(scheme);
208 }
209
210 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const String& scheme)
211 {
212     if (scheme.isEmpty())
213         return;
214
215     if (forbidden)
216         schemesForbiddenFromDomainRelaxation().add(scheme);
217     else
218         schemesForbiddenFromDomainRelaxation().remove(scheme);
219 }
220
221 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(const String& scheme)
222 {
223     if (scheme.isEmpty())
224         return false;
225     return schemesForbiddenFromDomainRelaxation().contains(scheme);
226 }
227
228 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme)
229 {
230     if (scheme.isEmpty())
231         return false;
232     return canDisplayOnlyIfCanRequestSchemes().contains(scheme);
233 }
234
235 void SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(const String& scheme)
236 {
237     canDisplayOnlyIfCanRequestSchemes().add(scheme);
238 }
239
240 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(const String& scheme) 
241 {
242     notAllowingJavascriptURLsSchemes().add(scheme);
243 }
244
245 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
246 {
247     if (scheme.isEmpty())
248         return false;
249     return notAllowingJavascriptURLsSchemes().contains(scheme);
250 }
251
252 void SchemeRegistry::registerURLSchemeAsAllowingLocalStorageAccessInPrivateBrowsing(const String& scheme)
253 {
254     schemesAllowingLocalStorageAccessInPrivateBrowsing().add(scheme);
255 }
256
257 bool SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(const String& scheme)
258 {
259     if (scheme.isEmpty())
260         return false;
261     return schemesAllowingLocalStorageAccessInPrivateBrowsing().contains(scheme);
262 }
263
264 void SchemeRegistry::registerURLSchemeAsAllowingDatabaseAccessInPrivateBrowsing(const String& scheme)
265 {
266     schemesAllowingDatabaseAccessInPrivateBrowsing().add(scheme);
267 }
268
269 bool SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(const String& scheme)
270 {
271     if (scheme.isEmpty())
272         return false;
273     return schemesAllowingDatabaseAccessInPrivateBrowsing().contains(scheme);
274 }
275
276 } // namespace WebCore