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

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

Issue 2657443005: Migrate WTF::HashSet::add() to ::insert() [part 1 of N] (Closed)
Patch Set: Created 3 years, 10 months 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
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 29 matching lines...) Expand all
40 public: 40 public:
41 URLSchemesRegistry() 41 URLSchemesRegistry()
42 : emptyDocumentSchemes({"about"}), 42 : emptyDocumentSchemes({"about"}),
43 // For ServiceWorker schemes: HTTP is required because http://localhost 43 // For ServiceWorker schemes: HTTP is required because http://localhost
44 // is considered secure. Additional checks are performed to ensure that 44 // is considered secure. Additional checks are performed to ensure that
45 // other http pages are filtered out. 45 // other http pages are filtered out.
46 serviceWorkerSchemes({"http", "https"}), 46 serviceWorkerSchemes({"http", "https"}),
47 fetchAPISchemes({"http", "https"}), 47 fetchAPISchemes({"http", "https"}),
48 allowedInReferrerSchemes({"http", "https"}) { 48 allowedInReferrerSchemes({"http", "https"}) {
49 for (auto& scheme : url::GetLocalSchemes()) 49 for (auto& scheme : url::GetLocalSchemes())
50 localSchemes.add(scheme.c_str()); 50 localSchemes.insert(scheme.c_str());
51 for (auto& scheme : url::GetSecureSchemes()) 51 for (auto& scheme : url::GetSecureSchemes())
52 secureSchemes.add(scheme.c_str()); 52 secureSchemes.insert(scheme.c_str());
53 for (auto& scheme : url::GetNoAccessSchemes()) 53 for (auto& scheme : url::GetNoAccessSchemes())
54 schemesWithUniqueOrigins.add(scheme.c_str()); 54 schemesWithUniqueOrigins.insert(scheme.c_str());
55 for (auto& scheme : url::GetCORSEnabledSchemes()) 55 for (auto& scheme : url::GetCORSEnabledSchemes())
56 CORSEnabledSchemes.add(scheme.c_str()); 56 CORSEnabledSchemes.insert(scheme.c_str());
57 } 57 }
58 ~URLSchemesRegistry() = default; 58 ~URLSchemesRegistry() = default;
59 59
60 URLSchemesSet localSchemes; 60 URLSchemesSet localSchemes;
61 URLSchemesSet displayIsolatedURLSchemes; 61 URLSchemesSet displayIsolatedURLSchemes;
62 URLSchemesSet secureSchemes; 62 URLSchemesSet secureSchemes;
63 URLSchemesSet schemesWithUniqueOrigins; 63 URLSchemesSet schemesWithUniqueOrigins;
64 URLSchemesSet emptyDocumentSchemes; 64 URLSchemesSet emptyDocumentSchemes;
65 URLSchemesSet schemesForbiddenFromDomainRelaxation; 65 URLSchemesSet schemesForbiddenFromDomainRelaxation;
66 URLSchemesSet notAllowingJavascriptURLsSchemes; 66 URLSchemesSet notAllowingJavascriptURLsSchemes;
(...skipping 30 matching lines...) Expand all
97 } // namespace 97 } // namespace
98 98
99 // Must be called before we create other threads to avoid racy static local 99 // Must be called before we create other threads to avoid racy static local
100 // initialization. 100 // initialization.
101 void SchemeRegistry::initialize() { 101 void SchemeRegistry::initialize() {
102 getURLSchemesRegistry(); 102 getURLSchemesRegistry();
103 } 103 }
104 104
105 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme) { 105 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme) {
106 DCHECK_EQ(scheme, scheme.lower()); 106 DCHECK_EQ(scheme, scheme.lower());
107 getMutableURLSchemesRegistry().localSchemes.add(scheme); 107 getMutableURLSchemesRegistry().localSchemes.insert(scheme);
108 } 108 }
109 109
110 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme) { 110 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme) {
111 DCHECK_EQ(scheme, scheme.lower()); 111 DCHECK_EQ(scheme, scheme.lower());
112 if (scheme.isEmpty()) 112 if (scheme.isEmpty())
113 return false; 113 return false;
114 return getURLSchemesRegistry().localSchemes.contains(scheme); 114 return getURLSchemesRegistry().localSchemes.contains(scheme);
115 } 115 }
116 116
117 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme) { 117 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme) {
118 DCHECK_EQ(scheme, scheme.lower()); 118 DCHECK_EQ(scheme, scheme.lower());
119 getMutableURLSchemesRegistry().schemesWithUniqueOrigins.add(scheme); 119 getMutableURLSchemesRegistry().schemesWithUniqueOrigins.insert(scheme);
120 } 120 }
121 121
122 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme) { 122 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme) {
123 DCHECK_EQ(scheme, scheme.lower()); 123 DCHECK_EQ(scheme, scheme.lower());
124 if (scheme.isEmpty()) 124 if (scheme.isEmpty())
125 return false; 125 return false;
126 return getURLSchemesRegistry().schemesWithUniqueOrigins.contains(scheme); 126 return getURLSchemesRegistry().schemesWithUniqueOrigins.contains(scheme);
127 } 127 }
128 128
129 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme) { 129 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme) {
130 DCHECK_EQ(scheme, scheme.lower()); 130 DCHECK_EQ(scheme, scheme.lower());
131 getMutableURLSchemesRegistry().displayIsolatedURLSchemes.add(scheme); 131 getMutableURLSchemesRegistry().displayIsolatedURLSchemes.insert(scheme);
132 } 132 }
133 133
134 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated( 134 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated(
135 const String& scheme) { 135 const String& scheme) {
136 DCHECK_EQ(scheme, scheme.lower()); 136 DCHECK_EQ(scheme, scheme.lower());
137 if (scheme.isEmpty()) 137 if (scheme.isEmpty())
138 return false; 138 return false;
139 return getURLSchemesRegistry().displayIsolatedURLSchemes.contains(scheme); 139 return getURLSchemesRegistry().displayIsolatedURLSchemes.contains(scheme);
140 } 140 }
141 141
142 bool SchemeRegistry::shouldTreatURLSchemeAsRestrictingMixedContent( 142 bool SchemeRegistry::shouldTreatURLSchemeAsRestrictingMixedContent(
143 const String& scheme) { 143 const String& scheme) {
144 DCHECK_EQ(scheme, scheme.lower()); 144 DCHECK_EQ(scheme, scheme.lower());
145 return scheme == "https"; 145 return scheme == "https";
146 } 146 }
147 147
148 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme) { 148 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme) {
149 DCHECK_EQ(scheme, scheme.lower()); 149 DCHECK_EQ(scheme, scheme.lower());
150 getMutableURLSchemesRegistry().secureSchemes.add(scheme); 150 getMutableURLSchemesRegistry().secureSchemes.insert(scheme);
151 } 151 }
152 152
153 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme) { 153 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme) {
154 DCHECK_EQ(scheme, scheme.lower()); 154 DCHECK_EQ(scheme, scheme.lower());
155 if (scheme.isEmpty()) 155 if (scheme.isEmpty())
156 return false; 156 return false;
157 return getURLSchemesRegistry().secureSchemes.contains(scheme); 157 return getURLSchemesRegistry().secureSchemes.contains(scheme);
158 } 158 }
159 159
160 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme) { 160 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme) {
161 DCHECK_EQ(scheme, scheme.lower()); 161 DCHECK_EQ(scheme, scheme.lower());
162 getMutableURLSchemesRegistry().emptyDocumentSchemes.add(scheme); 162 getMutableURLSchemesRegistry().emptyDocumentSchemes.insert(scheme);
163 } 163 }
164 164
165 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme) { 165 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme) {
166 DCHECK_EQ(scheme, scheme.lower()); 166 DCHECK_EQ(scheme, scheme.lower());
167 if (scheme.isEmpty()) 167 if (scheme.isEmpty())
168 return false; 168 return false;
169 return getURLSchemesRegistry().emptyDocumentSchemes.contains(scheme); 169 return getURLSchemesRegistry().emptyDocumentSchemes.contains(scheme);
170 } 170 }
171 171
172 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme( 172 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(
173 bool forbidden, 173 bool forbidden,
174 const String& scheme) { 174 const String& scheme) {
175 DCHECK_EQ(scheme, scheme.lower()); 175 DCHECK_EQ(scheme, scheme.lower());
176 if (scheme.isEmpty()) 176 if (scheme.isEmpty())
177 return; 177 return;
178 178
179 if (forbidden) { 179 if (forbidden) {
180 getMutableURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.add( 180 getMutableURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.insert(
181 scheme); 181 scheme);
182 } else { 182 } else {
183 getMutableURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.remove( 183 getMutableURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.remove(
184 scheme); 184 scheme);
185 } 185 }
186 } 186 }
187 187
188 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme( 188 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(
189 const String& scheme) { 189 const String& scheme) {
190 DCHECK_EQ(scheme, scheme.lower()); 190 DCHECK_EQ(scheme, scheme.lower());
191 if (scheme.isEmpty()) 191 if (scheme.isEmpty())
192 return false; 192 return false;
193 return getURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.contains( 193 return getURLSchemesRegistry().schemesForbiddenFromDomainRelaxation.contains(
194 scheme); 194 scheme);
195 } 195 }
196 196
197 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme) { 197 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme) {
198 DCHECK_EQ(scheme, scheme.lower()); 198 DCHECK_EQ(scheme, scheme.lower());
199 return scheme == "blob" || scheme == "filesystem"; 199 return scheme == "blob" || scheme == "filesystem";
200 } 200 }
201 201
202 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs( 202 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs(
203 const String& scheme) { 203 const String& scheme) {
204 DCHECK_EQ(scheme, scheme.lower()); 204 DCHECK_EQ(scheme, scheme.lower());
205 getMutableURLSchemesRegistry().notAllowingJavascriptURLsSchemes.add(scheme); 205 getMutableURLSchemesRegistry().notAllowingJavascriptURLsSchemes.insert(
206 scheme);
206 } 207 }
207 208
208 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs( 209 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(
209 const String& scheme) { 210 const String& scheme) {
210 DCHECK_EQ(scheme, scheme.lower()); 211 DCHECK_EQ(scheme, scheme.lower());
211 if (scheme.isEmpty()) 212 if (scheme.isEmpty())
212 return false; 213 return false;
213 return getURLSchemesRegistry().notAllowingJavascriptURLsSchemes.contains( 214 return getURLSchemesRegistry().notAllowingJavascriptURLsSchemes.contains(
214 scheme); 215 scheme);
215 } 216 }
216 217
217 void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme) { 218 void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme) {
218 DCHECK_EQ(scheme, scheme.lower()); 219 DCHECK_EQ(scheme, scheme.lower());
219 getMutableURLSchemesRegistry().CORSEnabledSchemes.add(scheme); 220 getMutableURLSchemesRegistry().CORSEnabledSchemes.insert(scheme);
220 } 221 }
221 222
222 bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme) { 223 bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme) {
223 DCHECK_EQ(scheme, scheme.lower()); 224 DCHECK_EQ(scheme, scheme.lower());
224 if (scheme.isEmpty()) 225 if (scheme.isEmpty())
225 return false; 226 return false;
226 return getURLSchemesRegistry().CORSEnabledSchemes.contains(scheme); 227 return getURLSchemesRegistry().CORSEnabledSchemes.contains(scheme);
227 } 228 }
228 229
229 String SchemeRegistry::listOfCORSEnabledURLSchemes() { 230 String SchemeRegistry::listOfCORSEnabledURLSchemes() {
(...skipping 22 matching lines...) Expand all
252 // point (the webstore) and are designed specifically for Chrome. 253 // point (the webstore) and are designed specifically for Chrome.
253 // "data" is not included because real sites shouldn't be using it for 254 // "data" is not included because real sites shouldn't be using it for
254 // top-level 255 // top-level
255 // pages and Chrome does use it internally (eg. PluginPlaceholder). 256 // pages and Chrome does use it internally (eg. PluginPlaceholder).
256 return scheme == "http" || scheme == "https" || scheme == "file"; 257 return scheme == "http" || scheme == "https" || scheme == "file";
257 } 258 }
258 259
259 void SchemeRegistry::registerURLSchemeAsAllowingServiceWorkers( 260 void SchemeRegistry::registerURLSchemeAsAllowingServiceWorkers(
260 const String& scheme) { 261 const String& scheme) {
261 DCHECK_EQ(scheme, scheme.lower()); 262 DCHECK_EQ(scheme, scheme.lower());
262 getMutableURLSchemesRegistry().serviceWorkerSchemes.add(scheme); 263 getMutableURLSchemesRegistry().serviceWorkerSchemes.insert(scheme);
263 } 264 }
264 265
265 bool SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( 266 bool SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(
266 const String& scheme) { 267 const String& scheme) {
267 DCHECK_EQ(scheme, scheme.lower()); 268 DCHECK_EQ(scheme, scheme.lower());
268 if (scheme.isEmpty()) 269 if (scheme.isEmpty())
269 return false; 270 return false;
270 return getURLSchemesRegistry().serviceWorkerSchemes.contains(scheme); 271 return getURLSchemesRegistry().serviceWorkerSchemes.contains(scheme);
271 } 272 }
272 273
273 void SchemeRegistry::registerURLSchemeAsSupportingFetchAPI( 274 void SchemeRegistry::registerURLSchemeAsSupportingFetchAPI(
274 const String& scheme) { 275 const String& scheme) {
275 DCHECK_EQ(scheme, scheme.lower()); 276 DCHECK_EQ(scheme, scheme.lower());
276 getMutableURLSchemesRegistry().fetchAPISchemes.add(scheme); 277 getMutableURLSchemesRegistry().fetchAPISchemes.insert(scheme);
277 } 278 }
278 279
279 bool SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI( 280 bool SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(
280 const String& scheme) { 281 const String& scheme) {
281 DCHECK_EQ(scheme, scheme.lower()); 282 DCHECK_EQ(scheme, scheme.lower());
282 if (scheme.isEmpty()) 283 if (scheme.isEmpty())
283 return false; 284 return false;
284 return getURLSchemesRegistry().fetchAPISchemes.contains(scheme); 285 return getURLSchemesRegistry().fetchAPISchemes.contains(scheme);
285 } 286 }
286 287
287 void SchemeRegistry::registerURLSchemeAsFirstPartyWhenTopLevel( 288 void SchemeRegistry::registerURLSchemeAsFirstPartyWhenTopLevel(
288 const String& scheme) { 289 const String& scheme) {
289 DCHECK_EQ(scheme, scheme.lower()); 290 DCHECK_EQ(scheme, scheme.lower());
290 getMutableURLSchemesRegistry().firstPartyWhenTopLevelSchemes.add(scheme); 291 getMutableURLSchemesRegistry().firstPartyWhenTopLevelSchemes.insert(scheme);
291 } 292 }
292 293
293 void SchemeRegistry::removeURLSchemeAsFirstPartyWhenTopLevel( 294 void SchemeRegistry::removeURLSchemeAsFirstPartyWhenTopLevel(
294 const String& scheme) { 295 const String& scheme) {
295 DCHECK_EQ(scheme, scheme.lower()); 296 DCHECK_EQ(scheme, scheme.lower());
296 getMutableURLSchemesRegistry().firstPartyWhenTopLevelSchemes.remove(scheme); 297 getMutableURLSchemesRegistry().firstPartyWhenTopLevelSchemes.remove(scheme);
297 } 298 }
298 299
299 bool SchemeRegistry::shouldTreatURLSchemeAsFirstPartyWhenTopLevel( 300 bool SchemeRegistry::shouldTreatURLSchemeAsFirstPartyWhenTopLevel(
300 const String& scheme) { 301 const String& scheme) {
301 DCHECK_EQ(scheme, scheme.lower()); 302 DCHECK_EQ(scheme, scheme.lower());
302 if (scheme.isEmpty()) 303 if (scheme.isEmpty())
303 return false; 304 return false;
304 return getURLSchemesRegistry().firstPartyWhenTopLevelSchemes.contains(scheme); 305 return getURLSchemesRegistry().firstPartyWhenTopLevelSchemes.contains(scheme);
305 } 306 }
306 307
307 void SchemeRegistry::registerURLSchemeAsAllowedForReferrer( 308 void SchemeRegistry::registerURLSchemeAsAllowedForReferrer(
308 const String& scheme) { 309 const String& scheme) {
309 DCHECK_EQ(scheme, scheme.lower()); 310 DCHECK_EQ(scheme, scheme.lower());
310 getMutableURLSchemesRegistry().allowedInReferrerSchemes.add(scheme); 311 getMutableURLSchemesRegistry().allowedInReferrerSchemes.insert(scheme);
311 } 312 }
312 313
313 void SchemeRegistry::removeURLSchemeAsAllowedForReferrer(const String& scheme) { 314 void SchemeRegistry::removeURLSchemeAsAllowedForReferrer(const String& scheme) {
314 getMutableURLSchemesRegistry().allowedInReferrerSchemes.remove(scheme); 315 getMutableURLSchemesRegistry().allowedInReferrerSchemes.remove(scheme);
315 } 316 }
316 317
317 bool SchemeRegistry::shouldTreatURLSchemeAsAllowedForReferrer( 318 bool SchemeRegistry::shouldTreatURLSchemeAsAllowedForReferrer(
318 const String& scheme) { 319 const String& scheme) {
319 DCHECK_EQ(scheme, scheme.lower()); 320 DCHECK_EQ(scheme, scheme.lower());
320 if (scheme.isEmpty()) 321 if (scheme.isEmpty())
(...skipping 26 matching lines...) Expand all
347 // get() returns 0 (PolicyAreaNone) if there is no entry in the map. 348 // get() returns 0 (PolicyAreaNone) if there is no entry in the map.
348 // Thus by default, schemes do not bypass CSP. 349 // Thus by default, schemes do not bypass CSP.
349 return (getURLSchemesRegistry().contentSecurityPolicyBypassingSchemes.get( 350 return (getURLSchemesRegistry().contentSecurityPolicyBypassingSchemes.get(
350 scheme) & 351 scheme) &
351 policyAreas) == policyAreas; 352 policyAreas) == policyAreas;
352 } 353 }
353 354
354 void SchemeRegistry::registerURLSchemeBypassingSecureContextCheck( 355 void SchemeRegistry::registerURLSchemeBypassingSecureContextCheck(
355 const String& scheme) { 356 const String& scheme) {
356 DCHECK_EQ(scheme, scheme.lower()); 357 DCHECK_EQ(scheme, scheme.lower());
357 getMutableURLSchemesRegistry().secureContextBypassingSchemes.add(scheme); 358 getMutableURLSchemesRegistry().secureContextBypassingSchemes.insert(scheme);
358 } 359 }
359 360
360 bool SchemeRegistry::schemeShouldBypassSecureContextCheck( 361 bool SchemeRegistry::schemeShouldBypassSecureContextCheck(
361 const String& scheme) { 362 const String& scheme) {
362 if (scheme.isEmpty()) 363 if (scheme.isEmpty())
363 return false; 364 return false;
364 DCHECK_EQ(scheme, scheme.lower()); 365 DCHECK_EQ(scheme, scheme.lower());
365 return getURLSchemesRegistry().secureContextBypassingSchemes.contains(scheme); 366 return getURLSchemesRegistry().secureContextBypassingSchemes.contains(scheme);
366 } 367 }
367 368
368 } // namespace blink 369 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698