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