Index: Source/core/html/HTMLImportsController.cpp |
diff --git a/Source/core/html/HTMLImportsController.cpp b/Source/core/html/HTMLImportsController.cpp |
index 7202664f6a9afdedcfb91de5ecbcdbdd67d6b654..f147f4780b2068cf759edf9a48cf24ce9a763b38 100644 |
--- a/Source/core/html/HTMLImportsController.cpp |
+++ b/Source/core/html/HTMLImportsController.cpp |
@@ -49,120 +49,126 @@ PassRefPtr<LinkImport> LinkImport::create(HTMLLinkElement* owner) |
LinkImport::LinkImport(HTMLLinkElement* owner) |
: LinkResource(owner) |
- , m_controller(0) |
- , m_ofSameLocation(0) |
- , m_state(StatePreparing) |
{ |
} |
LinkImport::~LinkImport() |
{ |
- if (m_resource) |
- m_resource->removeClient(this); |
} |
-LinkImport::State LinkImport::finish() |
+Document* LinkImport::importedDocument() const |
{ |
- if (!m_controller) |
- return StateError; |
+ if (!m_loader) |
+ return 0; |
+ return m_loader->importedDocument(); |
+} |
- if (m_resource->loadFailedOrCanceled()) |
- return StateError; |
+void LinkImport::process() |
+{ |
+ if (m_loader) |
+ return; |
+ if (!m_owner) |
+ return; |
- String error; |
- if (!m_controller->securityOrigin()->canRequest(m_resource->response().url()) |
- && !m_resource->passesAccessControlCheck(m_controller->securityOrigin(), error)) { |
- m_controller->showSecurityErrorMessage("Import from origin '" + SecurityOrigin::create(m_resource->response().url())->toString() + "' has been blocked from loading by Cross-Origin Resource Sharing policy: " + error); |
- return StateError; |
+ // FIXME(morrita): Should take care of sub-imports whose document doesn't have frame. |
+ if (!m_owner->document()->frame()) |
+ return; |
+ |
+ LinkRequestBuilder builder(m_owner); |
+ if (!builder.isValid()) |
+ return; |
+ |
+ HTMLImportsController* controller = m_owner->document()->ensureImports(); |
+ if (RefPtr<HTMLImportLoader> found = controller->findLinkFor(builder.url())) { |
+ m_loader = found; |
+ return; |
} |
- // FIXME(morrita): This should be done in incremental way. |
- m_importedDocument = HTMLDocument::create(0, m_resource->response().url()); |
- m_importedDocument->setContent(m_resource->script()); |
+ CachedResourceRequest request = builder.build(true); |
+ CachedResourceHandle<CachedScript> resource = m_owner->document()->cachedResourceLoader()->requestScript(request); |
+ m_loader = HTMLImportLoader::create(controller, builder.url(), resource); |
+} |
- return StateReady; |
+void LinkImport::ownerRemoved() |
+{ |
+ m_owner = 0; |
+ m_loader.clear(); |
} |
-void LinkImport::notifyFinished(CachedResource*) |
+ |
+PassRefPtr<HTMLImportLoader> HTMLImportLoader::create(HTMLImportsController* controller, const KURL& url, const CachedResourceHandle<CachedScript>& resource) |
+{ |
+ RefPtr<HTMLImportLoader> loader = adoptRef(new HTMLImportLoader(controller, url, resource)); |
+ controller->addImport(loader); |
+ return loader; |
+} |
+ |
+HTMLImportLoader::HTMLImportLoader(HTMLImportsController* controller, const KURL& url, const CachedResourceHandle<CachedScript>& resource) |
+ : m_controller(controller) |
+ , m_state(StateLoading) |
+ , m_resource(resource) |
+ , m_url(url) |
+{ |
+ m_resource->addClient(this); |
+} |
+ |
+HTMLImportLoader::~HTMLImportLoader() |
+{ |
+ if (m_resource) |
+ m_resource->removeClient(this); |
+} |
+ |
+void HTMLImportLoader::notifyFinished(CachedResource*) |
{ |
setState(finish()); |
} |
-void LinkImport::setState(State state) |
+void HTMLImportLoader::setState(State state) |
{ |
if (m_state == state) |
return; |
m_state = state; |
- if ((m_state == StateReady || m_state == StateError) |
- && m_controller) |
+ if ((m_state == StateReady || m_state == StateError) && m_controller) |
m_controller->didLoad(); |
} |
-LinkImport::State LinkImport::startRequest() |
+HTMLImportLoader::State HTMLImportLoader::finish() |
{ |
- ASSERT(m_owner); |
- ASSERT(m_state == StatePreparing); |
- |
- // FIXME(morrita): Should take care of sub-imports whose document doesn't have frame. |
- if (!m_owner->document()->frame()) |
+ if (!m_controller) |
return StateError; |
- LinkRequestBuilder builder(m_owner); |
- if (!builder.isValid()) |
+ if (m_resource->loadFailedOrCanceled()) |
return StateError; |
- m_controller = m_owner->document()->ensureImports(); |
- if (RefPtr<LinkImport> found = m_controller->findLinkFor(builder.url())) { |
- m_ofSameLocation = found.get(); |
- return StateReady; |
- } |
- |
- CachedResourceRequest request = builder.build(true); |
- m_resource = m_owner->document()->cachedResourceLoader()->requestScript(request); |
- if (!m_resource) |
+ String error; |
+ if (!m_controller->securityOrigin()->canRequest(m_resource->response().url()) |
+ && !m_resource->passesAccessControlCheck(m_controller->securityOrigin(), error)) { |
+ m_controller->showSecurityErrorMessage("Import from origin '" + SecurityOrigin::create(m_resource->response().url())->toString() + "' has been blocked from loading by Cross-Origin Resource Sharing policy: " + error); |
return StateError; |
+ } |
- m_resource->addClient(this); |
- m_url = builder.url(); |
- m_controller->addImport(this); |
+ // FIXME(morrita): This should be done in incremental way. |
+ m_importedDocument = HTMLDocument::create(0, m_resource->response().url()); |
+ m_importedDocument->setContent(m_resource->script()); |
- return StateStarted; |
+ return StateReady; |
} |
-Document* LinkImport::importedDocument() const |
+Document* HTMLImportLoader::importedDocument() const |
{ |
- if (!m_owner) |
- return 0; |
if (m_state != StateReady) |
return 0; |
- |
- if (m_ofSameLocation) { |
- ASSERT(!m_importedDocument); |
- return m_ofSameLocation->importedDocument(); |
- } |
- |
return m_importedDocument.get(); |
} |
-void LinkImport::process() |
-{ |
- if (StatePreparing != m_state) |
- return; |
- setState(startRequest()); |
-} |
- |
-void LinkImport::ownerRemoved() |
-{ |
- m_owner = 0; |
-} |
- |
-void LinkImport::importDestroyed() |
+void HTMLImportLoader::importDestroyed() |
{ |
m_controller = 0; |
m_importedDocument.clear(); |
} |
+ |
PassOwnPtr<HTMLImportsController> HTMLImportsController::create(Document* master) |
{ |
return adoptPtr(new HTMLImportsController(master)); |
@@ -179,7 +185,7 @@ HTMLImportsController::~HTMLImportsController() |
m_imports[i]->importDestroyed(); |
} |
-void HTMLImportsController::addImport(PassRefPtr<LinkImport> link) |
+void HTMLImportsController::addImport(PassRefPtr<HTMLImportLoader> link) |
{ |
ASSERT(!link->url().isEmpty() && link->url().isValid()); |
m_imports.append(link); |
@@ -196,7 +202,7 @@ void HTMLImportsController::didLoad() |
m_master->didLoadAllImports(); |
} |
-PassRefPtr<LinkImport> HTMLImportsController::findLinkFor(const KURL& url) const |
+PassRefPtr<HTMLImportLoader> HTMLImportsController::findLinkFor(const KURL& url) const |
{ |
for (size_t i = 0; i < m_imports.size(); ++i) { |
if (m_imports[i]->url() == url) |