Commit d47f25b8 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

[Reland] Loader: Introduce FetchSettingsClientObject in BaseFetchContext

This is a reland CL for:
https://chromium-review.googlesource.com/c/chromium/src/+/1124209

The original CL was reverted because of the random crashes in the WebGL 2.0
conformance tests:
https://chromium-review.googlesource.com/c/chromium/src/+/1127420

This was caused by an Oilpan's GC bug happening only on the debug build. That
was already fixed by keishi@chromium.org:
https://chromium-review.googlesource.com/c/chromium/src/+/1131154

Therefore, this CL changes nothing from the original CL.

===== Original CL description =====

<Overview>

This CL introduces FetchSettingsClientObject in BaseFetchContext and replaces
some functions of BaseFetchContext with that. This makes the scope of
responsibilities of BaseFetchContext clearer.

Also, this is a preparation for separating ResourceFetcher for main resource
request and subresource requests for workers and worklets. The main resource
request needs a snapshot of the fetch client settings object of the parent
execution context, while the subresource requests need up-to-date values of the
fetch client settings object of the worker / worklet execution context. This
change enables a subsequent CL easily to inject the fetch client settings object
from externals of WorkerFetchContext.

<Technical details>

- This CL introduces FetchSettingsClientObject interface and
  FetchSettingsClientObjectImpl. Also, this makes
  FetchSettingsClientObjectSnapshot inherit the interface so that
  BaseFetchContext doesn't have to take care of an actual implementation.
- FrameFetchContext has the FrozenState concept that is used for keeping states
  even after the frame is detached. Similarly, this CL makes FrameFetchContext
  creates a new instance of FetchSettingsClientObjectSnapshot on frame detach,
  and replace the current |fetch_client_settings_object_| with that.

