Index: url/origin.h |
diff --git a/url/origin.h b/url/origin.h |
index 777e4e1ef481bc062557b2fc8d7fe2437f784c0d..acebc7ee969e84d2a0cf11bfcbdd43e2ccd7d68e 100644 |
--- a/url/origin.h |
+++ b/url/origin.h |
@@ -7,27 +7,74 @@ |
#include <string> |
+#include "url/gurl.h" |
#include "url/url_export.h" |
namespace url { |
-// Origin represents a Web Origin serialized to a string. |
-// See RFC6454 for details. |
+// Origin represents a scheme/host/port tuple, as described in RFC6454. |
Ryan Sleevi
2015/05/22 20:43:36
At the risk of being a pain, I think it would be g
Mike West
2015/05/28 07:24:29
Makes sense.
|
class URL_EXPORT Origin { |
public: |
+ // Creates a unique Origin. |
Origin(); |
- explicit Origin(const std::string& origin); |
- const std::string& string() const { return string_; } |
+ // Creates an origin from a scheme/host/port tuple. If the scheme, host, or |
+ // port are invalid, a unique origin will be created. |
+ Origin(const std::string& scheme, |
+ const std::string& host, |
+ unsigned short port); |
+ |
+ // Creates an origin for a given URL, as specified in |
+ // https://url.spec.whatwg.org/#origin. Invalid URLs are parsed as unique |
+ // origins, and non-standard URLs will be parsed as ([scheme], '', 0). |
+ explicit Origin(const GURL& url); |
+ |
+ // Returns true if the origin is "the same" as |other|, as defined in Section |
+ // 5 of RFC6454: https://tools.ietf.org/html/rfc6454#section-5. Note that |
+ // unique origins are not "the same" as any other origin, including |
+ // themselves. |
+ bool IsSameOriginWith(const Origin& other) const; |
+ |
+ bool SchemeIs(const std::string& scheme) const; |
+ bool SchemeIsCryptographic() const; |
+ |
+ std::string scheme() const { return scheme_; } |
+ std::string host() const { return host_; } |
+ unsigned short port() const { return port_; } |
+ bool unique() const { return unique_; } |
Ryan Sleevi
2015/05/22 20:43:36
I'm not sure what the utility of this is, nor if i
Mike West
2015/05/28 07:24:29
Happy to drop it. If it turns out that we need it,
|
- bool IsSameAs(const Origin& that) const { |
- return string_ == that.string_; |
- } |
+ // Returns a serialization of the origin, suitable for passing around via IPC. |
+ // This is _not_ the serialization of the origin which ought to be displayed |
+ // to a user in browser UI. |
Ryan Sleevi
2015/05/22 20:43:35
s/browser//
//net, and below (including URL) have
Mike West
2015/05/28 07:24:29
Got it. Expanded this comment to point to the FAQ
|
+ // |
+ // This is an implementation of the algorithm defined in RFC6454: |
+ // https://tools.ietf.org/html/rfc6454#section-6, with the following |
Ryan Sleevi
2015/05/28 07:32:53
Follow-up expansion: Is this serializing to Unicod
|
+ // divergences: |
+ // |
+ // 1. Origins with a scheme of 'file' serialize to 'file://'. |
+ // 2. Origins with a |
Ryan Sleevi
2015/05/22 20:43:36
Incomplete?
Mike West
2015/05/28 07:24:29
Killed this; we're not divergent.
|
+ // 3. IPv6 addresses serialize with bracketed hostnames: 'http://[::1]'. |
Ryan Sleevi
2015/05/22 20:43:36
Why is this a divergence? This is exactly what's r
|
+ std::string serialize() const; |
Mike West
2015/05/28 07:24:29
Are you still unhappy with serialization being def
Ryan Sleevi
2015/05/28 07:32:53
Well, naming, s/serialize/Serialize()/, but if the
|
+ |
+ // TODO(mkwst): Remove tese once blink::WebSerializedOrigin is gone. |
Ryan Sleevi
2015/05/22 20:43:36
s/these/
|
+ explicit Origin(const std::string& origin); |
Ryan Sleevi
2015/05/22 20:43:35
STYLE: This belongs at line 31, even if it's depre
Mike West
2015/05/28 07:24:29
Moved, and incorporated the documentation into the
|
+ std::string string() const { return serialize(); } |
Ryan Sleevi
2015/05/22 20:43:35
Naming: ToString() / AsString()
Mike West
2015/05/28 07:24:29
Can't rename or remove until Blink doesn't use 'st
|
private: |
+ void Init(const GURL& url); |
+ |
+ std::string scheme_; |
+ std::string host_; |
+ unsigned short port_; |
+ bool unique_; |
+ bool serialization_requires_port_; |
+ |
std::string string_; |
}; |
+// Stream operator so Origin can be used in assertion statements. |
+URL_EXPORT std::ostream& operator<<(std::ostream& out, const url::Origin& url); |
+ |
} // namespace url |
#endif // URL_ORIGIN_H_ |