File: blink_schemeful_site.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (128 lines) | stat: -rw-r--r-- 4,918 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_NETWORK_BLINK_SCHEMEFUL_SITE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_NETWORK_BLINK_SCHEMEFUL_SITE_H_

#include "base/check.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace network {
namespace mojom {
class SchemefulSiteDataView;
}  // namespace mojom
}  // namespace network

namespace url {
class Origin;
}  // namespace url

namespace blink {

// This class is the blink version of net::SchemefulSite and only implements a
// subset of its features. Its data members should be kept in sync.
//
// It represents a scheme and eTLD+1 for an origin, as specified by
// https://html.spec.whatwg.org/multipage/origin.html#obtain-a-site.
//
// See schemeful_site.h for more information.
class PLATFORM_EXPORT BlinkSchemefulSite {
 public:
  // Creates a BlinkSchemefulSite with a new unique origin.
  BlinkSchemefulSite();

  // Creates a BlinkSchemefulSite with the provided `origin`.
  // The passed `origin` may not match the resulting internal representation in
  // certain circumstances. See the comment, below, on the `site_as_origin_`
  // member.
  explicit BlinkSchemefulSite(scoped_refptr<const SecurityOrigin> origin);
  explicit BlinkSchemefulSite(const url::Origin& origin);

  // Creates a BlinkSchemefulSite by converting a net::SchemefulSite.
  explicit BlinkSchemefulSite(const net::SchemefulSite& site);

  // Converts this BlinkSchemefulSite into a net::SchemefulSite.
  explicit operator net::SchemefulSite() const;

  BlinkSchemefulSite(const BlinkSchemefulSite& other) = default;
  BlinkSchemefulSite& operator=(const BlinkSchemefulSite& other) = default;
  BlinkSchemefulSite(BlinkSchemefulSite&& other) = default;
  BlinkSchemefulSite& operator=(BlinkSchemefulSite&& other) = default;

  // Returns a string version of the internal site_as_origin_. If this origin is
  // unique then this will return "null".
  String Serialize() const;

  // Returns the results of `Serialize()` with some additional human friendly
  // text.
  String GetDebugString() const;

  bool operator==(const BlinkSchemefulSite& rhs) const {
    DCHECK(site_as_origin_);
    DCHECK(rhs.site_as_origin_);
    return site_as_origin_->IsSameOriginWith(rhs.site_as_origin_.get());
  }

  bool operator!=(const BlinkSchemefulSite& rhs) const {
    return !operator==(rhs);
  }

  bool IsOpaque() const { return site_as_origin_->IsOpaque(); }

 private:
  friend struct WTF::HashTraits<BlinkSchemefulSite>;

  // IPC serialization code needs to access internal origin.
  friend struct mojo::StructTraits<network::mojom::SchemefulSiteDataView,
                                   blink::BlinkSchemefulSite>;

  FRIEND_TEST_ALL_PREFIXES(BlinkSchemefulSiteMojomTraitsTest,
                           DeserializeFailure);

  FRIEND_TEST_ALL_PREFIXES(BlinkSchemefulSiteTest, FromWire);

  // Tries to construct an instance from a (potentially
  // untrusted) value of the internal `site_as_origin_`
  // that got received over an RPC.
  //
  // Returns whether successful or not. Doesn't touch
  // `*out` if false is returned.  This returning true does
  // not mean that whoever sent the values did not lie,
  // merely that they are well-formed.
  static bool FromWire(const url::Origin& site_as_origin,
                       BlinkSchemefulSite* out);

  // Origin which stores the result of running the steps documented at
  // https://html.spec.whatwg.org/multipage/origin.html#obtain-a-site. This is
  // not an arbitrary origin. It must either be an opaque origin, or a scheme +
  // eTLD+1 + default port.
  //
  // The `origin` passed into the BlinkSchemefulSite constructors might not
  // match the internal representation used by this class to track the scheme
  // and eTLD+1 representing a schemeful site. This may be the case if, e.g.,
  // the passed `origin` has an eTLD+1 that is not equal to its hostname, or if
  // the port number is not the default port for its scheme.
  //
  // In general, this `site_as_origin_` used for the internal representation
  // should NOT be used directly by SchemefulSite consumers.
  scoped_refptr<const SecurityOrigin> site_as_origin_;
};

}  // namespace blink

namespace WTF {

template <>
struct HashTraits<blink::BlinkSchemefulSite>
    : OneFieldHashTraits<blink::BlinkSchemefulSite,
                         &blink::BlinkSchemefulSite::site_as_origin_> {};

}  // namespace WTF

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_NETWORK_BLINK_SCHEMEFUL_SITE_H_