summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/dom/context_lifecycle_observer.cc
blob: 4df3f8a4ba985055504014259893fcc7ce9ee744 (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
// 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/dom/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 {

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

ContextClient::ContextClient(LocalFrame* frame)
    : execution_context_(frame ? frame->GetDocument() : nullptr) {}

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

Document* ContextClient::GetDocument() const {
  return execution_context_
             ? DynamicTo<Document>(
                   static_cast<ExecutionContext*>(execution_context_))
             : nullptr;
}

LocalFrame* ContextClient::GetFrame() const {
  auto* document = GetDocument();
  return document ? document->GetFrame() : nullptr;
}

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

LocalFrame* ContextLifecycleObserver::GetFrame() const {
  auto* document = DynamicTo<Document>(GetExecutionContext());
  return document ? document->GetFrame() : nullptr;
}

DOMWindowClient::DOMWindowClient(LocalDOMWindow* window)
    : dom_window_(window) {}

DOMWindowClient::DOMWindowClient(LocalFrame* frame)
    : dom_window_(frame ? frame->DomWindow() : nullptr) {}

LocalDOMWindow* DOMWindowClient::DomWindow() const {
  return dom_window_ && dom_window_->GetFrame() ? dom_window_ : nullptr;
}

LocalFrame* DOMWindowClient::GetFrame() const {
  return dom_window_ ? dom_window_->GetFrame() : nullptr;
}

void DOMWindowClient::Trace(Visitor* visitor) {
  visitor->Trace(dom_window_);
}
}