Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: address haraken/yhirano comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..38e1429f6938a901f19c101d1a1211a711e4307d 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"
@@ -60,6 +63,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 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);
+
+ 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,
@@ -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,24 @@ 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();
+
+ Document* elementDocument = &(m_element->document());
+ Modulator::from(elementDocument->frame())
dominicc (has gone to gerrit) 2017/01/11 03:23:48 Feel like all these places need guards against shu
kouhei (in TOK) 2017/01/17 05:26:13 Is Line 381 isConnected check enough? Would you he
+ ->fetchTree(url, baseURL, m_elementModuleClient);
+ return true;
+ }
+
+ FetchRequest request(ResourceRequest(url), m_element->localName());
CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(
m_element->fastGetAttribute(HTMLNames::crossoriginAttr));

Powered by Google App Engine
This is Rietveld 408576698