| OLD | NEW |
| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 * | 24 * |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "platform/weborigin/SchemeRegistry.h" | 27 #include "platform/weborigin/SchemeRegistry.h" |
| 28 | 28 |
| 29 #include "wtf/ThreadSpecific.h" | 29 #include "wtf/ThreadSpecific.h" |
| 30 #include "wtf/Threading.h" |
| 30 #include "wtf/ThreadingPrimitives.h" | 31 #include "wtf/ThreadingPrimitives.h" |
| 31 #include "wtf/text/StringBuilder.h" | 32 #include "wtf/text/StringBuilder.h" |
| 32 | 33 |
| 33 namespace blink { | 34 namespace blink { |
| 34 | 35 |
| 35 static Mutex& mutex() { | 36 namespace { |
| 36 // The first call to this should be made before or during blink | 37 |
| 37 // initialization to avoid racy static local initialization. | 38 void checkIsBeforeThreadCreated() { |
| 38 DEFINE_STATIC_LOCAL(Mutex, m, ()); | 39 #if DCHECK_IS_ON() |
| 39 return m; | 40 DCHECK(WTF::isBeforeThreadCreated()); |
| 41 #endif |
| 40 } | 42 } |
| 41 | 43 |
| 42 // Defines static local variable after making sure that a lock is held. | 44 } // namespace |
| 43 // (We can't use DEFINE_STATIC_LOCAL for this because it asserts thread | |
| 44 // safety, which is externally guaranteed by the local mutex() lock) | |
| 45 #define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \ | |
| 46 ASSERT(mutex().locked()); \ | |
| 47 static type& name = *new type arguments | |
| 48 | 45 |
| 49 static URLSchemesSet& localURLSchemes() { | 46 static URLSchemesSet& localURLSchemes() { |
| 50 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, localSchemes, ()); | 47 DEFINE_STATIC_LOCAL(URLSchemesSet, localSchemes, ()); |
| 51 | 48 |
| 52 if (localSchemes.isEmpty()) | 49 if (localSchemes.isEmpty()) |
| 53 localSchemes.add("file"); | 50 localSchemes.add("file"); |
| 54 | 51 |
| 55 return localSchemes; | 52 return localSchemes; |
| 56 } | 53 } |
| 57 | 54 |
| 58 static URLSchemesSet& displayIsolatedURLSchemes() { | 55 static URLSchemesSet& displayIsolatedURLSchemes() { |
| 59 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, displayIsolatedSchemes, ()); | 56 DEFINE_STATIC_LOCAL(URLSchemesSet, displayIsolatedSchemes, ()); |
| 60 return displayIsolatedSchemes; | 57 return displayIsolatedSchemes; |
| 61 } | 58 } |
| 62 | 59 |
| 63 static URLSchemesSet& secureSchemes() { | 60 static URLSchemesSet& secureSchemes() { |
| 64 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, secureSchemes, | 61 DEFINE_STATIC_LOCAL(URLSchemesSet, secureSchemes, |
| 65 ({ | 62 ({ |
| 66 "https", "about", "data", "wss", | 63 "https", "about", "data", "wss", |
| 67 })); | 64 })); |
| 68 return secureSchemes; | 65 return secureSchemes; |
| 69 } | 66 } |
| 70 | 67 |
| 71 static URLSchemesSet& schemesWithUniqueOrigins() { | 68 static URLSchemesSet& schemesWithUniqueOrigins() { |
| 72 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, schemesWithUniqueOrigins, | 69 DEFINE_STATIC_LOCAL(URLSchemesSet, schemesWithUniqueOrigins, |
| 73 ({ | 70 ({ |
| 74 "about", "javascript", "data", | 71 "about", "javascript", "data", |
| 75 })); | 72 })); |
| 76 return schemesWithUniqueOrigins; | 73 return schemesWithUniqueOrigins; |
| 77 } | 74 } |
| 78 | 75 |
| 79 static URLSchemesSet& emptyDocumentSchemes() { | 76 static URLSchemesSet& emptyDocumentSchemes() { |
| 80 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, emptyDocumentSchemes, | 77 DEFINE_STATIC_LOCAL(URLSchemesSet, emptyDocumentSchemes, ({ |
| 81 ({ | 78 "about", |
| 82 "about", | 79 })); |
| 83 })); | |
| 84 return emptyDocumentSchemes; | 80 return emptyDocumentSchemes; |
| 85 } | 81 } |
| 86 | 82 |
| 87 static HashSet<String>& schemesForbiddenFromDomainRelaxation() { | 83 static HashSet<String>& schemesForbiddenFromDomainRelaxation() { |
| 88 DEFINE_STATIC_LOCAL_WITH_LOCK(HashSet<String>, schemes, ()); | 84 DEFINE_STATIC_LOCAL(HashSet<String>, schemes, ()); |
| 89 return schemes; | 85 return schemes; |
| 90 } | 86 } |
| 91 | 87 |
| 92 static URLSchemesSet& notAllowingJavascriptURLsSchemes() { | 88 static URLSchemesSet& notAllowingJavascriptURLsSchemes() { |
| 93 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, notAllowingJavascriptURLsSchemes, | 89 DEFINE_STATIC_LOCAL(URLSchemesSet, notAllowingJavascriptURLsSchemes, ()); |
| 94 ()); | |
| 95 return notAllowingJavascriptURLsSchemes; | 90 return notAllowingJavascriptURLsSchemes; |
| 96 } | 91 } |
| 97 | 92 |
| 98 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme) { | 93 void SchemeRegistry::registerURLSchemeAsLocal(const String& scheme) { |
| 94 checkIsBeforeThreadCreated(); |
| 99 DCHECK_EQ(scheme, scheme.lower()); | 95 DCHECK_EQ(scheme, scheme.lower()); |
| 100 MutexLocker locker(mutex()); | |
| 101 localURLSchemes().add(scheme); | 96 localURLSchemes().add(scheme); |
| 102 } | 97 } |
| 103 | 98 |
| 104 const URLSchemesSet& SchemeRegistry::localSchemes() { | 99 const URLSchemesSet& SchemeRegistry::localSchemes() { |
| 105 MutexLocker locker(mutex()); | |
| 106 return localURLSchemes(); | 100 return localURLSchemes(); |
| 107 } | 101 } |
| 108 | 102 |
| 109 static URLSchemesSet& CORSEnabledSchemes() { | 103 static URLSchemesSet& CORSEnabledSchemes() { |
| 110 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, CORSEnabledSchemes, ()); | 104 DEFINE_STATIC_LOCAL(URLSchemesSet, CORSEnabledSchemes, ()); |
| 111 | 105 |
| 112 if (CORSEnabledSchemes.isEmpty()) { | 106 if (CORSEnabledSchemes.isEmpty()) { |
| 113 CORSEnabledSchemes.add("http"); | 107 CORSEnabledSchemes.add("http"); |
| 114 CORSEnabledSchemes.add("https"); | 108 CORSEnabledSchemes.add("https"); |
| 115 CORSEnabledSchemes.add("data"); | 109 CORSEnabledSchemes.add("data"); |
| 116 } | 110 } |
| 117 | 111 |
| 118 return CORSEnabledSchemes; | 112 return CORSEnabledSchemes; |
| 119 } | 113 } |
| 120 | 114 |
| 121 static URLSchemesSet& serviceWorkerSchemes() { | 115 static URLSchemesSet& serviceWorkerSchemes() { |
| 122 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, serviceWorkerSchemes, ()); | 116 DEFINE_STATIC_LOCAL(URLSchemesSet, serviceWorkerSchemes, ()); |
| 123 | 117 |
| 124 if (serviceWorkerSchemes.isEmpty()) { | 118 if (serviceWorkerSchemes.isEmpty()) { |
| 125 // HTTP is required because http://localhost is considered secure. | 119 // HTTP is required because http://localhost is considered secure. |
| 126 // Additional checks are performed to ensure that other http pages | 120 // Additional checks are performed to ensure that other http pages |
| 127 // are filtered out. | 121 // are filtered out. |
| 128 serviceWorkerSchemes.add("http"); | 122 serviceWorkerSchemes.add("http"); |
| 129 serviceWorkerSchemes.add("https"); | 123 serviceWorkerSchemes.add("https"); |
| 130 } | 124 } |
| 131 | 125 |
| 132 return serviceWorkerSchemes; | 126 return serviceWorkerSchemes; |
| 133 } | 127 } |
| 134 | 128 |
| 135 static URLSchemesSet& fetchAPISchemes() { | 129 static URLSchemesSet& fetchAPISchemes() { |
| 136 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, fetchAPISchemes, ()); | 130 DEFINE_STATIC_LOCAL(URLSchemesSet, fetchAPISchemes, ()); |
| 137 | 131 |
| 138 if (fetchAPISchemes.isEmpty()) { | 132 if (fetchAPISchemes.isEmpty()) { |
| 139 fetchAPISchemes.add("http"); | 133 fetchAPISchemes.add("http"); |
| 140 fetchAPISchemes.add("https"); | 134 fetchAPISchemes.add("https"); |
| 141 } | 135 } |
| 142 | 136 |
| 143 return fetchAPISchemes; | 137 return fetchAPISchemes; |
| 144 } | 138 } |
| 145 | 139 |
| 146 static URLSchemesSet& firstPartyWhenTopLevelSchemes() { | 140 static URLSchemesSet& firstPartyWhenTopLevelSchemes() { |
| 147 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, firstPartyWhenTopLevelSchemes, | 141 DEFINE_STATIC_LOCAL(URLSchemesSet, firstPartyWhenTopLevelSchemes, ()); |
| 148 ()); | |
| 149 return firstPartyWhenTopLevelSchemes; | 142 return firstPartyWhenTopLevelSchemes; |
| 150 } | 143 } |
| 151 | 144 |
| 152 static URLSchemesMap<SchemeRegistry::PolicyAreas>& | 145 static URLSchemesMap<SchemeRegistry::PolicyAreas>& |
| 153 ContentSecurityPolicyBypassingSchemes() { | 146 ContentSecurityPolicyBypassingSchemes() { |
| 154 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesMap<SchemeRegistry::PolicyAreas>, | 147 DEFINE_STATIC_LOCAL(URLSchemesMap<SchemeRegistry::PolicyAreas>, schemes, ()); |
| 155 schemes, ()); | |
| 156 return schemes; | 148 return schemes; |
| 157 } | 149 } |
| 158 | 150 |
| 159 static URLSchemesSet& secureContextBypassingSchemes() { | 151 static URLSchemesSet& secureContextBypassingSchemes() { |
| 160 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, secureContextBypassingSchemes, | 152 DEFINE_STATIC_LOCAL(URLSchemesSet, secureContextBypassingSchemes, ()); |
| 161 ()); | |
| 162 return secureContextBypassingSchemes; | 153 return secureContextBypassingSchemes; |
| 163 } | 154 } |
| 164 | 155 |
| 165 static URLSchemesSet& allowedInReferrerSchemes() { | 156 static URLSchemesSet& allowedInReferrerSchemes() { |
| 166 DEFINE_STATIC_LOCAL_WITH_LOCK(URLSchemesSet, allowedInReferrerSchemes, ()); | 157 DEFINE_STATIC_LOCAL(URLSchemesSet, allowedInReferrerSchemes, ()); |
| 167 | 158 |
| 168 if (allowedInReferrerSchemes.isEmpty()) { | 159 if (allowedInReferrerSchemes.isEmpty()) { |
| 169 allowedInReferrerSchemes.add("http"); | 160 allowedInReferrerSchemes.add("http"); |
| 170 allowedInReferrerSchemes.add("https"); | 161 allowedInReferrerSchemes.add("https"); |
| 171 } | 162 } |
| 172 | 163 |
| 173 return allowedInReferrerSchemes; | 164 return allowedInReferrerSchemes; |
| 174 } | 165 } |
| 175 | 166 |
| 167 // All new maps should be added here. Must be called before we create other |
| 168 // threads to avoid racy static local initialization. |
| 176 void SchemeRegistry::initialize() { | 169 void SchemeRegistry::initialize() { |
| 177 // Instantiate the mutex object. | 170 localURLSchemes(); |
| 178 mutex(); | 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(); |
| 179 } | 184 } |
| 180 | 185 |
| 181 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme) { | 186 bool SchemeRegistry::shouldTreatURLSchemeAsLocal(const String& scheme) { |
| 182 DCHECK_EQ(scheme, scheme.lower()); | 187 DCHECK_EQ(scheme, scheme.lower()); |
| 183 if (scheme.isEmpty()) | 188 if (scheme.isEmpty()) |
| 184 return false; | 189 return false; |
| 185 MutexLocker locker(mutex()); | |
| 186 return localURLSchemes().contains(scheme); | 190 return localURLSchemes().contains(scheme); |
| 187 } | 191 } |
| 188 | 192 |
| 189 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme) { | 193 void SchemeRegistry::registerURLSchemeAsNoAccess(const String& scheme) { |
| 194 checkIsBeforeThreadCreated(); |
| 190 DCHECK_EQ(scheme, scheme.lower()); | 195 DCHECK_EQ(scheme, scheme.lower()); |
| 191 MutexLocker locker(mutex()); | |
| 192 schemesWithUniqueOrigins().add(scheme); | 196 schemesWithUniqueOrigins().add(scheme); |
| 193 } | 197 } |
| 194 | 198 |
| 195 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme) { | 199 bool SchemeRegistry::shouldTreatURLSchemeAsNoAccess(const String& scheme) { |
| 196 DCHECK_EQ(scheme, scheme.lower()); | 200 DCHECK_EQ(scheme, scheme.lower()); |
| 197 if (scheme.isEmpty()) | 201 if (scheme.isEmpty()) |
| 198 return false; | 202 return false; |
| 199 MutexLocker locker(mutex()); | |
| 200 return schemesWithUniqueOrigins().contains(scheme); | 203 return schemesWithUniqueOrigins().contains(scheme); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme) { | 206 void SchemeRegistry::registerURLSchemeAsDisplayIsolated(const String& scheme) { |
| 207 checkIsBeforeThreadCreated(); |
| 204 DCHECK_EQ(scheme, scheme.lower()); | 208 DCHECK_EQ(scheme, scheme.lower()); |
| 205 MutexLocker locker(mutex()); | |
| 206 displayIsolatedURLSchemes().add(scheme); | 209 displayIsolatedURLSchemes().add(scheme); |
| 207 } | 210 } |
| 208 | 211 |
| 209 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated( | 212 bool SchemeRegistry::shouldTreatURLSchemeAsDisplayIsolated( |
| 210 const String& scheme) { | 213 const String& scheme) { |
| 211 DCHECK_EQ(scheme, scheme.lower()); | 214 DCHECK_EQ(scheme, scheme.lower()); |
| 212 if (scheme.isEmpty()) | 215 if (scheme.isEmpty()) |
| 213 return false; | 216 return false; |
| 214 MutexLocker locker(mutex()); | |
| 215 return displayIsolatedURLSchemes().contains(scheme); | 217 return displayIsolatedURLSchemes().contains(scheme); |
| 216 } | 218 } |
| 217 | 219 |
| 218 bool SchemeRegistry::shouldTreatURLSchemeAsRestrictingMixedContent( | 220 bool SchemeRegistry::shouldTreatURLSchemeAsRestrictingMixedContent( |
| 219 const String& scheme) { | 221 const String& scheme) { |
| 220 DCHECK_EQ(scheme, scheme.lower()); | 222 DCHECK_EQ(scheme, scheme.lower()); |
| 221 return scheme == "https"; | 223 return scheme == "https"; |
| 222 } | 224 } |
| 223 | 225 |
| 224 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme) { | 226 void SchemeRegistry::registerURLSchemeAsSecure(const String& scheme) { |
| 227 checkIsBeforeThreadCreated(); |
| 225 DCHECK_EQ(scheme, scheme.lower()); | 228 DCHECK_EQ(scheme, scheme.lower()); |
| 226 MutexLocker locker(mutex()); | |
| 227 secureSchemes().add(scheme); | 229 secureSchemes().add(scheme); |
| 228 } | 230 } |
| 229 | 231 |
| 230 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme) { | 232 bool SchemeRegistry::shouldTreatURLSchemeAsSecure(const String& scheme) { |
| 231 DCHECK_EQ(scheme, scheme.lower()); | 233 DCHECK_EQ(scheme, scheme.lower()); |
| 232 if (scheme.isEmpty()) | 234 if (scheme.isEmpty()) |
| 233 return false; | 235 return false; |
| 234 MutexLocker locker(mutex()); | |
| 235 return secureSchemes().contains(scheme); | 236 return secureSchemes().contains(scheme); |
| 236 } | 237 } |
| 237 | 238 |
| 238 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme) { | 239 void SchemeRegistry::registerURLSchemeAsEmptyDocument(const String& scheme) { |
| 240 checkIsBeforeThreadCreated(); |
| 239 DCHECK_EQ(scheme, scheme.lower()); | 241 DCHECK_EQ(scheme, scheme.lower()); |
| 240 MutexLocker locker(mutex()); | |
| 241 emptyDocumentSchemes().add(scheme); | 242 emptyDocumentSchemes().add(scheme); |
| 242 } | 243 } |
| 243 | 244 |
| 244 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme) { | 245 bool SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(const String& scheme) { |
| 245 DCHECK_EQ(scheme, scheme.lower()); | 246 DCHECK_EQ(scheme, scheme.lower()); |
| 246 if (scheme.isEmpty()) | 247 if (scheme.isEmpty()) |
| 247 return false; | 248 return false; |
| 248 MutexLocker locker(mutex()); | |
| 249 return emptyDocumentSchemes().contains(scheme); | 249 return emptyDocumentSchemes().contains(scheme); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme( | 252 void SchemeRegistry::setDomainRelaxationForbiddenForURLScheme( |
| 253 bool forbidden, | 253 bool forbidden, |
| 254 const String& scheme) { | 254 const String& scheme) { |
| 255 checkIsBeforeThreadCreated(); |
| 255 DCHECK_EQ(scheme, scheme.lower()); | 256 DCHECK_EQ(scheme, scheme.lower()); |
| 256 if (scheme.isEmpty()) | 257 if (scheme.isEmpty()) |
| 257 return; | 258 return; |
| 258 | 259 |
| 259 MutexLocker locker(mutex()); | |
| 260 if (forbidden) | 260 if (forbidden) |
| 261 schemesForbiddenFromDomainRelaxation().add(scheme); | 261 schemesForbiddenFromDomainRelaxation().add(scheme); |
| 262 else | 262 else |
| 263 schemesForbiddenFromDomainRelaxation().remove(scheme); | 263 schemesForbiddenFromDomainRelaxation().remove(scheme); |
| 264 } | 264 } |
| 265 | 265 |
| 266 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme( | 266 bool SchemeRegistry::isDomainRelaxationForbiddenForURLScheme( |
| 267 const String& scheme) { | 267 const String& scheme) { |
| 268 DCHECK_EQ(scheme, scheme.lower()); | 268 DCHECK_EQ(scheme, scheme.lower()); |
| 269 if (scheme.isEmpty()) | 269 if (scheme.isEmpty()) |
| 270 return false; | 270 return false; |
| 271 MutexLocker locker(mutex()); | |
| 272 return schemesForbiddenFromDomainRelaxation().contains(scheme); | 271 return schemesForbiddenFromDomainRelaxation().contains(scheme); |
| 273 } | 272 } |
| 274 | 273 |
| 275 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme) { | 274 bool SchemeRegistry::canDisplayOnlyIfCanRequest(const String& scheme) { |
| 276 DCHECK_EQ(scheme, scheme.lower()); | 275 DCHECK_EQ(scheme, scheme.lower()); |
| 277 return scheme == "blob" || scheme == "filesystem"; | 276 return scheme == "blob" || scheme == "filesystem"; |
| 278 } | 277 } |
| 279 | 278 |
| 280 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs( | 279 void SchemeRegistry::registerURLSchemeAsNotAllowingJavascriptURLs( |
| 281 const String& scheme) { | 280 const String& scheme) { |
| 281 checkIsBeforeThreadCreated(); |
| 282 DCHECK_EQ(scheme, scheme.lower()); | 282 DCHECK_EQ(scheme, scheme.lower()); |
| 283 MutexLocker locker(mutex()); | |
| 284 notAllowingJavascriptURLsSchemes().add(scheme); | 283 notAllowingJavascriptURLsSchemes().add(scheme); |
| 285 } | 284 } |
| 286 | 285 |
| 287 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs( | 286 bool SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs( |
| 288 const String& scheme) { | 287 const String& scheme) { |
| 289 DCHECK_EQ(scheme, scheme.lower()); | 288 DCHECK_EQ(scheme, scheme.lower()); |
| 290 if (scheme.isEmpty()) | 289 if (scheme.isEmpty()) |
| 291 return false; | 290 return false; |
| 292 MutexLocker locker(mutex()); | |
| 293 return notAllowingJavascriptURLsSchemes().contains(scheme); | 291 return notAllowingJavascriptURLsSchemes().contains(scheme); |
| 294 } | 292 } |
| 295 | 293 |
| 296 void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme) { | 294 void SchemeRegistry::registerURLSchemeAsCORSEnabled(const String& scheme) { |
| 295 checkIsBeforeThreadCreated(); |
| 297 DCHECK_EQ(scheme, scheme.lower()); | 296 DCHECK_EQ(scheme, scheme.lower()); |
| 298 MutexLocker locker(mutex()); | |
| 299 CORSEnabledSchemes().add(scheme); | 297 CORSEnabledSchemes().add(scheme); |
| 300 } | 298 } |
| 301 | 299 |
| 302 bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme) { | 300 bool SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(const String& scheme) { |
| 303 DCHECK_EQ(scheme, scheme.lower()); | 301 DCHECK_EQ(scheme, scheme.lower()); |
| 304 if (scheme.isEmpty()) | 302 if (scheme.isEmpty()) |
| 305 return false; | 303 return false; |
| 306 MutexLocker locker(mutex()); | |
| 307 return CORSEnabledSchemes().contains(scheme); | 304 return CORSEnabledSchemes().contains(scheme); |
| 308 } | 305 } |
| 309 | 306 |
| 310 String SchemeRegistry::listOfCORSEnabledURLSchemes() { | 307 String SchemeRegistry::listOfCORSEnabledURLSchemes() { |
| 311 StringBuilder builder; | 308 StringBuilder builder; |
| 312 bool addSeparator = false; | 309 bool addSeparator = false; |
| 313 URLSchemesSet schemes; | 310 for (const auto& scheme : CORSEnabledSchemes()) { |
| 314 { | |
| 315 MutexLocker locker(mutex()); | |
| 316 schemes = CORSEnabledSchemes(); | |
| 317 } | |
| 318 for (const auto& scheme : schemes) { | |
| 319 if (addSeparator) | 311 if (addSeparator) |
| 320 builder.append(", "); | 312 builder.append(", "); |
| 321 else | 313 else |
| 322 addSeparator = true; | 314 addSeparator = true; |
| 323 | 315 |
| 324 builder.append(scheme); | 316 builder.append(scheme); |
| 325 } | 317 } |
| 326 return builder.toString(); | 318 return builder.toString(); |
| 327 } | 319 } |
| 328 | 320 |
| 329 bool SchemeRegistry::shouldTreatURLSchemeAsLegacy(const String& scheme) { | 321 bool SchemeRegistry::shouldTreatURLSchemeAsLegacy(const String& scheme) { |
| 330 return scheme == "ftp" || scheme == "gopher"; | 322 return scheme == "ftp" || scheme == "gopher"; |
| 331 } | 323 } |
| 332 | 324 |
| 333 void SchemeRegistry::registerURLSchemeAsAllowingServiceWorkers( | 325 void SchemeRegistry::registerURLSchemeAsAllowingServiceWorkers( |
| 334 const String& scheme) { | 326 const String& scheme) { |
| 327 checkIsBeforeThreadCreated(); |
| 335 DCHECK_EQ(scheme, scheme.lower()); | 328 DCHECK_EQ(scheme, scheme.lower()); |
| 336 MutexLocker locker(mutex()); | |
| 337 serviceWorkerSchemes().add(scheme); | 329 serviceWorkerSchemes().add(scheme); |
| 338 } | 330 } |
| 339 | 331 |
| 340 bool SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( | 332 bool SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( |
| 341 const String& scheme) { | 333 const String& scheme) { |
| 342 DCHECK_EQ(scheme, scheme.lower()); | 334 DCHECK_EQ(scheme, scheme.lower()); |
| 343 if (scheme.isEmpty()) | 335 if (scheme.isEmpty()) |
| 344 return false; | 336 return false; |
| 345 MutexLocker locker(mutex()); | |
| 346 return serviceWorkerSchemes().contains(scheme); | 337 return serviceWorkerSchemes().contains(scheme); |
| 347 } | 338 } |
| 348 | 339 |
| 349 void SchemeRegistry::registerURLSchemeAsSupportingFetchAPI( | 340 void SchemeRegistry::registerURLSchemeAsSupportingFetchAPI( |
| 350 const String& scheme) { | 341 const String& scheme) { |
| 342 checkIsBeforeThreadCreated(); |
| 351 DCHECK_EQ(scheme, scheme.lower()); | 343 DCHECK_EQ(scheme, scheme.lower()); |
| 352 MutexLocker locker(mutex()); | |
| 353 fetchAPISchemes().add(scheme); | 344 fetchAPISchemes().add(scheme); |
| 354 } | 345 } |
| 355 | 346 |
| 356 bool SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI( | 347 bool SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI( |
| 357 const String& scheme) { | 348 const String& scheme) { |
| 358 DCHECK_EQ(scheme, scheme.lower()); | 349 DCHECK_EQ(scheme, scheme.lower()); |
| 359 if (scheme.isEmpty()) | 350 if (scheme.isEmpty()) |
| 360 return false; | 351 return false; |
| 361 MutexLocker locker(mutex()); | |
| 362 return fetchAPISchemes().contains(scheme); | 352 return fetchAPISchemes().contains(scheme); |
| 363 } | 353 } |
| 364 | 354 |
| 365 void SchemeRegistry::registerURLSchemeAsFirstPartyWhenTopLevel( | 355 void SchemeRegistry::registerURLSchemeAsFirstPartyWhenTopLevel( |
| 366 const String& scheme) { | 356 const String& scheme) { |
| 357 checkIsBeforeThreadCreated(); |
| 367 DCHECK_EQ(scheme, scheme.lower()); | 358 DCHECK_EQ(scheme, scheme.lower()); |
| 368 MutexLocker locker(mutex()); | |
| 369 firstPartyWhenTopLevelSchemes().add(scheme); | 359 firstPartyWhenTopLevelSchemes().add(scheme); |
| 370 } | 360 } |
| 371 | 361 |
| 372 void SchemeRegistry::removeURLSchemeAsFirstPartyWhenTopLevel( | 362 void SchemeRegistry::removeURLSchemeAsFirstPartyWhenTopLevel( |
| 373 const String& scheme) { | 363 const String& scheme) { |
| 364 checkIsBeforeThreadCreated(); |
| 374 DCHECK_EQ(scheme, scheme.lower()); | 365 DCHECK_EQ(scheme, scheme.lower()); |
| 375 MutexLocker locker(mutex()); | |
| 376 firstPartyWhenTopLevelSchemes().remove(scheme); | 366 firstPartyWhenTopLevelSchemes().remove(scheme); |
| 377 } | 367 } |
| 378 | 368 |
| 379 bool SchemeRegistry::shouldTreatURLSchemeAsFirstPartyWhenTopLevel( | 369 bool SchemeRegistry::shouldTreatURLSchemeAsFirstPartyWhenTopLevel( |
| 380 const String& scheme) { | 370 const String& scheme) { |
| 381 DCHECK_EQ(scheme, scheme.lower()); | 371 DCHECK_EQ(scheme, scheme.lower()); |
| 382 if (scheme.isEmpty()) | 372 if (scheme.isEmpty()) |
| 383 return false; | 373 return false; |
| 384 MutexLocker locker(mutex()); | |
| 385 return firstPartyWhenTopLevelSchemes().contains(scheme); | 374 return firstPartyWhenTopLevelSchemes().contains(scheme); |
| 386 } | 375 } |
| 387 | 376 |
| 388 void SchemeRegistry::registerURLSchemeAsAllowedForReferrer( | 377 void SchemeRegistry::registerURLSchemeAsAllowedForReferrer( |
| 389 const String& scheme) { | 378 const String& scheme) { |
| 379 checkIsBeforeThreadCreated(); |
| 390 DCHECK_EQ(scheme, scheme.lower()); | 380 DCHECK_EQ(scheme, scheme.lower()); |
| 391 MutexLocker locker(mutex()); | |
| 392 allowedInReferrerSchemes().add(scheme); | 381 allowedInReferrerSchemes().add(scheme); |
| 393 } | 382 } |
| 394 | 383 |
| 395 void SchemeRegistry::removeURLSchemeAsAllowedForReferrer(const String& scheme) { | 384 void SchemeRegistry::removeURLSchemeAsAllowedForReferrer(const String& scheme) { |
| 396 MutexLocker locker(mutex()); | 385 checkIsBeforeThreadCreated(); |
| 397 allowedInReferrerSchemes().remove(scheme); | 386 allowedInReferrerSchemes().remove(scheme); |
| 398 } | 387 } |
| 399 | 388 |
| 400 bool SchemeRegistry::shouldTreatURLSchemeAsAllowedForReferrer( | 389 bool SchemeRegistry::shouldTreatURLSchemeAsAllowedForReferrer( |
| 401 const String& scheme) { | 390 const String& scheme) { |
| 402 DCHECK_EQ(scheme, scheme.lower()); | 391 DCHECK_EQ(scheme, scheme.lower()); |
| 403 if (scheme.isEmpty()) | 392 if (scheme.isEmpty()) |
| 404 return false; | 393 return false; |
| 405 MutexLocker locker(mutex()); | |
| 406 return allowedInReferrerSchemes().contains(scheme); | 394 return allowedInReferrerSchemes().contains(scheme); |
| 407 } | 395 } |
| 408 | 396 |
| 409 void SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy( | 397 void SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy( |
| 410 const String& scheme, | 398 const String& scheme, |
| 411 PolicyAreas policyAreas) { | 399 PolicyAreas policyAreas) { |
| 400 checkIsBeforeThreadCreated(); |
| 412 DCHECK_EQ(scheme, scheme.lower()); | 401 DCHECK_EQ(scheme, scheme.lower()); |
| 413 MutexLocker locker(mutex()); | |
| 414 ContentSecurityPolicyBypassingSchemes().add(scheme, policyAreas); | 402 ContentSecurityPolicyBypassingSchemes().add(scheme, policyAreas); |
| 415 } | 403 } |
| 416 | 404 |
| 417 void SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy( | 405 void SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy( |
| 418 const String& scheme) { | 406 const String& scheme) { |
| 407 checkIsBeforeThreadCreated(); |
| 419 DCHECK_EQ(scheme, scheme.lower()); | 408 DCHECK_EQ(scheme, scheme.lower()); |
| 420 MutexLocker locker(mutex()); | |
| 421 ContentSecurityPolicyBypassingSchemes().remove(scheme); | 409 ContentSecurityPolicyBypassingSchemes().remove(scheme); |
| 422 } | 410 } |
| 423 | 411 |
| 424 bool SchemeRegistry::schemeShouldBypassContentSecurityPolicy( | 412 bool SchemeRegistry::schemeShouldBypassContentSecurityPolicy( |
| 425 const String& scheme, | 413 const String& scheme, |
| 426 PolicyAreas policyAreas) { | 414 PolicyAreas policyAreas) { |
| 427 ASSERT(policyAreas != PolicyAreaNone); | 415 ASSERT(policyAreas != PolicyAreaNone); |
| 428 if (scheme.isEmpty() || policyAreas == PolicyAreaNone) | 416 if (scheme.isEmpty() || policyAreas == PolicyAreaNone) |
| 429 return false; | 417 return false; |
| 430 | 418 |
| 431 // get() returns 0 (PolicyAreaNone) if there is no entry in the map. | 419 // get() returns 0 (PolicyAreaNone) if there is no entry in the map. |
| 432 // Thus by default, schemes do not bypass CSP. | 420 // Thus by default, schemes do not bypass CSP. |
| 433 MutexLocker locker(mutex()); | |
| 434 return (ContentSecurityPolicyBypassingSchemes().get(scheme) & policyAreas) == | 421 return (ContentSecurityPolicyBypassingSchemes().get(scheme) & policyAreas) == |
| 435 policyAreas; | 422 policyAreas; |
| 436 } | 423 } |
| 437 | 424 |
| 438 void SchemeRegistry::registerURLSchemeBypassingSecureContextCheck( | 425 void SchemeRegistry::registerURLSchemeBypassingSecureContextCheck( |
| 439 const String& scheme) { | 426 const String& scheme) { |
| 427 checkIsBeforeThreadCreated(); |
| 440 DCHECK_EQ(scheme, scheme.lower()); | 428 DCHECK_EQ(scheme, scheme.lower()); |
| 441 MutexLocker locker(mutex()); | |
| 442 secureContextBypassingSchemes().add(scheme.lower()); | 429 secureContextBypassingSchemes().add(scheme.lower()); |
| 443 } | 430 } |
| 444 | 431 |
| 445 bool SchemeRegistry::schemeShouldBypassSecureContextCheck( | 432 bool SchemeRegistry::schemeShouldBypassSecureContextCheck( |
| 446 const String& scheme) { | 433 const String& scheme) { |
| 447 if (scheme.isEmpty()) | 434 if (scheme.isEmpty()) |
| 448 return false; | 435 return false; |
| 449 MutexLocker locker(mutex()); | |
| 450 return secureContextBypassingSchemes().contains(scheme.lower()); | 436 return secureContextBypassingSchemes().contains(scheme.lower()); |
| 451 } | 437 } |
| 452 | 438 |
| 453 } // namespace blink | 439 } // namespace blink |
| OLD | NEW |