mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
fix: allow PDF viewer to show save file picker (#51072)
The PDF viewer's "save with changes" feature uses `window.showSaveFilePicker()`, but the PDF extension runs in a cross-origin iframe (chrome-extension:// inside the app's origin). Chromium's File System Access API blocks cross-origin subframes from showing file pickers unless the embedder explicitly allows them via `ContentClient::IsFilePickerAllowedForCrossOriginSubframe()`. Chrome overrides this in `ChromeContentClient` to allowlist the PDF extension origin, but Electron never did — so the picker was always blocked with a SecurityError. This adds the same override to `ElectronContentClient`, allowing the built-in PDF extension origin to bypass the cross-origin check. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
#include "components/pdf/common/constants.h" // nogncheck
|
||||
#include "components/pdf/common/pdf_util.h" // nogncheck
|
||||
#include "shell/common/electron_constants.h"
|
||||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
|
||||
@@ -217,4 +218,13 @@ void ElectronContentClient::AddContentDecryptionModules(
|
||||
}
|
||||
}
|
||||
|
||||
bool ElectronContentClient::IsFilePickerAllowedForCrossOriginSubframe(
|
||||
const url::Origin& origin) {
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
return IsPdfExtensionOrigin(origin);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
namespace electron {
|
||||
|
||||
@@ -33,6 +34,8 @@ class ElectronContentClient : public content::ContentClient {
|
||||
void AddContentDecryptionModules(
|
||||
std::vector<content::CdmInfo>* cdms,
|
||||
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) override;
|
||||
bool IsFilePickerAllowedForCrossOriginSubframe(
|
||||
const url::Origin& origin) override;
|
||||
};
|
||||
|
||||
} // namespace electron
|
||||
|
||||
Reference in New Issue
Block a user