[go: nahoru, domu]

blob: 845d5730513071b59049a6a9e76891d87a650b3e [file] [log] [blame]
mkwst9f2cc892015-07-22 06:03:251// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef URL_ORIGIN_H_
6#define URL_ORIGIN_H_
7
avic0c60312015-12-21 21:03:508#include <stdint.h>
9
Robert Ogdendd74d732020-03-12 17:33:1910#include <memory>
mkwst9f2cc892015-07-22 06:03:2511#include <string>
12
Staphany Park6fd74a22018-12-04 21:15:4113#include "base/component_export.h"
Lukasz Anforowicz3d58b9392018-01-05 20:56:2214#include "base/debug/alias.h"
Lukasz Anforowicz731c39c2020-02-07 23:35:5815#include "base/debug/crash_logging.h"
Daniel Cheng62ff0182018-08-25 07:59:3316#include "base/optional.h"
mkwst9f2cc892015-07-22 06:03:2517#include "base/strings/string16.h"
mkwstd8335d982015-07-25 05:18:4818#include "base/strings/string_piece.h"
Daniel Cheng62ff0182018-08-25 07:59:3319#include "base/strings/string_util.h"
20#include "base/unguessable_token.h"
Rouslan Solomakhin63cdb1482019-09-30 21:53:1421#include "build/build_config.h"
Nasko Oskovd9e41d52018-09-27 23:12:4222#include "ipc/ipc_param_traits.h"
mkwst9f2cc892015-07-22 06:03:2523#include "url/scheme_host_port.h"
24#include "url/third_party/mozilla/url_parse.h"
25#include "url/url_canon.h"
26#include "url/url_constants.h"
mkwst9f2cc892015-07-22 06:03:2527
Rouslan Solomakhin63cdb1482019-09-30 21:53:1428#if defined(OS_ANDROID)
29#include <jni.h>
30
31namespace base {
32namespace android {
33template <typename>
34class ScopedJavaLocalRef;
35template <typename>
36class JavaRef;
37} // namespace android
38} // namespace base
39#endif // OS_ANDROID
40
mkwst9f2cc892015-07-22 06:03:2541class GURL;
42
Nasko Oskov99445acd2018-10-10 16:46:0043namespace blink {
44class SecurityOrigin;
45} // namespace blink
46
Nasko Oskov9277dfc2018-09-17 23:20:5447namespace ipc_fuzzer {
48template <class T>
49struct FuzzTraits;
50} // namespace ipc_fuzzer
51
Nasko Oskovd9e41d52018-09-27 23:12:4252namespace mojo {
53template <typename DataViewType, typename T>
54struct StructTraits;
Nasko Oskov99445acd2018-10-10 16:46:0055struct UrlOriginAdapter;
Nasko Oskovd9e41d52018-09-27 23:12:4256} // namespace mojo
57
Robert Ogdendd74d732020-03-12 17:33:1958namespace net {
59class NetworkIsolationKey;
60class OpaqueNonTransientNetworkIsolationKeyTest;
61} // namespace net
62
mkwst9f2cc892015-07-22 06:03:2563namespace url {
64
Nasko Oskovd9e41d52018-09-27 23:12:4265namespace mojom {
66class OriginDataView;
67} // namespace mojom
68
Daniel Cheng62ff0182018-08-25 07:59:3369// Per https://html.spec.whatwg.org/multipage/origin.html#origin, an origin is
70// either:
71// - a tuple origin of (scheme, host, port) as described in RFC 6454.
Nasko Oskov9277dfc2018-09-17 23:20:5472// - an opaque origin with an internal value, and a memory of the tuple origin
73// from which it was derived.
mkwst9f2cc892015-07-22 06:03:2574//
75// TL;DR: If you need to make a security-relevant decision, use 'url::Origin'.
76// If you only need to extract the bits of a URL which are relevant for a
77// network connection, use 'url::SchemeHostPort'.
78//
79// STL;SDR: If you aren't making actual network connections, use 'url::Origin'.
80//
mkwst9f2cc892015-07-22 06:03:2581// This class ought to be used when code needs to determine if two resources
82// are "same-origin", and when a canonical serialization of an origin is
Daniel Cheng62ff0182018-08-25 07:59:3383// required. Note that the canonical serialization of an origin *must not* be
84// used to determine if two resources are same-origin.
85//
86// A tuple origin, like 'SchemeHostPort', is composed of a tuple of (scheme,
87// host, port), but contains a number of additional concepts which make it
88// appropriate for use as a security boundary and access control mechanism
89// between contexts. Two tuple origins are same-origin if the tuples are equal.
90// A tuple origin may also be re-created from its serialization.
91//
Nasko Oskov9277dfc2018-09-17 23:20:5492// An opaque origin has an internal globally unique identifier. When creating a
93// new opaque origin from a URL, a fresh globally unique identifier is
94// generated. However, if an opaque origin is copied or moved, the internal
95// globally unique identifier is preserved. Two opaque origins are same-origin
96// iff the globally unique identifiers match. Unlike tuple origins, an opaque
97// origin cannot be re-created from its serialization, which is always the
98// string "null".
Daniel Cheng62ff0182018-08-25 07:59:3399//
100// IMPORTANT: Since opaque origins always serialize as the string "null", it is
101// *never* safe to use the serialization for security checks!
102//
103// A tuple origin and an opaque origin are never same-origin.
mkwst9f2cc892015-07-22 06:03:25104//
105// There are a few subtleties to note:
106//
Nasko Oskov9277dfc2018-09-17 23:20:54107// * A default constructed Origin is opaque, with no precursor origin.
Daniel Cheng62ff0182018-08-25 07:59:33108//
109// * Invalid and non-standard GURLs are parsed as opaque origins. This includes
mkwst9f2cc892015-07-22 06:03:25110// non-hierarchical URLs like 'data:text/html,...' and 'javascript:alert(1)'.
111//
112// * GURLs with schemes of 'filesystem' or 'blob' parse the origin out of the
113// internals of the URL. That is, 'filesystem:https://example.com/temporary/f'
114// is parsed as ('https', 'example.com', 443).
115//
mkwst9f2cc892015-07-22 06:03:25116// * GURLs with a 'file' scheme are tricky. They are parsed as ('file', '', 0),
117// but their behavior may differ from embedder to embedder.
Daniel Cheng62ff0182018-08-25 07:59:33118// TODO(dcheng): This behavior is not consistent with Blink's notion of file
119// URLs, which always creates an opaque origin.
mkwst9f2cc892015-07-22 06:03:25120//
121// * The host component of an IPv6 address includes brackets, just like the URL
122// representation.
123//
124// Usage:
125//
126// * Origins are generally constructed from an already-canonicalized GURL:
127//
128// GURL url("https://example.com/");
Daniel Vogelheimdf4cf9e2018-06-14 11:42:40129// url::Origin origin = Origin::Create(url);
mkwst9f2cc892015-07-22 06:03:25130// origin.scheme(); // "https"
131// origin.host(); // "example.com"
132// origin.port(); // 443
Chris Palmerab5e5b52018-09-28 19:19:30133// origin.opaque(); // false
mkwst9f2cc892015-07-22 06:03:25134//
135// * To answer the question "Are |this| and |that| "same-origin" with each
136// other?", use |Origin::IsSameOriginWith|:
137//
138// if (this.IsSameOriginWith(that)) {
139// // Amazingness goes here.
140// }
Staphany Park6fd74a22018-12-04 21:15:41141class COMPONENT_EXPORT(URL) Origin {
mkwst9f2cc892015-07-22 06:03:25142 public:
Nasko Oskov9277dfc2018-09-17 23:20:54143 // Creates an opaque Origin with a nonce that is different from all previously
144 // existing origins.
mkwst9f2cc892015-07-22 06:03:25145 Origin();
146
147 // Creates an Origin from |url|, as described at
148 // https://url.spec.whatwg.org/#origin, with the following additions:
149 //
Daniel Cheng62ff0182018-08-25 07:59:33150 // 1. If |url| is invalid or non-standard, an opaque Origin is constructed.
mkwst9f2cc892015-07-22 06:03:25151 // 2. 'filesystem' URLs behave as 'blob' URLs (that is, the origin is parsed
152 // out of everything in the URL which follows the scheme).
153 // 3. 'file' URLs all parse as ("file", "", 0).
Lukasz Anforowiczfd7834ec2020-03-04 02:11:57154 //
155 // Note that the returned Origin may have a different scheme and host from
156 // |url| (e.g. in case of blob URLs - see OriginTest.ConstructFromGURL).
Daniel Cheng88186bd52017-10-20 08:14:46157 static Origin Create(const GURL& url);
mkwst9f2cc892015-07-22 06:03:25158
Nasko Oskov9277dfc2018-09-17 23:20:54159 // Creates an Origin for the resource |url| as if it were requested
160 // from the context of |base_origin|. If |url| is standard
161 // (in the sense that it embeds a complete origin, like http/https),
162 // this returns the same value as would Create().
163 //
164 // If |url| is "about:blank", this returns a copy of |base_origin|.
165 //
166 // Otherwise, returns a new opaque origin derived from |base_origin|.
167 // In this case, the resulting opaque origin will inherit the tuple
168 // (or precursor tuple) of |base_origin|, but will not be same origin
169 // with |base_origin|, even if |base_origin| is already opaque.
170 static Origin Resolve(const GURL& url, const Origin& base_origin);
171
John Melloref62bce2017-10-04 11:25:33172 // Copyable and movable.
Daniel Cheng6ae11ad72017-10-17 20:42:33173 Origin(const Origin&);
174 Origin& operator=(const Origin&);
175 Origin(Origin&&);
176 Origin& operator=(Origin&&);
John Melloref62bce2017-10-04 11:25:33177
Takashi Toyoshima5641d7552018-02-09 08:57:52178 // Creates an Origin from a |scheme|, |host|, and |port|. All the parameters
Nasko Oskov9277dfc2018-09-17 23:20:54179 // must be valid and canonicalized. Returns nullopt if any parameter is not
180 // canonical, or if all the parameters are empty.
mkwstd8335d982015-07-25 05:18:48181 //
182 // This constructor should be used in order to pass 'Origin' objects back and
183 // forth over IPC (as transitioning through GURL would risk potentially
184 // dangerous recanonicalization); other potential callers should prefer the
185 // 'GURL'-based constructor.
Nasko Oskov9277dfc2018-09-17 23:20:54186 static base::Optional<Origin> UnsafelyCreateTupleOriginWithoutNormalization(
mkwstd8335d982015-07-25 05:18:48187 base::StringPiece scheme,
188 base::StringPiece host,
Takashi Toyoshima5641d7552018-02-09 08:57:52189 uint16_t port);
mkwstd8335d982015-07-25 05:18:48190
csharrisonedf893f2016-10-12 01:42:56191 // Creates an origin without sanity checking that the host is canonicalized.
192 // This should only be used when converting between already normalized types,
csharrisonf07ac3c2016-12-13 04:15:02193 // and should NOT be used for IPC. Method takes std::strings for use with move
194 // operators to avoid copies.
Takashi Toyoshima5641d7552018-02-09 08:57:52195 static Origin CreateFromNormalizedTuple(std::string scheme,
196 std::string host,
197 uint16_t port);
jww908428c2016-10-26 21:51:46198
mkwst9f2cc892015-07-22 06:03:25199 ~Origin();
200
Daniel Cheng62ff0182018-08-25 07:59:33201 // For opaque origins, these return ("", "", 0).
202 const std::string& scheme() const {
Chris Palmerab5e5b52018-09-28 19:19:30203 return !opaque() ? tuple_.scheme() : base::EmptyString();
Daniel Cheng62ff0182018-08-25 07:59:33204 }
205 const std::string& host() const {
Chris Palmerab5e5b52018-09-28 19:19:30206 return !opaque() ? tuple_.host() : base::EmptyString();
Daniel Cheng62ff0182018-08-25 07:59:33207 }
Chris Palmerab5e5b52018-09-28 19:19:30208 uint16_t port() const { return !opaque() ? tuple_.port() : 0; }
mkwst9f2cc892015-07-22 06:03:25209
Chris Palmerab5e5b52018-09-28 19:19:30210 bool opaque() const { return nonce_.has_value(); }
mkwst9f2cc892015-07-22 06:03:25211
212 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with
213 // the addition that all Origins with a 'file' scheme serialize to "file://".
214 std::string Serialize() const;
215
Nasko Oskov9277dfc2018-09-17 23:20:54216 // Two non-opaque Origins are "same-origin" if their schemes, hosts, and ports
217 // are exact matches. Two opaque origins are same-origin only if their
218 // internal nonce values match. A non-opaque origin is never same-origin with
219 // an opaque origin.
mkwst9f2cc892015-07-22 06:03:25220 bool IsSameOriginWith(const Origin& other) const;
Nasko Oskov9277dfc2018-09-17 23:20:54221 bool operator==(const Origin& other) const { return IsSameOriginWith(other); }
222 bool operator!=(const Origin& other) const {
223 return !IsSameOriginWith(other);
224 }
225
Nasko Oskov97e305f2019-01-05 03:52:10226 // This method returns true for any |url| which if navigated to could result
227 // in an origin compatible with |this|.
228 bool CanBeDerivedFrom(const GURL& url) const;
229
Nasko Oskov9277dfc2018-09-17 23:20:54230 // Get the scheme, host, and port from which this origin derives. For
231 // a tuple Origin, this gives the same values as calling scheme(), host()
232 // and port(). For an opaque Origin that was created by calling
233 // Origin::DeriveNewOpaqueOrigin() on a precursor or Origin::Resolve(),
234 // this returns the tuple inherited from the precursor.
235 //
236 // If this Origin is opaque and was created via the default constructor or
237 // Origin::Create(), the precursor origin is unknown.
238 //
239 // Use with great caution: opaque origins should generally not inherit
240 // privileges from the origins they derive from. However, in some cases
241 // (such as restrictions on process placement, or determining the http lock
242 // icon) this information may be relevant to ensure that entering an
243 // opaque origin does not grant privileges initially denied to the original
244 // non-opaque origin.
245 //
246 // This method has a deliberately obnoxious name to prompt caution in its use.
247 const SchemeHostPort& GetTupleOrPrecursorTupleIfOpaque() const {
248 return tuple_;
mek0126c132016-02-17 23:50:59249 }
mkwst9f2cc892015-07-22 06:03:25250
csharrison048bee12016-10-04 00:08:21251 // Efficiently returns what GURL(Serialize()) would without re-parsing the
252 // URL. This can be used for the (rare) times a GURL representation is needed
253 // for an Origin.
254 // Note: The returned URL will not necessarily be serialized to the same value
255 // as the Origin would. The GURL will have an added "/" path for Origins with
256 // valid SchemeHostPorts and file Origins.
Charles Harrisonc5f8c91b2017-08-22 18:08:24257 //
258 // Try not to use this method under normal circumstances, as it loses type
259 // information. Downstream consumers can mistake the returned GURL with a full
260 // URL (e.g. with a path component).
csharrison048bee12016-10-04 00:08:21261 GURL GetURL() const;
262
Chris Palmerab5e5b52018-09-28 19:19:30263 // Same as GURL::DomainIs. If |this| origin is opaque, then returns false.
Charles Harrison81dc2fb2017-08-30 23:41:12264 bool DomainIs(base::StringPiece canonical_domain) const;
pkalinnikov054f4032016-08-31 10:54:17265
nick1466c842015-11-25 20:08:06266 // Allows Origin to be used as a key in STL (for example, a std::set or
mkwst9f2cc892015-07-22 06:03:25267 // std::map).
268 bool operator<(const Origin& other) const;
269
Daniel Cheng62ff0182018-08-25 07:59:33270 // Creates a new opaque origin that is guaranteed to be cross-origin to all
271 // currently existing origins. An origin created by this method retains its
272 // identity across copies. Copies are guaranteed to be same-origin to each
273 // other, e.g.
274 //
Nasko Oskov9277dfc2018-09-17 23:20:54275 // url::Origin page = Origin::Create(GURL("http://example.com"))
276 // url::Origin a = page.DeriveNewOpaqueOrigin();
277 // url::Origin b = page.DeriveNewOpaqueOrigin();
Daniel Cheng62ff0182018-08-25 07:59:33278 // url::Origin c = a;
279 // url::Origin d = b;
280 //
281 // |a| and |c| are same-origin, since |c| was copied from |a|. |b| and |d| are
282 // same-origin as well, since |d| was copied from |b|. All other combinations
283 // of origins are considered cross-origin, e.g. |a| is cross-origin to |b| and
284 // |d|, |b| is cross-origin to |a| and |c|, |c| is cross-origin to |b| and
285 // |d|, and |d| is cross-origin to |a| and |c|.
Nasko Oskov9277dfc2018-09-17 23:20:54286 Origin DeriveNewOpaqueOrigin() const;
287
Nasko Oskov1ed4e8f2019-02-13 01:39:19288 // Creates a string representation of the object that can be used for logging
289 // and debugging. It serializes the internal state, such as the nonce value
290 // and precursor information.
291 std::string GetDebugString() const;
292
Rouslan Solomakhin63cdb1482019-09-30 21:53:14293#if defined(OS_ANDROID)
294 base::android::ScopedJavaLocalRef<jobject> CreateJavaObject() const;
295 static Origin FromJavaObject(
296 const base::android::JavaRef<jobject>& java_origin);
297#endif // OS_ANDROID
298
Nasko Oskov9277dfc2018-09-17 23:20:54299 private:
Nasko Oskov99445acd2018-10-10 16:46:00300 friend class blink::SecurityOrigin;
Robert Ogdendd74d732020-03-12 17:33:19301 friend class net::NetworkIsolationKey;
302 friend class net::OpaqueNonTransientNetworkIsolationKeyTest;
Nasko Oskov9277dfc2018-09-17 23:20:54303 friend class OriginTest;
Nasko Oskov99445acd2018-10-10 16:46:00304 friend struct mojo::UrlOriginAdapter;
Nasko Oskov9277dfc2018-09-17 23:20:54305 friend struct ipc_fuzzer::FuzzTraits<Origin>;
Nasko Oskovd9e41d52018-09-27 23:12:42306 friend struct mojo::StructTraits<url::mojom::OriginDataView, url::Origin>;
Nasko Oskov99445acd2018-10-10 16:46:00307 friend IPC::ParamTraits<url::Origin>;
Staphany Park6fd74a22018-12-04 21:15:41308 friend COMPONENT_EXPORT(URL) std::ostream& operator<<(std::ostream& out,
309 const Origin& origin);
Nasko Oskov9277dfc2018-09-17 23:20:54310
311 // Origin::Nonce is a wrapper around base::UnguessableToken that generates
312 // the random value only when the value is first accessed. The lazy generation
313 // allows Origin to be default-constructed quickly, without spending time
314 // in random number generation.
Daniel Cheng62ff0182018-08-25 07:59:33315 //
Nasko Oskov9277dfc2018-09-17 23:20:54316 // TODO(nick): Should this optimization move into UnguessableToken, once it no
317 // longer treats the Null case specially?
Staphany Park6fd74a22018-12-04 21:15:41318 class COMPONENT_EXPORT(URL) Nonce {
Nasko Oskov9277dfc2018-09-17 23:20:54319 public:
320 // Creates a nonce to hold a newly-generated UnguessableToken. The actual
321 // token value will be generated lazily.
322 Nonce();
Daniel Cheng62ff0182018-08-25 07:59:33323
Nasko Oskov9277dfc2018-09-17 23:20:54324 // Creates a nonce to hold an already-generated UnguessableToken value. This
325 // constructor should only be used for IPC serialization and testing --
326 // regular code should never need to touch the UnguessableTokens directly,
327 // and the default constructor is faster.
328 explicit Nonce(const base::UnguessableToken& token);
Daniel Cheng62ff0182018-08-25 07:59:33329
Nasko Oskov9277dfc2018-09-17 23:20:54330 // Accessor, which lazily initializes the underlying |token_| member.
331 const base::UnguessableToken& token() const;
Daniel Cheng62ff0182018-08-25 07:59:33332
Nasko Oskov9277dfc2018-09-17 23:20:54333 // Do not use in cases where lazy initialization is expected! This
334 // accessor does not initialize the |token_| member.
335 const base::UnguessableToken& raw_token() const;
336
337 // Copyable and movable. Copying a Nonce triggers lazy-initialization,
338 // moving it does not.
339 Nonce(const Nonce&);
340 Nonce& operator=(const Nonce&);
341 Nonce(Nonce&&);
342 Nonce& operator=(Nonce&&);
343
344 // Note that operator<, used by maps type containers, will trigger |token_|
345 // lazy-initialization. Equality comparisons do not.
346 bool operator<(const Nonce& other) const;
347 bool operator==(const Nonce& other) const;
348 bool operator!=(const Nonce& other) const;
349
350 private:
351 friend class OriginTest;
352
353 // mutable to support lazy generation.
354 mutable base::UnguessableToken token_;
355 };
356
357 // This needs to be friended within Origin as well, since Nonce is a private
358 // nested class of Origin.
Staphany Park6fd74a22018-12-04 21:15:41359 friend COMPONENT_EXPORT(URL) std::ostream& operator<<(std::ostream& out,
360 const Nonce& nonce);
Nasko Oskov9277dfc2018-09-17 23:20:54361
362 // Creates an origin without sanity checking that the host is canonicalized.
363 // This should only be used when converting between already normalized types,
364 // and should NOT be used for IPC. Method takes std::strings for use with move
365 // operators to avoid copies.
366 static Origin CreateOpaqueFromNormalizedPrecursorTuple(
367 std::string precursor_scheme,
368 std::string precursor_host,
369 uint16_t precursor_port,
370 const Nonce& nonce);
371
372 // Creates an opaque Origin with the identity given by |nonce|, and an
373 // optional precursor origin given by |precursor_scheme|, |precursor_host| and
374 // |precursor_port|. Returns nullopt if any parameter is not canonical. When
375 // the precursor is unknown, the precursor parameters should be ("", "", 0).
376 //
377 // This factory method should be used in order to pass opaque Origin objects
378 // back and forth over IPC (as transitioning through GURL would risk
379 // potentially dangerous recanonicalization).
380 static base::Optional<Origin> UnsafelyCreateOpaqueOriginWithoutNormalization(
381 base::StringPiece precursor_scheme,
382 base::StringPiece precursor_host,
383 uint16_t precursor_port,
384 const Nonce& nonce);
385
386 // Constructs a non-opaque tuple origin. |tuple| must be valid.
Takashi Toyoshima5641d7552018-02-09 08:57:52387 explicit Origin(SchemeHostPort tuple);
mkwstd8335d982015-07-25 05:18:48388
Nasko Oskov9277dfc2018-09-17 23:20:54389 // Constructs an opaque origin derived from the |precursor| tuple, with the
390 // given |nonce|.
391 Origin(const Nonce& nonce, SchemeHostPort precursor);
392
Chris Palmerab5e5b52018-09-28 19:19:30393 // Get the nonce associated with this origin, if it is opaque. This should be
Nasko Oskov9277dfc2018-09-17 23:20:54394 // used only when trying to send an Origin across an IPC pipe.
395 base::Optional<base::UnguessableToken> GetNonceForSerialization() const;
396
Robert Ogdendd74d732020-03-12 17:33:19397 // Serializes this Origin, including its nonce if it is opaque. If an opaque
398 // origin's |tuple_| is invalid or the nonce isn't initialized, nullopt is
399 // returned. Use of this method should be limited as an opaque origin will
400 // never be matchable in future browser sessions.
401 base::Optional<std::string> SerializeWithNonce() const;
402
403 // Deserializes an origin from |ToValueWithNonce|. Returns nullopt if the
404 // value was invalid in any way.
405 static base::Optional<Origin> Deserialize(const std::string& value);
406
Nasko Oskov9277dfc2018-09-17 23:20:54407 // The tuple is used for both tuple origins (e.g. https://example.com:80), as
408 // well as for opaque origins, where it tracks the tuple origin from which
409 // the opaque origin was initially derived (we call this the "precursor"
410 // origin).
mkwst9f2cc892015-07-22 06:03:25411 SchemeHostPort tuple_;
Daniel Cheng62ff0182018-08-25 07:59:33412
413 // The nonce is used for maintaining identity of an opaque origin. This
Nasko Oskov9277dfc2018-09-17 23:20:54414 // nonce is preserved when an opaque origin is copied or moved. An Origin
415 // is considered opaque if and only if |nonce_| holds a value.
416 base::Optional<Nonce> nonce_;
mkwst9f2cc892015-07-22 06:03:25417};
418
Nasko Oskov9277dfc2018-09-17 23:20:54419// Pretty-printers for logging. These expose the internal state of the nonce.
Staphany Park6fd74a22018-12-04 21:15:41420COMPONENT_EXPORT(URL)
421std::ostream& operator<<(std::ostream& out, const Origin& origin);
422COMPONENT_EXPORT(URL)
423std::ostream& operator<<(std::ostream& out, const Origin::Nonce& origin);
palmer5c437bcc2016-02-03 23:21:36424
Staphany Park6fd74a22018-12-04 21:15:41425COMPONENT_EXPORT(URL) bool IsSameOriginWith(const GURL& a, const GURL& b);
mkwst9f2cc892015-07-22 06:03:25426
Lukasz Anforowicz3d58b9392018-01-05 20:56:22427// DEBUG_ALIAS_FOR_ORIGIN(var_name, origin) copies |origin| into a new
428// stack-allocated variable named |<var_name>|. This helps ensure that the
429// value of |origin| gets preserved in crash dumps.
430#define DEBUG_ALIAS_FOR_ORIGIN(var_name, origin) \
Daniel Chengafbf6352018-04-24 23:59:25431 DEBUG_ALIAS_FOR_CSTR(var_name, (origin).Serialize().c_str(), 128)
Lukasz Anforowicz3d58b9392018-01-05 20:56:22432
Lukasz Anforowicz731c39c2020-02-07 23:35:58433namespace debug {
434
435class COMPONENT_EXPORT(URL) ScopedOriginCrashKey
436 : public base::debug::ScopedCrashKeyString {
437 public:
438 ScopedOriginCrashKey(base::debug::CrashKeyString* crash_key,
439 const url::Origin* value);
440 ~ScopedOriginCrashKey();
441
442 ScopedOriginCrashKey(const ScopedOriginCrashKey&) = delete;
443 ScopedOriginCrashKey& operator=(const ScopedOriginCrashKey&) = delete;
444};
445
446} // namespace debug
447
mkwst9f2cc892015-07-22 06:03:25448} // namespace url
449
qyearsley2bc727d2015-08-14 20:17:15450#endif // URL_ORIGIN_H_