File: agent.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 (143 lines) | stat: -rw-r--r-- 5,839 bytes parent folder | download | duplicates (6)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2019 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_CORE_EXECUTION_CONTEXT_AGENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_EXECUTION_CONTEXT_AGENT_H_

#include "base/dcheck_is_on.h"
#include "base/memory/scoped_refptr.h"
#include "base/unguessable_token.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "v8/include/v8-forward.h"
#include "v8/include/v8-microtask-queue.h"

namespace blink {

class ExecutionContext;
class RejectedPromises;

// Corresponding spec concept is:
// https://html.spec.whatwg.org/C#integration-with-the-javascript-agent-formalism
//
// Agent is a group of browsing contexts that can access each other
// synchronously. E.g. same-site iframes share the same agent, Workers and
// Worklets have their own agent.
// While an WindowAgentFactory is shared across a group of reachable frames,
// Agent is shared across a group of reachable and same-site frames.
class CORE_EXPORT Agent : public GarbageCollected<Agent>,
                          public Supplementable<Agent>,
                          public scheduler::EventLoop::Delegate {
 public:
  // Do not create the instance directly.
  // Use MakeGarbageCollected<Agent>() or
  // WindowAgentFactory::GetAgentForOrigin().
  Agent(v8::Isolate* isolate,
        const base::UnguessableToken& cluster_id,
        std::unique_ptr<v8::MicrotaskQueue> microtask_queue = nullptr);
  virtual ~Agent();

  const scoped_refptr<scheduler::EventLoop>& event_loop() const {
    return event_loop_;
  }

  v8::Isolate* isolate() { return isolate_; }

  void Trace(Visitor*) const override;

  void AttachContext(ExecutionContext*);
  void DetachContext(ExecutionContext*);

  const base::UnguessableToken& cluster_id() const { return cluster_id_; }

  // Representing agent cluster's "cross-origin isolated" concept.
  // TODO(yhirano): Have the spec URL.
  // This property is renderer process global because we ensure that a
  // renderer process host only cross-origin isolated agents or only
  // non-cross-origin isolated agents, not both.
  // This variable is initialized before any frame is created, and will not
  // be modified after that. Hence this can be accessed from the main thread
  // and worker/worklet threads.
  static bool IsCrossOriginIsolated();
  // Only called from blink::SetIsCrossOriginIsolated.
  static void SetIsCrossOriginIsolated(bool value);

  static bool IsWebSecurityDisabled();
  static void SetIsWebSecurityDisabled(bool value);

  // Represents adherence to an additional set of restrictions above and beyond
  // "cross-origin isolated".
  //
  // TODO(mkwst): We need a specification for these restrictions:
  // https://crbug.com/1206150.
  static bool IsIsolatedContext();
  static void ResetIsIsolatedContextForTest();
  // Only called from blink::SetIsIsolatedContext.
  static void SetIsIsolatedContext(bool value);

  // Representing agent cluster's "is origin-keyed" concept:
  // https://html.spec.whatwg.org/C/#is-origin-keyed
  //
  // Note that unlike IsCrossOriginIsolated(), this is not static/process-global
  // because we do not guarantee that a given process only contains agents with
  // the same origin-keying status.
  //
  // For example, a page with no Origin-Agent-Cluster header, that uses a data:
  // URL to create an iframe, would have an origin-keyed data: URL Agent,
  // plus a site-keyed outer page Agent, both in the same process.
  bool IsOriginKeyed() const;

  // TODO(domenic,wjmaclean): once logical cross-origin isolation is implemented
  // and unified with origin-keyed agent clusters, then this should no longer be
  // necessary; we can just check IsOriginKeyed().
  //
  // IsOriginKeyedForInheritance() returns true if either this agent represents
  // an origin-keyed agent cluster, as determined by the navigation request,
  // or if ForceOriginKeyedBecauseOfInheritance has been called by the loader.
  bool IsOriginKeyedForInheritance() const;

  // If no Origin-Agent-Cluster http header was set, the decision for site- or
  // origin-keyed agent clusters is based on the default behaviour, which is
  // scheduled to change in the M106 release. If this clustering is based on
  // the default handling, IsOriginOrSiteKeyedBasedOnDefault is true.
  bool IsOriginOrSiteKeyedBasedOnDefault() const;

  // Force usage of origin-keyed agent cluster. For use by the document loader,
  // for cases where the origin-keyed should be inherited from parent documents.
  void ForceOriginKeyedBecauseOfInheritance();

  // Returns if this is a Window Agent or not.
  virtual bool IsWindowAgent() const;

  virtual void Dispose();
  virtual void PerformMicrotaskCheckpoint();

  RejectedPromises& GetRejectedPromises();

 protected:
  Agent(v8::Isolate* isolate,
        const base::UnguessableToken& cluster_id,
        std::unique_ptr<v8::MicrotaskQueue> microtask_queue,
        bool is_origin_agent_cluster,
        bool origin_agent_cluster_left_as_default);

 private:
  // scheduler::EventLoopDelegate overrides:
  void NotifyRejectedPromises() override;

  v8::Isolate* isolate_;
  scoped_refptr<RejectedPromises> rejected_promises_;
  scoped_refptr<scheduler::EventLoop> event_loop_;
  const base::UnguessableToken cluster_id_;
  bool origin_keyed_because_of_inheritance_;
  const bool is_origin_agent_cluster_;
  const bool origin_agent_cluster_left_as_default_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_EXECUTION_CONTEXT_AGENT_H_