Commit 6c6179d7 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

ES Modules: Introduce base URL in FetchClientSettingsObject

This CL introduces the base URL in FetchClientSettingsObject to avoid a
dependency on ExecutionContext from ModulatorImplBase. The dependency was not
correct because the base URL must be provided by "fetch client settings object",
not by "module map settings object". ModulatorImplBase corresponds to "module
map settings object".

Bug: 845285
Change-Id: I7986e16e3f160e145fa11357fe4a77cdff8113b7
Reviewed-on: https://chromium-review.googlesource.com/1102443
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567949}
parent 68b2894c
......@@ -21,7 +21,6 @@ namespace blink {
void ModuleTreeLinker::Fetch(
const KURL& url,
const FetchClientSettingsObjectSnapshot& fetch_client_settings_object,
const KURL& base_url,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions& options,
Modulator* modulator,
......@@ -30,7 +29,7 @@ void ModuleTreeLinker::Fetch(
ModuleTreeLinker* fetcher = new ModuleTreeLinker(
fetch_client_settings_object, destination, modulator, registry, client);
registry->AddFetcher(fetcher);
fetcher->FetchRoot(url, base_url, options);
fetcher->FetchRoot(url, options);
DCHECK(fetcher->IsFetching());
}
......@@ -144,7 +143,6 @@ void ModuleTreeLinker::AdvanceState(State new_state) {
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
void ModuleTreeLinker::FetchRoot(const KURL& original_url,
const KURL& base_url,
const ScriptFetchOptions& options) {
#if DCHECK_IS_ON()
original_url_ = original_url;
......@@ -158,8 +156,10 @@ void ModuleTreeLinker::FetchRoot(const KURL& original_url,
// href="https://github.com/drufball/layered-apis/blob/master/spec.md#fetch-a-module-script-graph"
// step="1">Set url to the layered API fetching URL given url and the current
// settings object's API base URL.</spec>
if (RuntimeEnabledFeatures::LayeredAPIEnabled())
url = blink::layered_api::ResolveFetchingURL(url, base_url);
if (RuntimeEnabledFeatures::LayeredAPIEnabled()) {
url = blink::layered_api::ResolveFetchingURL(
url, fetch_client_settings_object_.BaseURL());
}
#if DCHECK_IS_ON()
url_ = url;
......
......@@ -37,13 +37,9 @@ class ModuleTreeLinkerRegistry;
class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient {
public:
// https://html.spec.whatwg.org/#fetch-a-module-script-tree
//
// TODO(hiroshige): |base_url| is used only for Layered APIs and will be
// removed soon once an upcoming spec change lands.
static void Fetch(
const KURL&,
const FetchClientSettingsObjectSnapshot& fetch_client_settings_object,
const KURL& base_url,
WebURLRequest::RequestContext destination,
const ScriptFetchOptions&,
Modulator*,
......@@ -90,7 +86,7 @@ class CORE_EXPORT ModuleTreeLinker final : public SingleModuleClient {
#endif
void AdvanceState(State);
void FetchRoot(const KURL&, const KURL& base_url, const ScriptFetchOptions&);
void FetchRoot(const KURL&, const ScriptFetchOptions&);
void FetchRootInline(ModuleScript*);
// Steps 1--2 of [IMSGF].
......
......@@ -209,7 +209,7 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeNoDeps) {
KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient;
ModuleTreeLinker::Fetch(url, FetchClientSettingsObjectSnapshot(GetDocument()),
NullURL(), WebURLRequest::kRequestContextScript,
WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), registry,
client);
......@@ -231,7 +231,7 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeInstantiationFailure) {
KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient;
ModuleTreeLinker::Fetch(url, FetchClientSettingsObjectSnapshot(GetDocument()),
NullURL(), WebURLRequest::kRequestContextScript,
WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), registry,
client);
......@@ -257,7 +257,7 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWithSingleDependency) {
KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient;
ModuleTreeLinker::Fetch(url, FetchClientSettingsObjectSnapshot(GetDocument()),
NullURL(), WebURLRequest::kRequestContextScript,
WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), registry,
client);
......@@ -284,7 +284,7 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps) {
KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient;
ModuleTreeLinker::Fetch(url, FetchClientSettingsObjectSnapshot(GetDocument()),
NullURL(), WebURLRequest::kRequestContextScript,
WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), registry,
client);
......@@ -324,7 +324,7 @@ TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps1Fail) {
KURL url("http://example.com/root.js");
TestModuleTreeClient* client = new TestModuleTreeClient;
ModuleTreeLinker::Fetch(url, FetchClientSettingsObjectSnapshot(GetDocument()),
NullURL(), WebURLRequest::kRequestContextScript,
WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), registry,
client);
......@@ -383,7 +383,7 @@ TEST_F(ModuleTreeLinkerTest, FetchDependencyTree) {
KURL url("http://example.com/depth1.js");
TestModuleTreeClient* client = new TestModuleTreeClient;
ModuleTreeLinker::Fetch(url, FetchClientSettingsObjectSnapshot(GetDocument()),
NullURL(), WebURLRequest::kRequestContextScript,
WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), registry,
client);
......@@ -409,7 +409,7 @@ TEST_F(ModuleTreeLinkerTest, FetchDependencyOfCyclicGraph) {
KURL url("http://example.com/a.js");
TestModuleTreeClient* client = new TestModuleTreeClient;
ModuleTreeLinker::Fetch(url, FetchClientSettingsObjectSnapshot(GetDocument()),
NullURL(), WebURLRequest::kRequestContextScript,
WebURLRequest::kRequestContextScript,
ScriptFetchOptions(), GetModulator(), registry,
client);
......
......@@ -10,15 +10,18 @@ namespace blink {
FetchClientSettingsObjectSnapshot::FetchClientSettingsObjectSnapshot(
ExecutionContext& execution_context)
: FetchClientSettingsObjectSnapshot(execution_context.GetSecurityOrigin(),
: FetchClientSettingsObjectSnapshot(execution_context.BaseURL(),
execution_context.GetSecurityOrigin(),
execution_context.GetReferrerPolicy(),
execution_context.OutgoingReferrer()) {}
FetchClientSettingsObjectSnapshot::FetchClientSettingsObjectSnapshot(
const KURL& base_url,
const scoped_refptr<const SecurityOrigin> security_origin,
ReferrerPolicy referrer_policy,
const String& outgoing_referrer)
: security_origin_(std::move(security_origin)),
: base_url_(base_url),
security_origin_(std::move(security_origin)),
referrer_policy_(referrer_policy),
outgoing_referrer_(outgoing_referrer) {}
......
......@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/cross_thread_copier.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/referrer_policy.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
......@@ -34,12 +35,18 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final {
public:
explicit FetchClientSettingsObjectSnapshot(ExecutionContext&);
FetchClientSettingsObjectSnapshot(
const KURL& base_url,
const scoped_refptr<const SecurityOrigin> security_origin,
ReferrerPolicy referrer_policy,
const String& outgoing_referrer);
virtual ~FetchClientSettingsObjectSnapshot() = default;
// "A URL used by APIs called by scripts that use this environment settings
// object to parse URLs."
// https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url
const KURL& BaseURL() const { return base_url_; }
// "An origin used in security checks."
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-origin
const SecurityOrigin* GetSecurityOrigin() const {
......@@ -58,12 +65,13 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final {
// Makes an copy of this instance. This is typically used for cross-thread
// communication in CrossThreadCopier.
FetchClientSettingsObjectSnapshot IsolatedCopy() const {
return FetchClientSettingsObjectSnapshot(security_origin_->IsolatedCopy(),
referrer_policy_,
outgoing_referrer_.IsolatedCopy());
return FetchClientSettingsObjectSnapshot(
base_url_.Copy(), security_origin_->IsolatedCopy(), referrer_policy_,
outgoing_referrer_.IsolatedCopy());
}
private:
const KURL base_url_;
const scoped_refptr<const SecurityOrigin> security_origin_;
const ReferrerPolicy referrer_policy_;
const String outgoing_referrer_;
......
......@@ -67,8 +67,7 @@ void ModulatorImplBase::FetchTree(
// of this algorithm specified custom perform the fetch steps, pass those
// along as well.</spec>
ModuleTreeLinker::Fetch(url, fetch_client_settings_object,
GetExecutionContext()->BaseURL(), destination,
ModuleTreeLinker::Fetch(url, fetch_client_settings_object, destination,
options, this, tree_linker_registry_, client);
// <spec label="fetch-a-module-script-tree" step="3">When the internal module
......
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