| 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 f85f7ca523bfd0215bbf113a5eea03f0935ae9b5..35377b8b84234fc8425fd6e7b410dde98c0f5f26 100644
|
| --- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| @@ -26,11 +26,14 @@
|
|
|
| #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"
|
| @@ -45,6 +48,7 @@
|
| #include "core/html/imports/HTMLImport.h"
|
| #include "core/html/parser/HTMLParserIdioms.h"
|
| #include "core/inspector/ConsoleMessage.h"
|
| +#include "core/loader/modulescript/ModuleScriptFetchRequest.h"
|
| #include "core/svg/SVGScriptElement.h"
|
| #include "platform/WebFrameScheduler.h"
|
| #include "platform/loader/fetch/AccessControlStatus.h"
|
| @@ -60,6 +64,48 @@
|
|
|
| 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 notifyModuleTreeLoadFinished(ModuleScript*) override;
|
| +
|
| + Member<Element> m_element;
|
| +};
|
| +
|
| +void ScriptElementModuleClient::notifyModuleTreeLoadFinished(
|
| + ModuleScript* moduleScript) {
|
| + printf("notifyFinishedModuleTree!!! moduleScript: %p\n", moduleScript);
|
| + if (!moduleScript)
|
| + return;
|
| + DCHECK_EQ(moduleScript->instantiationState(),
|
| + ModuleInstantiationState::Instantiated);
|
| +
|
| + LocalFrame* frame = m_element->document().frame();
|
| +
|
| + // TODO(kouhei): Actually we should just return w/ the prepared script here.
|
| + // In this prototype, we will execute the module immediately just for fun. :)
|
| + Modulator::from(frame)->executeModule(moduleScript->record());
|
| +}
|
| +
|
| +DEFINE_TRACE(ScriptElementModuleClient) {
|
| + visitor->trace(m_element);
|
| + ModuleTreeClient::trace(visitor);
|
| +}
|
| +
|
| ScriptLoader::ScriptLoader(Element* element,
|
| bool parserInserted,
|
| bool alreadyStarted,
|
| @@ -107,6 +153,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);
|
| }
|
| @@ -319,6 +366,7 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition,
|
| if (m_documentWriteIntervention ==
|
| DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle)
|
| defer = FetchRequest::IdleLoad;
|
| +
|
| if (!fetchScript(client->sourceAttributeValue(), encoding, defer))
|
| return false;
|
| }
|
| @@ -522,19 +570,52 @@ bool ScriptLoader::fetchScript(const String& sourceUrl,
|
| DCHECK(!m_resource);
|
| // 21. "If the element has a src content attribute, run these substeps:"
|
| if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) {
|
| - // 21.4. "Parse src relative to the element's node document."
|
| - FetchRequest request(
|
| - ResourceRequest(elementDocument->completeURL(sourceUrl)),
|
| - m_element->localName());
|
| + KURL url = elementDocument->completeURL(sourceUrl);
|
|
|
| // 15. "Let CORS setting be the current state of the element's
|
| // crossorigin content attribute."
|
| CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(
|
| m_element->fastGetAttribute(HTMLNames::crossoriginAttr));
|
|
|
| - // 16. "Let module script credentials mode be determined by switching
|
| - // on CORS setting:"
|
| - // TODO(hiroshige): Implement this step for "module".
|
| + if (RuntimeEnabledFeatures::moduleScriptsEnabled() &&
|
| + client()->typeAttributeValue() == "module") {
|
| + m_elementModuleClient = ScriptElementModuleClient::create(m_element);
|
| +
|
| + String nonce;
|
| + if (ContentSecurityPolicy::isNonceableElement(m_element.get())) {
|
| + nonce = m_element->fastGetAttribute(HTMLNames::nonceAttr);
|
| + }
|
| + ParserDisposition parserState =
|
| + isParserInserted() ? ParserInserted : NotParserInserted;
|
| +
|
| + // 16. "Let module script credentials mode be determined by switching
|
| + // on CORS setting:"
|
| + WebURLRequest::FetchCredentialsMode credentialsMode;
|
| + switch (crossOrigin) {
|
| + case CrossOriginAttributeNotSet:
|
| + credentialsMode = WebURLRequest::FetchCredentialsModeOmit;
|
| + break;
|
| + case CrossOriginAttributeAnonymous:
|
| + credentialsMode = WebURLRequest::FetchCredentialsModeSameOrigin;
|
| + break;
|
| + case CrossOriginAttributeUseCredentials:
|
| + credentialsMode = WebURLRequest::FetchCredentialsModeInclude;
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| +
|
| + ModuleScriptFetchRequest moduleRequest(url, nonce, parserState,
|
| + credentialsMode);
|
| + Modulator::from(elementDocument->frame())
|
| + ->fetchTree(moduleRequest, m_elementModuleClient);
|
| + return true;
|
| + }
|
| +
|
| + // 21.4. "Parse src relative to the element's node document."
|
| + FetchRequest request(
|
| + ResourceRequest(elementDocument->completeURL(sourceUrl)),
|
| + m_element->localName());
|
|
|
| // 21.6, "classic": "Fetch a classic script given ... CORS setting
|
| // ... and encoding."
|
|
|