| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "url/origin.h" | 5 #include "url/origin.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } else { | 76 } else { |
| 77 tuple_ = SchemeHostPort(url); | 77 tuple_ = SchemeHostPort(url); |
| 78 } | 78 } |
| 79 | 79 |
| 80 unique_ = tuple_.IsInvalid(); | 80 unique_ = tuple_.IsInvalid(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 Origin::Origin(base::StringPiece scheme, | 83 Origin::Origin(base::StringPiece scheme, |
| 84 base::StringPiece host, | 84 base::StringPiece host, |
| 85 uint16_t port, | 85 uint16_t port, |
| 86 base::StringPiece suborigin, |
| 86 SchemeHostPort::ConstructPolicy policy) | 87 SchemeHostPort::ConstructPolicy policy) |
| 87 : tuple_(scheme, host, port, policy) { | 88 : tuple_(scheme, host, port, policy) { |
| 88 unique_ = tuple_.IsInvalid(); | 89 unique_ = tuple_.IsInvalid(); |
| 90 suborigin_ = suborigin.as_string(); |
| 89 } | 91 } |
| 90 | 92 |
| 91 Origin::~Origin() { | 93 Origin::~Origin() { |
| 92 } | 94 } |
| 93 | 95 |
| 94 // static | 96 // static |
| 95 Origin Origin::UnsafelyCreateOriginWithoutNormalization( | 97 Origin Origin::UnsafelyCreateOriginWithoutNormalization( |
| 96 base::StringPiece scheme, | 98 base::StringPiece scheme, |
| 97 base::StringPiece host, | 99 base::StringPiece host, |
| 98 uint16_t port) { | 100 uint16_t port) { |
| 99 return Origin(scheme, host, port, SchemeHostPort::CHECK_CANONICALIZATION); | 101 return Origin(scheme, host, port, "", SchemeHostPort::CHECK_CANONICALIZATION); |
| 100 } | 102 } |
| 101 | 103 |
| 102 Origin Origin::CreateFromNormalizedTuple(base::StringPiece scheme, | 104 Origin Origin::CreateFromNormalizedTuple(base::StringPiece scheme, |
| 103 base::StringPiece host, | 105 base::StringPiece host, |
| 104 uint16_t port) { | 106 uint16_t port) { |
| 105 return Origin(scheme, host, port, SchemeHostPort::ALREADY_CANONICALIZED); | 107 return CreateFromNormalizedTupleWithSuborigin(scheme, host, port, ""); |
| 108 } |
| 109 |
| 110 Origin Origin::CreateFromNormalizedTupleWithSuborigin( |
| 111 base::StringPiece scheme, |
| 112 base::StringPiece host, |
| 113 uint16_t port, |
| 114 base::StringPiece suborigin) { |
| 115 return Origin(scheme, host, port, suborigin, |
| 116 SchemeHostPort::ALREADY_CANONICALIZED); |
| 106 } | 117 } |
| 107 | 118 |
| 108 std::string Origin::Serialize() const { | 119 std::string Origin::Serialize() const { |
| 109 if (unique()) | 120 if (unique()) |
| 110 return "null"; | 121 return "null"; |
| 111 | 122 |
| 112 if (scheme() == kFileScheme) | 123 if (scheme() == kFileScheme) |
| 113 return "file://"; | 124 return "file://"; |
| 114 | 125 |
| 115 if (!suborigin_.empty()) { | 126 if (!suborigin_.empty()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 178 |
| 168 bool IsSameOriginWith(const GURL& a, const GURL& b) { | 179 bool IsSameOriginWith(const GURL& a, const GURL& b) { |
| 169 return Origin(a).IsSameOriginWith(Origin(b)); | 180 return Origin(a).IsSameOriginWith(Origin(b)); |
| 170 } | 181 } |
| 171 | 182 |
| 172 bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b) { | 183 bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b) { |
| 173 return Origin(a).IsSamePhysicalOriginWith(Origin(b)); | 184 return Origin(a).IsSamePhysicalOriginWith(Origin(b)); |
| 174 } | 185 } |
| 175 | 186 |
| 176 } // namespace url | 187 } // namespace url |
| OLD | NEW |