Commit 3b83cf41 authored by Camillo Bruni's avatar Camillo Bruni Committed by Chromium LUCI CQ

[blink] Add base URL to ModuleScriptCreationParams

Pass the base URL for modules as member ModuleScriptCreationParams to
JSModuleScript::Create.

Bug: 1154943
Change-Id: I7c5fb214a638c4808d5412199ad093797e4cb451
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2572097
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarDominic Farolino <dom@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837999}
parent def0010a
...@@ -48,7 +48,6 @@ void ModuleRecordProduceCacheData::Trace(Visitor* visitor) const { ...@@ -48,7 +48,6 @@ void ModuleRecordProduceCacheData::Trace(Visitor* visitor) const {
v8::Local<v8::Module> ModuleRecord::Compile( v8::Local<v8::Module> ModuleRecord::Compile(
v8::Isolate* isolate, v8::Isolate* isolate,
const ModuleScriptCreationParams& params, const ModuleScriptCreationParams& params,
const KURL& base_url,
const ScriptFetchOptions& options, const ScriptFetchOptions& options,
const TextPosition& text_position, const TextPosition& text_position,
ExceptionState& exception_state, ExceptionState& exception_state,
...@@ -76,7 +75,7 @@ v8::Local<v8::Module> ModuleRecord::Compile( ...@@ -76,7 +75,7 @@ v8::Local<v8::Module> ModuleRecord::Compile(
if (!V8ScriptRunner::CompileModule( if (!V8ScriptRunner::CompileModule(
isolate, params, text_position, compile_options, no_cache_reason, isolate, params, text_position, compile_options, no_cache_reason,
ReferrerScriptInfo(base_url, options, ReferrerScriptInfo(params.BaseURL(), options,
ReferrerScriptInfo::BaseUrlSource::kOther)) ReferrerScriptInfo::BaseUrlSource::kOther))
.ToLocal(&module)) { .ToLocal(&module)) {
DCHECK(try_catch.HasCaught()); DCHECK(try_catch.HasCaught());
......
...@@ -65,7 +65,6 @@ class CORE_EXPORT ModuleRecord final { ...@@ -65,7 +65,6 @@ class CORE_EXPORT ModuleRecord final {
static v8::Local<v8::Module> Compile( static v8::Local<v8::Module> Compile(
v8::Isolate*, v8::Isolate*,
const ModuleScriptCreationParams& params, const ModuleScriptCreationParams& params,
const KURL& base_url,
const ScriptFetchOptions&, const ScriptFetchOptions&,
const TextPosition&, const TextPosition&,
ExceptionState&, ExceptionState&,
......
...@@ -47,10 +47,14 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) { ...@@ -47,10 +47,14 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) {
} }
} }
// TODO(crbug.com/1061857): Pass ScriptStreamer to the client here. // TODO(crbug.com/1061857): Pass ScriptStreamer to the client here.
const KURL& url = script_resource->GetResponse().CurrentRequestUrl();
// Create an external module script where base_url == source_url.
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams( client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
script_resource->GetResponse().CurrentRequestUrl(), module_type, /*source_url=*/url, /*base_url=*/url, module_type,
script_resource->SourceText(), script_resource->CacheHandler(), script_resource->SourceText(), script_resource->CacheHandler(),
script_resource->GetResourceRequest().GetCredentialsMode(), nullptr, script_resource->GetResourceRequest().GetCredentialsMode(),
/*script_streamer=*/nullptr,
ScriptStreamer::NotStreamingReason::kStreamingDisabled)); ScriptStreamer::NotStreamingReason::kStreamingDisabled));
} }
......
...@@ -103,10 +103,12 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch( ...@@ -103,10 +103,12 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch(
return; return;
} }
// Create an external module script where base_url == source_url.
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
client->NotifyFetchFinishedSuccess(ModuleScriptCreationParams( client->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
fetch_params.Url(), module_type, /*source_url=*/fetch_params.Url(), /*base_url=*/fetch_params.Url(),
ParkableString(script_data->TakeSourceText().Impl()), module_type, ParkableString(script_data->TakeSourceText().Impl()),
nullptr /* cache_handler */, /*cache_handler=*/nullptr,
fetch_params.GetResourceRequest().GetCredentialsMode())); fetch_params.GetResourceRequest().GetCredentialsMode()));
} }
......
...@@ -27,6 +27,7 @@ class ModuleScriptCreationParams { ...@@ -27,6 +27,7 @@ class ModuleScriptCreationParams {
public: public:
ModuleScriptCreationParams( ModuleScriptCreationParams(
const KURL& source_url, const KURL& source_url,
const KURL& base_url,
const ModuleScriptCreationParams::ModuleType module_type, const ModuleScriptCreationParams::ModuleType module_type,
const ParkableString& source_text, const ParkableString& source_text,
SingleCachedMetadataHandler* cache_handler, SingleCachedMetadataHandler* cache_handler,
...@@ -35,6 +36,7 @@ class ModuleScriptCreationParams { ...@@ -35,6 +36,7 @@ class ModuleScriptCreationParams {
ScriptStreamer::NotStreamingReason not_streaming_reason = ScriptStreamer::NotStreamingReason not_streaming_reason =
ScriptStreamer::NotStreamingReason::kStreamingDisabled) ScriptStreamer::NotStreamingReason::kStreamingDisabled)
: source_url_(source_url), : source_url_(source_url),
base_url_(base_url),
module_type_(module_type), module_type_(module_type),
is_isolated_(false), is_isolated_(false),
source_text_(source_text), source_text_(source_text),
...@@ -54,8 +56,8 @@ class ModuleScriptCreationParams { ...@@ -54,8 +56,8 @@ class ModuleScriptCreationParams {
String isolated_source_text = String isolated_source_text =
isolated_source_text_ ? isolated_source_text_.IsolatedCopy() isolated_source_text_ ? isolated_source_text_.IsolatedCopy()
: GetSourceText().ToString().IsolatedCopy(); : GetSourceText().ToString().IsolatedCopy();
return ModuleScriptCreationParams(SourceURL().Copy(), module_type_, return ModuleScriptCreationParams(SourceURL().Copy(), BaseURL().Copy(),
isolated_source_text, module_type_, isolated_source_text,
GetFetchCredentialsMode()); GetFetchCredentialsMode());
} }
...@@ -64,6 +66,7 @@ class ModuleScriptCreationParams { ...@@ -64,6 +66,7 @@ class ModuleScriptCreationParams {
} }
const KURL& SourceURL() const { return source_url_; } const KURL& SourceURL() const { return source_url_; }
const KURL& BaseURL() const { return base_url_; }
const ParkableString& GetSourceText() const { const ParkableString& GetSourceText() const {
if (is_isolated_) { if (is_isolated_) {
...@@ -76,7 +79,7 @@ class ModuleScriptCreationParams { ...@@ -76,7 +79,7 @@ class ModuleScriptCreationParams {
ModuleScriptCreationParams CopyWithClearedSourceText() const { ModuleScriptCreationParams CopyWithClearedSourceText() const {
return ModuleScriptCreationParams( return ModuleScriptCreationParams(
source_url_, module_type_, ParkableString(), cache_handler_, source_url_, base_url_, module_type_, ParkableString(), cache_handler_,
credentials_mode_, script_streamer_, not_streaming_reason_); credentials_mode_, script_streamer_, not_streaming_reason_);
} }
...@@ -87,17 +90,20 @@ class ModuleScriptCreationParams { ...@@ -87,17 +90,20 @@ class ModuleScriptCreationParams {
} }
bool IsSafeToSendToAnotherThread() const { bool IsSafeToSendToAnotherThread() const {
return source_url_.IsSafeToSendToAnotherThread() && is_isolated_; return source_url_.IsSafeToSendToAnotherThread() &&
base_url_.IsSafeToSendToAnotherThread() && is_isolated_;
} }
private: private:
// Creates an isolated copy. // Creates an isolated copy.
ModuleScriptCreationParams( ModuleScriptCreationParams(
const KURL& source_url, const KURL& source_url,
const KURL& base_url,
const ModuleScriptCreationParams::ModuleType& module_type, const ModuleScriptCreationParams::ModuleType& module_type,
const String& isolated_source_text, const String& isolated_source_text,
network::mojom::CredentialsMode credentials_mode) network::mojom::CredentialsMode credentials_mode)
: source_url_(source_url), : source_url_(source_url),
base_url_(base_url),
module_type_(module_type), module_type_(module_type),
is_isolated_(true), is_isolated_(true),
source_text_(), source_text_(),
...@@ -112,6 +118,7 @@ class ModuleScriptCreationParams { ...@@ -112,6 +118,7 @@ class ModuleScriptCreationParams {
ScriptStreamer::NotStreamingReason::kStreamingDisabled) {} ScriptStreamer::NotStreamingReason::kStreamingDisabled) {}
const KURL source_url_; const KURL source_url_;
const KURL base_url_;
const ModuleType module_type_; const ModuleType module_type_;
// Mutable because an isolated copy can become bound to a thread when // Mutable because an isolated copy can become bound to a thread when
......
...@@ -276,8 +276,8 @@ void ModuleScriptLoader::NotifyFetchFinishedSuccess( ...@@ -276,8 +276,8 @@ void ModuleScriptLoader::NotifyFetchFinishedSuccess(
// a module script given source text, module map settings object, // a module script given source text, module map settings object,
// response's url, and options." [spec text] // response's url, and options." [spec text]
module_script_ = JSModuleScript::Create( module_script_ = JSModuleScript::Create(
params, /*base_url=*/params.SourceURL(), params, ScriptSourceLocationType::kExternalFile, modulator_,
ScriptSourceLocationType::kExternalFile, modulator_, options_); options_);
break; break;
}; };
} }
......
...@@ -181,9 +181,12 @@ void WorkerModuleScriptFetcher::NotifyClient( ...@@ -181,9 +181,12 @@ void WorkerModuleScriptFetcher::NotifyClient(
// <spec step="12.7">Asynchronously complete the perform the fetch steps with // <spec step="12.7">Asynchronously complete the perform the fetch steps with
// response.</spec> // response.</spec>
client_->NotifyFetchFinishedSuccess( const KURL& url = response.CurrentRequestUrl();
ModuleScriptCreationParams(response.CurrentRequestUrl(), module_type, // Create an external module script where base_url == source_url.
source_text, cache_handler, credentials_mode)); // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
/*source_url=*/url, /*base_url=*/url, module_type, source_text,
cache_handler, credentials_mode));
} }
void WorkerModuleScriptFetcher::DidReceiveData(base::span<const char> span) { void WorkerModuleScriptFetcher::DidReceiveData(base::span<const char> span) {
......
...@@ -49,8 +49,11 @@ void WorkletModuleScriptFetcher::NotifyFinished(Resource* resource) { ...@@ -49,8 +49,11 @@ void WorkletModuleScriptFetcher::NotifyFinished(Resource* resource) {
HeapVector<Member<ConsoleMessage>> error_messages; HeapVector<Member<ConsoleMessage>> error_messages;
ModuleScriptCreationParams::ModuleType module_type; ModuleScriptCreationParams::ModuleType module_type;
if (WasModuleLoadSuccessful(script_resource, &error_messages, &module_type)) { if (WasModuleLoadSuccessful(script_resource, &error_messages, &module_type)) {
params.emplace(script_resource->GetResponse().CurrentRequestUrl(), const KURL& url = script_resource->GetResponse().CurrentRequestUrl();
module_type, script_resource->SourceText(), // Create an external module script where base_url == source_url.
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
params.emplace(/*source_url=*/url, /*base_url=*/url, module_type,
script_resource->SourceText(),
script_resource->CacheHandler(), script_resource->CacheHandler(),
script_resource->GetResourceRequest().GetCredentialsMode()); script_resource->GetResourceRequest().GetCredentialsMode());
} }
......
...@@ -19,7 +19,6 @@ namespace blink { ...@@ -19,7 +19,6 @@ namespace blink {
// href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script"> // href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script">
JSModuleScript* JSModuleScript::Create( JSModuleScript* JSModuleScript::Create(
const ModuleScriptCreationParams& original_params, const ModuleScriptCreationParams& original_params,
const KURL& base_url,
ScriptSourceLocationType source_location_type, ScriptSourceLocationType source_location_type,
Modulator* modulator, Modulator* modulator,
const ScriptFetchOptions& options, const ScriptFetchOptions& options,
...@@ -49,7 +48,7 @@ JSModuleScript* JSModuleScript::Create( ...@@ -49,7 +48,7 @@ JSModuleScript* JSModuleScript::Create(
ModuleRecordProduceCacheData* produce_cache_data = nullptr; ModuleRecordProduceCacheData* produce_cache_data = nullptr;
v8::Local<v8::Module> result = v8::Local<v8::Module> result =
ModuleRecord::Compile(isolate, params, base_url, options, start_position, ModuleRecord::Compile(isolate, params, options, start_position,
exception_state, modulator->GetV8CacheOptions(), exception_state, modulator->GetV8CacheOptions(),
source_location_type, &produce_cache_data); source_location_type, &produce_cache_data);
...@@ -61,7 +60,7 @@ JSModuleScript* JSModuleScript::Create( ...@@ -61,7 +60,7 @@ JSModuleScript* JSModuleScript::Create(
// be used for the speced algorithms, but may be used from inspector. // be used for the speced algorithms, but may be used from inspector.
JSModuleScript* script = CreateInternal( JSModuleScript* script = CreateInternal(
params.GetSourceText().length(), modulator, result, params.SourceURL(), params.GetSourceText().length(), modulator, result, params.SourceURL(),
base_url, options, start_position, produce_cache_data); params.BaseURL(), options, start_position, produce_cache_data);
// <spec step="8">If result is a list of errors, then:</spec> // <spec step="8">If result is a list of errors, then:</spec>
if (exception_state.HadException()) { if (exception_state.HadException()) {
......
...@@ -26,7 +26,6 @@ class CORE_EXPORT JSModuleScript final : public ModuleScript, ...@@ -26,7 +26,6 @@ class CORE_EXPORT JSModuleScript final : public ModuleScript,
// https://html.spec.whatwg.org/C/#creating-a-javascript-module-script // https://html.spec.whatwg.org/C/#creating-a-javascript-module-script
static JSModuleScript* Create( static JSModuleScript* Create(
const ModuleScriptCreationParams& params, const ModuleScriptCreationParams& params,
const KURL& base_url,
ScriptSourceLocationType, ScriptSourceLocationType,
Modulator*, Modulator*,
const ScriptFetchOptions&, const ScriptFetchOptions&,
......
...@@ -153,7 +153,7 @@ class ModuleMapTestModulator final : public DummyModulator { ...@@ -153,7 +153,7 @@ class ModuleMapTestModulator final : public DummyModulator {
: url_(url), credential_mode_(credential_mode), client_(client) {} : url_(url), credential_mode_(credential_mode), client_(client) {}
void NotifyFetchFinished() { void NotifyFetchFinished() {
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams( client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
url_, ModuleScriptCreationParams::ModuleType::kJavaScriptModule, url_, url_, ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(String("").ReleaseImpl()), nullptr, credential_mode_)); ParkableString(String("").ReleaseImpl()), nullptr, credential_mode_));
} }
void Trace(Visitor* visitor) const { visitor->Trace(client_); } void Trace(Visitor* visitor) const { visitor->Trace(client_); }
......
...@@ -82,11 +82,11 @@ class ModuleScriptTest : public ::testing::Test, public ParametrizedModuleTest { ...@@ -82,11 +82,11 @@ class ModuleScriptTest : public ::testing::Test, public ParametrizedModuleTest {
const String& source_text, const String& source_text,
SingleCachedMetadataHandler* cache_handler) { SingleCachedMetadataHandler* cache_handler) {
ModuleScriptCreationParams params( ModuleScriptCreationParams params(
KURL("https://fox.url/script.js"), KURL("https://fox.url/script.js"), KURL("https://fox.url/"),
ModuleScriptCreationParams::ModuleType::kJavaScriptModule, ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source_text.IsolatedCopy().ReleaseImpl()), cache_handler, ParkableString(source_text.IsolatedCopy().ReleaseImpl()), cache_handler,
network::mojom::CredentialsMode::kOmit); network::mojom::CredentialsMode::kOmit);
return JSModuleScript::Create(params, KURL("https://fox.url/"), return JSModuleScript::Create(params,
ScriptSourceLocationType::kExternalFile, ScriptSourceLocationType::kExternalFile,
modulator, ScriptFetchOptions()); modulator, ScriptFetchOptions());
} }
......
...@@ -710,13 +710,13 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -710,13 +710,13 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// text, settings object, base URL, and options.</spec> // text, settings object, base URL, and options.</spec>
ModuleScriptCreationParams params( ModuleScriptCreationParams params(
source_url, source_url, base_url,
ModuleScriptCreationParams::ModuleType::kJavaScriptModule, ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source_text.Impl()), nullptr, ParkableString(source_text.Impl()), nullptr,
options.CredentialsMode()); options.CredentialsMode());
ModuleScript* module_script = JSModuleScript::Create( ModuleScript* module_script =
params, base_url, ScriptSourceLocationType::kInline, modulator, JSModuleScript::Create(params, ScriptSourceLocationType::kInline,
options, position); modulator, options, position);
// <spec label="fetch-an-inline-module-script-graph" step="2">If script // <spec label="fetch-an-inline-module-script-graph" step="2">If script
// is null, asynchronously complete this algorithm with null, and abort // is null, asynchronously complete this algorithm with null, and abort
......
...@@ -27,10 +27,11 @@ v8::Local<v8::Module> ModuleTestBase::CompileModule( ...@@ -27,10 +27,11 @@ v8::Local<v8::Module> ModuleTestBase::CompileModule(
const KURL& url, const KURL& url,
ExceptionState& exception_state) { ExceptionState& exception_state) {
ModuleScriptCreationParams params( ModuleScriptCreationParams params(
url, ModuleScriptCreationParams::ModuleType::kJavaScriptModule, /*source_url=*/url, /*base_url=*/url,
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source.Impl()), nullptr, ParkableString(source.Impl()), nullptr,
network::mojom::CredentialsMode::kOmit); network::mojom::CredentialsMode::kOmit);
return ModuleRecord::Compile(isolate, params, url, ScriptFetchOptions(), return ModuleRecord::Compile(isolate, params, ScriptFetchOptions(),
TextPosition::MinimumPosition(), TextPosition::MinimumPosition(),
exception_state); exception_state);
} }
......
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