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