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

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

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: rebased Created 3 years, 9 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/ModulatorImpl.cpp
diff --git a/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9782dc6200fe80cc7825eb69de613d505153d9c8
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
@@ -0,0 +1,153 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/ModulatorImpl.h"
+
+#include "core/dom/Document.h"
+#include "core/dom/ExecutionContext.h"
+#include "core/dom/ModuleMap.h"
+#include "core/dom/ModuleScript.h"
+#include "core/dom/ScriptModuleResolverImpl.h"
+#include "core/dom/TaskRunnerHelper.h"
+#include "core/frame/LocalFrame.h"
+#include "core/loader/modulescript//ModuleScriptFetchRequest.h"
+#include "core/loader/modulescript/ModuleScriptLoaderRegistry.h"
+#include "core/loader/modulescript/ModuleTreeLinkerRegistry.h"
+#include "platform/loader/fetch/ResourceFetcher.h"
+
+namespace blink {
+
+ModulatorImpl* ModulatorImpl::create(RefPtr<ScriptState> scriptState,
+ Document& document) {
+ return new ModulatorImpl(
+ std::move(scriptState),
+ TaskRunnerHelper::get(TaskType::Networking, &document), &document,
+ document.fetcher());
+}
+
+ModulatorImpl::ModulatorImpl(RefPtr<ScriptState> scriptState,
+ RefPtr<WebTaskRunner> taskRunner,
+ ExecutionContext* executionContext,
+ ResourceFetcher* fetcher)
+ : m_scriptState(std::move(scriptState)),
+ m_taskRunner(std::move(taskRunner)),
+ m_executionContext(executionContext),
+ m_fetcher(fetcher),
+ m_map(this, ModuleMap::create(this)),
+ m_loaderRegistry(ModuleScriptLoaderRegistry::create()),
+ m_treeLinkerRegistry(ModuleTreeLinkerRegistry::create()),
+ m_scriptModuleResolver(ScriptModuleResolverImpl::create(this)) {
+ DCHECK(m_scriptState);
+ DCHECK(m_taskRunner);
+ DCHECK(m_executionContext);
+ DCHECK(m_fetcher);
+}
+
+ModulatorImpl::~ModulatorImpl() {}
+
+ReferrerPolicy ModulatorImpl::referrerPolicy() {
+ return m_executionContext->getReferrerPolicy();
+}
+
+SecurityOrigin* ModulatorImpl::securityOrigin() {
+ return m_executionContext->getSecurityOrigin();
+}
+
+void ModulatorImpl::fetchTree(const ModuleScriptFetchRequest& request,
+ ModuleTreeClient* client) {
+ // Step 1. Perform the internal module script graph fetching procedure given
+ // url, settings object, destination, cryptographic nonce, parser state,
+ // credentials mode, settings object, a new empty list, "client", and with the
+ // top-level module fetch flag set. If the caller of this algorithm specified
+ // custom perform the fetch steps, pass those along as well.
+
+ // Note: "Fetch a module script graph" algorithm doesn't have "referrer" as
+ // its argument.
+ DCHECK(request.referrer().isNull());
+
+ AncestorList emptyAncestorList;
+ fetchTreeInternal(request, emptyAncestorList,
+ ModuleGraphLevel::TopLevelModuleFetch, client);
+
+ // Step 2. When the internal module script graph fetching procedure
+ // asynchronously completes with result, asynchronously complete this
+ // algorithm with result.
+ // Note: We delegate to ModuleTreeLinker to notify ModuleTreeClient.
+}
+
+void ModulatorImpl::fetchTreeInternal(const ModuleScriptFetchRequest& request,
+ const AncestorList& ancestorList,
+ ModuleGraphLevel level,
+ ModuleTreeClient* client) {
+ m_treeLinkerRegistry->fetch(request, ancestorList, level, this, client);
+}
+
+void ModulatorImpl::fetchSingle(const ModuleScriptFetchRequest& request,
+ ModuleGraphLevel level,
+ SingleModuleClient* client) {
+ m_map->fetchSingleModuleScript(request, level, client);
+}
+
+void ModulatorImpl::fetchNewSingleModule(
+ const ModuleScriptFetchRequest& request,
+ ModuleGraphLevel level,
+ ModuleScriptLoaderClient* client) {
+ m_loaderRegistry->fetch(request, level, this, m_fetcher.get(), client);
+}
+
+ModuleScript* ModulatorImpl::getFetchedModuleScript(const KURL& url) {
+ return m_map->getFetchedModuleScript(url);
+}
+
+ScriptModule ModulatorImpl::compileModule(const String& script,
+ const String& urlStr) {
+ // Implements Steps 3-6 of
+ // https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-module-script
+
+ // Step 3. Let realm be the provided environment settings object's Realm.
+ // Note: Realm is v8::Context.
+ // Step 4. If scripting is disabled for the given environment settings
+ // object's responsible browsing context, then let script source be the empty
+ // string. Otherwise, let script source be the provided script source.
+ // TODO(kouhei): if(m_executionContext->canExecuteScripts) after the CL
+ // landed.
+ // Step 5. Let result be ParseModule(script source, realm, script).
+ // Step 6. If result is a List of errors, report the exception given by the
+ // first element of result for script, return null, and abort these steps.
+ // Note: reporting is routed via V8Initializer::messageHandlerInMainThread.
+ ScriptState::Scope scope(m_scriptState.get());
+ return ScriptModule::compile(m_scriptState->isolate(), script, urlStr);
+}
+
+ScriptValue ModulatorImpl::instantiateModule(ScriptModule scriptModule) {
+ ScriptState::Scope scope(m_scriptState.get());
+ return scriptModule.instantiate(m_scriptState.get());
+}
+
+Vector<String> ModulatorImpl::moduleRequestsFromScriptModule(
+ ScriptModule scriptModule) {
+ ScriptState::Scope scope(m_scriptState.get());
+ return scriptModule.moduleRequests(m_scriptState.get());
+}
+
+void ModulatorImpl::executeModule(ScriptModule scriptModule) {
+ ScriptState::Scope scope(m_scriptState.get());
+ scriptModule.evaluate(m_scriptState.get());
+}
+
+DEFINE_TRACE(ModulatorImpl) {
+ Modulator::trace(visitor);
+ visitor->trace(m_executionContext);
+ visitor->trace(m_fetcher);
+ visitor->trace(m_map);
+ visitor->trace(m_loaderRegistry);
+ visitor->trace(m_treeLinkerRegistry);
+ visitor->trace(m_scriptModuleResolver);
+}
+
+DEFINE_TRACE_WRAPPERS(ModulatorImpl) {
+ visitor->traceWrappers(m_map);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698