This source file includes following definitions.
- m_client
- wasAlreadyLoaded
- startLoading
- didFinish
- didFinishLoading
- importedDocument
- importDestroyed
- root
- document
- wasDetachedFromDocument
- didFinishParsing
- didRemoveAllPendingStylesheet
- stateDidChange
- ensureLoader
- createLoader
- shareLoader
- isDone
- hasLoader
- ownsLoader
- loaderHasError
- setClient
- clearClient
- link
- showThis
#include "config.h"
#include "core/html/imports/HTMLImportChild.h"
#include "core/dom/Document.h"
#include "core/dom/custom/CustomElement.h"
#include "core/dom/custom/CustomElementMicrotaskImportStep.h"
#include "core/html/imports/HTMLImportChildClient.h"
#include "core/html/imports/HTMLImportLoader.h"
namespace WebCore {
HTMLImportChild::HTMLImportChild(Document& master, const KURL& url, SyncMode sync)
: HTMLImport(sync)
, m_master(master)
, m_url(url)
, m_customElementMicrotaskStep(0)
, m_client(0)
{
m_master.guardRef();
}
HTMLImportChild::~HTMLImportChild()
{
ASSERT(!m_loader);
if (m_customElementMicrotaskStep) {
m_customElementMicrotaskStep->importDidFinish();
m_customElementMicrotaskStep = 0;
}
if (m_client)
m_client->importChildWasDestroyed(this);
m_master.guardDeref();
}
void HTMLImportChild::wasAlreadyLoaded()
{
ASSERT(!m_loader);
ASSERT(m_client);
stateWillChange();
}
void HTMLImportChild::startLoading(const ResourcePtr<RawResource>& resource)
{
ASSERT(!this->resource());
ASSERT(!m_loader);
if (isSync()) {
ASSERT(!m_customElementMicrotaskStep);
m_customElementMicrotaskStep = CustomElement::didCreateImport(this);
}
setResource(resource);
if (state().shouldBlockDocumentCreation())
return;
ensureLoader();
}
void HTMLImportChild::didFinish()
{
if (m_client)
m_client->didFinish();
if (m_customElementMicrotaskStep) {
m_customElementMicrotaskStep->importDidFinish();
m_customElementMicrotaskStep = 0;
}
}
void HTMLImportChild::didFinishLoading()
{
clearResource();
stateWillChange();
}
Document* HTMLImportChild::importedDocument() const
{
if (!m_loader)
return 0;
return m_loader->importedDocument();
}
void HTMLImportChild::importDestroyed()
{
if (parent())
parent()->removeChild(this);
if (m_loader) {
m_loader->removeImport(this);
m_loader.clear();
}
}
HTMLImportRoot* HTMLImportChild::root()
{
return parent() ? parent()->root() : 0;
}
Document* HTMLImportChild::document() const
{
return (m_loader && m_loader->isOwnedBy(this)) ? m_loader->document() : 0;
}
void HTMLImportChild::wasDetachedFromDocument()
{
ASSERT_NOT_REACHED();
}
void HTMLImportChild::didFinishParsing()
{
ASSERT(m_loader->isOwnedBy(this));
m_loader->didFinishParsing();
}
void HTMLImportChild::didRemoveAllPendingStylesheet()
{
ASSERT(m_loader->isOwnedBy(this));
m_loader->didRemoveAllPendingStylesheet();
}
void HTMLImportChild::stateDidChange()
{
HTMLImport::stateDidChange();
if (!state().shouldBlockDocumentCreation())
ensureLoader();
if (state().isReady())
didFinish();
}
void HTMLImportChild::ensureLoader()
{
if (m_loader)
return;
if (HTMLImportChild* found = root()->findLinkFor(m_url, this))
shareLoader(found);
else
createLoader();
}
void HTMLImportChild::createLoader()
{
ASSERT(!state().shouldBlockDocumentCreation());
ASSERT(!m_loader);
m_loader = HTMLImportLoader::create();
m_loader->addImport(this);
m_loader->startLoading(resource());
}
void HTMLImportChild::shareLoader(HTMLImportChild* loader)
{
ASSERT(!m_loader);
m_loader = loader->m_loader;
m_loader->addImport(this);
stateWillChange();
}
bool HTMLImportChild::isDone() const
{
return m_loader && m_loader->isDone();
}
bool HTMLImportChild::hasLoader() const
{
return m_loader;
}
bool HTMLImportChild::ownsLoader() const
{
return m_loader && m_loader->isOwnedBy(this);
}
bool HTMLImportChild::loaderHasError() const
{
return m_loader && m_loader->hasError();
}
void HTMLImportChild::setClient(HTMLImportChildClient* client)
{
ASSERT(client);
ASSERT(!m_client);
m_client = client;
}
void HTMLImportChild::clearClient()
{
m_client = 0;
}
HTMLLinkElement* HTMLImportChild::link() const
{
if (!m_client)
return 0;
return m_client->link();
}
#if !defined(NDEBUG)
void HTMLImportChild::showThis()
{
HTMLImport::showThis();
fprintf(stderr, " loader=%p own=%s async=%s url=%s",
m_loader.get(),
hasLoader() && ownsLoader() ? "Y" : "N",
isSync() ? "Y" : "N",
url().string().utf8().data());
}
#endif
}