summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/modules/worklet/DOMWindowWorklet.cpp
blob: 07a4a32dba258e9ae7e023b52444318eb4160942 (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
// 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 "modules/worklet/DOMWindowWorklet.h"

#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "modules/worklet/Worklet.h"

namespace blink {

DOMWindowWorklet::DOMWindowWorklet(LocalDOMWindow& window)
    : DOMWindowProperty(window.frame())
{
}

DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DOMWindowWorklet);

const char* DOMWindowWorklet::supplementName()
{
    return "DOMWindowWorklet";
}

// static
DOMWindowWorklet& DOMWindowWorklet::from(LocalDOMWindow& window)
{
    DOMWindowWorklet* supplement = static_cast<DOMWindowWorklet*>(WillBeHeapSupplement<LocalDOMWindow>::from(window, supplementName()));
    if (!supplement) {
        supplement = new DOMWindowWorklet(window);
        provideTo(window, supplementName(), adoptPtrWillBeNoop(supplement));
    }
    return *supplement;
}

// static
Worklet* DOMWindowWorklet::renderWorklet(ExecutionContext* executionContext, DOMWindow& window)
{
    return from(toLocalDOMWindow(window)).renderWorklet(executionContext);
}

Worklet* DOMWindowWorklet::renderWorklet(ExecutionContext* executionContext) const
{
    if (!m_renderWorklet && frame())
        m_renderWorklet = Worklet::create(frame(), executionContext);
    return m_renderWorklet.get();
}

DEFINE_TRACE(DOMWindowWorklet)
{
    visitor->trace(m_renderWorklet);
    WillBeHeapSupplement<LocalDOMWindow>::trace(visitor);
    DOMWindowProperty::trace(visitor);
}

} // namespace blink