From 45232e2ce7fb4cca6acda169887b45e1dbc6d340 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:10:35 +0200 Subject: [PATCH] fix: PDF support when site isolation trials disabled (#50845) * fix: use proper OOPIF PDF check in `StreamsPrivateAPI` * fix: add `ShouldEnableSubframeZoom` override to `ElectronBrowserClient` for upstream parity * fix: add `MaybeOverrideLocalURLCrossOriginEmbedderPolicy` override to `ElectronBrowserClient` for upstream parity * fix: add `DoesSiteRequireDedicatedProcess` override to `ElectronBrowserClient` for upstream parity * style: move `DoesSiteRequireDedicatedProcess` to correct override section Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Noah Gregory --- shell/browser/electron_browser_client.cc | 41 +++++++++++++++++++ shell/browser/electron_browser_client.h | 9 ++++ .../streams_private/streams_private_api.cc | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/shell/browser/electron_browser_client.cc b/shell/browser/electron_browser_client.cc index 760cb8b1d2..5426960fb4 100644 --- a/shell/browser/electron_browser_client.cc +++ b/shell/browser/electron_browser_client.cc @@ -61,6 +61,7 @@ #include "mojo/public/cpp/bindings/self_owned_associated_receiver.h" #include "net/ssl/ssl_cert_request_info.h" #include "net/ssl/ssl_private_key.h" +#include "pdf/pdf_features.h" #include "printing/buildflags/buildflags.h" #include "services/device/public/cpp/geolocation/geolocation_system_permission_manager.h" #include "services/device/public/cpp/geolocation/location_provider.h" @@ -1587,6 +1588,46 @@ bool ElectronBrowserClient::ShouldEnableStrictSiteIsolation() { return true; } +bool ElectronBrowserClient::ShouldEnableSubframeZoom() { +#if BUILDFLAG(ENABLE_PDF_VIEWER) + return chrome_pdf::features::IsOopifPdfEnabled(); +#else + return false; +#endif +} + +#if BUILDFLAG(ENABLE_PDF_VIEWER) +std::optional +ElectronBrowserClient::MaybeOverrideLocalURLCrossOriginEmbedderPolicy( + content::NavigationHandle* navigation_handle) { + if (!chrome_pdf::features::IsOopifPdfEnabled() || + !navigation_handle->IsPdf()) { + return std::nullopt; + } + + content::RenderFrameHost* pdf_extension = navigation_handle->GetParentFrame(); + if (!pdf_extension) { + return std::nullopt; + } + + content::RenderFrameHost* pdf_embedder = pdf_extension->GetParent(); + CHECK(pdf_embedder); + return pdf_embedder->GetCrossOriginEmbedderPolicy(); +} +#endif // BUILDFLAG(ENABLE_PDF_VIEWER) + +bool ElectronBrowserClient::DoesSiteRequireDedicatedProcess( + content::BrowserContext* browser_context, + const GURL& effective_site_url) { +#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) + return GetEnabledExtensionFromEffectiveURL(browser_context, + effective_site_url) != nullptr; +#else + return content::ContentBrowserClient::DoesSiteRequireDedicatedProcess( + browser_context, effective_site_url); +#endif +} + void ElectronBrowserClient::BindHostReceiverForRenderer( content::RenderProcessHost* render_process_host, mojo::GenericPendingReceiver receiver) { diff --git a/shell/browser/electron_browser_client.h b/shell/browser/electron_browser_client.h index 46eb0e790a..cc8cbe76b1 100644 --- a/shell/browser/electron_browser_client.h +++ b/shell/browser/electron_browser_client.h @@ -30,6 +30,7 @@ class FilePath; namespace content { class ClientCertificateDelegate; +class NavigationHandle; class PlatformNotificationService; class NavigationThrottleRegistry; class QuotaPermissionContext; @@ -82,6 +83,14 @@ class ElectronBrowserClient : public content::ContentBrowserClient, // content::ContentBrowserClient: std::string GetApplicationLocale() override; bool ShouldEnableStrictSiteIsolation() override; + bool ShouldEnableSubframeZoom() override; +#if BUILDFLAG(ENABLE_PDF_VIEWER) + std::optional + MaybeOverrideLocalURLCrossOriginEmbedderPolicy( + content::NavigationHandle* navigation_handle) override; +#endif // BUILDFLAG(ENABLE_PDF_VIEWER) + bool DoesSiteRequireDedicatedProcess(content::BrowserContext* browser_context, + const GURL& effective_site_url) override; void BindHostReceiverForRenderer( content::RenderProcessHost* render_process_host, mojo::GenericPendingReceiver receiver) override; diff --git a/shell/browser/extensions/api/streams_private/streams_private_api.cc b/shell/browser/extensions/api/streams_private/streams_private_api.cc index d3153b05c6..62a9848c04 100644 --- a/shell/browser/extensions/api/streams_private/streams_private_api.cc +++ b/shell/browser/extensions/api/streams_private/streams_private_api.cc @@ -70,7 +70,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent( std::move(transferrable_loader), original_url); #if BUILDFLAG(ENABLE_PDF_VIEWER) - if (base::FeatureList::IsEnabled(chrome_pdf::features::kPdfOopif) && + if (chrome_pdf::features::IsOopifPdfEnabled() && extension_id == extension_misc::kPdfExtensionId) { pdf::PdfViewerStreamManager::Create(web_contents); pdf::PdfViewerStreamManager::FromWebContents(web_contents)