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 if (oldProtocol != "http-so" && oldProtocol != "https-so") |
483 if (suboriginEnd == 0 || suboriginEnd == WTF::kNotFound) | |
484 return false; | 483 return false; |
485 | 484 |
| 485 size_t protocolEnd = oldProtocol.reverseFind("-so"); |
| 486 DCHECK_NE(protocolEnd, WTF::kNotFound); |
| 487 newProtocol = oldProtocol.substring(0, protocolEnd); |
| 488 |
| 489 size_t suboriginEnd = oldHost.find('.'); |
| 490 // Suborigins cannot be empty. |
| 491 if (suboriginEnd == 0 || suboriginEnd == WTF::kNotFound) { |
| 492 newProtocol = originalProtocol; |
| 493 return false; |
| 494 } |
| 495 |
486 suboriginName = oldHost.substring(0, suboriginEnd); | 496 suboriginName = oldHost.substring(0, suboriginEnd); |
487 newHost = oldHost.substring(suboriginEnd + 1); | 497 newHost = oldHost.substring(suboriginEnd + 1); |
488 | 498 |
489 return true; | 499 return true; |
490 } | 500 } |
491 | 501 |
492 | 502 |
493 AtomicString SecurityOrigin::toRawAtomicString() const | 503 AtomicString SecurityOrigin::toRawAtomicString() const |
494 { | 504 { |
495 if (m_protocol == "file") | 505 if (m_protocol == "file") |
496 return AtomicString("file://"); | 506 return AtomicString("file://"); |
497 | 507 |
498 StringBuilder result; | 508 StringBuilder result; |
499 buildRawString(result, true); | 509 buildRawString(result, true); |
500 return result.toAtomicString(); | 510 return result.toAtomicString(); |
501 } | 511 } |
502 | 512 |
503 void SecurityOrigin::buildRawString(StringBuilder& builder, bool includeSuborigi
n) const | 513 void SecurityOrigin::buildRawString(StringBuilder& builder, bool includeSuborigi
n) const |
504 { | 514 { |
505 builder.append(m_protocol); | 515 builder.append(m_protocol); |
506 builder.append("://"); | |
507 if (includeSuborigin && hasSuborigin()) { | 516 if (includeSuborigin && hasSuborigin()) { |
| 517 builder.append("-so://"); |
508 builder.append(m_suborigin.name()); | 518 builder.append(m_suborigin.name()); |
509 builder.append('_'); | 519 builder.append('.'); |
| 520 } else { |
| 521 builder.append("://"); |
510 } | 522 } |
511 builder.append(m_host); | 523 builder.append(m_host); |
512 | 524 |
513 if (m_port) { | 525 if (m_port) { |
514 builder.append(':'); | 526 builder.append(':'); |
515 builder.appendNumber(m_port); | 527 builder.appendNumber(m_port); |
516 } | 528 } |
517 } | 529 } |
518 | 530 |
519 PassRefPtr<SecurityOrigin> SecurityOrigin::createFromString(const String& origin
String) | 531 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; | 596 m_blockLocalAccessFromLocalOrigin = privilegeData->m_blockLocalAccessFromLoc
alOrigin; |
585 } | 597 } |
586 | 598 |
587 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy(bool isUniqueOrigin
PotentiallyTrustworthy) | 599 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy(bool isUniqueOrigin
PotentiallyTrustworthy) |
588 { | 600 { |
589 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique()); | 601 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique()); |
590 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworth
y; | 602 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworth
y; |
591 } | 603 } |
592 | 604 |
593 } // namespace blink | 605 } // namespace blink |
OLD | NEW |