flutter_flutter/engine/core/html/HTMLImportElement.cpp
Adam Barth 8323fb1e88 Basic implementation of <import>
This CL adds basic support for the <import> elements. We're using the same imports
machinery as <link rel="import">, which simplifies this patch substantially.

Currently we support both <link rel="import"> and <import>. Once this CL lands, I'll
update all the existing modules and then we can drop support for
<link rel="import">.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/681983005
2014-11-03 10:14:09 -08:00

75 lines
1.7 KiB
C++

// 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/HTMLImportElement.h"
#include "core/dom/Document.h"
#include "core/html/imports/HTMLImportsController.h"
#include "core/html/imports/HTMLImportChild.h"
namespace blink {
HTMLImportElement::HTMLImportElement(Document& document)
: HTMLElement(HTMLNames::importTag, document)
, m_child(nullptr)
{
ScriptWrappable::init(this);
}
PassRefPtr<HTMLImportElement> HTMLImportElement::create(Document& document)
{
return adoptRef(new HTMLImportElement(document));
}
Node::InsertionNotificationRequest HTMLImportElement::insertedInto(ContainerNode* insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
if (!insertionPoint->inDocument() || isInShadowTree())
return InsertionDone;
if (shouldLoad())
load();
return InsertionDone;
}
bool HTMLImportElement::shouldLoad() const
{
return document().frame() || document().importsController();
}
void HTMLImportElement::load()
{
if (m_child || !hasAttribute(HTMLNames::srcAttr))
return;
KURL url = document().completeURL(getAttribute(HTMLNames::srcAttr));
m_child = document().ensureImportsController().load(document().import(), this, FetchRequest(ResourceRequest(url)));
if (m_child)
m_child->ownerInserted();
}
void HTMLImportElement::didFinish()
{
}
void HTMLImportElement::importChildWasDestroyed(HTMLImportChild* child)
{
ASSERT(m_child == child);
m_child = nullptr;
}
bool HTMLImportElement::isSync() const
{
return true;
}
Element* HTMLImportElement::link()
{
return this;
}
}