summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/web/OpenedFrameTracker.cpp
blob: 40930f4584c84ddd9ead0efa203fdb18f69433ea (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
// Copyright 2014 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 "web/OpenedFrameTracker.h"

#include "platform/heap/Handle.h"
#include "public/web/WebFrame.h"

namespace blink {

OpenedFrameTracker::OpenedFrameTracker()
{
}

OpenedFrameTracker::~OpenedFrameTracker()
{
#if !ENABLE(OILPAN)
    // Oilpan takes care of clearing weak m_opener fields during GC.
    transferTo(nullptr);
#endif
}

bool OpenedFrameTracker::isEmpty() const
{
    return m_openedFrames.isEmpty();
}

void OpenedFrameTracker::add(WebFrame* frame)
{
    m_openedFrames.add(frame);
}

void OpenedFrameTracker::remove(WebFrame* frame)
{
    m_openedFrames.remove(frame);
}

void OpenedFrameTracker::transferTo(WebFrame* opener)
{
    // Copy the set of opened frames, since changing the owner will mutate this set.
    HashSet<WebFrame*> frames(m_openedFrames);
    for (WebFrame* frame : frames)
        frame->setOpener(opener);
}

template <typename VisitorDispatcher>
ALWAYS_INLINE void OpenedFrameTracker::traceFramesImpl(VisitorDispatcher visitor)
{
#if ENABLE(OILPAN)
    HashSet<WebFrame*>::iterator end = m_openedFrames.end();
    for (HashSet<WebFrame*>::iterator it = m_openedFrames.begin(); it != end; ++it)
        WebFrame::traceFrame(visitor, *it);
#endif
}

void OpenedFrameTracker::traceFrames(Visitor* visitor) { traceFramesImpl(visitor); }
void OpenedFrameTracker::traceFrames(InlinedGlobalMarkingVisitor visitor) { traceFramesImpl(visitor); }

} // namespace blink