13c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch/*
23c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * Copyright (C) 2013 Google Inc. All rights reserved.
33c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch *
43c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * Redistribution and use in source and binary forms, with or without
53c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * modification, are permitted provided that the following conditions are
63c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * met:
73c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch *
83c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch *     * Redistributions of source code must retain the above copyright
93c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * notice, this list of conditions and the following disclaimer.
103c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch *     * Redistributions in binary form must reproduce the above
113c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * copyright notice, this list of conditions and the following disclaimer
123c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * in the documentation and/or other materials provided with the
133c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * distribution.
143c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch *     * Neither the name of Google Inc. nor the names of its
153c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * contributors may be used to endorse or promote products derived from
163c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * this software without specific prior written permission.
173c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch *
183c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
193c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
203c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
213c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
223c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
233c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
243c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
253c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
263c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
273c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
283c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
293c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch */
303c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
313c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch#include "config.h"
32d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/html/imports/HTMLImportLoader.h"
333c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
343c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch#include "core/dom/Document.h"
357242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/dom/DocumentParser.h"
36d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/dom/StyleEngine.h"
3776c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)#include "core/dom/custom/CustomElementSyncMicrotaskQueue.h"
383c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch#include "core/html/HTMLDocument.h"
3907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch#include "core/html/imports/HTMLImportChild.h"
406f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch#include "core/html/imports/HTMLImportsController.h"
413c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch#include "core/loader/DocumentWriter.h"
42d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "platform/network/ContentSecurityPolicyResponseHeaders.h"
433c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
443c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
45c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
463c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
476f543c786fc42989f552b4daa774ca5ff32fa697Ben MurdochHTMLImportLoader::HTMLImportLoader(HTMLImportsController* controller)
486f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    : m_controller(controller)
496f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    , m_state(StateLoading)
5076c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)    , m_microtaskQueue(CustomElementSyncMicrotaskQueue::create())
513c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
523c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
533c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)HTMLImportLoader::~HTMLImportLoader()
553c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
56f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#if !ENABLE(OILPAN)
576f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    clear();
58f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#endif
596f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch}
606f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
61f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#if !ENABLE(OILPAN)
626f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdochvoid HTMLImportLoader::importDestroyed()
636f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch{
646f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    clear();
656f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch}
666f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
676f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdochvoid HTMLImportLoader::clear()
686f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch{
69f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_controller = nullptr;
70f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (m_document) {
71f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        m_document->setImportsController(0);
72f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        m_document->cancelParsing();
73f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        m_document.clear();
74a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    }
753c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
76f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#endif
773c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void HTMLImportLoader::startLoading(const ResourcePtr<RawResource>& resource)
793c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
80a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    setResource(resource);
813c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
823c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void HTMLImportLoader::responseReceived(Resource* resource, const ResourceResponse& response)
843c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Resource may already have been loaded with the import loader
8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // being added as a client later & now being notified. Fail early.
8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (resource->loadFailedOrCanceled() || response.httpStatusCode() >= 400) {
88a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        setState(StateError);
893c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return;
903c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    }
91a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    setState(startWritingAndParsing(response));
923c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
933c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void HTMLImportLoader::dataReceived(Resource*, const char* data, int length)
953c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
96f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    RefPtrWillBeRawPtr<DocumentWriter> protectingWriter(m_writer.get());
97a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    m_writer->addData(data, length);
98a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}
993c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
10009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void HTMLImportLoader::notifyFinished(Resource* resource)
101a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){
102a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // The writer instance indicates that a part of the document can be already loaded.
103a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // We don't take such a case as an error because the partially-loaded document has been visible from script at this point.
104a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (resource->loadFailedOrCanceled() && !m_writer) {
105a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        setState(StateError);
106a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        return;
1073c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    }
1083c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
109a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    setState(finishWriting());
1103c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
1113c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
11209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceResponse& response)
1133c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
11407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    ASSERT(!m_imports.isEmpty());
1156f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    DocumentInit init = DocumentInit(response.url(), 0, m_controller->master()->contextDocument(), m_controller)
1166f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch        .withRegistrationContext(m_controller->master()->registrationContext());
117f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_document = HTMLDocument::create(init);
118f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_writer = DocumentWriter::create(m_document.get(), response.mimeType(), "UTF-8");
1193c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1207242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    DocumentParser* parser = m_document->parser();
1217242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ASSERT(parser);
1227242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    parser->addClient(this);
1237242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1243c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    return StateLoading;
1253c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
1263c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
12709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)HTMLImportLoader::State HTMLImportLoader::finishWriting()
1283c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
1293c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    return StateWritten;
1303c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
1313c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
13209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)HTMLImportLoader::State HTMLImportLoader::finishParsing()
1333c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
134d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return StateParsed;
135d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
136d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
137d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)HTMLImportLoader::State HTMLImportLoader::finishLoading()
138d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
139d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return StateLoaded;
1403c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
1413c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
14209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void HTMLImportLoader::setState(State state)
1433c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
144a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (m_state == state)
145a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        return;
1463c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
147a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    m_state = state;
1483c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
149d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (m_state == StateParsed || m_state == StateError || m_state == StateWritten) {
150f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        if (RefPtrWillBeRawPtr<DocumentWriter> writer = m_writer.release())
151a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            writer->end();
152a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    }
153a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
154a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // Since DocumentWriter::end() can let setState() reenter, we shouldn't refer to m_state here.
155d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (state == StateLoaded || state == StateError)
156d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        didFinishLoading();
1573c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
1583c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1597242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccivoid HTMLImportLoader::notifyParserStopped()
1603c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
161a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    setState(finishParsing());
162d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (!hasPendingResources())
163d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        setState(finishLoading());
1647242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1657242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    DocumentParser* parser = m_document->parser();
1667242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ASSERT(parser);
1677242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    parser->removeClient(this);
168d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
169d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
170d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void HTMLImportLoader::didRemoveAllPendingStylesheet()
171d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
172d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (m_state == StateParsed)
173d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        setState(finishLoading());
174d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
175d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
176d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)bool HTMLImportLoader::hasPendingResources() const
177d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
178f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    return m_document && m_document->styleEngine()->hasPendingSheets();
1793c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
1803c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
181d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void HTMLImportLoader::didFinishLoading()
1823c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
18307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    for (size_t i = 0; i < m_imports.size(); ++i)
18407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        m_imports[i]->didFinishLoading();
185a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
186a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    clearResource();
187a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
188f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    ASSERT(!m_document || !m_document->parsing());
1893c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
1903c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
191d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)void HTMLImportLoader::moveToFirst(HTMLImportChild* import)
192d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles){
193d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    size_t position = m_imports.find(import);
194d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    ASSERT(kNotFound != position);
195d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    m_imports.remove(position);
196d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    m_imports.insert(0, import);
197d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)}
198d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
19910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochvoid HTMLImportLoader::addImport(HTMLImportChild* import)
2003c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
20110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    ASSERT(kNotFound == m_imports.find(import));
20210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
203d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    m_imports.append(import);
204d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    import->normalize();
205a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (isDone())
20610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        import->didFinishLoading();
2073c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
2083c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
209f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#if !ENABLE(OILPAN)
21007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochvoid HTMLImportLoader::removeImport(HTMLImportChild* client)
2113c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch{
21207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    ASSERT(kNotFound != m_imports.find(client));
21307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    m_imports.remove(m_imports.find(client));
2143c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch}
215f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#endif
2163c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
21710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochbool HTMLImportLoader::shouldBlockScriptExecution() const
21810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch{
219d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    return firstImport()->state().shouldBlockScriptExecution();
22010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch}
22110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
22276c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)PassRefPtrWillBeRawPtr<CustomElementSyncMicrotaskQueue> HTMLImportLoader::microtaskQueue() const
22310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch{
22410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    return m_microtaskQueue;
22510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch}
22610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
227f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)void HTMLImportLoader::trace(Visitor* visitor)
228f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles){
229f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    visitor->trace(m_controller);
230f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#if ENABLE(OILPAN)
231f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    visitor->trace(m_imports);
232f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#endif
233f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    visitor->trace(m_document);
234f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    visitor->trace(m_writer);
235f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    visitor->trace(m_microtaskQueue);
236f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)}
237f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
238c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
239