Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: third_party/WebKit/Source/platform/weborigin/SchemeRegistry.cpp

Issue 2545443002: Cleanup multiple URLSchemesSet static variables (Closed)
Patch Set: remove a test that expects lower() Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/weborigin/SchemeRegistryTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2010 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 17 matching lines...) Expand all
28 28
29 #include "wtf/ThreadSpecific.h" 29 #include "wtf/ThreadSpecific.h"
30 #include "wtf/Threading.h" 30 #include "wtf/Threading.h"
31 #include "wtf/ThreadingPrimitives.h" 31 #include "wtf/ThreadingPrimitives.h"
32 #include "wtf/text/StringBuilder.h" 32 #include "wtf/text/StringBuilder.h"
33 33
34 namespace blink { 34 namespace blink {
35 35
36 namespace { 36 namespace {
37 37
38 void checkIsBeforeThreadCreated() { 38 class URLSchemesRegistry final {
39 public:
40 URLSchemesRegistry()
41 : localSchemes({"file"}),
42 secureSchemes({"https", "about", "data", "wss"}),
43 schemesWithUniqueOrigins({"about", "javascript", "data"}),
44 emptyDocumentSchemes({"about"}),
45 CORSEnabledSchemes({"http", "https", "data"}),
46 // For ServiceWorker schemes: HTTP is required because http://localhost
47 // is considered secure. Additional checks are performed to ensure that
48 // other http pages are filtered out.
49 serviceWorkerSchemes({"http", "https"}),
50 fetchAPISchemes({"http", "https"}),
51 allowedInReferrerSchemes({"http", "https"}) {}
52 ~URLSchemesRegistry() = default;
53
54 URLSchemesSet localSchemes;
55 URLSchemesSet displayIsolatedURLSchemes;
56 URLSchemesSet secureSchemes;
57 URLSchemesSet schemesWithUniqueOrigins;
58 URLSchemesSet emptyDocumentSchemes;
59 URLSchemesSet schemesForbiddenFromDomainRelaxation;
60 URLSchemesSet notAllowingJavascriptURLsSchemes;
61 URLSchemesSet CORSEnabledSchemes;
62 URLSchemesSet serviceWorkerSchemes;
63 URLSchemesSet fetchAPISchemes;
64 URLSchemesSet firstPartyWhenTopLevelSchemes;
65 URLSchemesMap<SchemeRegistry::PolicyAreas>
66 contentSecurityPolicyBypassingSchemes;
67 URLSchemesSet secureContextBypassingSchemes;
68 URLSchemesSet allowedInReferrerSchemes;
69
70 private:
71 friend const URLSchemesRegistry& getURLSchemesRegistry();
72 friend URLSchemesRegistry& getMutableURLSchemesRegistry();
73
74 static URLSchemesRegistry& getInstance() {
75 DEFINE_STATIC_LOCAL(URLSchemesRegistry, schemes, ());
76 return schemes;
77 }
78 };
79
80 const URLSchemesRegistry& getURLSchemesRegistry() {
81 return URLSchemesRegistry::getInstance();
82 }
83
84 URLSchemesRegistry& getMutableURLSchemesRegistry() {
39 #if DCHECK_IS_ON() 85 #if DCHECK_IS_ON()
40 DCHECK(WTF::isBeforeThreadCreated()); 86 DCHECK(WTF::isBeforeThreadCreated());
41 #endif 87 #endif
88 return URLSchemesRegistry::getInstance();
42 } 89 }
43 90
44 } // namespace 91 } // namespace
45 92
46 static URLSchemesSet& localURLSchemes() { 93 // Must be called before we create other threads to avoid racy static local
47 DEFINE_STATIC_LOCAL(URLSchemesSet, localSchemes, ()); 94 // initialization.
48 95 void SchemeRegistry::initialize() {
49 if (localSchemes.isEmpty()) 96 getURLSchemesRegistry();
50 localSchemes.add("file");
51
52 return localSchemes;
53 }
54
55 static URLSchemesSet& displayIsolatedURLSchemes() {
56 DEFINE_STATIC_LOCAL(URLSchemesSet, displayIsolatedSchemes, ());
57 return displayIsolatedSchemes;
58 }
59
60 static URLSchemesSet& secureSchemes() {
61 DEFINE_STATIC_LOCAL(URLSchemesSet, secureSchemes,
62 ({
63 "https", "about", "data", "wss",
64 }));
65 return secureSchemes;
66 }
67
68 static URLSchemesSet& schemesWithUniqueOrigins() {
69 DEFINE_STATIC_LOCAL(URLSchemesSet, schemesWithUniqueOrigins,
70 ({
71 "about", "javascript", "data",
72 }));
73 return schemesWithUniqueOrigins;
74 }
75
76 static URLSchemesSet& emptyDocumentSchemes() {
77 DEFINE_STATIC_LOCAL(URLSchemesSet, emptyDocumentSchemes, ({
78 "about",
79 }));
80 return emptyDocumentSchemes;
81 }
82
83 static HashSet<String>& schemesForbiddenFromDomainRelaxation() {
84 DEFINE_STATIC_LOCAL(HashSet<String>, schemes, ());
85 return schemes;
86 }
87
88 static URLSchemesSet& notAllowingJavascriptURLsSchemes() {
89 DEFINE_STATIC_LOCAL(URLSchemesSet, notAllowingJavascriptURLsSchemes, ());
90 return notAllowingJavascriptURLsSchemes;
91 } 97 }
92 98
93 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme) { 99 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme) {
94 checkIsBeforeThreadCreated();
95 DCHECK_EQ(scheme, scheme.lower()); 100 DCHECK_EQ(scheme, scheme.lower());
96 localURLSchemes().add(scheme); 101 getMutableURLSchemesRegistry().localSchemes.add(scheme);
97 }
98
99 const URLSchemesSet& SchemeRegistry::localSchemes() {
100 return localURLSchemes();
101 }
102
103 static URLSchemesSet& CORSEnabledSchemes() {
104 DEFINE_STATIC_LOCAL(URLSchemesSet, CORSEnabledSchemes, ());
105
106 if (CORSEnabledSchemes.isEmpty()) {
107 CORSEnabledSchemes.add("http");
108 CORSEnabledSchemes.add("https");
109 CORSEnabledSchemes.add("data");
110 }
111
112 return CORSEnabledSchemes;
113 }
114
115 static URLSchemesSet& serviceWorkerSchemes() {
116 DEFINE_STATIC_LOCAL(URLSchemesSet, serviceWorkerSchemes, ());
117
118 if (serviceWorkerSchemes.isEmpty()) {
119 // HTTP is required because http://localhost is considered secure.
120 // Additional checks are performed to ensure that other http pages
121 // are filtered out.
122 serviceWorkerSchemes.add("http");
123 serviceWorkerSchemes.add("https");
124 }
125
126 return serviceWorkerSchemes;
127 }
128
129 static URLSchemesSet& fetchAPISchemes() {
130 DEFINE_STATIC_LOCAL(URLSchemesSet, fetchAPISchemes, ());
131
132 if (fetchAPISchemes.isEmpty()) {
133 fetchAPISchemes.add("http");
134 fetchAPISchemes.add("https");
135 }
136
137 return fetchAPISchemes;
138 }
139
140 static URLSchemesSet& firstPartyWhenTopLevelSchemes() {
141 DEFINE_STATIC_LOCAL(URLSchemesSet, firstPartyWhenTopLevelSchemes, ());
142 return firstPartyWhenTopLevelSchemes;
143 }
144
145 static URLSchemesMap<SchemeRegistry::PolicyAreas>&
146 ContentSecurityPolicyBypassingSchemes() {
147 DEFINE_STATIC_LOCAL(URLSchemesMap<SchemeRegistry::PolicyAreas>, schemes, ());
148 return schemes;
149 }
150
151 static URLSchemesSet& secureContextBypassingSchemes() {
152 DEFINE_STATIC_LOCAL(URLSchemesSet, secureContextBypassingSchemes, ());
153 return secureContextBypassingSchemes;
154 }
155
156 static URLSchemesSet& allowedInReferrerSchemes() {
157 DEFINE_STATIC_LOCAL(URLSchemesSet, allowedInReferrerSchemes, ());
158
159 if (allowedInReferrerSchemes.isEmpty()) {
160 allowedInReferrerSchemes.add("http");
161 allowedInReferrerSchemes.add("https");
162 }
163
164 return allowedInReferrerSchemes;
165 }
166
167 // All new maps should be added here. Must be called before we create other
168 // threads to avoid racy static local initialization.
169 void SchemeRegistry::initialize() {
170 localURLSchemes();
171 displayIsolatedURLSchemes();
172 secureSchemes();
173 schemesWithUniqueOrigins();
174 emptyDocumentSchemes();
175 schemesForbiddenFromDomainRelaxation();
176 notAllowingJavascriptURLsSchemes();
177 CORSEnabledSchemes();
178 serviceWorkerSchemes();
179 fetchAPISchemes();
180 firstPartyWhenTopLevelSchemes();
181 ContentSecurityPolicyBypassingSchemes();
182 secureContextBypassingSchemes();
183 allowedInReferrerSchemes();
184 } 102 }
185 103
186 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme) { 104 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme) {
187 DCHECK_EQ(scheme, scheme.lower()); 105 DCHECK_EQ(scheme, scheme.lower());
188 if (scheme.isEmpty()) 106 if (scheme.isEmpty())
189 return false; 107 return false;
190 return localURLSchemes().contains(scheme); 108 return getURLSchemesRegistry().localSchemes.contains(scheme);
191 } 109 }
192 110
193 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme) { 111 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme) {
194 checkIsBeforeThreadCreated();
195 DCHECK_EQ(scheme, scheme.lower()); 112 DCHECK_EQ(scheme, scheme.lower());
196 schemesWithUniqueOrigins().add(scheme); 113 getMutableURLSchemesRegistry().schemesWithUniqueOrigins.add(scheme);
197 } 114 }
198 115
199 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme) { 116 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme) {
200 DCHECK_EQ(scheme, scheme.lower()); 117 DCHECK_EQ(scheme, scheme.lower());
201 if (scheme.isEmpty()) 118 if (scheme.isEmpty())
202 return false; 119 return false;
203 return schemesWithUniqueOrigins().contains(scheme); 120 return getURLSchemesRegistry().schemesWithUniqueOrigins.contains(scheme);
204 } 121 }
205 122
206 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme) { 123 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme) {
207 checkIsBeforeThreadCreated();
208 DCHECK_EQ(scheme, scheme.lower()); 124 DCHECK_EQ(scheme, scheme.lower());
209 displayIsolatedURLSchemes().add(scheme); 125 getMutableURLSchemesRegistry().displayIsolatedURLSchemes.add(scheme);
210 } 126 }
211 127
212 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated( 128 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(
213 const String& scheme) { 129 const String& scheme) {
214 DCHECK_EQ(scheme, scheme.lower()); 130 DCHECK_EQ(scheme, scheme.lower());
215 if (scheme.isEmpty()) 131 if (scheme.isEmpty())
216 return false; 132 return false;
217 return displayIsolatedURLSchemes().contains(scheme); 133 return getURLSchemesRegistry().displayIsolatedURLSchemes.contains(scheme);
218 } 134 }
219 135
220 bool SchemeRegistry::shouldTreatURLSchemeAsRestrictingMixedContent( 136 bool SchemeRegistry::shouldTreatURLSchemeAsRestrictingMixedContent(
221 const String& scheme) { 137 const String& scheme) {
222 DCHECK_EQ(scheme, scheme.lower()); 138 DCHECK_EQ(scheme, scheme.lower());
223 return scheme == "https"; 139 return scheme == "https";
224 } 140 }
225 141
226 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme) { 142 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme) {
227 checkIsBeforeThreadCreated();
228 DCHECK_EQ(scheme, scheme.lower()); 143 DCHECK_EQ(scheme, scheme.lower());
229 secureSchemes().add(scheme); 144 getMutableURLSchemesRegistry().secureSchemes.add(scheme);
230 } 145 }
231 146
232 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme) { 147 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme) {
233 DCHECK_EQ(scheme, scheme.lower()); 148 DCHECK_EQ(scheme, scheme.lower());
234 if (scheme.isEmpty()) 149 if (scheme.isEmpty())
235 return false; 150 return false;
236 return secureSchemes().contains(scheme); 151 return getURLSchemesRegistry().secureSchemes.contains(scheme);
237 } 152 }
238 153
239 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme) { 154 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme) {
240 checkIsBeforeThreadCreated();
241 DCHECK_EQ(scheme, scheme.lower()); 155 DCHECK_EQ(scheme, scheme.lower());
242 emptyDocumentSchemes().add(scheme); 156 getMutableURLSchemesRegistry().emptyDocumentSchemes.add(scheme);
243 } 157 }
244 158
245 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme) { 159 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme) {
246 DCHECK_EQ(scheme, scheme.lower()); 160 DCHECK_EQ(scheme, scheme.lower());
247 if (scheme.isEmpty()) 161 if (scheme.isEmpty())
248 return false; 162 return false;
249 return emptyDocumentSchemes().contains(scheme); 163 return getURLSchemesRegistry().emptyDocumentSchemes.contains(scheme);
250 } 164 }
251 165
252 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme( 166 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(
253 bool forbidden, 167 bool forbidden,
254 const String& scheme) { 168 const String& scheme) {
255 checkIsBeforeThreadCreated();
256 DCHECK_EQ(scheme, scheme.lower()); 169 DCHECK_EQ(scheme, scheme.lower());
257 if (scheme.isEmpty()) 170 if (scheme.isEmpty())
258 return; 171 return;
259 172
260 if (forbidden) 173 if (forbidden) {
261 schemesForbiddenFromDomainRelaxation().add(scheme); 174 getMutableURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.add(
262 else 175 scheme);
263 schemesForbiddenFromDomainRelaxation().remove(scheme); 176 } else {
177 getMutableURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.remove(
178 scheme);
179 }
264 } 180 }
265 181
266 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme( 182 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(
267 const String& scheme) { 183 const String& scheme) {
268 DCHECK_EQ(scheme, scheme.lower()); 184 DCHECK_EQ(scheme, scheme.lower());
269 if (scheme.isEmpty()) 185 if (scheme.isEmpty())
270 return false; 186 return false;
271 return schemesForbiddenFromDomainRelaxation().contains(scheme); 187 return getURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.contains(
188 scheme);
272 } 189 }
273 190
274 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme) { 191 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme) {
275 DCHECK_EQ(scheme, scheme.lower()); 192 DCHECK_EQ(scheme, scheme.lower());
276 return scheme == "blob" || scheme == "filesystem"; 193 return scheme == "blob" || scheme == "filesystem";
277 } 194 }
278 195
279 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs( 196 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(
280 const String& scheme) { 197 const String& scheme) {
281 checkIsBeforeThreadCreated();
282 DCHECK_EQ(scheme, scheme.lower()); 198 DCHECK_EQ(scheme, scheme.lower());
283 notAllowingJavascriptURLsSchemes().add(scheme); 199 getMutableURLSchemesRegistry().notAllowingJavascriptURLsSchemes.add(scheme);
284 } 200 }
285 201
286 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs( 202 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(
287 const String& scheme) { 203 const String& scheme) {
288 DCHECK_EQ(scheme, scheme.lower()); 204 DCHECK_EQ(scheme, scheme.lower());
289 if (scheme.isEmpty()) 205 if (scheme.isEmpty())
290 return false; 206 return false;
291 return notAllowingJavascriptURLsSchemes().contains(scheme); 207 return getURLSchemesRegistry().notAllowingJavascriptURLsSchemes.contains(
208 scheme);
292 } 209 }
293 210
294 void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme) { 211 void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme) {
295 checkIsBeforeThreadCreated();
296 DCHECK_EQ(scheme, scheme.lower()); 212 DCHECK_EQ(scheme, scheme.lower());
297 CORSEnabledSchemes().add(scheme); 213 getMutableURLSchemesRegistry().CORSEnabledSchemes.add(scheme);
298 } 214 }
299 215
300 bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme) { 216 bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme) {
301 DCHECK_EQ(scheme, scheme.lower()); 217 DCHECK_EQ(scheme, scheme.lower());
302 if (scheme.isEmpty()) 218 if (scheme.isEmpty())
303 return false; 219 return false;
304 return CORSEnabledSchemes().contains(scheme); 220 return getURLSchemesRegistry().CORSEnabledSchemes.contains(scheme);
305 } 221 }
306 222
307 String SchemeRegistry::listOfCORSEnabledURLSchemes() { 223 String SchemeRegistry::listOfCORSEnabledURLSchemes() {
308 StringBuilder builder; 224 StringBuilder builder;
309 bool addSeparator = false; 225 bool addSeparator = false;
310 for (const auto& scheme : CORSEnabledSchemes()) { 226 for (const auto& scheme : getURLSchemesRegistry().CORSEnabledSchemes) {
311 if (addSeparator) 227 if (addSeparator)
312 builder.append(", "); 228 builder.append(", ");
313 else 229 else
314 addSeparator = true; 230 addSeparator = true;
315 231
316 builder.append(scheme); 232 builder.append(scheme);
317 } 233 }
318 return builder.toString(); 234 return builder.toString();
319 } 235 }
320 236
321 bool SchemeRegistry::shouldTreatURLSchemeAsLegacy(const String& scheme) { 237 bool SchemeRegistry::shouldTreatURLSchemeAsLegacy(const String& scheme) {
322 return scheme == "ftp" || scheme == "gopher"; 238 return scheme == "ftp" || scheme == "gopher";
323 } 239 }
324 240
325 void SchemeRegistry::registerURLSchemeAsAllowingServiceWorkers( 241 void SchemeRegistry::registerURLSchemeAsAllowingServiceWorkers(
326 const String& scheme) { 242 const String& scheme) {
327 checkIsBeforeThreadCreated();
328 DCHECK_EQ(scheme, scheme.lower()); 243 DCHECK_EQ(scheme, scheme.lower());
329 serviceWorkerSchemes().add(scheme); 244 getMutableURLSchemesRegistry().serviceWorkerSchemes.add(scheme);
330 } 245 }
331 246
332 bool SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( 247 bool SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(
333 const String& scheme) { 248 const String& scheme) {
334 DCHECK_EQ(scheme, scheme.lower()); 249 DCHECK_EQ(scheme, scheme.lower());
335 if (scheme.isEmpty()) 250 if (scheme.isEmpty())
336 return false; 251 return false;
337 return serviceWorkerSchemes().contains(scheme); 252 return getURLSchemesRegistry().serviceWorkerSchemes.contains(scheme);
338 } 253 }
339 254
340 void SchemeRegistry::registerURLSchemeAsSupportingFetchAPI( 255 void SchemeRegistry::registerURLSchemeAsSupportingFetchAPI(
341 const String& scheme) { 256 const String& scheme) {
342 checkIsBeforeThreadCreated();
343 DCHECK_EQ(scheme, scheme.lower()); 257 DCHECK_EQ(scheme, scheme.lower());
344 fetchAPISchemes().add(scheme); 258 getMutableURLSchemesRegistry().fetchAPISchemes.add(scheme);
345 } 259 }
346 260
347 bool SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI( 261 bool SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(
348 const String& scheme) { 262 const String& scheme) {
349 DCHECK_EQ(scheme, scheme.lower()); 263 DCHECK_EQ(scheme, scheme.lower());
350 if (scheme.isEmpty()) 264 if (scheme.isEmpty())
351 return false; 265 return false;
352 return fetchAPISchemes().contains(scheme); 266 return getURLSchemesRegistry().fetchAPISchemes.contains(scheme);
353 } 267 }
354 268
355 void SchemeRegistry::registerURLSchemeAsFirstPartyWhenTopLevel( 269 void SchemeRegistry::registerURLSchemeAsFirstPartyWhenTopLevel(
356 const String& scheme) { 270 const String& scheme) {
357 checkIsBeforeThreadCreated();
358 DCHECK_EQ(scheme, scheme.lower()); 271 DCHECK_EQ(scheme, scheme.lower());
359 firstPartyWhenTopLevelSchemes().add(scheme); 272 getMutableURLSchemesRegistry().firstPartyWhenTopLevelSchemes.add(scheme);
360 } 273 }
361 274
362 void SchemeRegistry::removeURLSchemeAsFirstPartyWhenTopLevel( 275 void SchemeRegistry::removeURLSchemeAsFirstPartyWhenTopLevel(
363 const String& scheme) { 276 const String& scheme) {
364 checkIsBeforeThreadCreated();
365 DCHECK_EQ(scheme, scheme.lower()); 277 DCHECK_EQ(scheme, scheme.lower());
366 firstPartyWhenTopLevelSchemes().remove(scheme); 278 getMutableURLSchemesRegistry().firstPartyWhenTopLevelSchemes.remove(scheme);
367 } 279 }
368 280
369 bool SchemeRegistry::shouldTreatURLSchemeAsFirstPartyWhenTopLevel( 281 bool SchemeRegistry::shouldTreatURLSchemeAsFirstPartyWhenTopLevel(
370 const String& scheme) { 282 const String& scheme) {
371 DCHECK_EQ(scheme, scheme.lower()); 283 DCHECK_EQ(scheme, scheme.lower());
372 if (scheme.isEmpty()) 284 if (scheme.isEmpty())
373 return false; 285 return false;
374 return firstPartyWhenTopLevelSchemes().contains(scheme); 286 return getURLSchemesRegistry().firstPartyWhenTopLevelSchemes.contains(scheme);
375 } 287 }
376 288
377 void SchemeRegistry::registerURLSchemeAsAllowedForReferrer( 289 void SchemeRegistry::registerURLSchemeAsAllowedForReferrer(
378 const String& scheme) { 290 const String& scheme) {
379 checkIsBeforeThreadCreated();
380 DCHECK_EQ(scheme, scheme.lower()); 291 DCHECK_EQ(scheme, scheme.lower());
381 allowedInReferrerSchemes().add(scheme); 292 getMutableURLSchemesRegistry().allowedInReferrerSchemes.add(scheme);
382 } 293 }
383 294
384 void SchemeRegistry::removeURLSchemeAsAllowedForReferrer(const String& scheme) { 295 void SchemeRegistry::removeURLSchemeAsAllowedForReferrer(const String& scheme) {
385 checkIsBeforeThreadCreated(); 296 getMutableURLSchemesRegistry().allowedInReferrerSchemes.remove(scheme);
386 allowedInReferrerSchemes().remove(scheme);
387 } 297 }
388 298
389 bool SchemeRegistry::shouldTreatURLSchemeAsAllowedForReferrer( 299 bool SchemeRegistry::shouldTreatURLSchemeAsAllowedForReferrer(
390 const String& scheme) { 300 const String& scheme) {
391 DCHECK_EQ(scheme, scheme.lower()); 301 DCHECK_EQ(scheme, scheme.lower());
392 if (scheme.isEmpty()) 302 if (scheme.isEmpty())
393 return false; 303 return false;
394 return allowedInReferrerSchemes().contains(scheme); 304 return getURLSchemesRegistry().allowedInReferrerSchemes.contains(scheme);
395 } 305 }
396 306
397 void SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy( 307 void SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(
398 const String& scheme, 308 const String& scheme,
399 PolicyAreas policyAreas) { 309 PolicyAreas policyAreas) {
400 checkIsBeforeThreadCreated();
401 DCHECK_EQ(scheme, scheme.lower()); 310 DCHECK_EQ(scheme, scheme.lower());
402 ContentSecurityPolicyBypassingSchemes().add(scheme, policyAreas); 311 getMutableURLSchemesRegistry().contentSecurityPolicyBypassingSchemes.add(
312 scheme, policyAreas);
403 } 313 }
404 314
405 void SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy( 315 void SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(
406 const String& scheme) { 316 const String& scheme) {
407 checkIsBeforeThreadCreated();
408 DCHECK_EQ(scheme, scheme.lower()); 317 DCHECK_EQ(scheme, scheme.lower());
409 ContentSecurityPolicyBypassingSchemes().remove(scheme); 318 getMutableURLSchemesRegistry().contentSecurityPolicyBypassingSchemes.remove(
319 scheme);
410 } 320 }
411 321
412 bool SchemeRegistry::schemeShouldBypassContentSecurityPolicy( 322 bool SchemeRegistry::schemeShouldBypassContentSecurityPolicy(
413 const String& scheme, 323 const String& scheme,
414 PolicyAreas policyAreas) { 324 PolicyAreas policyAreas) {
415 ASSERT(policyAreas != PolicyAreaNone); 325 ASSERT(policyAreas != PolicyAreaNone);
416 if (scheme.isEmpty() || policyAreas == PolicyAreaNone) 326 if (scheme.isEmpty() || policyAreas == PolicyAreaNone)
417 return false; 327 return false;
418 328
419 // get() returns 0 (PolicyAreaNone) if there is no entry in the map. 329 // get() returns 0 (PolicyAreaNone) if there is no entry in the map.
420 // Thus by default, schemes do not bypass CSP. 330 // Thus by default, schemes do not bypass CSP.
421 return (ContentSecurityPolicyBypassingSchemes().get(scheme) & policyAreas) == 331 return (getURLSchemesRegistry().contentSecurityPolicyBypassingSchemes.get(
422 policyAreas; 332 scheme) &
333 policyAreas) == policyAreas;
423 } 334 }
424 335
425 void SchemeRegistry::registerURLSchemeBypassingSecureContextCheck( 336 void SchemeRegistry::registerURLSchemeBypassingSecureContextCheck(
426 const String& scheme) { 337 const String& scheme) {
427 checkIsBeforeThreadCreated();
428 DCHECK_EQ(scheme, scheme.lower()); 338 DCHECK_EQ(scheme, scheme.lower());
429 secureContextBypassingSchemes().add(scheme.lower()); 339 getMutableURLSchemesRegistry().secureContextBypassingSchemes.add(scheme);
430 } 340 }
431 341
432 bool SchemeRegistry::schemeShouldBypassSecureContextCheck( 342 bool SchemeRegistry::schemeShouldBypassSecureContextCheck(
433 const String& scheme) { 343 const String& scheme) {
434 if (scheme.isEmpty()) 344 if (scheme.isEmpty())
435 return false; 345 return false;
436 return secureContextBypassingSchemes().contains(scheme.lower()); 346 DCHECK_EQ(scheme, scheme.lower());
347 return getURLSchemesRegistry().secureContextBypassingSchemes.contains(scheme);
437 } 348 }
438 349
439 } // namespace blink 350 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/weborigin/SchemeRegistryTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698