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