initial import
[vuplus_webkit] / 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     // 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
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
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
107 static URLSchemesMap& notAllowingJavascriptURLsSchemes()
108 {
109     DEFINE_STATIC_LOCAL(URLSchemesMap, notAllowingJavascriptURLsSchemes, ());
110     return notAllowingJavascriptURLsSchemes;
111 }
112
113 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme)
114 {
115     localURLSchemes().add(scheme);
116 }
117
118 void SchemeRegistry::removeURLSchemeRegisteredAsLocal(const String& scheme)
119 {
120     if (scheme == "file")
121         return;
122 #if PLATFORM(MAC)
123     if (scheme == "applewebdata")
124         return;
125 #endif
126     localURLSchemes().remove(scheme);
127 }
128
129 const URLSchemesMap& SchemeRegistry::localSchemes()
130 {
131     return localURLSchemes();
132 }
133
134 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme)
135 {
136     if (scheme.isEmpty())
137         return false;
138     return localURLSchemes().contains(scheme);
139 }
140
141 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme)
142 {
143     schemesWithUniqueOrigins().add(scheme);
144 }
145
146 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme)
147 {
148     if (scheme.isEmpty())
149         return false;
150     return schemesWithUniqueOrigins().contains(scheme);
151 }
152
153 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme)
154 {
155     displayIsolatedURLSchemes().add(scheme);
156 }
157
158 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(const String& scheme)
159 {
160     if (scheme.isEmpty())
161         return false;
162     return displayIsolatedURLSchemes().contains(scheme);
163 }
164
165 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme)
166 {
167     secureSchemes().add(scheme);
168 }
169
170 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme)
171 {
172     if (scheme.isEmpty())
173         return false;
174     return secureSchemes().contains(scheme);
175 }
176
177 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme)
178 {
179     emptyDocumentSchemes().add(scheme);
180 }
181
182 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme)
183 {
184     if (scheme.isEmpty())
185         return false;
186     return emptyDocumentSchemes().contains(scheme);
187 }
188
189 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme)
190 {
191     if (scheme.isEmpty())
192         return false;
193     return canDisplayOnlyIfCanRequestSchemes().contains(scheme);
194 }
195
196 void SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(const String& scheme)
197 {
198     canDisplayOnlyIfCanRequestSchemes().add(scheme);
199 }
200
201 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(const String& scheme) 
202 {
203     notAllowingJavascriptURLsSchemes().add(scheme);
204 }
205
206 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(const String& scheme)
207 {
208     if (scheme.isEmpty())
209         return false;
210     return notAllowingJavascriptURLsSchemes().contains(scheme);
211 }
212
213 } // namespace WebCore