| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "platform/weborigin/SecurityOrigin.h" | 29 #include "platform/weborigin/SecurityOrigin.h" |
| 30 | 30 |
| 31 #include "platform/RuntimeEnabledFeatures.h" | 31 #include "platform/RuntimeEnabledFeatures.h" |
| 32 #include "platform/weborigin/KURL.h" | 32 #include "platform/weborigin/KURL.h" |
| 33 #include "platform/weborigin/KnownPorts.h" | 33 #include "platform/weborigin/KnownPorts.h" |
| 34 #include "platform/weborigin/SchemeRegistry.h" | 34 #include "platform/weborigin/SchemeRegistry.h" |
| 35 #include "platform/weborigin/SecurityOriginCache.h" | |
| 36 #include "platform/weborigin/SecurityPolicy.h" | 35 #include "platform/weborigin/SecurityPolicy.h" |
| 36 #include "platform/weborigin/URLSecurityOriginMap.h" |
| 37 #include "url/url_canon_ip.h" | 37 #include "url/url_canon_ip.h" |
| 38 #include "wtf/HexNumber.h" | 38 #include "wtf/HexNumber.h" |
| 39 #include "wtf/NotFound.h" | 39 #include "wtf/NotFound.h" |
| 40 #include "wtf/PtrUtil.h" | 40 #include "wtf/PtrUtil.h" |
| 41 #include "wtf/StdLibExtras.h" | 41 #include "wtf/StdLibExtras.h" |
| 42 #include "wtf/text/StringBuilder.h" | 42 #include "wtf/text/StringBuilder.h" |
| 43 #include <memory> | 43 #include <memory> |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 const int InvalidPort = 0; | 47 const int InvalidPort = 0; |
| 48 const int MaxAllowedPort = 65535; | 48 const int MaxAllowedPort = 65535; |
| 49 | 49 |
| 50 static SecurityOriginCache* s_originCache = 0; | 50 static URLSecurityOriginMap* s_urlOriginMap = 0; |
| 51 | 51 |
| 52 static SecurityOrigin* cachedOrigin(const KURL& url) | 52 static SecurityOrigin* getOriginFromMap(const KURL& url) |
| 53 { | 53 { |
| 54 if (s_originCache) | 54 if (s_urlOriginMap) |
| 55 return s_originCache->cachedOrigin(url); | 55 return s_urlOriginMap->getOrigin(url); |
| 56 return 0; | 56 return nullptr; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool SecurityOrigin::shouldUseInnerURL(const KURL& url) | 59 bool SecurityOrigin::shouldUseInnerURL(const KURL& url) |
| 60 { | 60 { |
| 61 // FIXME: Blob URLs don't have inner URLs. Their form is "blob:<inner-origin
>/<UUID>", so treating the part after "blob:" as a URL is incorrect. | 61 // FIXME: Blob URLs don't have inner URLs. Their form is "blob:<inner-origin
>/<UUID>", so treating the part after "blob:" as a URL is incorrect. |
| 62 if (url.protocolIs("blob")) | 62 if (url.protocolIs("blob")) |
| 63 return true; | 63 return true; |
| 64 if (url.protocolIs("filesystem")) | 64 if (url.protocolIs("filesystem")) |
| 65 return true; | 65 return true; |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // In general, extracting the inner URL varies by scheme. It just so happens | 69 // In general, extracting the inner URL varies by scheme. It just so happens |
| 70 // that all the URL schemes we currently support that use inner URLs for their | 70 // that all the URL schemes we currently support that use inner URLs for their |
| 71 // security origin can be parsed using this algorithm. | 71 // security origin can be parsed using this algorithm. |
| 72 KURL SecurityOrigin::extractInnerURL(const KURL& url) | 72 KURL SecurityOrigin::extractInnerURL(const KURL& url) |
| 73 { | 73 { |
| 74 if (url.innerURL()) | 74 if (url.innerURL()) |
| 75 return *url.innerURL(); | 75 return *url.innerURL(); |
| 76 // FIXME: Update this callsite to use the innerURL member function when | 76 // FIXME: Update this callsite to use the innerURL member function when |
| 77 // we finish implementing it. | 77 // we finish implementing it. |
| 78 return KURL(ParsedURLString, url.path()); | 78 return KURL(ParsedURLString, url.path()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void SecurityOrigin::setCache(SecurityOriginCache* originCache) | 81 void SecurityOrigin::setMap(URLSecurityOriginMap* map) |
| 82 { | 82 { |
| 83 s_originCache = originCache; | 83 s_urlOriginMap = map; |
| 84 } | 84 } |
| 85 | 85 |
| 86 static bool shouldTreatAsUniqueOrigin(const KURL& url) | 86 static bool shouldTreatAsUniqueOrigin(const KURL& url) |
| 87 { | 87 { |
| 88 if (!url.isValid()) | 88 if (!url.isValid()) |
| 89 return true; | 89 return true; |
| 90 | 90 |
| 91 // FIXME: Do we need to unwrap the URL further? | 91 // FIXME: Do we need to unwrap the URL further? |
| 92 KURL relevantURL; | 92 KURL relevantURL; |
| 93 if (SecurityOrigin::shouldUseInnerURL(url)) { | 93 if (SecurityOrigin::shouldUseInnerURL(url)) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 , m_universalAccess(other->m_universalAccess) | 168 , m_universalAccess(other->m_universalAccess) |
| 169 , m_domainWasSetInDOM(other->m_domainWasSetInDOM) | 169 , m_domainWasSetInDOM(other->m_domainWasSetInDOM) |
| 170 , m_canLoadLocalResources(other->m_canLoadLocalResources) | 170 , m_canLoadLocalResources(other->m_canLoadLocalResources) |
| 171 , m_blockLocalAccessFromLocalOrigin(other->m_blockLocalAccessFromLocalOrigin
) | 171 , m_blockLocalAccessFromLocalOrigin(other->m_blockLocalAccessFromLocalOrigin
) |
| 172 , m_isUniqueOriginPotentiallyTrustworthy(other->m_isUniqueOriginPotentiallyT
rustworthy) | 172 , m_isUniqueOriginPotentiallyTrustworthy(other->m_isUniqueOriginPotentiallyT
rustworthy) |
| 173 { | 173 { |
| 174 } | 174 } |
| 175 | 175 |
| 176 PassRefPtr<SecurityOrigin> SecurityOrigin::create(const KURL& url) | 176 PassRefPtr<SecurityOrigin> SecurityOrigin::create(const KURL& url) |
| 177 { | 177 { |
| 178 if (RefPtr<SecurityOrigin> origin = cachedOrigin(url)) | 178 if (RefPtr<SecurityOrigin> origin = getOriginFromMap(url)) |
| 179 return origin.release(); | 179 return origin.release(); |
| 180 | 180 |
| 181 if (shouldTreatAsUniqueOrigin(url)) { | 181 if (shouldTreatAsUniqueOrigin(url)) { |
| 182 RefPtr<SecurityOrigin> origin = adoptRef(new SecurityOrigin()); | 182 RefPtr<SecurityOrigin> origin = adoptRef(new SecurityOrigin()); |
| 183 return origin.release(); | 183 return origin.release(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 if (shouldUseInnerURL(url)) | 186 if (shouldUseInnerURL(url)) |
| 187 return adoptRef(new SecurityOrigin(extractInnerURL(url))); | 187 return adoptRef(new SecurityOrigin(extractInnerURL(url))); |
| 188 | 188 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 ASSERT(isLocal() && other->isLocal()); | 274 ASSERT(isLocal() && other->isLocal()); |
| 275 | 275 |
| 276 return !m_blockLocalAccessFromLocalOrigin && !other->m_blockLocalAccessFromL
ocalOrigin; | 276 return !m_blockLocalAccessFromLocalOrigin && !other->m_blockLocalAccessFromL
ocalOrigin; |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool SecurityOrigin::canRequest(const KURL& url) const | 279 bool SecurityOrigin::canRequest(const KURL& url) const |
| 280 { | 280 { |
| 281 if (m_universalAccess) | 281 if (m_universalAccess) |
| 282 return true; | 282 return true; |
| 283 | 283 |
| 284 if (cachedOrigin(url) == this) | 284 if (getOriginFromMap(url) == this) |
| 285 return true; | 285 return true; |
| 286 | 286 |
| 287 if (isUnique()) | 287 if (isUnique()) |
| 288 return false; | 288 return false; |
| 289 | 289 |
| 290 RefPtr<SecurityOrigin> targetOrigin = SecurityOrigin::create(url); | 290 RefPtr<SecurityOrigin> targetOrigin = SecurityOrigin::create(url); |
| 291 | 291 |
| 292 if (targetOrigin->isUnique()) | 292 if (targetOrigin->isUnique()) |
| 293 return false; | 293 return false; |
| 294 | 294 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 m_blockLocalAccessFromLocalOrigin = privilegeData->m_blockLocalAccessFromLoc
alOrigin; | 584 m_blockLocalAccessFromLocalOrigin = privilegeData->m_blockLocalAccessFromLoc
alOrigin; |
| 585 } | 585 } |
| 586 | 586 |
| 587 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy(bool isUniqueOrigin
PotentiallyTrustworthy) | 587 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy(bool isUniqueOrigin
PotentiallyTrustworthy) |
| 588 { | 588 { |
| 589 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique()); | 589 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique()); |
| 590 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworth
y; | 590 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworth
y; |
| 591 } | 591 } |
| 592 | 592 |
| 593 } // namespace blink | 593 } // namespace blink |
| OLD | NEW |