| 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 <string.h> | 8 #include <string.h> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 #include "url/url_canon.h" | 13 #include "url/url_canon.h" |
| 13 #include "url/url_canon_stdstring.h" | 14 #include "url/url_canon_stdstring.h" |
| 14 #include "url/url_constants.h" | 15 #include "url/url_constants.h" |
| 15 #include "url/url_util.h" | 16 #include "url/url_util.h" |
| 16 | 17 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 31 // 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 |
| 32 // 'GetContent()' gives us exactly that. | 33 // 'GetContent()' gives us exactly that. |
| 33 tuple_ = SchemeHostPort(GURL(url.GetContent())); | 34 tuple_ = SchemeHostPort(GURL(url.GetContent())); |
| 34 } else { | 35 } else { |
| 35 tuple_ = SchemeHostPort(url); | 36 tuple_ = SchemeHostPort(url); |
| 36 } | 37 } |
| 37 | 38 |
| 38 unique_ = tuple_.IsInvalid(); | 39 unique_ = tuple_.IsInvalid(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 Origin::Origin(base::StringPiece scheme, base::StringPiece host, uint16 port) | 42 Origin::Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port) |
| 42 : tuple_(scheme, host, port) { | 43 : tuple_(scheme, host, port) { |
| 43 unique_ = tuple_.IsInvalid(); | 44 unique_ = tuple_.IsInvalid(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 Origin::~Origin() { | 47 Origin::~Origin() { |
| 47 } | 48 } |
| 48 | 49 |
| 49 // static | 50 // static |
| 50 Origin Origin::UnsafelyCreateOriginWithoutNormalization( | 51 Origin Origin::UnsafelyCreateOriginWithoutNormalization( |
| 51 base::StringPiece scheme, | 52 base::StringPiece scheme, |
| 52 base::StringPiece host, | 53 base::StringPiece host, |
| 53 uint16 port) { | 54 uint16_t port) { |
| 54 return Origin(scheme, host, port); | 55 return Origin(scheme, host, port); |
| 55 } | 56 } |
| 56 | 57 |
| 57 std::string Origin::Serialize() const { | 58 std::string Origin::Serialize() const { |
| 58 if (unique()) | 59 if (unique()) |
| 59 return "null"; | 60 return "null"; |
| 60 | 61 |
| 61 if (scheme() == kFileScheme) | 62 if (scheme() == kFileScheme) |
| 62 return "file://"; | 63 return "file://"; |
| 63 | 64 |
| 64 return tuple_.Serialize(); | 65 return tuple_.Serialize(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 bool Origin::IsSameOriginWith(const Origin& other) const { | 68 bool Origin::IsSameOriginWith(const Origin& other) const { |
| 68 if (unique_ || other.unique_) | 69 if (unique_ || other.unique_) |
| 69 return false; | 70 return false; |
| 70 | 71 |
| 71 return tuple_.Equals(other.tuple_); | 72 return tuple_.Equals(other.tuple_); |
| 72 } | 73 } |
| 73 | 74 |
| 74 bool Origin::operator<(const Origin& other) const { | 75 bool Origin::operator<(const Origin& other) const { |
| 75 return tuple_ < other.tuple_; | 76 return tuple_ < other.tuple_; |
| 76 } | 77 } |
| 77 | 78 |
| 78 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { | 79 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { |
| 79 return out << origin.Serialize(); | 80 return out << origin.Serialize(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace url | 83 } // namespace url |
| OLD | NEW |