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" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 #include "url/url_canon.h" | 13 #include "url/url_canon.h" |
14 #include "url/url_canon_stdstring.h" | 14 #include "url/url_canon_stdstring.h" |
15 #include "url/url_constants.h" | 15 #include "url/url_constants.h" |
16 #include "url/url_util.h" | 16 #include "url/url_util.h" |
17 | 17 |
18 namespace url { | 18 namespace url { |
19 | 19 |
20 namespace { | |
21 | |
22 const char kRootFileUrl[] = "file:///"; | |
23 | |
24 } // namespace | |
25 | |
20 Origin::Origin() : unique_(true) { | 26 Origin::Origin() : unique_(true) { |
21 } | 27 } |
22 | 28 |
23 Origin::Origin(const GURL& url) : unique_(true) { | 29 Origin::Origin(const GURL& url) : unique_(true) { |
24 if (!url.is_valid() || (!url.IsStandard() && !url.SchemeIsBlob())) | 30 if (!url.is_valid() || (!url.IsStandard() && !url.SchemeIsBlob())) |
25 return; | 31 return; |
26 | 32 |
27 if (url.SchemeIsFileSystem()) { | 33 if (url.SchemeIsFileSystem()) { |
28 tuple_ = SchemeHostPort(*url.inner_url()); | 34 tuple_ = SchemeHostPort(*url.inner_url()); |
29 } else if (url.SchemeIsBlob()) { | 35 } else if (url.SchemeIsBlob()) { |
(...skipping 23 matching lines...) Expand all Loading... | |
53 base::StringPiece host, | 59 base::StringPiece host, |
54 uint16_t port) { | 60 uint16_t port) { |
55 return Origin(scheme, host, port); | 61 return Origin(scheme, host, port); |
56 } | 62 } |
57 | 63 |
58 std::string Origin::Serialize() const { | 64 std::string Origin::Serialize() const { |
59 if (unique()) | 65 if (unique()) |
60 return "null"; | 66 return "null"; |
61 | 67 |
62 if (scheme() == kFileScheme) | 68 if (scheme() == kFileScheme) |
63 return "file://"; | 69 return kRootFileUrl; |
brettw
2016/10/03 18:56:34
It looks like this returns the new "file:///" inst
| |
64 | 70 |
65 return tuple_.Serialize(); | 71 return tuple_.Serialize(); |
66 } | 72 } |
67 | 73 |
74 GURL Origin::GetURL() const { | |
75 if (unique()) | |
76 return GURL(); | |
77 | |
78 if (scheme() == kFileScheme) | |
79 return GURL(kRootFileUrl); | |
80 | |
81 return tuple_.GetURL(); | |
82 } | |
83 | |
68 bool Origin::IsSameOriginWith(const Origin& other) const { | 84 bool Origin::IsSameOriginWith(const Origin& other) const { |
69 if (unique_ || other.unique_) | 85 if (unique_ || other.unique_) |
70 return false; | 86 return false; |
71 | 87 |
72 return tuple_.Equals(other.tuple_); | 88 return tuple_.Equals(other.tuple_); |
73 } | 89 } |
74 | 90 |
75 bool Origin::DomainIs(base::StringPiece lower_ascii_domain) const { | 91 bool Origin::DomainIs(base::StringPiece lower_ascii_domain) const { |
76 return !unique_ && url::DomainIs(tuple_.host(), lower_ascii_domain); | 92 return !unique_ && url::DomainIs(tuple_.host(), lower_ascii_domain); |
77 } | 93 } |
78 | 94 |
79 bool Origin::operator<(const Origin& other) const { | 95 bool Origin::operator<(const Origin& other) const { |
80 return tuple_ < other.tuple_; | 96 return tuple_ < other.tuple_; |
81 } | 97 } |
82 | 98 |
83 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { | 99 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { |
84 return out << origin.Serialize(); | 100 return out << origin.Serialize(); |
85 } | 101 } |
86 | 102 |
87 bool IsSameOriginWith(const GURL& a, const GURL& b) { | 103 bool IsSameOriginWith(const GURL& a, const GURL& b) { |
88 return Origin(a).IsSameOriginWith(Origin(b)); | 104 return Origin(a).IsSameOriginWith(Origin(b)); |
89 } | 105 } |
90 | 106 |
91 } // namespace url | 107 } // namespace url |
OLD | NEW |