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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 std::string Origin::Serialize() const { | 58 std::string Origin::Serialize() const { |
| 59 if (unique()) | 59 if (unique()) |
| 60 return "null"; | 60 return "null"; |
| 61 | 61 |
| 62 if (scheme() == kFileScheme) | 62 if (scheme() == kFileScheme) |
| 63 return "file://"; | 63 return "file://"; |
| 64 | 64 |
| 65 return tuple_.Serialize(); | 65 return tuple_.Serialize(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 GURL Origin::GetURL() const { | |
| 69 if (unique()) | |
| 70 return GURL("null"); | |
|
Mike West
2016/09/30 12:37:40
Hrm. I think `GURL::GetOrigin()` returns an empty
Charlie Harrison
2016/09/30 14:29:58
GURL("null") == GURL() so that's fine.
I would li
| |
| 71 | |
| 72 if (scheme() == kFileScheme) | |
| 73 return GURL("file://"); | |
| 74 | |
| 75 return tuple_.GetURL(); | |
| 76 } | |
| 77 | |
| 68 bool Origin::IsSameOriginWith(const Origin& other) const { | 78 bool Origin::IsSameOriginWith(const Origin& other) const { |
| 69 if (unique_ || other.unique_) | 79 if (unique_ || other.unique_) |
| 70 return false; | 80 return false; |
| 71 | 81 |
| 72 return tuple_.Equals(other.tuple_); | 82 return tuple_.Equals(other.tuple_); |
| 73 } | 83 } |
| 74 | 84 |
| 75 bool Origin::DomainIs(base::StringPiece lower_ascii_domain) const { | 85 bool Origin::DomainIs(base::StringPiece lower_ascii_domain) const { |
| 76 return !unique_ && url::DomainIs(tuple_.host(), lower_ascii_domain); | 86 return !unique_ && url::DomainIs(tuple_.host(), lower_ascii_domain); |
| 77 } | 87 } |
| 78 | 88 |
| 79 bool Origin::operator<(const Origin& other) const { | 89 bool Origin::operator<(const Origin& other) const { |
| 80 return tuple_ < other.tuple_; | 90 return tuple_ < other.tuple_; |
| 81 } | 91 } |
| 82 | 92 |
| 83 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { | 93 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { |
| 84 return out << origin.Serialize(); | 94 return out << origin.Serialize(); |
| 85 } | 95 } |
| 86 | 96 |
| 87 bool IsSameOriginWith(const GURL& a, const GURL& b) { | 97 bool IsSameOriginWith(const GURL& a, const GURL& b) { |
| 88 return Origin(a).IsSameOriginWith(Origin(b)); | 98 return Origin(a).IsSameOriginWith(Origin(b)); |
| 89 } | 99 } |
| 90 | 100 |
| 91 } // namespace url | 101 } // namespace url |
| OLD | NEW |