| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 , m_port(url.port()) | 122 , m_port(url.port()) |
| 123 , m_effectivePort(url.port() ? url.port() : defaultPortForProtocol(m_protoco
l)) | 123 , m_effectivePort(url.port() ? url.port() : defaultPortForProtocol(m_protoco
l)) |
| 124 , m_isUnique(false) | 124 , m_isUnique(false) |
| 125 , m_universalAccess(false) | 125 , m_universalAccess(false) |
| 126 , m_domainWasSetInDOM(false) | 126 , m_domainWasSetInDOM(false) |
| 127 , m_blockLocalAccessFromLocalOrigin(false) | 127 , m_blockLocalAccessFromLocalOrigin(false) |
| 128 , m_isUniqueOriginPotentiallyTrustworthy(false) | 128 , m_isUniqueOriginPotentiallyTrustworthy(false) |
| 129 { | 129 { |
| 130 // Suborigins are serialized into the host, so extract it if necessary. | 130 // Suborigins are serialized into the host, so extract it if necessary. |
| 131 String suboriginName; | 131 String suboriginName; |
| 132 if (deserializeSuboriginAndHost(m_host, suboriginName, m_host)) | 132 if (deserializeSuboriginAndProtocolAndHost(m_protocol, m_host, suboriginName
, m_protocol, m_host)) |
| 133 m_suborigin.setName(suboriginName); | 133 m_suborigin.setName(suboriginName); |
| 134 | 134 |
| 135 // document.domain starts as m_host, but can be set by the DOM. | 135 // document.domain starts as m_host, but can be set by the DOM. |
| 136 m_domain = m_host; | 136 m_domain = m_host; |
| 137 | 137 |
| 138 if (isDefaultPortForProtocol(m_port, m_protocol)) | 138 if (isDefaultPortForProtocol(m_port, m_protocol)) |
| 139 m_port = InvalidPort; | 139 m_port = InvalidPort; |
| 140 | 140 |
| 141 // By default, only local SecurityOrigins can load local resources. | 141 // By default, only local SecurityOrigins can load local resources. |
| 142 m_canLoadLocalResources = isLocal(); | 142 m_canLoadLocalResources = isLocal(); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 if (m_protocol == "file") | 466 if (m_protocol == "file") |
| 467 return "file://"; | 467 return "file://"; |
| 468 | 468 |
| 469 StringBuilder result; | 469 StringBuilder result; |
| 470 buildRawString(result, false); | 470 buildRawString(result, false); |
| 471 return result.toString(); | 471 return result.toString(); |
| 472 } | 472 } |
| 473 | 473 |
| 474 // Returns true if and only if a suborigin component was found. If false, no | 474 // Returns true if and only if a suborigin component was found. If false, no |
| 475 // guarantees about the return value |suboriginName| are made. | 475 // guarantees about the return value |suboriginName| are made. |
| 476 bool SecurityOrigin::deserializeSuboriginAndHost(const String& oldHost, String&
suboriginName, String& newHost) | 476 bool SecurityOrigin::deserializeSuboriginAndProtocolAndHost(const String& oldPro
tocol, const String& oldHost, String& suboriginName, String& newProtocol, String
& newHost) |
| 477 { | 477 { |
| 478 if (!RuntimeEnabledFeatures::suboriginsEnabled()) | 478 if (!RuntimeEnabledFeatures::suboriginsEnabled()) |
| 479 return false; | 479 return false; |
| 480 | 480 |
| 481 size_t suboriginEnd = oldHost.find('_'); | 481 String originalProtocol = oldProtocol; |
| 482 // Suborigins cannot be empty | 482 // Suborigin URLs must have the -so option in the scheme. |
| 483 if (suboriginEnd == 0 || suboriginEnd == WTF::kNotFound) | 483 if (!oldProtocol.endsWith("-so")) |
| 484 return false; | 484 return false; |
| 485 | 485 |
| 486 size_t protocolEnd = oldProtocol.reverseFind("-so"); |
| 487 DCHECK_NE(protocolEnd, WTF::kNotFound); |
| 488 newProtocol = oldProtocol.substring(0, protocolEnd); |
| 489 |
| 490 size_t suboriginEnd = oldHost.find('.'); |
| 491 // Suborigins cannot be empty. |
| 492 if (suboriginEnd == 0 || suboriginEnd == WTF::kNotFound) { |
| 493 newProtocol = originalProtocol; |
| 494 return false; |
| 495 } |
| 496 |
| 486 suboriginName = oldHost.substring(0, suboriginEnd); | 497 suboriginName = oldHost.substring(0, suboriginEnd); |
| 487 newHost = oldHost.substring(suboriginEnd + 1); | 498 newHost = oldHost.substring(suboriginEnd + 1); |
| 488 | 499 |
| 489 return true; | 500 return true; |
| 490 } | 501 } |
| 491 | 502 |
| 492 | 503 |
| 493 AtomicString SecurityOrigin::toRawAtomicString() const | 504 AtomicString SecurityOrigin::toRawAtomicString() const |
| 494 { | 505 { |
| 495 if (m_protocol == "file") | 506 if (m_protocol == "file") |
| 496 return AtomicString("file://"); | 507 return AtomicString("file://"); |
| 497 | 508 |
| 498 StringBuilder result; | 509 StringBuilder result; |
| 499 buildRawString(result, true); | 510 buildRawString(result, true); |
| 500 return result.toAtomicString(); | 511 return result.toAtomicString(); |
| 501 } | 512 } |
| 502 | 513 |
| 503 void SecurityOrigin::buildRawString(StringBuilder& builder, bool includeSuborigi
n) const | 514 void SecurityOrigin::buildRawString(StringBuilder& builder, bool includeSuborigi
n) const |
| 504 { | 515 { |
| 505 builder.append(m_protocol); | 516 builder.append(m_protocol); |
| 506 builder.append("://"); | |
| 507 if (includeSuborigin && hasSuborigin()) { | 517 if (includeSuborigin && hasSuborigin()) { |
| 518 builder.append("-so://"); |
| 508 builder.append(m_suborigin.name()); | 519 builder.append(m_suborigin.name()); |
| 509 builder.append('_'); | 520 builder.append('.'); |
| 521 } else { |
| 522 builder.append("://"); |
| 510 } | 523 } |
| 511 builder.append(m_host); | 524 builder.append(m_host); |
| 512 | 525 |
| 513 if (m_port) { | 526 if (m_port) { |
| 514 builder.append(':'); | 527 builder.append(':'); |
| 515 builder.appendNumber(m_port); | 528 builder.appendNumber(m_port); |
| 516 } | 529 } |
| 517 } | 530 } |
| 518 | 531 |
| 519 PassRefPtr<SecurityOrigin> SecurityOrigin::createFromString(const String& origin
String) | 532 PassRefPtr<SecurityOrigin> SecurityOrigin::createFromString(const String& origin
String) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 m_blockLocalAccessFromLocalOrigin = privilegeData->m_blockLocalAccessFromLoc
alOrigin; | 597 m_blockLocalAccessFromLocalOrigin = privilegeData->m_blockLocalAccessFromLoc
alOrigin; |
| 585 } | 598 } |
| 586 | 599 |
| 587 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy(bool isUniqueOrigin
PotentiallyTrustworthy) | 600 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy(bool isUniqueOrigin
PotentiallyTrustworthy) |
| 588 { | 601 { |
| 589 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique()); | 602 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique()); |
| 590 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworth
y; | 603 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworth
y; |
| 591 } | 604 } |
| 592 | 605 |
| 593 } // namespace blink | 606 } // namespace blink |
| OLD | NEW |