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