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, ...@@ -95,8 +95,10 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request,
if (!is_main_resource) { if (!is_main_resource) {
if (!request.DidSetHTTPReferrer()) { if (!request.DidSetHTTPReferrer()) {
request.SetHTTPReferrer(SecurityPolicy::GenerateReferrer( request.SetHTTPReferrer(SecurityPolicy::GenerateReferrer(
GetReferrerPolicy(), request.Url(), GetOutgoingReferrer())); GetFetchClientSettingsObject()->GetReferrerPolicy(), request.Url(),
request.SetHTTPOriginIfNeeded(GetSecurityOrigin()); GetFetchClientSettingsObject()->GetOutgoingReferrer()));
request.SetHTTPOriginIfNeeded(
GetFetchClientSettingsObject()->GetSecurityOrigin());
} else { } else {
DCHECK_EQ(SecurityPolicy::GenerateReferrer(request.GetReferrerPolicy(), DCHECK_EQ(SecurityPolicy::GenerateReferrer(request.GetReferrerPolicy(),
request.Url(), request.Url(),
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/core_export.h" #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/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/web_feature_forward.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/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
...@@ -50,6 +51,8 @@ class CORE_EXPORT BaseFetchContext : public FetchContext { ...@@ -50,6 +51,8 @@ class CORE_EXPORT BaseFetchContext : public FetchContext {
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
virtual const FetchClientSettingsObject* GetFetchClientSettingsObject()
const = 0;
virtual KURL GetSiteForCookies() const = 0; virtual KURL GetSiteForCookies() const = 0;
virtual SubresourceFilter* GetSubresourceFilter() const = 0; virtual SubresourceFilter* GetSubresourceFilter() const = 0;
virtual void CountUsage(WebFeature) const = 0; virtual void CountUsage(WebFeature) const = 0;
...@@ -85,8 +88,6 @@ class CORE_EXPORT BaseFetchContext : public FetchContext { ...@@ -85,8 +88,6 @@ class CORE_EXPORT BaseFetchContext : public FetchContext {
SecurityViolationReportingPolicy) const = 0; SecurityViolationReportingPolicy) const = 0;
virtual bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&, virtual bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&,
const KURL&) const = 0; const KURL&) const = 0;
virtual ReferrerPolicy GetReferrerPolicy() const = 0;
virtual String GetOutgoingReferrer() const = 0;
virtual const KURL& Url() const = 0; virtual const KURL& Url() const = 0;
virtual const SecurityOrigin* GetParentSecurityOrigin() const = 0; virtual const SecurityOrigin* GetParentSecurityOrigin() const = 0;
virtual base::Optional<mojom::IPAddressSpace> GetAddressSpace() const = 0; virtual base::Optional<mojom::IPAddressSpace> GetAddressSpace() const = 0;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/websocket_handshake_throttle.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/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/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h" #include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
...@@ -42,10 +43,16 @@ namespace blink { ...@@ -42,10 +43,16 @@ namespace blink {
class MockBaseFetchContext final : public BaseFetchContext { class MockBaseFetchContext final : public BaseFetchContext {
public: public:
explicit MockBaseFetchContext(ExecutionContext* execution_context) explicit MockBaseFetchContext(ExecutionContext* execution_context)
: execution_context_(execution_context) {} : execution_context_(execution_context),
fetch_client_settings_object_(
new FetchClientSettingsObjectImpl(*execution_context)) {}
~MockBaseFetchContext() override = default; ~MockBaseFetchContext() override = default;
// BaseFetchContext overrides: // BaseFetchContext overrides:
const FetchClientSettingsObject* GetFetchClientSettingsObject()
const override {
return fetch_client_settings_object_.Get();
}
KURL GetSiteForCookies() const override { return KURL(); } KURL GetSiteForCookies() const override { return KURL(); }
bool AllowScriptFromSource(const KURL&) const override { return false; } bool AllowScriptFromSource(const KURL&) const override { return false; }
SubresourceFilter* GetSubresourceFilter() const override { return nullptr; } SubresourceFilter* GetSubresourceFilter() const override { return nullptr; }
...@@ -79,16 +86,10 @@ class MockBaseFetchContext final : public BaseFetchContext { ...@@ -79,16 +86,10 @@ class MockBaseFetchContext final : public BaseFetchContext {
const KURL&) const override { const KURL&) const override {
return false; 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 KURL& Url() const override { return execution_context_->Url(); }
const SecurityOrigin* GetSecurityOrigin() const override { const SecurityOrigin* GetSecurityOrigin() const override {
return execution_context_->GetSecurityOrigin(); return fetch_client_settings_object_->GetSecurityOrigin();
} }
const SecurityOrigin* GetParentSecurityOrigin() const override { const SecurityOrigin* GetParentSecurityOrigin() const override {
return nullptr; return nullptr;
...@@ -104,6 +105,7 @@ class MockBaseFetchContext final : public BaseFetchContext { ...@@ -104,6 +105,7 @@ class MockBaseFetchContext final : public BaseFetchContext {
void Trace(blink::Visitor* visitor) override { void Trace(blink::Visitor* visitor) override {
visitor->Trace(execution_context_); visitor->Trace(execution_context_);
visitor->Trace(fetch_client_settings_object_);
BaseFetchContext::Trace(visitor); BaseFetchContext::Trace(visitor);
} }
...@@ -112,6 +114,7 @@ class MockBaseFetchContext final : public BaseFetchContext { ...@@ -112,6 +114,7 @@ class MockBaseFetchContext final : public BaseFetchContext {
private: private:
Member<ExecutionContext> execution_context_; Member<ExecutionContext> execution_context_;
Member<FetchClientSettingsObjectImpl> fetch_client_settings_object_;
bool is_detached_ = false; bool is_detached_ = false;
}; };
......
...@@ -226,10 +226,7 @@ mojom::FetchCacheMode DetermineFrameCacheMode(Frame* frame, ...@@ -226,10 +226,7 @@ mojom::FetchCacheMode DetermineFrameCacheMode(Frame* frame,
struct FrameFetchContext::FrozenState final struct FrameFetchContext::FrozenState final
: GarbageCollectedFinalized<FrozenState> { : GarbageCollectedFinalized<FrozenState> {
FrozenState(ReferrerPolicy referrer_policy, FrozenState(const KURL& url,
const String& outgoing_referrer,
const KURL& url,
scoped_refptr<const SecurityOrigin> security_origin,
scoped_refptr<const SecurityOrigin> parent_security_origin, scoped_refptr<const SecurityOrigin> parent_security_origin,
const base::Optional<mojom::IPAddressSpace>& address_space, const base::Optional<mojom::IPAddressSpace>& address_space,
const ContentSecurityPolicy* content_security_policy, const ContentSecurityPolicy* content_security_policy,
...@@ -240,10 +237,7 @@ struct FrameFetchContext::FrozenState final ...@@ -240,10 +237,7 @@ struct FrameFetchContext::FrozenState final
const String& user_agent, const String& user_agent,
bool is_main_frame, bool is_main_frame,
bool is_svg_image_chrome_client) bool is_svg_image_chrome_client)
: referrer_policy(referrer_policy), : url(url),
outgoing_referrer(outgoing_referrer),
url(url),
security_origin(std::move(security_origin)),
parent_security_origin(std::move(parent_security_origin)), parent_security_origin(std::move(parent_security_origin)),
address_space(address_space), address_space(address_space),
content_security_policy(content_security_policy), content_security_policy(content_security_policy),
...@@ -255,10 +249,7 @@ struct FrameFetchContext::FrozenState final ...@@ -255,10 +249,7 @@ struct FrameFetchContext::FrozenState final
is_main_frame(is_main_frame), is_main_frame(is_main_frame),
is_svg_image_chrome_client(is_svg_image_chrome_client) {} is_svg_image_chrome_client(is_svg_image_chrome_client) {}
const ReferrerPolicy referrer_policy;
const String outgoing_referrer;
const KURL url; const KURL url;
const scoped_refptr<const SecurityOrigin> security_origin;
const scoped_refptr<const SecurityOrigin> parent_security_origin; const scoped_refptr<const SecurityOrigin> parent_security_origin;
const base::Optional<mojom::IPAddressSpace> address_space; const base::Optional<mojom::IPAddressSpace> address_space;
const Member<const ContentSecurityPolicy> content_security_policy; const Member<const ContentSecurityPolicy> content_security_policy;
...@@ -298,6 +289,10 @@ FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) ...@@ -298,6 +289,10 @@ FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
document_(document), document_(document),
save_data_enabled_(GetNetworkStateNotifier().SaveDataEnabled() && save_data_enabled_(GetNetworkStateNotifier().SaveDataEnabled() &&
!GetSettings()->GetDataSaverHoldbackWebApi()) { !GetSettings()->GetDataSaverHoldbackWebApi()) {
if (document_) {
fetch_client_settings_object_ =
new FetchClientSettingsObjectImpl(*document_);
}
DCHECK(GetFrame()); DCHECK(GetFrame());
} }
...@@ -306,6 +301,8 @@ void FrameFetchContext::ProvideDocumentToContext(FetchContext& context, ...@@ -306,6 +301,8 @@ void FrameFetchContext::ProvideDocumentToContext(FetchContext& context,
DCHECK(document); DCHECK(document);
CHECK(context.IsFrameFetchContext()); CHECK(context.IsFrameFetchContext());
static_cast<FrameFetchContext&>(context).document_ = document; static_cast<FrameFetchContext&>(context).document_ = document;
static_cast<FrameFetchContext&>(context).fetch_client_settings_object_ =
new FetchClientSettingsObjectImpl(*document);
} }
FrameFetchContext::~FrameFetchContext() { FrameFetchContext::~FrameFetchContext() {
...@@ -352,6 +349,12 @@ FrameScheduler* FrameFetchContext::GetFrameScheduler() const { ...@@ -352,6 +349,12 @@ FrameScheduler* FrameFetchContext::GetFrameScheduler() const {
return GetFrame()->GetFrameScheduler(); return GetFrame()->GetFrameScheduler();
} }
const FetchClientSettingsObject*
FrameFetchContext::GetFetchClientSettingsObject() const {
DCHECK(fetch_client_settings_object_);
return fetch_client_settings_object_.Get();
}
KURL FrameFetchContext::GetSiteForCookies() const { KURL FrameFetchContext::GetSiteForCookies() const {
if (IsDetached()) if (IsDetached())
return frozen_state_->site_for_cookies; return frozen_state_->site_for_cookies;
...@@ -880,9 +883,10 @@ bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation( ...@@ -880,9 +883,10 @@ bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation(
} }
const SecurityOrigin* FrameFetchContext::GetSecurityOrigin() const { const SecurityOrigin* FrameFetchContext::GetSecurityOrigin() const {
if (IsDetached()) // This can be called before |fetch_client_settings_object_| is set.
return frozen_state_->security_origin.get(); if (!fetch_client_settings_object_)
return document_ ? document_->GetSecurityOrigin() : nullptr; return nullptr;
return fetch_client_settings_object_->GetSecurityOrigin();
} }
void FrameFetchContext::ModifyRequestForCSP(ResourceRequest& resource_request) { void FrameFetchContext::ModifyRequestForCSP(ResourceRequest& resource_request) {
...@@ -1200,18 +1204,6 @@ bool FrameFetchContext::ShouldBlockFetchAsCredentialedSubresource( ...@@ -1200,18 +1204,6 @@ bool FrameFetchContext::ShouldBlockFetchAsCredentialedSubresource(
return RuntimeEnabledFeatures::BlockCredentialedSubresourcesEnabled(); 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 { const KURL& FrameFetchContext::Url() const {
if (IsDetached()) if (IsDetached())
return frozen_state_->url; return frozen_state_->url;
...@@ -1418,20 +1410,22 @@ FetchContext* FrameFetchContext::Detach() { ...@@ -1418,20 +1410,22 @@ FetchContext* FrameFetchContext::Detach() {
if (document_) { if (document_) {
frozen_state_ = new FrozenState( frozen_state_ = new FrozenState(
GetReferrerPolicy(), GetOutgoingReferrer(), Url(), GetSecurityOrigin(), Url(), GetParentSecurityOrigin(), GetAddressSpace(),
GetParentSecurityOrigin(), GetAddressSpace(),
GetContentSecurityPolicy(), GetSiteForCookies(), GetRequestorOrigin(), GetContentSecurityPolicy(), GetSiteForCookies(), GetRequestorOrigin(),
GetClientHintsPreferences(), GetDevicePixelRatio(), GetUserAgent(), GetClientHintsPreferences(), GetDevicePixelRatio(), GetUserAgent(),
IsMainFrame(), IsSVGImageChromeClient()); IsMainFrame(), IsSVGImageChromeClient());
fetch_client_settings_object_ =
new FetchClientSettingsObjectSnapshot(*document_);
} else { } else {
// Some getters are unavailable in this case. // Some getters are unavailable in this case.
frozen_state_ = new FrozenState( frozen_state_ = new FrozenState(
kReferrerPolicyDefault, String(), NullURL(), GetSecurityOrigin(), NullURL(), GetParentSecurityOrigin(), GetAddressSpace(),
GetParentSecurityOrigin(), GetAddressSpace(),
GetContentSecurityPolicy(), GetSiteForCookies(), GetContentSecurityPolicy(), GetSiteForCookies(),
SecurityOrigin::CreateUniqueOpaque(), GetClientHintsPreferences(), SecurityOrigin::CreateUniqueOpaque(), GetClientHintsPreferences(),
GetDevicePixelRatio(), GetUserAgent(), IsMainFrame(), GetDevicePixelRatio(), GetUserAgent(), IsMainFrame(),
IsSVGImageChromeClient()); IsSVGImageChromeClient());
fetch_client_settings_object_ = new FetchClientSettingsObjectSnapshot(
NullURL(), nullptr, kReferrerPolicyDefault, String());
} }
// This is needed to break a reference cycle in which off-heap // This is needed to break a reference cycle in which off-heap
...@@ -1445,6 +1439,7 @@ void FrameFetchContext::Trace(blink::Visitor* visitor) { ...@@ -1445,6 +1439,7 @@ void FrameFetchContext::Trace(blink::Visitor* visitor) {
visitor->Trace(document_loader_); visitor->Trace(document_loader_);
visitor->Trace(document_); visitor->Trace(document_);
visitor->Trace(frozen_state_); visitor->Trace(frozen_state_);
visitor->Trace(fetch_client_settings_object_);
BaseFetchContext::Trace(visitor); BaseFetchContext::Trace(visitor);
} }
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "third_party/blink/renderer/core/core_export.h" #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/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/loader/base_fetch_context.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/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/client_hints_preferences.h" #include "third_party/blink/renderer/platform/loader/fetch/client_hints_preferences.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
...@@ -206,6 +208,8 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext { ...@@ -206,6 +208,8 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
scoped_refptr<base::SingleThreadTaskRunner> GetLoadingTaskRunner() override; scoped_refptr<base::SingleThreadTaskRunner> GetLoadingTaskRunner() override;
// BaseFetchContext overrides: // BaseFetchContext overrides:
const FetchClientSettingsObject* GetFetchClientSettingsObject()
const override;
KURL GetSiteForCookies() const override; KURL GetSiteForCookies() const override;
SubresourceFilter* GetSubresourceFilter() const override; SubresourceFilter* GetSubresourceFilter() const override;
bool AllowScriptFromSource(const KURL&) const override; bool AllowScriptFromSource(const KURL&) const override;
...@@ -230,8 +234,6 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext { ...@@ -230,8 +234,6 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&, bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&,
const KURL&) const override; const KURL&) const override;
ReferrerPolicy GetReferrerPolicy() const override;
String GetOutgoingReferrer() const override;
const KURL& Url() const override; const KURL& Url() const override;
const SecurityOrigin* GetParentSecurityOrigin() const override; const SecurityOrigin* GetParentSecurityOrigin() const override;
base::Optional<mojom::IPAddressSpace> GetAddressSpace() const override; base::Optional<mojom::IPAddressSpace> GetAddressSpace() const override;
...@@ -275,6 +277,8 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext { ...@@ -275,6 +277,8 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
// Non-null only when detached. // Non-null only when detached.
Member<const FrozenState> frozen_state_; Member<const FrozenState> frozen_state_;
Member<FetchClientSettingsObject> fetch_client_settings_object_;
}; };
} // namespace blink } // namespace blink
......
...@@ -232,7 +232,7 @@ void ModuleTreeLinker::InitiateInternalModuleScriptGraphFetching( ...@@ -232,7 +232,7 @@ void ModuleTreeLinker::InitiateInternalModuleScriptGraphFetching(
++num_incomplete_fetches_; ++num_incomplete_fetches_;
// [IMSGF] Step 2. Fetch a single module script given ... // [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); custom_fetch_type_, this);
// [IMSGF] Step 3-- are executed when NotifyModuleLoadFinished() is called. // [IMSGF] Step 3-- are executed when NotifyModuleLoadFinished() is called.
......
...@@ -96,6 +96,8 @@ WorkerFetchContext::WorkerFetchContext( ...@@ -96,6 +96,8 @@ WorkerFetchContext::WorkerFetchContext(
web_context_(std::move(web_context)), web_context_(std::move(web_context)),
loading_task_runner_( loading_task_runner_(
global_scope_->GetTaskRunner(TaskType::kInternalLoading)), global_scope_->GetTaskRunner(TaskType::kInternalLoading)),
fetch_client_settings_object_(
new FetchClientSettingsObjectImpl(*global_scope_)),
save_data_enabled_(GetNetworkStateNotifier().SaveDataEnabled()) { save_data_enabled_(GetNetworkStateNotifier().SaveDataEnabled()) {
web_context_->InitializeOnWorkerThread(); web_context_->InitializeOnWorkerThread();
std::unique_ptr<blink::WebDocumentSubresourceFilter> web_filter = std::unique_ptr<blink::WebDocumentSubresourceFilter> web_filter =
...@@ -105,6 +107,10 @@ WorkerFetchContext::WorkerFetchContext( ...@@ -105,6 +107,10 @@ WorkerFetchContext::WorkerFetchContext(
SubresourceFilter::Create(global_scope, std::move(web_filter)); SubresourceFilter::Create(global_scope, std::move(web_filter));
} }
} }
const FetchClientSettingsObject*
WorkerFetchContext::GetFetchClientSettingsObject() const {
return fetch_client_settings_object_.Get();
}
KURL WorkerFetchContext::GetSiteForCookies() const { KURL WorkerFetchContext::GetSiteForCookies() const {
return web_context_->SiteForCookies(); return web_context_->SiteForCookies();
...@@ -198,14 +204,6 @@ bool WorkerFetchContext::ShouldBlockFetchAsCredentialedSubresource( ...@@ -198,14 +204,6 @@ bool WorkerFetchContext::ShouldBlockFetchAsCredentialedSubresource(
return false; return false;
} }
ReferrerPolicy WorkerFetchContext::GetReferrerPolicy() const {
return global_scope_->GetReferrerPolicy();
}
String WorkerFetchContext::GetOutgoingReferrer() const {
return global_scope_->OutgoingReferrer();
}
const KURL& WorkerFetchContext::Url() const { const KURL& WorkerFetchContext::Url() const {
return global_scope_->Url(); return global_scope_->Url();
} }
...@@ -233,7 +231,7 @@ void WorkerFetchContext::AddConsoleMessage(ConsoleMessage* message) const { ...@@ -233,7 +231,7 @@ void WorkerFetchContext::AddConsoleMessage(ConsoleMessage* message) const {
} }
const SecurityOrigin* WorkerFetchContext::GetSecurityOrigin() const { const SecurityOrigin* WorkerFetchContext::GetSecurityOrigin() const {
return global_scope_->GetSecurityOrigin(); return GetFetchClientSettingsObject()->GetSecurityOrigin();
} }
std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader( std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader(
...@@ -424,6 +422,7 @@ WorkerFetchContext::GetWorkerContentSettingsClient() const { ...@@ -424,6 +422,7 @@ WorkerFetchContext::GetWorkerContentSettingsClient() const {
void WorkerFetchContext::Trace(blink::Visitor* visitor) { void WorkerFetchContext::Trace(blink::Visitor* visitor) {
visitor->Trace(global_scope_); visitor->Trace(global_scope_);
visitor->Trace(subresource_filter_); visitor->Trace(subresource_filter_);
visitor->Trace(fetch_client_settings_object_);
BaseFetchContext::Trace(visitor); BaseFetchContext::Trace(visitor);
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom-blink.h" #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/core_export.h"
#include "third_party/blink/renderer/core/loader/base_fetch_context.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" #include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink { namespace blink {
...@@ -36,6 +37,8 @@ class WorkerFetchContext final : public BaseFetchContext { ...@@ -36,6 +37,8 @@ class WorkerFetchContext final : public BaseFetchContext {
~WorkerFetchContext() override; ~WorkerFetchContext() override;
// BaseFetchContext implementation: // BaseFetchContext implementation:
const FetchClientSettingsObject* GetFetchClientSettingsObject()
const override;
KURL GetSiteForCookies() const override; KURL GetSiteForCookies() const override;
SubresourceFilter* GetSubresourceFilter() const override; SubresourceFilter* GetSubresourceFilter() const override;
bool AllowScriptFromSource(const KURL&) const override; bool AllowScriptFromSource(const KURL&) const override;
...@@ -60,8 +63,6 @@ class WorkerFetchContext final : public BaseFetchContext { ...@@ -60,8 +63,6 @@ class WorkerFetchContext final : public BaseFetchContext {
bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&, bool ShouldBlockFetchAsCredentialedSubresource(const ResourceRequest&,
const KURL&) const override; const KURL&) const override;
bool ShouldLoadNewResource(Resource::Type) const override { return true; } bool ShouldLoadNewResource(Resource::Type) const override { return true; }
ReferrerPolicy GetReferrerPolicy() const override;
String GetOutgoingReferrer() const override;
const KURL& Url() const override; const KURL& Url() const override;
const SecurityOrigin* GetParentSecurityOrigin() const override; const SecurityOrigin* GetParentSecurityOrigin() const override;
base::Optional<mojom::IPAddressSpace> GetAddressSpace() const override; base::Optional<mojom::IPAddressSpace> GetAddressSpace() const override;
...@@ -143,6 +144,8 @@ class WorkerFetchContext final : public BaseFetchContext { ...@@ -143,6 +144,8 @@ class WorkerFetchContext final : public BaseFetchContext {
Member<SubresourceFilter> subresource_filter_; Member<SubresourceFilter> subresource_filter_;
const scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 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 // The value of |save_data_enabled_| is read once per frame from
// NetworkStateNotifier, which is guarded by a mutex lock, and cached locally // NetworkStateNotifier, which is guarded by a mutex lock, and cached locally
// here for performance. // here for performance.
......
...@@ -18,6 +18,9 @@ blink_core_sources("script") { ...@@ -18,6 +18,9 @@ blink_core_sources("script") {
"document_write_intervention.h", "document_write_intervention.h",
"dynamic_module_resolver.cc", "dynamic_module_resolver.cc",
"dynamic_module_resolver.h", "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.cc",
"fetch_client_settings_object_snapshot.h", "fetch_client_settings_object_snapshot.h",
"html_parser_script_runner.cc", "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 @@ ...@@ -6,9 +6,8 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_FETCH_CLIENT_SETTINGS_OBJECT_SNAPSHOT_H_ #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/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/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/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/referrer_policy.h" #include "third_party/blink/renderer/platform/weborigin/referrer_policy.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h" #include "third_party/blink/renderer/platform/weborigin/security_origin.h"
...@@ -46,24 +45,18 @@ struct CrossThreadFetchClientSettingsObjectData { ...@@ -46,24 +45,18 @@ struct CrossThreadFetchClientSettingsObjectData {
String outgoing_referrer; 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 // 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 // instance of this class can be passed to another thread without cross-thread
// synchronization. Don't keep this object persistently, instead create a new // synchronization. Don't keep this object persistently, instead create a new
// instance per each "fetch a module script graph" algorithm: // 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-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
//
// 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 class CORE_EXPORT FetchClientSettingsObjectSnapshot final
: public GarbageCollectedFinalized<FetchClientSettingsObjectSnapshot> { : public FetchClientSettingsObject {
public: public:
explicit FetchClientSettingsObjectSnapshot(ExecutionContext&); explicit FetchClientSettingsObjectSnapshot(ExecutionContext&);
explicit FetchClientSettingsObjectSnapshot( explicit FetchClientSettingsObjectSnapshot(
...@@ -74,27 +67,16 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final ...@@ -74,27 +67,16 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final
ReferrerPolicy referrer_policy, ReferrerPolicy referrer_policy,
const String& outgoing_referrer); const String& outgoing_referrer);
virtual ~FetchClientSettingsObjectSnapshot() = default; ~FetchClientSettingsObjectSnapshot() override = 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." const KURL& BaseURL() const override { return base_url_; }
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-origin const SecurityOrigin* GetSecurityOrigin() const override {
const SecurityOrigin* GetSecurityOrigin() const {
return security_origin_.get(); return security_origin_.get();
} }
ReferrerPolicy GetReferrerPolicy() const override { return referrer_policy_; }
// "The default referrer policy for fetches performed using this environment const String GetOutgoingReferrer() const override {
// settings object as a request client." return outgoing_referrer_;
// 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_; }
// Gets a copy of the data suitable for passing to another thread. // Gets a copy of the data suitable for passing to another thread.
std::unique_ptr<CrossThreadFetchClientSettingsObjectData> CopyData() const { std::unique_ptr<CrossThreadFetchClientSettingsObjectData> CopyData() const {
...@@ -103,8 +85,6 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final ...@@ -103,8 +85,6 @@ class CORE_EXPORT FetchClientSettingsObjectSnapshot final
outgoing_referrer_.IsolatedCopy()); outgoing_referrer_.IsolatedCopy());
} }
void Trace(Visitor*) {}
private: private:
const KURL base_url_; const KURL base_url_;
const scoped_refptr<const SecurityOrigin> security_origin_; 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