Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "url/gurl.h" | |
| 10 #include "url/url_export.h" | 11 #include "url/url_export.h" |
| 11 | 12 |
| 12 namespace url { | 13 namespace url { |
| 13 | 14 |
| 14 // Origin represents a Web Origin serialized to a string. | 15 // 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.
| |
| 15 // See RFC6454 for details. | |
| 16 class URL_EXPORT Origin { | 16 class URL_EXPORT Origin { |
| 17 public: | 17 public: |
| 18 // Creates a unique Origin. | |
| 18 Origin(); | 19 Origin(); |
| 20 | |
| 21 // Creates an origin from a scheme/host/port tuple. If the scheme, host, or | |
| 22 // port are invalid, a unique origin will be created. | |
| 23 Origin(const std::string& scheme, | |
| 24 const std::string& host, | |
| 25 unsigned short port); | |
| 26 | |
| 27 // Creates an origin for a given URL, as specified in | |
| 28 // https://url.spec.whatwg.org/#origin. Invalid URLs are parsed as unique | |
| 29 // origins, and non-standard URLs will be parsed as ([scheme], '', 0). | |
| 30 explicit Origin(const GURL& url); | |
| 31 | |
| 32 // Returns true if the origin is "the same" as |other|, as defined in Section | |
| 33 // 5 of RFC6454: https://tools.ietf.org/html/rfc6454#section-5. Note that | |
| 34 // unique origins are not "the same" as any other origin, including | |
| 35 // themselves. | |
| 36 bool IsSameOriginWith(const Origin& other) const; | |
| 37 | |
| 38 bool SchemeIs(const std::string& scheme) const; | |
| 39 bool SchemeIsCryptographic() const; | |
| 40 | |
| 41 std::string scheme() const { return scheme_; } | |
| 42 std::string host() const { return host_; } | |
| 43 unsigned short port() const { return port_; } | |
| 44 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,
| |
| 45 | |
| 46 // Returns a serialization of the origin, suitable for passing around via IPC. | |
| 47 // This is _not_ the serialization of the origin which ought to be displayed | |
| 48 // 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
| |
| 49 // | |
| 50 // This is an implementation of the algorithm defined in RFC6454: | |
| 51 // 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
| |
| 52 // divergences: | |
| 53 // | |
| 54 // 1. Origins with a scheme of 'file' serialize to 'file://'. | |
| 55 // 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.
| |
| 56 // 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
| |
| 57 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
| |
| 58 | |
| 59 // TODO(mkwst): Remove tese once blink::WebSerializedOrigin is gone. | |
|
Ryan Sleevi
2015/05/22 20:43:36
s/these/
| |
| 19 explicit Origin(const std::string& origin); | 60 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
| |
| 20 | 61 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
| |
| 21 const std::string& string() const { return string_; } | |
| 22 | |
| 23 bool IsSameAs(const Origin& that) const { | |
| 24 return string_ == that.string_; | |
| 25 } | |
| 26 | 62 |
| 27 private: | 63 private: |
| 64 void Init(const GURL& url); | |
| 65 | |
| 66 std::string scheme_; | |
| 67 std::string host_; | |
| 68 unsigned short port_; | |
| 69 bool unique_; | |
| 70 bool serialization_requires_port_; | |
| 71 | |
| 28 std::string string_; | 72 std::string string_; |
| 29 }; | 73 }; |
| 30 | 74 |
| 75 // Stream operator so Origin can be used in assertion statements. | |
| 76 URL_EXPORT std::ostream& operator<<(std::ostream& out, const url::Origin& url); | |
| 77 | |
| 31 } // namespace url | 78 } // namespace url |
| 32 | 79 |
| 33 #endif // URL_ORIGIN_H_ | 80 #endif // URL_ORIGIN_H_ |
| OLD | NEW |