Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 // the "path", which boils down to everything after the scheme. GURL's | 32 // the "path", which boils down to everything after the scheme. GURL's |
| 33 // 'GetContent()' gives us exactly that. | 33 // 'GetContent()' gives us exactly that. |
| 34 tuple_ = SchemeHostPort(GURL(url.GetContent())); | 34 tuple_ = SchemeHostPort(GURL(url.GetContent())); |
| 35 } else { | 35 } else { |
| 36 tuple_ = SchemeHostPort(url); | 36 tuple_ = SchemeHostPort(url); |
| 37 } | 37 } |
| 38 | 38 |
| 39 unique_ = tuple_.IsInvalid(); | 39 unique_ = tuple_.IsInvalid(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 Origin::Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port) | 42 Origin::Origin(base::StringPiece scheme, |
| 43 : tuple_(scheme, host, port) { | 43 base::StringPiece host, |
| 44 uint16_t port, | |
| 45 bool is_canonicalized) | |
| 46 : tuple_(scheme, host, port, is_canonicalized) { | |
| 44 unique_ = tuple_.IsInvalid(); | 47 unique_ = tuple_.IsInvalid(); |
| 45 } | 48 } |
| 46 | 49 |
| 47 Origin::~Origin() { | 50 Origin::~Origin() { |
| 48 } | 51 } |
| 49 | 52 |
| 50 // static | 53 // static |
| 51 Origin Origin::UnsafelyCreateOriginWithoutNormalization( | 54 Origin Origin::UnsafelyCreateOriginWithoutNormalization( |
| 52 base::StringPiece scheme, | 55 base::StringPiece scheme, |
| 53 base::StringPiece host, | 56 base::StringPiece host, |
| 54 uint16_t port) { | 57 uint16_t port) { |
| 55 return Origin(scheme, host, port); | 58 return Origin(scheme, host, port, false /* is_canonicalized */); |
| 59 } | |
| 60 | |
| 61 Origin Origin::CreateFromNormalizedTuple(base::StringPiece scheme, | |
| 62 base::StringPiece host, | |
| 63 uint16_t port) { | |
| 64 return Origin(scheme, host, port, true /* is_canonicalized */); | |
|
Mike West
2016/10/11 08:38:33
Nit: Did you consider making this an enum rather t
Charlie Harrison
2016/10/11 16:29:55
Done.
| |
| 56 } | 65 } |
| 57 | 66 |
| 58 std::string Origin::Serialize() const { | 67 std::string Origin::Serialize() const { |
| 59 if (unique()) | 68 if (unique()) |
| 60 return "null"; | 69 return "null"; |
| 61 | 70 |
| 62 if (scheme() == kFileScheme) | 71 if (scheme() == kFileScheme) |
| 63 return "file://"; | 72 return "file://"; |
| 64 | 73 |
| 65 return tuple_.Serialize(); | 74 return tuple_.Serialize(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 92 | 101 |
| 93 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { | 102 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { |
| 94 return out << origin.Serialize(); | 103 return out << origin.Serialize(); |
| 95 } | 104 } |
| 96 | 105 |
| 97 bool IsSameOriginWith(const GURL& a, const GURL& b) { | 106 bool IsSameOriginWith(const GURL& a, const GURL& b) { |
| 98 return Origin(a).IsSameOriginWith(Origin(b)); | 107 return Origin(a).IsSameOriginWith(Origin(b)); |
| 99 } | 108 } |
| 100 | 109 |
| 101 } // namespace url | 110 } // namespace url |
| OLD | NEW |