File: agent.cc

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 (150 lines) | stat: -rw-r--r-- 4,035 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
144
145
146
147
148
149
150
// 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.

#include "third_party/blink/renderer/core/execution_context/agent.h"

#include "third_party/blink/renderer/bindings/core/v8/rejected_promises.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/mutation_observer.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"

namespace blink {

namespace {
bool is_cross_origin_isolated = false;
bool is_isolated_context = false;
bool is_web_security_disabled = false;

#if DCHECK_IS_ON()
bool is_cross_origin_isolated_set = false;
bool is_isolated_context_set = false;
bool is_web_security_disabled_set = false;
#endif
}  // namespace

Agent::Agent(v8::Isolate* isolate,
             const base::UnguessableToken& cluster_id,
             std::unique_ptr<v8::MicrotaskQueue> microtask_queue)
    : Agent(isolate, cluster_id, std::move(microtask_queue), false, true) {}

Agent::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)
    : isolate_(isolate),
      rejected_promises_(RejectedPromises::Create()),
      event_loop_(base::AdoptRef(
          new scheduler::EventLoop(this, isolate, std::move(microtask_queue)))),
      cluster_id_(cluster_id),
      origin_keyed_because_of_inheritance_(false),
      is_origin_agent_cluster_(is_origin_agent_cluster),
      origin_agent_cluster_left_as_default_(
          origin_agent_cluster_left_as_default) {}

Agent::~Agent() = default;

void Agent::Trace(Visitor* visitor) const {
  Supplementable<Agent>::Trace(visitor);
}

void Agent::AttachContext(ExecutionContext* context) {
  event_loop_->AttachScheduler(context->GetScheduler());
}

void Agent::DetachContext(ExecutionContext* context) {
  event_loop_->DetachScheduler(context->GetScheduler());
}

// static
bool Agent::IsCrossOriginIsolated() {
  return is_cross_origin_isolated;
}

// static
void Agent::SetIsCrossOriginIsolated(bool value) {
#if DCHECK_IS_ON()
  if (is_cross_origin_isolated_set)
    DCHECK_EQ(is_cross_origin_isolated, value);
  is_cross_origin_isolated_set = true;
#endif
  is_cross_origin_isolated = value;
}

// static
bool Agent::IsWebSecurityDisabled() {
  return is_web_security_disabled;
}

// static
void Agent::SetIsWebSecurityDisabled(bool value) {
#if DCHECK_IS_ON()
  if (is_web_security_disabled_set) {
    DCHECK_EQ(is_web_security_disabled, value);
  }
  is_web_security_disabled_set = true;
#endif
  is_web_security_disabled = value;
}

// static
bool Agent::IsIsolatedContext() {
  return is_isolated_context;
}

// static
void Agent::ResetIsIsolatedContextForTest() {
#if DCHECK_IS_ON()
  is_isolated_context_set = false;
#endif
  is_isolated_context = false;
}

// static
void Agent::SetIsIsolatedContext(bool value) {
#if DCHECK_IS_ON()
  if (is_isolated_context_set)
    DCHECK_EQ(is_isolated_context, value);
  is_isolated_context_set = true;
#endif
  is_isolated_context = value;
}

bool Agent::IsOriginKeyed() const {
  return IsCrossOriginIsolated() || IsOriginKeyedForInheritance();
}

bool Agent::IsOriginKeyedForInheritance() const {
  return is_origin_agent_cluster_ || origin_keyed_because_of_inheritance_;
}

bool Agent::IsOriginOrSiteKeyedBasedOnDefault() const {
  return origin_agent_cluster_left_as_default_;
}

void Agent::ForceOriginKeyedBecauseOfInheritance() {
  origin_keyed_because_of_inheritance_ = true;
}

bool Agent::IsWindowAgent() const {
  return false;
}

void Agent::PerformMicrotaskCheckpoint() {
  event_loop_->PerformMicrotaskCheckpoint();
}

void Agent::Dispose() {
  rejected_promises_->Dispose();
}

RejectedPromises& Agent::GetRejectedPromises() {
  return *rejected_promises_;
}

void Agent::NotifyRejectedPromises() {
  rejected_promises_->ProcessQueue();
}

}  // namespace blink