| Index: third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| index 7b3915aaac0eec2ae7e42d89ecbea6a1915a3734..9e02c862dd56574202b494d47f0c6f6bbb53f34f 100644
|
| --- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| @@ -24,13 +24,17 @@
|
|
|
| #include "core/dom/ScriptLoader.h"
|
|
|
| +#include "bindings/core/v8/ModuleController.h"
|
| #include "bindings/core/v8/ScriptController.h"
|
| #include "bindings/core/v8/ScriptSourceCode.h"
|
| +#include "bindings/core/v8/ScriptState.h"
|
| #include "core/HTMLNames.h"
|
| #include "core/SVGNames.h"
|
| #include "core/dom/Document.h"
|
| #include "core/dom/DocumentParserTiming.h"
|
| #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
|
| +#include "core/dom/Modulator.h"
|
| +#include "core/dom/ModuleScript.h"
|
| #include "core/dom/ScriptLoaderClient.h"
|
| #include "core/dom/ScriptRunner.h"
|
| #include "core/dom/ScriptableDocumentParser.h"
|
| @@ -60,6 +64,47 @@
|
|
|
| namespace blink {
|
|
|
| +class ScriptElementModuleClient
|
| + : public GarbageCollectedFinalized<ScriptElementModuleClient>,
|
| + public ModuleTreeClient {
|
| + USING_GARBAGE_COLLECTED_MIXIN(ScriptElementModuleClient);
|
| +
|
| + public:
|
| + static ScriptElementModuleClient* create(Element* element) {
|
| + return new ScriptElementModuleClient(element);
|
| + }
|
| + virtual ~ScriptElementModuleClient() = default;
|
| +
|
| + DECLARE_TRACE();
|
| +
|
| + private:
|
| + ScriptElementModuleClient(Element* element) : m_element(element) {}
|
| +
|
| + // Implements ModuleTreeClient
|
| + void notifyFinishedModuleTree(ModuleScript*) override;
|
| +
|
| + Member<Element> m_element;
|
| +};
|
| +
|
| +void ScriptElementModuleClient::notifyFinishedModuleTree(
|
| + ModuleScript* moduleScript) {
|
| + printf("notifyFinishedModuleTree!!! moduleScript: %p\n", moduleScript);
|
| + if (!moduleScript)
|
| + return;
|
| + DCHECK(moduleScript->instantiationState() ==
|
| + InstantiationState::Instantiated);
|
| +
|
| + // TODO(kouhei): Actually we should just return w/ the prepared script here.
|
| + // In this prototype, we will execute the module immediately just for fun. :)
|
| + m_element->document().ensureModulator()->moduleController()->executeModule(
|
| + moduleScript->record());
|
| +}
|
| +
|
| +DEFINE_TRACE(ScriptElementModuleClient) {
|
| + visitor->trace(m_element);
|
| + ModuleTreeClient::trace(visitor);
|
| +}
|
| +
|
| ScriptLoader::ScriptLoader(Element* element,
|
| bool parserInserted,
|
| bool alreadyStarted,
|
| @@ -90,6 +135,7 @@ ScriptLoader::~ScriptLoader() {}
|
| DEFINE_TRACE(ScriptLoader) {
|
| visitor->trace(m_element);
|
| visitor->trace(m_resource);
|
| + visitor->trace(m_elementModuleClient);
|
| visitor->trace(m_pendingScript);
|
| PendingScriptClient::trace(visitor);
|
| }
|
| @@ -260,6 +306,7 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition,
|
| if (m_documentWriteIntervention ==
|
| DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle)
|
| defer = FetchRequest::IdleLoad;
|
| +
|
| if (!fetchScript(client->sourceAttributeValue(), defer))
|
| return false;
|
| }
|
| @@ -335,10 +382,22 @@ bool ScriptLoader::fetchScript(const String& sourceUrl,
|
| return false;
|
|
|
| DCHECK(!m_resource);
|
| +
|
| if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) {
|
| - FetchRequest request(
|
| - ResourceRequest(elementDocument->completeURL(sourceUrl)),
|
| - m_element->localName());
|
| + KURL url = elementDocument->completeURL(sourceUrl);
|
| + if (RuntimeEnabledFeatures::moduleScriptsEnabled() &&
|
| + client()->typeAttributeValue() == "module") {
|
| + m_elementModuleClient = ScriptElementModuleClient::create(m_element);
|
| +
|
| + // TODO(kouhei): Per spec, we should actually pass in "settings object"
|
| + // which contains the baseURL.
|
| + KURL baseURL = elementDocument->baseURL();
|
| + elementDocument->ensureModulator()->fetchTree(url, baseURL,
|
| + m_elementModuleClient);
|
| + return true;
|
| + }
|
| +
|
| + FetchRequest request(ResourceRequest(url), m_element->localName());
|
|
|
| CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(
|
| m_element->fastGetAttribute(HTMLNames::crossoriginAttr));
|
|
|