Bug: 845285
Change-Id: I74b43722002bb07197d718d3f266bbe384636b66
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
TBR: kouhei@chromium.org, kinuko@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/1127202Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573983}
parent 2ea09fc0
......@@ -95,8 +95,10 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request,
if (!is_main_resource) {
if (!request.DidSetHTTPReferrer()) {
request.SetHTTPReferrer(SecurityPolicy::GenerateReferrer(
GetReferrerPolicy(), request.Url(), GetOutgoingReferrer()));
request.SetHTTPOriginIfNeeded(GetSecurityOrigin());
GetFetchClientSettingsObject()->GetReferrerPolicy(), request.Url(),
GetFetchClientSettingsObject()->GetOutgoingReferrer()));
request.SetHTTPOriginIfNeeded(
GetFetchClientSettingsObject()->GetSecurityOrigin());
} else {
DCHECK_EQ(SecurityPolicy::GenerateReferrer(request.GetReferrerPolicy(),
request.Url(),
......
......@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/web_feature_forward.h"
#include "third_party/blink/renderer/core/script/fetch_client_settings_object.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
......@@ -50,6 +51,8 @@ class CORE_EXPORT BaseFetchContext : public FetchContext {
void Trace(blink::Visitor*) override;
virtual const FetchClientSettingsObject* GetFetchClientSettingsObject()
const = 0;
virtual KURL GetSiteForCookies() const = 0;
virtual SubresourceFilter* GetSubresourceFilter() const = 0;
virtual void CountUsage(WebFeature) const = 0;
......@@ -85,8 +88,6 @@ class CORE_EXPORT BaseFetchContext : public FetchContext {
SecurityViolationReportingPolicy) const = 0;
virtual bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&,
const KURL&) const = 0;
virtual ReferrerPolicy GetReferrerPolicy() const = 0;
virtual String GetOutgoingReferrer() const = 0;
virtual const KURL& Url() const = 0;
virtual const SecurityOrigin* GetParentSecurityOrigin() const = 0;
virtual base::Optional<mojom::IPAddressSpace> GetAddressSpace() const = 0;
......
......@@ -33,6 +33,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/websocket_handshake_throttle.h"
#include "third_party/blink/renderer/core/script/fetch_client_settings_object_impl.h"
#include "third_party/blink/renderer/core/testing/null_execution_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
......@@ -42,10 +43,16 @@ namespace blink {
class MockBaseFetchContext final : public BaseFetchContext {
public:
explicit MockBaseFetchContext(ExecutionContext* execution_context)
: execution_context_(execution_context) {}
: execution_context_(execution_context),
fetch_client_settings_object_(
new FetchClientSettingsObjectImpl(*execution_context)) {}
~MockBaseFetchContext() override = default;
// BaseFetchContext overrides:
const FetchClientSettingsObject* GetFetchClientSettingsObject()
const override {
return fetch_client_settings_object_.Get();
}
KURL GetSiteForCookies() const override { return KURL(); }
bool AllowScriptFromSource(const KURL&) const override { return false; }
SubresourceFilter* GetSubresourceFilter() const override { return nullptr; }
......@@ -79,16 +86,10 @@ class MockBaseFetchContext final : public BaseFetchContext {
const KURL&) const override {
return false;
}
ReferrerPolicy GetReferrerPolicy() const override {
return execution_context_->GetReferrerPolicy();
}
String GetOutgoingReferrer() const override {
return execution_context_->OutgoingReferrer();
}
const KURL& Url() const override { return execution_context_->Url(); }
const SecurityOrigin* GetSecurityOrigin() const override {
return execution_context_->GetSecurityOrigin();
return fetch_client_settings_object_->GetSecurityOrigin();
}
const SecurityOrigin* GetParentSecurityOrigin() const override {
return nullptr;
......@@ -104,6 +105,7 @@ class MockBaseFetchContext final : public BaseFetchContext {
void Trace(blink::Visitor* visitor) override {
visitor->Trace(execution_context_);
visitor->Trace(fetch_client_settings_object_);
BaseFetchContext::Trace(visitor);
}
......@@ -112,6 +114,7 @@ class MockBaseFetchContext final : public BaseFetchContext {
private:
Member<ExecutionContext> execution_context_;
Member<FetchClientSettingsObjectImpl> fetch_client_settings_object_;
bool is_detached_ = false;
};
......
......@@ -226,10 +226,7 @@ mojom::FetchCacheMode DetermineFrameCacheMode(Frame* frame,
struct FrameFetchContext::FrozenState final
: GarbageCollectedFinalized<FrozenState> {
FrozenState(ReferrerPolicy referrer_policy,
const String& outgoing_referrer,
const KURL& url,
scoped_refptr<const SecurityOrigin> security_origin,
FrozenState(const KURL& url,
scoped_refptr<const SecurityOrigin> parent_security_origin,
const base::Optional<mojom::IPAddressSpace>& address_space,
const ContentSecurityPolicy* content_security_policy,
......@@ -240,10 +237,7 @@ struct FrameFetchContext::FrozenState final
const String& user_agent,
bool is_main_frame,
bool is_svg_image_chrome_client)
: referrer_policy(referrer_policy),
outgoing_referrer(outgoing_referrer),
url(url),
security_origin(std::move(security_origin)),
: url(url),
parent_security_origin(std::move(parent_security_origin)),
address_space(address_space),
content_security_policy(content_security_policy),
......@@ -255,10 +249,7 @@ struct FrameFetchContext::FrozenState final
is_main_frame(is_main_frame),
is_svg_image_chrome_client(is_svg_image_chrome_client) {}
const ReferrerPolicy referrer_policy;
const String outgoing_referrer;
const KURL url;
const scoped_refptr<const SecurityOrigin> security_origin;
const scoped_refptr<const SecurityOrigin> parent_security_origin;
const base::Optional<mojom::IPAddressSpace> address_space;
const Member<const ContentSecurityPolicy> content_security_policy;
......@@ -298,6 +289,10 @@ FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
document_(document),
save_data_enabled_(GetNetworkStateNotifier().SaveDataEnabled() &&
!GetSettings()->GetDataSaverHoldbackWebApi()) {
if (document_) {
fetch_client_settings_object_ =
new FetchClientSettingsObjectImpl(*document_);
}
DCHECK(GetFrame());
}
......@@ -306,6 +301,8 @@ void FrameFetchContext::ProvideDocumentToContext(FetchContext& context,
DCHECK(document);
CHECK(context.IsFrameFetchContext());
static_cast<FrameFetchContext&>(context).document_ = document;
static_cast<FrameFetchContext&>(context).fetch_client_settings_object_ =
new FetchClientSettingsObjectImpl(*document);
}
FrameFetchContext::~FrameFetchContext() {
......@@ -352,6 +349,12 @@ FrameScheduler* FrameFetchContext::GetFrameScheduler() const {
return GetFrame()->GetFrameScheduler();
}
const FetchClientSettingsObject*
FrameFetchContext::GetFetchClientSettingsObject() const {
DCHECK(fetch_client_settings_object_);
return fetch_client_settings_object_.Get();
}
KURL FrameFetchContext::GetSiteForCookies() const {
if (IsDetached())
return frozen_state_->site_for_cookies;
......@@ -880,9 +883,10 @@ bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation(
}
const SecurityOrigin* FrameFetchContext::GetSecurityOrigin() const {
if (IsDetached())
return frozen_state_->security_origin.get();
return document_ ? document_->GetSecurityOrigin() : nullptr;
// This can be called before |fetch_client_settings_object_| is set.
if (!fetch_client_settings_object_)
return nullptr;
return fetch_client_settings_object_->GetSecurityOrigin();
}
void FrameFetchContext::ModifyRequestForCSP(ResourceRequest& resource_request) {
......@@ -1200,18 +1204,6 @@ bool FrameFetchContext::ShouldBlockFetchAsCredentialedSubresource(
return RuntimeEnabledFeatures::BlockCredentialedSubresourcesEnabled();
}
ReferrerPolicy FrameFetchContext::GetReferrerPolicy() const {
if (IsDetached())
return frozen_state_->referrer_policy;
return document_->GetReferrerPolicy();
}
String FrameFetchContext::GetOutgoingReferrer() const {
if (IsDetached())
return frozen_state_->outgoing_referrer;
return document_->OutgoingReferrer();
}
const KURL& FrameFetchContext::Url() const {
if (IsDetached())
return frozen_state_->url;
......@@ -1418,20 +1410,22 @@ FetchContext* FrameFetchContext::Detach() {
if (document_) {
frozen_state_ = new FrozenState(
GetReferrerPolicy(), GetOutgoingReferrer(), Url(), GetSecurityOrigin(),
GetParentSecurityOrigin(), GetAddressSpace(),
Url(), GetParentSecurityOrigin(), GetAddressSpace(),
GetContentSecurityPolicy(), GetSiteForCookies(), GetRequestorOrigin(),
GetClientHintsPreferences(), GetDevicePixelRatio(), GetUserAgent(),
IsMainFrame(), IsSVGImageChromeClient());
fetch_client_settings_object_ =
new FetchClientSettingsObjectSnapshot(*document_);
} else {
// Some getters are unavailable in this case.
frozen_state_ = new FrozenState(
kReferrerPolicyDefault, String(), NullURL(), GetSecurityOrigin(),
GetParentSecurityOrigin(), GetAddressSpace(),
NullURL(), GetParentSecurityOrigin(), GetAddressSpace(),
GetContentSecurityPolicy(), GetSiteForCookies(),
SecurityOrigin::CreateUniqueOpaque(), GetClientHintsPreferences(),
GetDevicePixelRatio(), GetUserAgent(), IsMainFrame(),
IsSVGImageChromeClient());
fetch_client_settings_object_ = new FetchClientSettingsObjectSnapshot(
NullURL(), nullptr, kReferrerPolicyDefault, String());
}
// This is needed to break a reference cycle in which off-heap
......@@ -1445,6 +1439,7 @@ void FrameFetchContext::Trace(blink::Visitor* visitor) {
visitor->Trace(document_loader_);
visitor->Trace(document_);
visitor->Trace(frozen_state_);
visitor->Trace(fetch_client_settings_object_);
BaseFetchContext::Trace(visitor);
}
......
......@@ -37,6 +37,8 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/loader/base_fetch_context.h"
#include "third_party/blink/renderer/core/script/fetch_client_settings_object_impl.h"
#include "third_party/blink/renderer/core/script/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/client_hints_preferences.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
......@@ -206,6 +208,8 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
scoped_refptr<base::SingleThreadTaskRunner> GetLoadingTaskRunner() override;
// BaseFetchContext overrides:
const FetchClientSettingsObject* GetFetchClientSettingsObject()
const override;
KURL GetSiteForCookies() const override;
SubresourceFilter* GetSubresourceFilter() const override;
bool AllowScriptFromSource(const KURL&) const override;
......@@ -230,8 +234,6 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&,
const KURL&) const override;
ReferrerPolicy GetReferrerPolicy() const override;
String GetOutgoingReferrer() const override;
const KURL& Url() const override;
const SecurityOrigin* GetParentSecurityOrigin() const override;
base::Optional<mojom::IPAddressSpace> GetAddressSpace() const override;
......@@ -275,6 +277,8 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
// Non-null only when detached.
Member<const FrozenState> frozen_state_;
Member<FetchClientSettingsObject> fetch_client_settings_object_;
};
} // namespace blink
......
......@@ -232,7 +232,7 @@ void ModuleTreeLinker::InitiateInternalModuleScriptGraphFetching(
++num_incomplete_fetches_;
// [IMSGF] Step 2. Fetch a single module script given ...
modulator_->FetchSingle(request, fetch_client_settings_object_, level,
modulator_->FetchSingle(request, fetch_client_settings_object_.Get(), level,
custom_fetch_type_, this);
// [IMSGF] Step 3-- are executed when NotifyModuleLoadFinished() is called.
......
......@@ -96,6 +96,8 @@ WorkerFetchContext::WorkerFetchContext(
web_context_(std::move(web_context)),
loading_task_runner_(
global_scope_->GetTaskRunner(TaskType::kInternalLoading)),
fetch_client_settings_object_(
new FetchClientSettingsObjectImpl(*global_scope_)),
save_data_enabled_(GetNetworkStateNotifier().SaveDataEnabled()) {
web_context_->InitializeOnWorkerThread();
std::unique_ptr<blink::WebDocumentSubresourceFilter> web_filter =
......@@ -105,6 +107,10 @@ WorkerFetchContext::WorkerFetchContext(
SubresourceFilter::Create(global_scope, std::move(web_filter));
}
}
const FetchClientSettingsObject*
WorkerFetchContext::GetFetchClientSettingsObject() const {
return fetch_client_settings_object_.Get();
}
KURL WorkerFetchContext::GetSiteForCookies() const {
return web_context_->SiteForCookies();
......@@ -198,14 +204,6 @@ bool WorkerFetchContext::ShouldBlockFetchAsCredentialedSubresource(
return false;
}
ReferrerPolicy WorkerFetchContext::GetReferrerPolicy() const {
return global_scope_->GetReferrerPolicy();
}
String WorkerFetchContext::GetOutgoingReferrer() const {
return global_scope_->OutgoingReferrer();
}
const KURL& WorkerFetchContext::Url() const {
return global_scope_->Url();
}
......@@ -233,7 +231,7 @@ void WorkerFetchContext::AddConsoleMessage(ConsoleMessage* message) const {
}
const SecurityOrigin* WorkerFetchContext::GetSecurityOrigin() const {
return global_scope_->GetSecurityOrigin();
return GetFetchClientSettingsObject()->GetSecurityOrigin();
}
std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader(
......@@ -424,6 +422,7 @@ WorkerFetchContext::GetWorkerContentSettingsClient() const {
void WorkerFetchContext::Trace(blink::Visitor* visitor) {
visitor->Trace(global_scope_);
visitor->Trace(subresource_filter_);
visitor->Trace(fetch_client_settings_object_);
BaseFetchContext::Trace(visitor);
}
......
......@@ -11,6 +11,7 @@
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom-blink.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/loader/base_fetch_context.h"
#include "third_party/blink/renderer/core/script/fetch_client_settings_object_impl.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
......@@ -36,6 +37,8 @@ class WorkerFetchContext final : public BaseFetchContext {
~WorkerFetchContext() override;
// BaseFetchContext implementation:
const FetchClientSettingsObject* GetFetchClientSettingsObject()
const override;
KURL GetSiteForCookies() const override;
SubresourceFilter* GetSubresourceFilter() const override;
bool AllowScriptFromSource(const KURL&) const override;
......@@ -60,8 +63,6 @@ class WorkerFetchContext final : public BaseFetchContext {
bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&,
const KURL&) const override;
bool ShouldLoadNewResource(Resource::Type) const override { return true; }
ReferrerPolicy GetReferrerPolicy() const override;
String GetOutgoingReferrer() const override;
const KURL& Url() const override;
const SecurityOrigin* GetParentSecurityOrigin() const override;
base::Optional<mojom::IPAddressSpace> GetAddressSpace() const override;
......@@ -143,6 +144,8 @@ class WorkerFetchContext final : public BaseFetchContext {
Member<SubresourceFilter> subresource_filter_;
const scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
const Member<FetchClientSettingsObjectImpl> fetch_client_settings_object_;
// The value of |save_data_enabled_| is read once per frame from
// NetworkStateNotifier, which is guarded by a mutex lock, and cached locally
// here for performance.
......
......@@ -18,6 +18,9 @@ blink_core_sources("script") {
"document_write_intervention.h",
"dynamic_module_resolver.cc",
"dynamic_module_resolver.h",
"fetch_client_settings_object.h",
"fetch_client_settings_object_impl.cc",
"fetch_client_settings_object_impl.h",
"fetch_client_settings_object_snapshot.cc",
"fetch_client_settings_object_snapshot.h",
"html_parser_script_runner.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_H_
#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/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/heap.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"
namespace blink {
// This is a partial interface of the "settings object" concept defined in the
// HTML spec:
// https://html.spec.whatwg.org/multipage/webappapis.html#settings-object
//
// This is also a partial interface of the "fetch client settings object" used
// in module script fetch. Other part of the "fetch client settings object" is
// currently implemented by ResourceFetcher and FetchContext, and this class is
// used together with them.
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
class CORE_EXPORT FetchClientSettingsObject
: public GarbageCollectedFinalized<FetchClientSettingsObject> {
public:
virtual ~FetchClientSettingsObject() = 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
virtual const KURL& BaseURL() const = 0;
// "An origin used in security checks."
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-origin
virtual const SecurityOrigin* GetSecurityOrigin() const = 0;
// "The default referrer policy for fetches performed using this environment
// settings object as a request client."
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-referrer-policy
virtual ReferrerPolicy GetReferrerPolicy() const = 0;
// "referrerURL" used in the "Determine request's Referrer" algorithm:
// https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer
virtual const String GetOutgoingReferrer() const = 0;
virtual void Trace(Visitor*) {}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/script/fetch_client_settings_object_impl.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
namespace blink {
FetchClientSettingsObjectImpl::FetchClientSettingsObjectImpl(
ExecutionContext& execution_context)
: execution_context_(execution_context) {
DCHECK(execution_context_->IsContextThread());
}
const KURL& FetchClientSettingsObjectImpl::BaseURL() const {
DCHECK(execution_context_->IsContextThread());
return execution_context_->BaseURL();
}
const SecurityOrigin* FetchClientSettingsObjectImpl::GetSecurityOrigin() const {
DCHECK(execution_context_->IsContextThread());
return execution_context_->GetSecurityOrigin();
}
ReferrerPolicy FetchClientSettingsObjectImpl::GetReferrerPolicy() const {
DCHECK(execution_context_->IsContextThread());
return execution_context_->GetReferrerPolicy();
}
const String FetchClientSettingsObjectImpl::GetOutgoingReferrer() const {
DCHECK(execution_context_->IsContextThread());
return execution_context_->OutgoingReferrer();
}
void FetchClientSettingsObjectImpl::Trace(Visitor* visitor) {
visitor->Trace(execution_context_);
FetchClientSettingsObject::Trace(visitor);
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_IMPL_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/script/fetch_client_settings_object.h"
#include "third_party/blink/renderer/platform/cross_thread_copier.h"
#include "third_party/blink/renderer/platform/heap/member.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"
namespace blink {
class ExecutionContext;
// This is an implementation of FetchClientSettingsObject. As opposed to
// FetchClientSettingsObjectSnapshot, this refers to up-to-date values of the
// settings object.
//
// This class should be used for resource loading other than main worker
// (worklet) scripts. For the main scripts, FetchClientSettingsObjectSnapshot
// should be used. See the class level comments on that class.
class CORE_EXPORT FetchClientSettingsObjectImpl final
: public FetchClientSettingsObject {
public:
explicit FetchClientSettingsObjectImpl(ExecutionContext&);
~FetchClientSettingsObjectImpl() override = default;
const KURL& BaseURL() const override;
const SecurityOrigin* GetSecurityOrigin() const override;
ReferrerPolicy GetReferrerPolicy() const override;
const String GetOutgoingReferrer() const override;
void Trace(Visitor* visitor) override;
private:
Member<ExecutionContext> execution_context_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_IMPL_H_
......@@ -6,9 +6,8 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_SNAPSHOT_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/script/fetch_client_settings_object.h"
#include "third_party/blink/renderer/platform/cross_thread_copier.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/trace_traits.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"
......@@ -46,24 +45,18 @@ struct CrossThreadFetchClientSettingsObjectData {
String outgoing_referrer;
};
// This is a partial implementation of the "settings object" concept defined in
// the HTML spec:
// https://html.spec.whatwg.org/multipage/webappapis.html#settings-object
//
// This is also a partial implementation of the "fetch client settings object"
// used in module script fetch. Actually, it's used with ResourceFetcher and
// FetchContext to compensate "fetch client settings object" that are not
// included in this class.
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
//
// This takes a partial snapshot of the execution context's states so that an
// instance of this class can be passed to another thread without cross-thread
// synchronization. Don't keep this object persistently, instead create a new
// instance per each "fetch a module script graph" algorithm:
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
//
// This class should be used only for main worker (worklet) script loading. For
// other resources, FetchClientSettingsObjectImpl should be used. See the class
// level comments on that class.
class CORE_EXPORT FetchClientSettingsObjectSnapshot final
: public GarbageCollectedFinalized<FetchClientSettingsObjectSnapshot> {
: public FetchClientSettingsObject {
public:
explicit FetchClientSettingsObjectSnapshot(ExecutionContext&);
explicit FetchClientSettingsObjectSnapshot(
......@@ -74,27 +67,16 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final
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_; }
~FetchClientSettingsObjectSnapshot() override = default;
// "An origin used in security checks."
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-origin
const SecurityOrigin* GetSecurityOrigin() const {
const KURL& BaseURL() const override { return base_url_; }
const SecurityOrigin* GetSecurityOrigin() const override {
return security_origin_.get();
}
// "The default referrer policy for fetches performed using this environment
// settings object as a request client."
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-referrer-policy
ReferrerPolicy GetReferrerPolicy() const { return referrer_policy_; }
// "referrerURL" used in the "Determine request's Referrer" algorithm:
// https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer
const String& GetOutgoingReferrer() const { return outgoing_referrer_; }
ReferrerPolicy GetReferrerPolicy() const override { return referrer_policy_; }
const String GetOutgoingReferrer() const override {
return outgoing_referrer_;
}
// Gets a copy of the data suitable for passing to another thread.
std::unique_ptr<CrossThreadFetchClientSettingsObjectData> CopyData() const {
......@@ -103,8 +85,6 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final
outgoing_referrer_.IsolatedCopy());
}
void Trace(Visitor*) {}
private:
const KURL base_url_;
const scoped_refptr<const SecurityOrigin> security_origin_;
......
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