summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.cc
blob: 6e0f64281db528a9433e008b834f371ddac00e1b (plain)
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
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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/execution_context_lifecycle_observer.h"

#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"

namespace blink {

ExecutionContextClient::ExecutionContextClient(
    ExecutionContext* execution_context)
    : execution_context_(execution_context) {}

ExecutionContextClient::ExecutionContextClient(LocalFrame* frame)
    : execution_context_(frame ? frame->DomWindow() : nullptr) {}

ExecutionContext* ExecutionContextClient::GetExecutionContext() const {
  return execution_context_ && !execution_context_->IsContextDestroyed()
             ? execution_context_.Get()
             : nullptr;
}

LocalDOMWindow* ExecutionContextClient::DomWindow() const {
  return DynamicTo<LocalDOMWindow>(GetExecutionContext());
}

LocalFrame* ExecutionContextClient::GetFrame() const {
  auto* window = DomWindow();
  return window ? window->GetFrame() : nullptr;
}

void ExecutionContextClient::Trace(Visitor* visitor) const {
  visitor->Trace(execution_context_);
}

ExecutionContextLifecycleObserver::ExecutionContextLifecycleObserver(
    ExecutionContext* execution_context,
    Type type)
    : observer_type_(type) {
  SetExecutionContext(execution_context);
}

ExecutionContext* ExecutionContextLifecycleObserver::GetExecutionContext()
    const {
  return static_cast<ExecutionContext*>(GetContextLifecycleNotifier());
}

void ExecutionContextLifecycleObserver::SetExecutionContext(
    ExecutionContext* execution_context) {
  SetContextLifecycleNotifier(execution_context);
}

LocalFrame* ExecutionContextLifecycleObserver::GetFrame() const {
  auto* window = DynamicTo<LocalDOMWindow>(GetExecutionContext());
  return window ? window->GetFrame() : nullptr;
}

void ExecutionContextLifecycleObserver::Trace(Visitor* visitor) const {
  ContextLifecycleObserver::Trace(visitor);
}

}  // namespace blink