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 #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> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | |
| 12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 14 #include "url/scheme_host_port.h" | 15 #include "url/scheme_host_port.h" |
| 15 #include "url/third_party/mozilla/url_parse.h" | 16 #include "url/third_party/mozilla/url_parse.h" |
| 16 #include "url/url_canon.h" | 17 #include "url/url_canon.h" |
| 17 #include "url/url_constants.h" | 18 #include "url/url_constants.h" |
| 18 #include "url/url_export.h" | 19 #include "url/url_export.h" |
| 19 | 20 |
| 20 class GURL; | 21 class GURL; |
| 21 | 22 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // | 96 // |
| 96 // This constructor should be used in order to pass 'Origin' objects back and | 97 // This constructor should be used in order to pass 'Origin' objects back and |
| 97 // forth over IPC (as transitioning through GURL would risk potentially | 98 // forth over IPC (as transitioning through GURL would risk potentially |
| 98 // dangerous recanonicalization); other potential callers should prefer the | 99 // dangerous recanonicalization); other potential callers should prefer the |
| 99 // 'GURL'-based constructor. | 100 // 'GURL'-based constructor. |
| 100 static Origin UnsafelyCreateOriginWithoutNormalization( | 101 static Origin UnsafelyCreateOriginWithoutNormalization( |
| 101 base::StringPiece scheme, | 102 base::StringPiece scheme, |
| 102 base::StringPiece host, | 103 base::StringPiece host, |
| 103 uint16_t port); | 104 uint16_t port); |
| 104 | 105 |
| 105 ~Origin(); | 106 virtual ~Origin(); |
| 106 | 107 |
| 107 // For unique origins, these return ("", "", 0). | 108 // For unique origins, these return ("", "", 0). |
| 108 const std::string& scheme() const { return tuple_.scheme(); } | 109 const std::string& scheme() const { return tuple_.scheme(); } |
| 109 const std::string& host() const { return tuple_.host(); } | 110 const std::string& host() const { return tuple_.host(); } |
| 110 uint16_t port() const { return tuple_.port(); } | 111 uint16_t port() const { return tuple_.port(); } |
| 111 | 112 |
| 112 bool unique() const { return unique_; } | 113 bool unique() const { return unique_; } |
| 113 | 114 |
| 114 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with | 115 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with |
| 115 // the addition that all Origins with a 'file' scheme serialize to "file://". | 116 // the addition that all Origins with a 'file' scheme serialize to "file://". |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 137 // std::map). | 138 // std::map). |
| 138 bool operator<(const Origin& other) const; | 139 bool operator<(const Origin& other) const; |
| 139 | 140 |
| 140 private: | 141 private: |
| 141 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); | 142 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); |
| 142 | 143 |
| 143 SchemeHostPort tuple_; | 144 SchemeHostPort tuple_; |
| 144 bool unique_; | 145 bool unique_; |
| 145 }; | 146 }; |
| 146 | 147 |
| 148 // A version of Origin that supports ref count and can be passed in a | |
| 149 // scoped_refptr. This allows to specify a null Origin (as opposed to a unique | |
| 150 // origin). | |
| 151 class URL_EXPORT NullableOrigin : public Origin, | |
|
Mike West
2016/10/11 08:50:31
This feels like a stopgap that we're doing just be
| |
| 152 public base::RefCounted<NullableOrigin> { | |
| 153 public: | |
| 154 explicit NullableOrigin(const GURL& url); | |
| 155 NullableOrigin(const Origin& origin); | |
| 156 | |
| 157 private: | |
| 158 friend base::RefCounted<NullableOrigin>; | |
| 159 ~NullableOrigin() override; | |
| 160 }; | |
| 161 | |
| 147 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); | 162 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); |
| 148 | 163 |
| 149 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); | 164 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); |
| 150 | 165 |
| 151 } // namespace url | 166 } // namespace url |
| 152 | 167 |
| 153 #endif // URL_ORIGIN_H_ | 168 #endif // URL_ORIGIN_H_ |
| OLD | NEW |