Skip to content

Commit

Permalink
#987 Fetch Keepalive should not report an exception when blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
uazo committed Apr 12, 2024
1 parent 82f065c commit 81d20d0
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions build/patches/Keep-disabled-FetchLaterAPI.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ From: uazo <[email protected]>
Date: Thu, 28 Sep 2023 08:11:00 +0000
Subject: Keep disabled FetchLaterAPI

Disallow a network request to survive to context destoy
Disallow a network request to survive to context destoy.
For Request with active keepalive, if the request does not
start from the same origin.
It also inhibits the blocked request exception to javascript.

License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
---
.../browser/loader/keep_alive_url_loader.cc | 33 +++++++++++++++++--
.../browser/loader/keep_alive_url_loader.h | 3 --
.../Keep-disabled-FetchLaterAPI.inc | 3 ++
.../loader/child_url_loader_factory_bundle.cc | 6 +---
.../renderer/core/fetch/fetch_manager.cc | 8 +++--
.../loader/child_url_loader_factory_bundle.cc | 14 ++++----
.../platform/loader/fetch/resource_fetcher.cc | 2 +-
.../platform/runtime_enabled_features.json5 | 5 ++-
6 files changed, 38 insertions(+), 14 deletions(-)
7 files changed, 51 insertions(+), 17 deletions(-)
create mode 100644 cromite_flags/third_party/blink/common/features_cc/Keep-disabled-FetchLaterAPI.inc

diff --git a/content/browser/loader/keep_alive_url_loader.cc b/content/browser/loader/keep_alive_url_loader.cc
Expand Down Expand Up @@ -91,18 +97,56 @@ new file mode 100644
+SET_CROMITE_FEATURE_ENABLED(kKeepAliveInBrowserMigration);
+SET_CROMITE_FEATURE_DISABLED(kPendingBeaconAPI);
+SET_CROMITE_FEATURE_DISABLED(kAttributionReportingInBrowserMigration);
diff --git a/third_party/blink/renderer/core/fetch/fetch_manager.cc b/third_party/blink/renderer/core/fetch/fetch_manager.cc
--- a/third_party/blink/renderer/core/fetch/fetch_manager.cc
+++ b/third_party/blink/renderer/core/fetch/fetch_manager.cc
@@ -1168,7 +1168,9 @@ void FetchManager::Loader::Failed(
if (resolver_) {
ScriptState::Scope scope(GetScriptState());
if (dom_exception) {
- resolver_->Reject(dom_exception);
+ if (!GetFetchRequestData()->Keepalive()) {
+ resolver_->Reject(dom_exception);
+ }
} else {
v8::Local<v8::Value> value =
exception_.Get(GetScriptState()->GetIsolate());
@@ -1188,7 +1190,9 @@ void FetchManager::Loader::Failed(
V8String(GetScriptState()->GetIsolate(),
IdentifiersFactory::IdFromToken(*issue_id)));
}
- resolver_->Reject(value);
+ if (!GetFetchRequestData()->Keepalive()) {
+ resolver_->Reject(value);;
+ }
SendHistogram(FetchManagerLoaderCheckPoint::kFailed);
LogIfKeepalive(FetchKeepAliveRendererMetricType::kLoadingFailed);
}
diff --git a/third_party/blink/renderer/platform/loader/child_url_loader_factory_bundle.cc b/third_party/blink/renderer/platform/loader/child_url_loader_factory_bundle.cc
--- a/third_party/blink/renderer/platform/loader/child_url_loader_factory_bundle.cc
+++ b/third_party/blink/renderer/platform/loader/child_url_loader_factory_bundle.cc
@@ -260,11 +260,7 @@ void ChildURLLoaderFactoryBundle::CreateLoaderAndStart(
@@ -254,17 +254,19 @@ void ChildURLLoaderFactoryBundle::CreateLoaderAndStart(
return;
}

+ bool keepalive = request.keepalive;
+ if (keepalive && !request.is_fetch_later_api &&
+ url::IsSameOriginWith(request.url, request.referrer)) {
+ keepalive = false;
+ }
+
// Use |keep_alive_loader_factory_| to send the keepalive requests to the
// KeepAliveURLLoaderService in the browser process and trigger the special
// keepalive request handling.
// |keep_alive_loader_factory_| only presents when
// features::kKeepAliveInBrowserMigration is true.
if (request.keepalive && keep_alive_loader_factory_ &&
- if (request.keepalive && keep_alive_loader_factory_ &&
- base::FeatureList::IsEnabled(features::kKeepAliveInBrowserMigration) &&
- (request.attribution_reporting_eligibility ==
- network::mojom::AttributionReportingEligibility::kUnset ||
- base::FeatureList::IsEnabled(
- features::kAttributionReportingInBrowserMigration))) {
+ if (keepalive && keep_alive_loader_factory_ &&
+ base::FeatureList::IsEnabled(features::kKeepAliveInBrowserMigration)) {
keep_alive_loader_factory_->CreateLoaderAndStart(
std::move(loader), request_id, options, request, std::move(client),
Expand Down

0 comments on commit 81d20d0

Please sign in to comment.