Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: url/origin.h

Issue 2403713002: Add suborigin logic to url::Origin (Closed)
Patch Set: Rebase on ToT Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef URL_ORIGIN_H_ 5 #ifndef URL_ORIGIN_H_
6 #define URL_ORIGIN_H_ 6 #define URL_ORIGIN_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 base::StringPiece host, 109 base::StringPiece host,
110 uint16_t port); 110 uint16_t port);
111 111
112 ~Origin(); 112 ~Origin();
113 113
114 // For unique origins, these return ("", "", 0). 114 // For unique origins, these return ("", "", 0).
115 const std::string& scheme() const { return tuple_.scheme(); } 115 const std::string& scheme() const { return tuple_.scheme(); }
116 const std::string& host() const { return tuple_.host(); } 116 const std::string& host() const { return tuple_.host(); }
117 uint16_t port() const { return tuple_.port(); } 117 uint16_t port() const { return tuple_.port(); }
118 118
119 // Note that an origin without a suborgin will return the empty string.
120 const std::string& suborigin() const { return suborigin_; }
121
119 bool unique() const { return unique_; } 122 bool unique() const { return unique_; }
120 123
121 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with 124 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with
122 // the addition that all Origins with a 'file' scheme serialize to "file://". 125 // the addition that all Origins with a 'file' scheme serialize to "file://".
126 // If the Origin has a suborigin, it will be serialized per
127 // https://w3c.github.io/webappsec-suborigins/#serializing.
123 std::string Serialize() const; 128 std::string Serialize() const;
124 129
130 // Same as above, but ignores the suborigin component of the origin, if it
131 // exists, returning only the physical origin. For example, when
132 // SerializePhysicalOrigin() is called on the origin
133 // https-so://foobar.example.com, it will return https://example.com.
134 std::string SerializePhysicalOrigin() const;
135
125 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact 136 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact
126 // matches; and neither is unique. 137 // matches; and neither is unique. If either of the origins have suborigins,
138 // the suborigins also must be exact matches.
127 bool IsSameOriginWith(const Origin& other) const; 139 bool IsSameOriginWith(const Origin& other) const;
128 bool operator==(const Origin& other) const { 140 bool operator==(const Origin& other) const {
129 return IsSameOriginWith(other); 141 return IsSameOriginWith(other);
130 } 142 }
131 143
144 // Same as above, but ignores suborigins if they exist.
145 bool IsSamePhysicalOriginWith(const Origin& other) const;
michaeln 2016/10/19 20:36:02 Might be nice to have an Origin GetPhysicalOrigin(
jww 2016/10/19 22:11:23 Indeed. Per a suggestion from nasko@, I'm thinking
jww 2016/10/20 06:03:47 Changed my mind and added it in this CL. I think i
146
132 // Efficiently returns what GURL(Serialize()) would without re-parsing the 147 // Efficiently returns what GURL(Serialize()) would without re-parsing the
133 // URL. This can be used for the (rare) times a GURL representation is needed 148 // URL. This can be used for the (rare) times a GURL representation is needed
134 // for an Origin. 149 // for an Origin.
135 // Note: The returned URL will not necessarily be serialized to the same value 150 // Note: The returned URL will not necessarily be serialized to the same value
136 // as the Origin would. The GURL will have an added "/" path for Origins with 151 // as the Origin would. The GURL will have an added "/" path for Origins with
137 // valid SchemeHostPorts and file Origins. 152 // valid SchemeHostPorts and file Origins.
138 GURL GetURL() const; 153 GURL GetURL() const;
139 154
140 // Same as GURL::DomainIs. If |this| origin is unique, then returns false. 155 // Same as GURL::DomainIs. If |this| origin is unique, then returns false.
141 bool DomainIs(base::StringPiece lower_ascii_domain) const; 156 bool DomainIs(base::StringPiece lower_ascii_domain) const;
142 157
143 // Allows Origin to be used as a key in STL (for example, a std::set or 158 // Allows Origin to be used as a key in STL (for example, a std::set or
144 // std::map). 159 // std::map).
145 bool operator<(const Origin& other) const; 160 bool operator<(const Origin& other) const;
146 161
147 private: 162 private:
148 Origin(base::StringPiece scheme, 163 Origin(base::StringPiece scheme,
149 base::StringPiece host, 164 base::StringPiece host,
150 uint16_t port, 165 uint16_t port,
151 SchemeHostPort::ConstructPolicy policy); 166 SchemeHostPort::ConstructPolicy policy);
152 167
153 SchemeHostPort tuple_; 168 SchemeHostPort tuple_;
154 bool unique_; 169 bool unique_;
170 std::string suborigin_;
155 }; 171 };
156 172
157 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); 173 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin);
158 174
159 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); 175 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b);
176 URL_EXPORT bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b);
160 177
161 } // namespace url 178 } // namespace url
162 179
163 #endif // URL_ORIGIN_H_ 180 #endif // URL_ORIGIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698