1 // Copyright 2019 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 #include "third_party/blink/renderer/core/execution_context/agent.h"
6 
7 #include "third_party/blink/renderer/core/dom/document.h"
8 #include "third_party/blink/renderer/core/dom/mutation_observer.h"
9 #include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
10 
11 namespace blink {
12 
13 namespace {
14 bool is_cross_origin_isolated = false;
15 
16 #if DCHECK_IS_ON()
17 bool is_cross_origin_isolated_set = false;
18 #endif
19 }  // namespace
20 
Agent(v8::Isolate * isolate,const base::UnguessableToken & cluster_id,std::unique_ptr<v8::MicrotaskQueue> microtask_queue)21 Agent::Agent(v8::Isolate* isolate,
22              const base::UnguessableToken& cluster_id,
23              std::unique_ptr<v8::MicrotaskQueue> microtask_queue)
24     : event_loop_(base::AdoptRef(
25           new scheduler::EventLoop(isolate, std::move(microtask_queue)))),
26       cluster_id_(cluster_id) {}
27 
28 Agent::~Agent() = default;
29 
Trace(Visitor * visitor) const30 void Agent::Trace(Visitor* visitor) const {}
31 
AttachContext(ExecutionContext * context)32 void Agent::AttachContext(ExecutionContext* context) {
33   event_loop_->AttachScheduler(context->GetScheduler());
34 }
35 
DetachContext(ExecutionContext * context)36 void Agent::DetachContext(ExecutionContext* context) {
37   event_loop_->DetachScheduler(context->GetScheduler());
38 }
39 
40 // static
IsCrossOriginIsolated()41 bool Agent::IsCrossOriginIsolated() {
42   return is_cross_origin_isolated;
43 }
44 
45 // static
SetIsCrossOriginIsolated(bool value)46 void Agent::SetIsCrossOriginIsolated(bool value) {
47 #if DCHECK_IS_ON()
48   if (is_cross_origin_isolated_set)
49     DCHECK_EQ(is_cross_origin_isolated, value);
50   is_cross_origin_isolated_set = true;
51 #endif
52   is_cross_origin_isolated = value;
53 }
54 
IsOriginIsolated()55 bool Agent::IsOriginIsolated() {
56 #if DCHECK_IS_ON()
57   DCHECK(is_origin_isolated_set_);
58 #endif
59   return is_origin_isolated_;
60 }
61 
SetIsOriginIsolated(bool value)62 void Agent::SetIsOriginIsolated(bool value) {
63 #if DCHECK_IS_ON()
64   DCHECK(!is_origin_isolated_set_ || value == is_origin_isolated_);
65   is_origin_isolated_set_ = true;
66 #endif
67   is_origin_isolated_ = value;
68 }
69 
70 }  // namespace blink
71