Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: service worker registration with custom protocols
Refs #32664
- Loading branch information
1 parent
c7cd23c
commit 36fcd81
Showing
4 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: deepak1556 <hop2deep@gmail.com> | ||
Date: Fri, 20 May 2022 00:29:34 +0900 | ||
Subject: custom_protocols_plzserviceworker.patch | ||
|
||
Allow registering custom protocols to handle service worker main script fetching with PlzServiceWorker. | ||
|
||
Refs https://bugs.chromium.org/p/chromium/issues/detail?id=996511 | ||
|
||
diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc | ||
index 9aba6deb9e11ec2803f163088d1c321dd256787f..1dc24bb4c83acd2ff618b085059c918261b2a3d4 100644 | ||
--- a/content/browser/service_worker/service_worker_context_wrapper.cc | ||
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc | ||
@@ -1616,6 +1616,28 @@ ServiceWorkerContextWrapper::GetLoaderFactoryForBrowserInitiatedRequest( | ||
loader_factory_bundle_info = | ||
context()->loader_factory_bundle_for_update_check()->Clone(); | ||
|
||
+ // Give the embedder a chance to register custom schemes that can | ||
+ // handle loading the service worker main script. | ||
+ // Previous registration triggered by | ||
+ // ServiceWorkerContextWrapper::CreateNonNetworkPendingURLLoaderFactoryBundleForUpdateCheck | ||
+ // happens early on browser startup before the JS in the main process | ||
+ // is run by the embedder. | ||
+ auto* factory_bundle = static_cast<blink::PendingURLLoaderFactoryBundle*>( | ||
+ loader_factory_bundle_info.get()); | ||
+ ContentBrowserClient::NonNetworkURLLoaderFactoryMap non_network_factories; | ||
+ GetContentClient() | ||
+ ->browser() | ||
+ ->RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories( | ||
+ storage_partition_->browser_context(), &non_network_factories); | ||
+ for (auto& pair : non_network_factories) { | ||
+ const std::string& scheme = pair.first; | ||
+ mojo::PendingRemote<network::mojom::URLLoaderFactory>& factory_remote = | ||
+ pair.second; | ||
+ | ||
+ factory_bundle->pending_scheme_specific_factories().emplace( | ||
+ scheme, std::move(factory_remote)); | ||
+ } | ||
+ | ||
if (base::FeatureList::IsEnabled( | ||
features::kEnableServiceWorkersForChromeUntrusted) && | ||
scope.scheme_piece() == kChromeUIUntrustedScheme) { | ||
@@ -1636,9 +1658,7 @@ ServiceWorkerContextWrapper::GetLoaderFactoryForBrowserInitiatedRequest( | ||
browser_context(), scope_origin)) { | ||
config->RegisterURLDataSource(browser_context()); | ||
|
||
- static_cast<blink::PendingURLLoaderFactoryBundle*>( | ||
- loader_factory_bundle_info.get()) | ||
- ->pending_scheme_specific_factories() | ||
+ factory_bundle->pending_scheme_specific_factories() | ||
.emplace(kChromeUIUntrustedScheme, | ||
CreateWebUIServiceWorkerLoaderFactory( | ||
browser_context(), kChromeUIUntrustedScheme, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters