Commit 72fbe934 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

ES Modules: Specify "destination" for module loading

This CL passes the "destination"[1] parameter through module loaders. This enables
workers/worklets to specify a unique destination defined in each spec.

Before this CL, any module scripts are loaded with the "script" destination.
After this CL, top-level and descendant module scripts for dedicated workers are
loaded with the "worker" destination, top-level and descendant module scripts
for documents and dynamic import() are still loaded with the "script"
destination though. Module scripts for worklets also must be loaded with their
own destination defined in each worklet spec (e.g., "paintworklet"), but such
destinations haven't been added yet and the "script" destination is still used.
Shared workers and service workers haven't supported module loading yet.
Subsequent CLs will address them.

Regarding detailed changes, this CL adds the "destination" parameters to
components for module loading, stops ScriptResource overriding the
"destination", and uses the given "destination" instead. Note that, in Chrome,
WebURLRequest::RequestContext enum[2] represents the "destination".

[1] https://fetch.spec.whatwg.org/#concept-request-destination
[2] https://chromium.googlesource.com/chromium/src/+/a204023d46bc02634f1c6f164cae99d327d53b86/third_party/blink/public/platform/web_url_request.h#73

Bug: 842566
Change-Id: Ib777fcc28de62e1c348ef5c79f97079e5399abaf
Reviewed-on: https://chromium-review.googlesource.com/1058734
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559493}
parent b564859b
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <memory> #include <memory>
#include "third_party/blink/public/platform/modules/serviceworker/web_service_worker_network_provider.h" #include "third_party/blink/public/platform/modules/serviceworker/web_service_worker_network_provider.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/web/web_history_commit_type.h" #include "third_party/blink/public/web/web_history_commit_type.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_parser.h" #include "third_party/blink/renderer/core/dom/document_parser.h"
...@@ -211,6 +212,7 @@ Resource* DocumentLoader::StartPreload(Resource::Type type, ...@@ -211,6 +212,7 @@ Resource* DocumentLoader::StartPreload(Resource::Type type,
resource = ImageResource::Fetch(params, Fetcher()); resource = ImageResource::Fetch(params, Fetcher());
break; break;
case Resource::kScript: case Resource::kScript:
params.SetRequestContext(WebURLRequest::kRequestContextScript);
resource = ScriptResource::Fetch(params, Fetcher(), nullptr); resource = ScriptResource::Fetch(params, Fetcher(), nullptr);
break; break;
case Resource::kCSSStyleSheet: case Resource::kCSSStyleSheet:
......
...@@ -463,6 +463,8 @@ static void ModulePreloadIfNeeded(const LinkLoadParameters& params, ...@@ -463,6 +463,8 @@ static void ModulePreloadIfNeeded(const LinkLoadParameters& params,
link_loader->DispatchLinkLoadingErroredAsync(); link_loader->DispatchLinkLoadingErroredAsync();
return; return;
} }
WebURLRequest::RequestContext destination =
WebURLRequest::kRequestContextScript;
// Step 4. "Parse the URL given by the href attribute, relative to the // Step 4. "Parse the URL given by the href attribute, relative to the
// element's node document. If that fails, then return. Otherwise, let url be // element's node document. If that fails, then return. Otherwise, let url be
...@@ -523,7 +525,7 @@ static void ModulePreloadIfNeeded(const LinkLoadParameters& params, ...@@ -523,7 +525,7 @@ static void ModulePreloadIfNeeded(const LinkLoadParameters& params,
// metadata is "not-parser-inserted", and credentials mode is credentials // metadata is "not-parser-inserted", and credentials mode is credentials
// mode." [spec text] // mode." [spec text]
ModuleScriptFetchRequest request( ModuleScriptFetchRequest request(
params.href, params.href, destination,
ScriptFetchOptions(params.nonce, integrity_metadata, params.integrity, ScriptFetchOptions(params.nonce, integrity_metadata, params.integrity,
kNotParserInserted, credentials_mode), kNotParserInserted, credentials_mode),
Referrer::NoReferrer(), params.referrer_policy, Referrer::NoReferrer(), params.referrer_policy,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_SCRIPT_FETCH_REQUEST_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_SCRIPT_FETCH_REQUEST_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_SCRIPT_FETCH_REQUEST_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_SCRIPT_FETCH_REQUEST_H_
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/platform/loader/fetch/script_fetch_options.h" #include "third_party/blink/renderer/platform/loader/fetch/script_fetch_options.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/referrer.h" #include "third_party/blink/renderer/platform/weborigin/referrer.h"
...@@ -21,11 +22,13 @@ class ModuleScriptFetchRequest final { ...@@ -21,11 +22,13 @@ class ModuleScriptFetchRequest final {
// Referrer is set only for internal module script fetch algorithms triggered // Referrer is set only for internal module script fetch algorithms triggered
// from ModuleTreeLinker to fetch descendant module scripts. // from ModuleTreeLinker to fetch descendant module scripts.
ModuleScriptFetchRequest(const KURL& url, ModuleScriptFetchRequest(const KURL& url,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions& options, const ScriptFetchOptions& options,
const String& referrer, const String& referrer,
ReferrerPolicy referrer_policy, ReferrerPolicy referrer_policy,
const TextPosition& referrer_position) const TextPosition& referrer_position)
: url_(url), : url_(url),
destination_(destination),
options_(options), options_(options),
referrer_(referrer), referrer_(referrer),
referrer_policy_(referrer_policy), referrer_policy_(referrer_policy),
...@@ -33,12 +36,14 @@ class ModuleScriptFetchRequest final { ...@@ -33,12 +36,14 @@ class ModuleScriptFetchRequest final {
static ModuleScriptFetchRequest CreateForTest(const KURL& url) { static ModuleScriptFetchRequest CreateForTest(const KURL& url) {
return ModuleScriptFetchRequest( return ModuleScriptFetchRequest(
url, ScriptFetchOptions(), Referrer::NoReferrer(), url, WebURLRequest::kRequestContextScript, ScriptFetchOptions(),
kReferrerPolicyDefault, TextPosition::MinimumPosition()); Referrer::NoReferrer(), kReferrerPolicyDefault,
TextPosition::MinimumPosition());
} }
~ModuleScriptFetchRequest() = default; ~ModuleScriptFetchRequest() = default;
const KURL& Url() const { return url_; } const KURL& Url() const { return url_; }
WebURLRequest::RequestContext Destination() const { return destination_; }
const ScriptFetchOptions& Options() const { return options_; } const ScriptFetchOptions& Options() const { return options_; }
const AtomicString& GetReferrer() const { return referrer_; } const AtomicString& GetReferrer() const { return referrer_; }
ReferrerPolicy GetReferrerPolicy() const { return referrer_policy_; } ReferrerPolicy GetReferrerPolicy() const { return referrer_policy_; }
...@@ -46,6 +51,7 @@ class ModuleScriptFetchRequest final { ...@@ -46,6 +51,7 @@ class ModuleScriptFetchRequest final {
private: private:
const KURL url_; const KURL url_;
const WebURLRequest::RequestContext destination_;
const ScriptFetchOptions options_; const ScriptFetchOptions options_;
const AtomicString referrer_; const AtomicString referrer_;
const ReferrerPolicy referrer_policy_; const ReferrerPolicy referrer_policy_;
......
...@@ -90,9 +90,10 @@ void ModuleScriptLoader::Fetch(const ModuleScriptFetchRequest& module_request, ...@@ -90,9 +90,10 @@ void ModuleScriptLoader::Fetch(const ModuleScriptFetchRequest& module_request,
url_ = module_request.Url(); url_ = module_request.Url();
#endif #endif
ResourceLoaderOptions options; // "destination is destination," [spec text]
resource_request.SetRequestContext(module_request.Destination());
// TODO(kouhei): handle "destination is destination," ResourceLoaderOptions options;
// Step 6. "Set up the module script request given request and options." // Step 6. "Set up the module script request given request and options."
// [spec text] // [spec text]
......
...@@ -17,32 +17,41 @@ ...@@ -17,32 +17,41 @@
namespace blink { namespace blink {
ModuleTreeLinker* ModuleTreeLinker::Fetch(const KURL& url, ModuleTreeLinker* ModuleTreeLinker::Fetch(
const KURL& base_url, const KURL& url,
const ScriptFetchOptions& options, const KURL& base_url,
Modulator* modulator, WebURLRequest::RequestContext destination,
ModuleTreeLinkerRegistry* registry, const ScriptFetchOptions& options,
ModuleTreeClient* client) { Modulator* modulator,
ModuleTreeLinker* fetcher = new ModuleTreeLinker(modulator, registry, client); ModuleTreeLinkerRegistry* registry,
ModuleTreeClient* client) {
ModuleTreeLinker* fetcher =
new ModuleTreeLinker(destination, modulator, registry, client);
fetcher->FetchRoot(url, base_url, options); fetcher->FetchRoot(url, base_url, options);
return fetcher; return fetcher;
} }
ModuleTreeLinker* ModuleTreeLinker::FetchDescendantsForInlineScript( ModuleTreeLinker* ModuleTreeLinker::FetchDescendantsForInlineScript(
ModuleScript* module_script, ModuleScript* module_script,
WebURLRequest::RequestContext destination,
Modulator* modulator, Modulator* modulator,
ModuleTreeLinkerRegistry* registry, ModuleTreeLinkerRegistry* registry,
ModuleTreeClient* client) { ModuleTreeClient* client) {
DCHECK(module_script); DCHECK(module_script);
ModuleTreeLinker* fetcher = new ModuleTreeLinker(modulator, registry, client); ModuleTreeLinker* fetcher =
new ModuleTreeLinker(destination, modulator, registry, client);
fetcher->FetchRootInline(module_script); fetcher->FetchRootInline(module_script);
return fetcher; return fetcher;
} }
ModuleTreeLinker::ModuleTreeLinker(Modulator* modulator, ModuleTreeLinker::ModuleTreeLinker(WebURLRequest::RequestContext destination,
Modulator* modulator,
ModuleTreeLinkerRegistry* registry, ModuleTreeLinkerRegistry* registry,
ModuleTreeClient* client) ModuleTreeClient* client)
: modulator_(modulator), registry_(registry), client_(client) { : destination_(destination),
modulator_(modulator),
registry_(registry),
client_(client) {
CHECK(modulator); CHECK(modulator);
CHECK(registry); CHECK(registry);
CHECK(client); CHECK(client);
...@@ -170,9 +179,9 @@ void ModuleTreeLinker::FetchRoot(const KURL& original_url, ...@@ -170,9 +179,9 @@ void ModuleTreeLinker::FetchRoot(const KURL& original_url,
// Step 2. Perform the internal module script graph fetching procedure given // Step 2. Perform the internal module script graph fetching procedure given
// ... with the top-level module fetch flag set. ... // ... with the top-level module fetch flag set. ...
ModuleScriptFetchRequest request(url, options, Referrer::NoReferrer(), ModuleScriptFetchRequest request(
modulator_->GetReferrerPolicy(), url, destination_, options, Referrer::NoReferrer(),
TextPosition::MinimumPosition()); modulator_->GetReferrerPolicy(), TextPosition::MinimumPosition());
InitiateInternalModuleScriptGraphFetching( InitiateInternalModuleScriptGraphFetching(
request, ModuleGraphLevel::kTopLevelModuleFetch); request, ModuleGraphLevel::kTopLevelModuleFetch);
...@@ -361,7 +370,7 @@ void ModuleTreeLinker::FetchDescendants(ModuleScript* module_script) { ...@@ -361,7 +370,7 @@ void ModuleTreeLinker::FetchDescendants(ModuleScript* module_script) {
// [FD] Step 7. ... perform the internal module script graph fetching // [FD] Step 7. ... perform the internal module script graph fetching
// procedure given ... with the top-level module fetch flag unset. ... // procedure given ... with the top-level module fetch flag unset. ...
ModuleScriptFetchRequest request( ModuleScriptFetchRequest request(
urls[i], options, module_script->BaseURL().GetString(), urls[i], destination_, options, module_script->BaseURL().GetString(),
modulator_->GetReferrerPolicy(), positions[i]); modulator_->GetReferrerPolicy(), positions[i]);
InitiateInternalModuleScriptGraphFetching( InitiateInternalModuleScriptGraphFetching(
request, ModuleGraphLevel::kDependentModuleFetch); request, ModuleGraphLevel::kDependentModuleFetch);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_H_
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/script/modulator.h" #include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
...@@ -40,6 +41,7 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient { ...@@ -40,6 +41,7 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient {
// removed soon once an upcoming spec change lands. // removed soon once an upcoming spec change lands.
static ModuleTreeLinker* Fetch(const KURL&, static ModuleTreeLinker* Fetch(const KURL&,
const KURL& base_url, const KURL& base_url,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions&, const ScriptFetchOptions&,
Modulator*, Modulator*,
ModuleTreeLinkerRegistry*, ModuleTreeLinkerRegistry*,
...@@ -48,6 +50,7 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient { ...@@ -48,6 +50,7 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient {
// [FDaI] for an inline script. // [FDaI] for an inline script.
static ModuleTreeLinker* FetchDescendantsForInlineScript( static ModuleTreeLinker* FetchDescendantsForInlineScript(
ModuleScript*, ModuleScript*,
WebURLRequest::RequestContext destination,
Modulator*, Modulator*,
ModuleTreeLinkerRegistry*, ModuleTreeLinkerRegistry*,
ModuleTreeClient*); ModuleTreeClient*);
...@@ -62,7 +65,10 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient { ...@@ -62,7 +65,10 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient {
bool HasFinished() const { return state_ == State::kFinished; } bool HasFinished() const { return state_ == State::kFinished; }
private: private:
ModuleTreeLinker(Modulator*, ModuleTreeLinkerRegistry*, ModuleTreeClient*); ModuleTreeLinker(WebURLRequest::RequestContext destination,
Modulator*,
ModuleTreeLinkerRegistry*,
ModuleTreeClient*);
enum class State { enum class State {
kInitial, kInitial,
...@@ -102,6 +108,7 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient { ...@@ -102,6 +108,7 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient {
ScriptValue FindFirstParseError(ModuleScript*, ScriptValue FindFirstParseError(ModuleScript*,
HeapHashSet<Member<ModuleScript>>*) const; HeapHashSet<Member<ModuleScript>>*) const;
const WebURLRequest::RequestContext destination_;
const Member<Modulator> modulator_; const Member<Modulator> modulator_;
HashSet<KURL> visited_set_; HashSet<KURL> visited_set_;
const Member<ModuleTreeLinkerRegistry> registry_; const Member<ModuleTreeLinkerRegistry> registry_;
......
...@@ -23,11 +23,12 @@ void ModuleTreeLinkerRegistry::TraceWrappers( ...@@ -23,11 +23,12 @@ void ModuleTreeLinkerRegistry::TraceWrappers(
ModuleTreeLinker* ModuleTreeLinkerRegistry::Fetch( ModuleTreeLinker* ModuleTreeLinkerRegistry::Fetch(
const KURL& url, const KURL& url,
const KURL& base_url, const KURL& base_url,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions& options, const ScriptFetchOptions& options,
Modulator* modulator, Modulator* modulator,
ModuleTreeClient* client) { ModuleTreeClient* client) {
ModuleTreeLinker* fetcher = ModuleTreeLinker* fetcher = ModuleTreeLinker::Fetch(
ModuleTreeLinker::Fetch(url, base_url, options, modulator, this, client); url, base_url, destination, options, modulator, this, client);
DCHECK(fetcher->IsFetching()); DCHECK(fetcher->IsFetching());
active_tree_linkers_.insert(fetcher); active_tree_linkers_.insert(fetcher);
return fetcher; return fetcher;
...@@ -35,10 +36,11 @@ ModuleTreeLinker* ModuleTreeLinkerRegistry::Fetch( ...@@ -35,10 +36,11 @@ ModuleTreeLinker* ModuleTreeLinkerRegistry::Fetch(
ModuleTreeLinker* ModuleTreeLinkerRegistry::FetchDescendantsForInlineScript( ModuleTreeLinker* ModuleTreeLinkerRegistry::FetchDescendantsForInlineScript(
ModuleScript* module_script, ModuleScript* module_script,
WebURLRequest::RequestContext destination,
Modulator* modulator, Modulator* modulator,
ModuleTreeClient* client) { ModuleTreeClient* client) {
ModuleTreeLinker* fetcher = ModuleTreeLinker::FetchDescendantsForInlineScript( ModuleTreeLinker* fetcher = ModuleTreeLinker::FetchDescendantsForInlineScript(
module_script, modulator, this, client); module_script, destination, modulator, this, client);
DCHECK(fetcher->IsFetching()); DCHECK(fetcher->IsFetching());
active_tree_linkers_.insert(fetcher); active_tree_linkers_.insert(fetcher);
return fetcher; return fetcher;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_REGISTRY_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_REGISTRY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_REGISTRY_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_MODULE_TREE_LINKER_REGISTRY_H_
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h" #include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
...@@ -35,12 +36,15 @@ class CORE_EXPORT ModuleTreeLinkerRegistry ...@@ -35,12 +36,15 @@ class CORE_EXPORT ModuleTreeLinkerRegistry
ModuleTreeLinker* Fetch(const KURL&, ModuleTreeLinker* Fetch(const KURL&,
const KURL& base_url, const KURL& base_url,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions&, const ScriptFetchOptions&,
Modulator*, Modulator*,
ModuleTreeClient*); ModuleTreeClient*);
ModuleTreeLinker* FetchDescendantsForInlineScript(ModuleScript*, ModuleTreeLinker* FetchDescendantsForInlineScript(
Modulator*, ModuleScript*,
ModuleTreeClient*); WebURLRequest::RequestContext destination,
Modulator*,
ModuleTreeClient*);
private: private:
ModuleTreeLinkerRegistry() = default; ModuleTreeLinkerRegistry() = default;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/scheduler/web_main_thread_scheduler.h" #include "third_party/blink/public/platform/scheduler/web_main_thread_scheduler.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/bindings/core/v8/script_module.h" #include "third_party/blink/renderer/bindings/core/v8/script_module.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
...@@ -199,7 +200,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeNoDeps) { ...@@ -199,7 +200,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeNoDeps) {
KURL url("http://example.com/root.js"); KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient; TestModuleTreeClient* client = new TestModuleTreeClient;
registry->Fetch(url, NullURL(), ScriptFetchOptions(), GetModulator(), client); registry->Fetch(url, NullURL(), WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), client);
EXPECT_FALSE(client->WasNotifyFinished()) EXPECT_FALSE(client->WasNotifyFinished())
<< "ModuleTreeLinker should always finish asynchronously."; << "ModuleTreeLinker should always finish asynchronously.";
...@@ -218,7 +220,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeInstantiationFailure) { ...@@ -218,7 +220,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeInstantiationFailure) {
KURL url("http://example.com/root.js"); KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient; TestModuleTreeClient* client = new TestModuleTreeClient;
registry->Fetch(url, NullURL(), ScriptFetchOptions(), GetModulator(), client); registry->Fetch(url, NullURL(), WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), client);
EXPECT_FALSE(client->WasNotifyFinished()) EXPECT_FALSE(client->WasNotifyFinished())
<< "ModuleTreeLinker should always finish asynchronously."; << "ModuleTreeLinker should always finish asynchronously.";
...@@ -241,7 +244,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWithSingleDependency) { ...@@ -241,7 +244,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWithSingleDependency) {
KURL url("http://example.com/root.js"); KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient; TestModuleTreeClient* client = new TestModuleTreeClient;
registry->Fetch(url, NullURL(), ScriptFetchOptions(), GetModulator(), client); registry->Fetch(url, NullURL(), WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), client);
EXPECT_FALSE(client->WasNotifyFinished()) EXPECT_FALSE(client->WasNotifyFinished())
<< "ModuleTreeLinker should always finish asynchronously."; << "ModuleTreeLinker should always finish asynchronously.";
...@@ -265,7 +269,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps) { ...@@ -265,7 +269,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps) {
KURL url("http://example.com/root.js"); KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient; TestModuleTreeClient* client = new TestModuleTreeClient;
registry->Fetch(url, NullURL(), ScriptFetchOptions(), GetModulator(), client); registry->Fetch(url, NullURL(), WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), client);
EXPECT_FALSE(client->WasNotifyFinished()) EXPECT_FALSE(client->WasNotifyFinished())
<< "ModuleTreeLinker should always finish asynchronously."; << "ModuleTreeLinker should always finish asynchronously.";
...@@ -302,7 +307,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps1Fail) { ...@@ -302,7 +307,8 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps1Fail) {
KURL url("http://example.com/root.js"); KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient; TestModuleTreeClient* client = new TestModuleTreeClient;
registry->Fetch(url, NullURL(), ScriptFetchOptions(), GetModulator(), client); registry->Fetch(url, NullURL(), WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), client);
EXPECT_FALSE(client->WasNotifyFinished()) EXPECT_FALSE(client->WasNotifyFinished())
<< "ModuleTreeLinker should always finish asynchronously."; << "ModuleTreeLinker should always finish asynchronously.";
...@@ -358,7 +364,8 @@ TEST_F(ModuleTreeLinkerTest, FetchDependencyTree) { ...@@ -358,7 +364,8 @@ TEST_F(ModuleTreeLinkerTest, FetchDependencyTree) {
KURL url("http://example.com/depth1.js"); KURL url("http://example.com/depth1.js");
TestModuleTreeClient* client = new TestModuleTreeClient; TestModuleTreeClient* client = new TestModuleTreeClient;
registry->Fetch(url, NullURL(), ScriptFetchOptions(), GetModulator(), client); registry->Fetch(url, NullURL(), WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), client);
EXPECT_FALSE(client->WasNotifyFinished()) EXPECT_FALSE(client->WasNotifyFinished())
<< "ModuleTreeLinker should always finish asynchronously."; << "ModuleTreeLinker should always finish asynchronously.";
...@@ -381,7 +388,8 @@ TEST_F(ModuleTreeLinkerTest, FetchDependencyOfCyclicGraph) { ...@@ -381,7 +388,8 @@ TEST_F(ModuleTreeLinkerTest, FetchDependencyOfCyclicGraph) {
KURL url("http://example.com/a.js"); KURL url("http://example.com/a.js");
TestModuleTreeClient* client = new TestModuleTreeClient; TestModuleTreeClient* client = new TestModuleTreeClient;
registry->Fetch(url, NullURL(), ScriptFetchOptions(), GetModulator(), client); registry->Fetch(url, NullURL(), WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), client);
EXPECT_FALSE(client->WasNotifyFinished()) EXPECT_FALSE(client->WasNotifyFinished())
<< "ModuleTreeLinker should always finish asynchronously."; << "ModuleTreeLinker should always finish asynchronously.";
......
...@@ -43,6 +43,30 @@ ...@@ -43,6 +43,30 @@
namespace blink { namespace blink {
namespace {
// Returns true if the given request context is a script-like destination
// defined in the Fetch spec:
// https://fetch.spec.whatwg.org/#request-destination-script-like
bool IsRequestContextSupported(WebURLRequest::RequestContext request_context) {
// TODO(nhiroki): Support |kRequestContextSharedWorker| for module loading for
// shared workers (https://crbug.com/824646).
// TODO(nhiroki): Support |kRequestContextServiceWorker| for module loading
// for service workers (https://crbug.com/824647).
// TODO(nhiroki): Support "audioworklet" and "paintworklet" destinations.
switch (request_context) {
case WebURLRequest::kRequestContextScript:
case WebURLRequest::kRequestContextWorker:
return true;
default:
break;
}
NOTREACHED() << "Incompatible request context type: " << request_context;
return false;
}
} // namespace
// SingleCachedMetadataHandlerImpl should be created when a response is // SingleCachedMetadataHandlerImpl should be created when a response is
// received, and can be used independently from Resource. - It doesn't have any // received, and can be used independently from Resource. - It doesn't have any
// references to Resource. Necessary data are captured // references to Resource. Necessary data are captured
...@@ -151,7 +175,8 @@ ScriptResource* ScriptResource::Fetch(FetchParameters& params, ...@@ -151,7 +175,8 @@ ScriptResource* ScriptResource::Fetch(FetchParameters& params,
ResourceClient* client) { ResourceClient* client) {
DCHECK_EQ(params.GetResourceRequest().GetFrameType(), DCHECK_EQ(params.GetResourceRequest().GetFrameType(),
network::mojom::RequestContextFrameType::kNone); network::mojom::RequestContextFrameType::kNone);
params.SetRequestContext(WebURLRequest::kRequestContextScript); DCHECK(IsRequestContextSupported(
params.GetResourceRequest().GetRequestContext()));
return ToScriptResource( return ToScriptResource(
fetcher->RequestResource(params, ScriptResourceFactory(), client)); fetcher->RequestResource(params, ScriptResourceFactory(), client));
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/script/dynamic_module_resolver.h" #include "third_party/blink/renderer/core/script/dynamic_module_resolver.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h" #include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
#include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h" #include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
...@@ -212,7 +213,8 @@ void DynamicModuleResolver::ResolveDynamically( ...@@ -212,7 +213,8 @@ void DynamicModuleResolver::ResolveDynamically(
// with result." // with result."
auto* tree_client = auto* tree_client =
DynamicImportTreeClient::Create(url, modulator_.Get(), promise_resolver); DynamicImportTreeClient::Create(url, modulator_.Get(), promise_resolver);
modulator_->FetchTree(url, options, tree_client); modulator_->FetchTree(url, WebURLRequest::kRequestContextScript, options,
tree_client);
// Steps 2.[5-8] are implemented at // Steps 2.[5-8] are implemented at
// DynamicImportTreeClient::NotifyModuleLoadFinished. // DynamicImportTreeClient::NotifyModuleLoadFinished.
......
...@@ -62,6 +62,7 @@ class DynamicModuleResolverTestModulator final : public DummyModulator { ...@@ -62,6 +62,7 @@ class DynamicModuleResolverTestModulator final : public DummyModulator {
} }
void FetchTree(const KURL& url, void FetchTree(const KURL& url,
WebURLRequest::RequestContext,
const ScriptFetchOptions&, const ScriptFetchOptions&,
ModuleTreeClient* client) final { ModuleTreeClient* client) final {
EXPECT_EQ(expected_fetch_tree_url_, url); EXPECT_EQ(expected_fetch_tree_url_, url);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_MODULATOR_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_MODULATOR_H_
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/bindings/core/v8/script_module.h" #include "third_party/blink/renderer/bindings/core/v8/script_module.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/script/module_import_meta.h" #include "third_party/blink/renderer/core/script/module_import_meta.h"
...@@ -102,6 +103,7 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>, ...@@ -102,6 +103,7 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>,
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
virtual void FetchTree(const KURL&, virtual void FetchTree(const KURL&,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions&, const ScriptFetchOptions&,
ModuleTreeClient*) = 0; ModuleTreeClient*) = 0;
...@@ -112,8 +114,10 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>, ...@@ -112,8 +114,10 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>,
ModuleGraphLevel, ModuleGraphLevel,
SingleModuleClient*) = 0; SingleModuleClient*) = 0;
virtual void FetchDescendantsForInlineScript(ModuleScript*, virtual void FetchDescendantsForInlineScript(
ModuleTreeClient*) = 0; ModuleScript*,
WebURLRequest::RequestContext destination,
ModuleTreeClient*) = 0;
// Synchronously retrieves a single module script from existing module map // Synchronously retrieves a single module script from existing module map
// entry. // entry.
......
...@@ -52,6 +52,7 @@ const SecurityOrigin* ModulatorImplBase::GetSecurityOriginForFetch() { ...@@ -52,6 +52,7 @@ const SecurityOrigin* ModulatorImplBase::GetSecurityOriginForFetch() {
// [fetch-a-module-worker-script-tree] // [fetch-a-module-worker-script-tree]
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
void ModulatorImplBase::FetchTree(const KURL& url, void ModulatorImplBase::FetchTree(const KURL& url,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions& options, const ScriptFetchOptions& options,
ModuleTreeClient* client) { ModuleTreeClient* client) {
// <spec label="fetch-a-module-script-tree" step="2">Perform the internal // <spec label="fetch-a-module-script-tree" step="2">Perform the internal
...@@ -67,8 +68,8 @@ void ModulatorImplBase::FetchTree(const KURL& url, ...@@ -67,8 +68,8 @@ void ModulatorImplBase::FetchTree(const KURL& url,
// of this algorithm specified custom perform the fetch steps, pass those // of this algorithm specified custom perform the fetch steps, pass those
// along as well.</spec> // along as well.</spec>
tree_linker_registry_->Fetch(url, GetExecutionContext()->BaseURL(), options, tree_linker_registry_->Fetch(url, GetExecutionContext()->BaseURL(),
this, client); destination, options, this, client);
// <spec label="fetch-a-module-script-tree" step="3">When the internal module // <spec label="fetch-a-module-script-tree" step="3">When the internal module
// script graph fetching procedure asynchronously completes with result, // script graph fetching procedure asynchronously completes with result,
...@@ -83,9 +84,10 @@ void ModulatorImplBase::FetchTree(const KURL& url, ...@@ -83,9 +84,10 @@ void ModulatorImplBase::FetchTree(const KURL& url,
void ModulatorImplBase::FetchDescendantsForInlineScript( void ModulatorImplBase::FetchDescendantsForInlineScript(
ModuleScript* module_script, ModuleScript* module_script,
WebURLRequest::RequestContext destination,
ModuleTreeClient* client) { ModuleTreeClient* client) {
tree_linker_registry_->FetchDescendantsForInlineScript(module_script, this, tree_linker_registry_->FetchDescendantsForInlineScript(
client); module_script, destination, this, client);
} }
void ModulatorImplBase::FetchSingle(const ModuleScriptFetchRequest& request, void ModulatorImplBase::FetchSingle(const ModuleScriptFetchRequest& request,
......
...@@ -52,10 +52,13 @@ class ModulatorImplBase : public Modulator { ...@@ -52,10 +52,13 @@ class ModulatorImplBase : public Modulator {
const SecurityOrigin* GetSecurityOriginForFetch() override; const SecurityOrigin* GetSecurityOriginForFetch() override;
void FetchTree(const KURL&, void FetchTree(const KURL&,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions&, const ScriptFetchOptions&,
ModuleTreeClient*) override; ModuleTreeClient*) override;
void FetchDescendantsForInlineScript(ModuleScript*, void FetchDescendantsForInlineScript(
ModuleTreeClient*) override; ModuleScript*,
WebURLRequest::RequestContext destination,
ModuleTreeClient*) override;
void FetchSingle(const ModuleScriptFetchRequest&, void FetchSingle(const ModuleScriptFetchRequest&,
ModuleGraphLevel, ModuleGraphLevel,
SingleModuleClient*) override; SingleModuleClient*) override;
......
...@@ -545,8 +545,9 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -545,8 +545,9 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// completes, set the script's script to the result. At that time, the // completes, set the script's script to the result. At that time, the
// script is ready.</spec> // script is ready.</spec>
auto* module_tree_client = ModulePendingScriptTreeClient::Create(); auto* module_tree_client = ModulePendingScriptTreeClient::Create();
modulator->FetchDescendantsForInlineScript(module_script, modulator->FetchDescendantsForInlineScript(
module_tree_client); module_script, WebURLRequest::kRequestContextScript,
module_tree_client);
prepared_pending_script_ = ModulePendingScript::Create( prepared_pending_script_ = ModulePendingScript::Create(
element_, module_tree_client, is_external_script_); element_, module_tree_client, is_external_script_);
break; break;
...@@ -732,7 +733,8 @@ void ScriptLoader::FetchModuleScriptTree(const KURL& url, ...@@ -732,7 +733,8 @@ void ScriptLoader::FetchModuleScriptTree(const KURL& url,
// Fetch a module script graph given url, settings object, "script", and // Fetch a module script graph given url, settings object, "script", and
// options.</spec> // options.</spec>
auto* module_tree_client = ModulePendingScriptTreeClient::Create(); auto* module_tree_client = ModulePendingScriptTreeClient::Create();
modulator->FetchTree(url, options, module_tree_client); modulator->FetchTree(url, WebURLRequest::kRequestContextScript, options,
module_tree_client);
prepared_pending_script_ = ModulePendingScript::Create( prepared_pending_script_ = ModulePendingScript::Create(
element_, module_tree_client, is_external_script_); element_, module_tree_client, is_external_script_);
} }
......
...@@ -69,6 +69,7 @@ base::SingleThreadTaskRunner* DummyModulator::TaskRunner() { ...@@ -69,6 +69,7 @@ base::SingleThreadTaskRunner* DummyModulator::TaskRunner() {
}; };
void DummyModulator::FetchTree(const KURL&, void DummyModulator::FetchTree(const KURL&,
WebURLRequest::RequestContext,
const ScriptFetchOptions&, const ScriptFetchOptions&,
ModuleTreeClient*) { ModuleTreeClient*) {
NOTREACHED(); NOTREACHED();
...@@ -80,8 +81,10 @@ void DummyModulator::FetchSingle(const ModuleScriptFetchRequest&, ...@@ -80,8 +81,10 @@ void DummyModulator::FetchSingle(const ModuleScriptFetchRequest&,
NOTREACHED(); NOTREACHED();
} }
void DummyModulator::FetchDescendantsForInlineScript(ModuleScript*, void DummyModulator::FetchDescendantsForInlineScript(
ModuleTreeClient*) { ModuleScript*,
WebURLRequest::RequestContext,
ModuleTreeClient*) {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -38,13 +38,16 @@ class DummyModulator : public Modulator { ...@@ -38,13 +38,16 @@ class DummyModulator : public Modulator {
ScriptState* GetScriptState() override; ScriptState* GetScriptState() override;
void FetchTree(const KURL&, void FetchTree(const KURL&,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions&, const ScriptFetchOptions&,
ModuleTreeClient*) override; ModuleTreeClient*) override;
void FetchSingle(const ModuleScriptFetchRequest&, void FetchSingle(const ModuleScriptFetchRequest&,
ModuleGraphLevel, ModuleGraphLevel,
SingleModuleClient*) override; SingleModuleClient*) override;
void FetchDescendantsForInlineScript(ModuleScript*, void FetchDescendantsForInlineScript(
ModuleTreeClient*) override; ModuleScript*,
WebURLRequest::RequestContext destination,
ModuleTreeClient*) override;
ModuleScript* GetFetchedModuleScript(const KURL&) override; ModuleScript* GetFetchedModuleScript(const KURL&) override;
void FetchNewSingleModule(const ModuleScriptFetchRequest&, void FetchNewSingleModule(const ModuleScriptFetchRequest&,
ModuleGraphLevel, ModuleGraphLevel,
......
...@@ -33,14 +33,17 @@ ...@@ -33,14 +33,17 @@
#include <memory> #include <memory>
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h" #include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/inspector/thread_debugger.h" #include "third_party/blink/renderer/core/inspector/thread_debugger.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/workers/dedicated_worker_object_proxy.h" #include "third_party/blink/renderer/core/workers/dedicated_worker_object_proxy.h"
#include "third_party/blink/renderer/core/workers/dedicated_worker_thread.h" #include "third_party/blink/renderer/core/workers/dedicated_worker_thread.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h" #include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/core/workers/worker_module_tree_client.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
namespace blink { namespace blink {
...@@ -57,6 +60,22 @@ const AtomicString& DedicatedWorkerGlobalScope::InterfaceName() const { ...@@ -57,6 +60,22 @@ const AtomicString& DedicatedWorkerGlobalScope::InterfaceName() const {
return EventTargetNames::DedicatedWorkerGlobalScope; return EventTargetNames::DedicatedWorkerGlobalScope;
} }
// https://html.spec.whatwg.org/multipage/workers.html#worker-processing-model
void DedicatedWorkerGlobalScope::ImportModuleScript(
const KURL& module_url_record,
network::mojom::FetchCredentialsMode credentials_mode) {
// Step 12: "Let destination be "sharedworker" if is shared is true, and
// "worker" otherwise."
WebURLRequest::RequestContext destination =
WebURLRequest::kRequestContextWorker;
Modulator* modulator = Modulator::From(ScriptController()->GetScriptState());
// Step 13: "... Fetch a module worker script graph given url, outside
// settings, destination, the value of the credentials member of options, and
// inside settings."
FetchModuleScript(module_url_record, destination, credentials_mode,
new WorkerModuleTreeClient(modulator));
}
void DedicatedWorkerGlobalScope::postMessage( void DedicatedWorkerGlobalScope::postMessage(
ScriptState* script_state, ScriptState* script_state,
scoped_refptr<SerializedScriptValue> message, scoped_refptr<SerializedScriptValue> message,
......
...@@ -58,6 +58,10 @@ class CORE_EXPORT DedicatedWorkerGlobalScope final : public WorkerGlobalScope { ...@@ -58,6 +58,10 @@ class CORE_EXPORT DedicatedWorkerGlobalScope final : public WorkerGlobalScope {
// EventTarget // EventTarget
const AtomicString& InterfaceName() const override; const AtomicString& InterfaceName() const override;
// WorkerGlobalScope
void ImportModuleScript(const KURL& module_url_record,
network::mojom::FetchCredentialsMode) override;
void postMessage(ScriptState*, void postMessage(ScriptState*,
scoped_refptr<SerializedScriptValue>, scoped_refptr<SerializedScriptValue>,
const MessagePortArray&, const MessagePortArray&,
......
...@@ -62,6 +62,22 @@ const AtomicString& SharedWorkerGlobalScope::InterfaceName() const { ...@@ -62,6 +62,22 @@ const AtomicString& SharedWorkerGlobalScope::InterfaceName() const {
return EventTargetNames::SharedWorkerGlobalScope; return EventTargetNames::SharedWorkerGlobalScope;
} }
// https://html.spec.whatwg.org/multipage/workers.html#worker-processing-model
void SharedWorkerGlobalScope::ImportModuleScript(
const KURL& module_url_record,
network::mojom::FetchCredentialsMode credentials_mode) {
// Step 12: "Let destination be "sharedworker" if is shared is true, and
// "worker" otherwise."
// Step 13: "... Fetch a module worker script graph given url, outside
// settings, destination, the value of the credentials member of options, and
// inside settings."
// TODO(nhiroki): Implement module loading for shared workers.
// (https://crbug.com/824646)
NOTREACHED();
}
void SharedWorkerGlobalScope::ExceptionThrown(ErrorEvent* event) { void SharedWorkerGlobalScope::ExceptionThrown(ErrorEvent* event) {
WorkerGlobalScope::ExceptionThrown(event); WorkerGlobalScope::ExceptionThrown(event);
if (WorkerThreadDebugger* debugger = if (WorkerThreadDebugger* debugger =
......
...@@ -57,6 +57,10 @@ class SharedWorkerGlobalScope final : public WorkerGlobalScope { ...@@ -57,6 +57,10 @@ class SharedWorkerGlobalScope final : public WorkerGlobalScope {
// EventTarget // EventTarget
const AtomicString& InterfaceName() const override; const AtomicString& InterfaceName() const override;
// WorkerGlobalScope
void ImportModuleScript(const KURL& module_url_record,
network::mojom::FetchCredentialsMode) override;
// Setters/Getters for attributes in SharedWorkerGlobalScope.idl // Setters/Getters for attributes in SharedWorkerGlobalScope.idl
DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
String name() const { return name_; } String name() const { return name_; }
......
...@@ -49,12 +49,10 @@ ...@@ -49,12 +49,10 @@
#include "third_party/blink/renderer/core/loader/worker_threadable_loader.h" #include "third_party/blink/renderer/core/loader/worker_threadable_loader.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/installed_scripts_manager.h" #include "third_party/blink/renderer/core/workers/installed_scripts_manager.h"
#include "third_party/blink/renderer/core/workers/worker_classic_script_loader.h" #include "third_party/blink/renderer/core/workers/worker_classic_script_loader.h"
#include "third_party/blink/renderer/core/workers/worker_location.h" #include "third_party/blink/renderer/core/workers/worker_location.h"
#include "third_party/blink/renderer/core/workers/worker_module_tree_client.h"
#include "third_party/blink/renderer/core/workers/worker_navigator.h" #include "third_party/blink/renderer/core/workers/worker_navigator.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h" #include "third_party/blink/renderer/core/workers/worker_thread.h"
...@@ -327,14 +325,6 @@ void WorkerGlobalScope::EvaluateClassicScript( ...@@ -327,14 +325,6 @@ void WorkerGlobalScope::EvaluateClassicScript(
ReportingProxy().DidEvaluateClassicScript(success); ReportingProxy().DidEvaluateClassicScript(success);
} }
void WorkerGlobalScope::ImportModuleScript(
const KURL& module_url_record,
network::mojom::FetchCredentialsMode credentials_mode) {
Modulator* modulator = Modulator::From(ScriptController()->GetScriptState());
FetchModuleScript(module_url_record, credentials_mode,
new WorkerModuleTreeClient(modulator));
}
WorkerGlobalScope::WorkerGlobalScope( WorkerGlobalScope::WorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
WorkerThread* thread, WorkerThread* thread,
......
...@@ -136,8 +136,8 @@ class CORE_EXPORT WorkerGlobalScope ...@@ -136,8 +136,8 @@ class CORE_EXPORT WorkerGlobalScope
std::unique_ptr<Vector<char>> cached_meta_data); std::unique_ptr<Vector<char>> cached_meta_data);
// Imports the top-level module script for |module_url_record|. // Imports the top-level module script for |module_url_record|.
void ImportModuleScript(const KURL& module_url_record, virtual void ImportModuleScript(const KURL& module_url_record,
network::mojom::FetchCredentialsMode); network::mojom::FetchCredentialsMode) = 0;
double TimeOrigin() const { return time_origin_; } double TimeOrigin() const { return time_origin_; }
WorkerSettings* GetWorkerSettings() const { return worker_settings_.get(); } WorkerSettings* GetWorkerSettings() const { return worker_settings_.get(); }
......
...@@ -203,6 +203,7 @@ void WorkerOrWorkletGlobalScope::ApplyContentSecurityPolicyFromVector( ...@@ -203,6 +203,7 @@ void WorkerOrWorkletGlobalScope::ApplyContentSecurityPolicyFromVector(
void WorkerOrWorkletGlobalScope::FetchModuleScript( void WorkerOrWorkletGlobalScope::FetchModuleScript(
const KURL& module_url_record, const KURL& module_url_record,
WebURLRequest::RequestContext destination,
network::mojom::FetchCredentialsMode credentials_mode, network::mojom::FetchCredentialsMode credentials_mode,
ModuleTreeClient* client) { ModuleTreeClient* client) {
// Step 2: "Let options be a script fetch options whose cryptographic nonce is // Step 2: "Let options be a script fetch options whose cryptographic nonce is
...@@ -218,7 +219,7 @@ void WorkerOrWorkletGlobalScope::FetchModuleScript( ...@@ -218,7 +219,7 @@ void WorkerOrWorkletGlobalScope::FetchModuleScript(
Modulator* modulator = Modulator::From(ScriptController()->GetScriptState()); Modulator* modulator = Modulator::From(ScriptController()->GetScriptState());
// Step 3. "Perform the internal module script graph fetching procedure ..." // Step 3. "Perform the internal module script graph fetching procedure ..."
modulator->FetchTree(module_url_record, options, client); modulator->FetchTree(module_url_record, destination, options, client);
} }
void WorkerOrWorkletGlobalScope::Trace(blink::Visitor* visitor) { void WorkerOrWorkletGlobalScope::Trace(blink::Visitor* visitor) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h" #include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_cache_options.h" #include "third_party/blink/renderer/bindings/core/v8/v8_cache_options.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h" #include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
...@@ -113,6 +114,7 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData, ...@@ -113,6 +114,7 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData,
// HTML spec: // HTML spec:
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
void FetchModuleScript(const KURL& module_url_record, void FetchModuleScript(const KURL& module_url_record,
WebURLRequest::RequestContext destination,
network::mojom::FetchCredentialsMode, network::mojom::FetchCredentialsMode,
ModuleTreeClient*); ModuleTreeClient*);
......
...@@ -72,6 +72,12 @@ class FakeWorkerGlobalScope : public WorkerGlobalScope { ...@@ -72,6 +72,12 @@ class FakeWorkerGlobalScope : public WorkerGlobalScope {
return EventTargetNames::DedicatedWorkerGlobalScope; return EventTargetNames::DedicatedWorkerGlobalScope;
} }
// WorkerGlobalScope
void ImportModuleScript(const KURL& module_url_record,
network::mojom::FetchCredentialsMode) override {
NOTREACHED();
}
void ExceptionThrown(ErrorEvent*) override {} void ExceptionThrown(ErrorEvent*) override {}
}; };
......
...@@ -101,7 +101,11 @@ void WorkletGlobalScope::FetchAndInvokeScript( ...@@ -101,7 +101,11 @@ void WorkletGlobalScope::FetchAndInvokeScript(
WorkletModuleTreeClient* client = new WorkletModuleTreeClient( WorkletModuleTreeClient* client = new WorkletModuleTreeClient(
modulator, std::move(outside_settings_task_runner), pending_tasks); modulator, std::move(outside_settings_task_runner), pending_tasks);
FetchModuleScript(module_url_record, credentials_mode, client); // TODO(nhiroki): Specify an appropriate destination defined in each worklet
// spec (e.g., "paint worklet", "audio worklet").
WebURLRequest::RequestContext destination =
WebURLRequest::kRequestContextScript;
FetchModuleScript(module_url_record, destination, credentials_mode, client);
} }
WorkerOrWorkletModuleFetchCoordinatorProxy* WorkerOrWorkletModuleFetchCoordinatorProxy*
......
...@@ -32,6 +32,9 @@ class WorkletModuleResponsesMapTest : public testing::Test { ...@@ -32,6 +32,9 @@ class WorkletModuleResponsesMapTest : public testing::Test {
void Fetch(const KURL& url, ClientImpl* client) { void Fetch(const KURL& url, ClientImpl* client) {
ResourceRequest resource_request(url); ResourceRequest resource_request(url);
// TODO(nhiroki): Specify worklet-specific request context (e.g.,
// "paintworklet").
resource_request.SetRequestContext(WebURLRequest::kRequestContextScript);
FetchParameters fetch_params(resource_request); FetchParameters fetch_params(resource_request);
map_->Fetch(fetch_params, client); map_->Fetch(fetch_params, client);
} }
......
...@@ -165,6 +165,14 @@ void ServiceWorkerGlobalScope::EvaluateClassicScript( ...@@ -165,6 +165,14 @@ void ServiceWorkerGlobalScope::EvaluateClassicScript(
std::move(cached_meta_data)); std::move(cached_meta_data));
} }
void ServiceWorkerGlobalScope::ImportModuleScript(
const KURL& module_url_record,
network::mojom::FetchCredentialsMode credentials_mode) {
// TODO(nhiroki): Implement module loading for service workers.
// (https://crbug.com/824647)
NOTREACHED();
}
void ServiceWorkerGlobalScope::CountWorkerScript(size_t script_size, void ServiceWorkerGlobalScope::CountWorkerScript(size_t script_size,
size_t cached_metadata_size) { size_t cached_metadata_size) {
DEFINE_THREAD_SAFE_STATIC_LOCAL( DEFINE_THREAD_SAFE_STATIC_LOCAL(
......
...@@ -70,6 +70,8 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final : public WorkerGlobalScope { ...@@ -70,6 +70,8 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final : public WorkerGlobalScope {
const KURL& script_url, const KURL& script_url,
String source_code, String source_code,
std::unique_ptr<Vector<char>> cached_meta_data) override; std::unique_ptr<Vector<char>> cached_meta_data) override;
void ImportModuleScript(const KURL& module_url_record,
network::mojom::FetchCredentialsMode) override;
// Counts an evaluated script and its size. Called for the main worker script. // Counts an evaluated script and its size. Called for the main worker script.
void CountWorkerScript(size_t script_size, size_t cached_metadata_size); void CountWorkerScript(size_t script_size, size_t cached_metadata_size);
......
...@@ -23,6 +23,7 @@ FetchParameters ScriptFetchOptions::CreateFetchParameters( ...@@ -23,6 +23,7 @@ FetchParameters ScriptFetchOptions::CreateFetchParameters(
ResourceLoaderOptions resource_loader_options; ResourceLoaderOptions resource_loader_options;
resource_loader_options.initiator_info.name = "script"; resource_loader_options.initiator_info.name = "script";
FetchParameters params(resource_request, resource_loader_options); FetchParameters params(resource_request, resource_loader_options);
params.SetRequestContext(WebURLRequest::kRequestContextScript);
// Step 1. ... and CORS setting. [spec text] // Step 1. ... and CORS setting. [spec text]
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment