summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/html/imports/HTMLImportTreeRoot.cpp
blob: bfe0beded33de35843f357700e2b4af4a64bde14 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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 "config.h"
#include "core/html/imports/HTMLImportTreeRoot.h"

#include "core/dom/Document.h"
#include "core/dom/StyleEngine.h"
#include "core/frame/LocalFrame.h"
#include "core/html/imports/HTMLImportChild.h"

namespace WebCore {

PassOwnPtrWillBeRawPtr<HTMLImportTreeRoot> HTMLImportTreeRoot::create(Document* document)
{
    return adoptPtrWillBeNoop(new HTMLImportTreeRoot(document));
}

HTMLImportTreeRoot::HTMLImportTreeRoot(Document* document)
    : HTMLImport(HTMLImport::Sync)
    , m_document(document)
    , m_recalcTimer(this, &HTMLImportTreeRoot::recalcTimerFired)
{
    recalcTreeState(this); // This recomputes initial state.
}

HTMLImportTreeRoot::~HTMLImportTreeRoot()
{
#if !ENABLE(OILPAN)
    for (size_t i = 0; i < m_imports.size(); ++i)
        m_imports[i]->importDestroyed();
    m_imports.clear();
    m_document = nullptr;
#endif
}

Document* HTMLImportTreeRoot::document() const
{
    return m_document;
}

bool HTMLImportTreeRoot::isDone() const
{
    return !m_document->parsing() && m_document->styleEngine()->haveStylesheetsLoaded();
}

void HTMLImportTreeRoot::stateWillChange()
{
    scheduleRecalcState();
}

void HTMLImportTreeRoot::stateDidChange()
{
    HTMLImport::stateDidChange();

    if (!state().isReady())
        return;
    if (LocalFrame* frame = m_document->frame())
        frame->loader().checkCompleted();
}

void HTMLImportTreeRoot::scheduleRecalcState()
{
#if ENABLE(OILPAN)
    ASSERT(m_document);
    if (m_recalcTimer.isActive() || !m_document->isActive())
        return;
#else
    if (m_recalcTimer.isActive() || !m_document)
        return;
#endif
    m_recalcTimer.startOneShot(0, FROM_HERE);
}

HTMLImportChild* HTMLImportTreeRoot::add(PassOwnPtrWillBeRawPtr<HTMLImportChild> child)
{
    m_imports.append(child);
    return m_imports.last().get();
}

HTMLImportChild* HTMLImportTreeRoot::find(const KURL& url) const
{
    for (size_t i = 0; i < m_imports.size(); ++i) {
        HTMLImportChild* candidate = m_imports[i].get();
        if (equalIgnoringFragmentIdentifier(candidate->url(), url))
            return candidate;
    }

    return 0;
}

void HTMLImportTreeRoot::recalcTimerFired(Timer<HTMLImportTreeRoot>*)
{
    ASSERT(m_document);

    do {
        m_recalcTimer.stop();
        HTMLImport::recalcTreeState(this);
    } while (m_recalcTimer.isActive());
}

void HTMLImportTreeRoot::trace(Visitor* visitor)
{
    visitor->trace(m_document);
    visitor->trace(m_imports);
    HTMLImport::trace(visitor);
}

}