Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: third_party/WebKit/Source/platform/weborigin/SecurityOrigin.cpp

Issue 2449233002: Add suborigins to WebSecurityOrigin (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
122 m_effectivePort(url.port() ? url.port() 122 m_effectivePort(url.port() ? url.port()
123 : defaultPortForProtocol(m_protocol)), 123 : defaultPortForProtocol(m_protocol)),
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 // Suborigins are serialized into the host, so extract it if necessary. 129 // Suborigins are serialized into the host, so extract it if necessary.
130 String suboriginName; 130 String suboriginName;
131 if (deserializeSuboriginAndProtocolAndHost(m_protocol, m_host, suboriginName, 131 if (deserializeSuboriginAndProtocolAndHost(m_protocol, m_host, suboriginName,
132 m_protocol, m_host)) 132 m_protocol, m_host)) {
133 if (!url.port()) {
134 m_effectivePort = defaultPortForProtocol(m_protocol);
135 }
Mike West 2016/10/26 08:22:23 Nit: No {} for single-line clause.
jww 2016/10/26 16:53:00 Done.
133 m_suborigin.setName(suboriginName); 136 m_suborigin.setName(suboriginName);
137 }
134 138
135 // document.domain starts as m_host, but can be set by the DOM. 139 // document.domain starts as m_host, but can be set by the DOM.
136 m_domain = m_host; 140 m_domain = m_host;
137 141
138 if (isDefaultPortForProtocol(m_port, m_protocol)) 142 if (isDefaultPortForProtocol(m_port, m_protocol))
139 m_port = InvalidPort; 143 m_port = InvalidPort;
140 144
141 // By default, only local SecurityOrigins can load local resources. 145 // By default, only local SecurityOrigins can load local resources.
142 m_canLoadLocalResources = isLocal(); 146 m_canLoadLocalResources = isLocal();
143 } 147 }
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 459 }
456 460
457 // Returns true if and only if a suborigin component was found. If false, no 461 // Returns true if and only if a suborigin component was found. If false, no
458 // guarantees about the return value |suboriginName| are made. 462 // guarantees about the return value |suboriginName| are made.
459 bool SecurityOrigin::deserializeSuboriginAndProtocolAndHost( 463 bool SecurityOrigin::deserializeSuboriginAndProtocolAndHost(
460 const String& oldProtocol, 464 const String& oldProtocol,
461 const String& oldHost, 465 const String& oldHost,
462 String& suboriginName, 466 String& suboriginName,
463 String& newProtocol, 467 String& newProtocol,
464 String& newHost) { 468 String& newHost) {
465 if (!RuntimeEnabledFeatures::suboriginsEnabled())
466 return false;
467
468 String originalProtocol = oldProtocol; 469 String originalProtocol = oldProtocol;
469 if (oldProtocol != "http-so" && oldProtocol != "https-so") 470 if (oldProtocol != "http-so" && oldProtocol != "https-so")
470 return false; 471 return false;
471 472
472 size_t protocolEnd = oldProtocol.reverseFind("-so"); 473 size_t protocolEnd = oldProtocol.reverseFind("-so");
473 DCHECK_NE(protocolEnd, WTF::kNotFound); 474 DCHECK_NE(protocolEnd, WTF::kNotFound);
474 newProtocol = oldProtocol.substring(0, protocolEnd); 475 newProtocol = oldProtocol.substring(0, protocolEnd);
475 476
476 size_t suboriginEnd = oldHost.find('.'); 477 size_t suboriginEnd = oldHost.find('.');
477 // Suborigins cannot be empty. 478 // Suborigins cannot be empty.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 int port) { 524 int port) {
524 if (port < 0 || port > MaxAllowedPort) 525 if (port < 0 || port > MaxAllowedPort)
525 return createUnique(); 526 return createUnique();
526 527
527 DCHECK_EQ(host, decodeURLEscapeSequences(host)); 528 DCHECK_EQ(host, decodeURLEscapeSequences(host));
528 529
529 String portPart = port ? ":" + String::number(port) : String(); 530 String portPart = port ? ":" + String::number(port) : String();
530 return create(KURL(KURL(), protocol + "://" + host + portPart + "/")); 531 return create(KURL(KURL(), protocol + "://" + host + portPart + "/"));
531 } 532 }
532 533
534 PassRefPtr<SecurityOrigin> SecurityOrigin::create(const String& protocol,
535 const String& host,
536 int port,
537 const String& suborigin) {
Mike West 2016/10/26 08:22:23 LGTM if you add specific tests for this new constr
jww 2016/10/26 16:53:00 Done.
538 RefPtr<SecurityOrigin> origin = create(protocol, host, port);
539 if (!suborigin.isEmpty())
540 origin->m_suborigin.setName(suborigin);
541 return origin.release();
542 }
543
533 bool SecurityOrigin::isSameSchemeHostPort(const SecurityOrigin* other) const { 544 bool SecurityOrigin::isSameSchemeHostPort(const SecurityOrigin* other) const {
534 if (this == other) 545 if (this == other)
535 return true; 546 return true;
536 547
537 if (isUnique() || other->isUnique()) 548 if (isUnique() || other->isUnique())
538 return false; 549 return false;
539 550
540 if (m_host != other->m_host) 551 if (m_host != other->m_host)
541 return false; 552 return false;
542 553
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 privilegeData->m_blockLocalAccessFromLocalOrigin; 596 privilegeData->m_blockLocalAccessFromLocalOrigin;
586 } 597 }
587 598
588 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy( 599 void SecurityOrigin::setUniqueOriginIsPotentiallyTrustworthy(
589 bool isUniqueOriginPotentiallyTrustworthy) { 600 bool isUniqueOriginPotentiallyTrustworthy) {
590 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique()); 601 ASSERT(!isUniqueOriginPotentiallyTrustworthy || isUnique());
591 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworthy; 602 m_isUniqueOriginPotentiallyTrustworthy = isUniqueOriginPotentiallyTrustworthy;
592 } 603 }
593 604
594 } // namespace blink 605 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/weborigin/SecurityOrigin.h ('k') | third_party/WebKit/public/platform/WebSecurityOrigin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698