mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
* chore: bump chromium in DEPS to 133.0.6836.0 * chore: bump chromium in DEPS to 133.0.6838.0 * chore: update patches * 6006096: [Sync ESB] Integrate Chrome Toast UI https://chromium-review.googlesource.com/c/chromium/src/+/6006096 * Confine enable_device_bound_sessions buildflag to //net https://chromium-review.googlesource.com/c/chromium/src/+/6014679 * revert [api] Delete deprecated struct FastApiTypedArray https://chromium-review.googlesource.com/c/v8/v8/+/5982984 Also https://chromium-review.googlesource.com/c/v8/v8/+/5979766/1 * fixup revert [api] Delete deprecated struct FastApiTypedArray * Migrate remaining NOTREACHED()s in chrome/ https://chromium-review.googlesource.com/c/chromium/src/+/5998172 * [Reland][Extensions] Remove ExtensionHostDelegate::GetJavaScriptDialogManager() https://chromium-review.googlesource.com/c/chromium/src/+/6020106 * Remove NOTREACHED_IN_MIGRATION() https://chromium-review.googlesource.com/c/chromium/src/+/6021996 * Remove Lock screen apps [#8] : remove lock screen extension https://chromium-review.googlesource.com/c/chromium/src/+/6005846 * Reland "Add CrashReporterClient::GetProductInfo(ProductInfo*)" https://chromium-review.googlesource.com/c/chromium/src/+/6012631 * Ozone/Wayland: remove lacros specific window states https://chromium-review.googlesource.com/c/chromium/src/+/6011215 * chore: bump chromium in DEPS to 133.0.6840.0 * chore: bump chromium in DEPS to 133.0.6841.0 * chore: bump chromium in DEPS to 133.0.6844.0 * implement virtual WebContents::CanUserEnterFullscreen * OnSearchifyStateChange -> OnSearchifyStarted * regen libc++ filenames * chore: bump chromium in DEPS to 133.0.6846.0 * chore: update patches --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
141 lines
5.0 KiB
Diff
141 lines
5.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Shelley Vohr <shelley.vohr@gmail.com>
|
|
Date: Mon, 17 Jan 2022 23:47:54 +0100
|
|
Subject: fix: crash when saving edited PDF files
|
|
|
|
This commit fixes a crash that persists any time a user attempts to
|
|
download an edited PDF. This was happening because the logic flow for
|
|
downloading of any edited PDF triggers a call to
|
|
chrome.fileSystem.chooseEntry, which we do not support and which
|
|
therefore causes unmapped page access crashes.
|
|
|
|
This patch can be removed should we choose to support chrome.fileSystem
|
|
or support it enough to fix the crash.
|
|
|
|
diff --git a/chrome/browser/resources/pdf/pdf_viewer.ts b/chrome/browser/resources/pdf/pdf_viewer.ts
|
|
index 25f2145d4202af9c386780366f726fbf6dcf558f..860d19e5ba1aa4dd027f3f5e5f2ccd37f54a99ad 100644
|
|
--- a/chrome/browser/resources/pdf/pdf_viewer.ts
|
|
+++ b/chrome/browser/resources/pdf/pdf_viewer.ts
|
|
@@ -1089,28 +1089,27 @@ export class PdfViewerElement extends PdfViewerBaseElement {
|
|
dataArray = [result.dataToSave];
|
|
}
|
|
|
|
- const blob = new Blob(dataArray);
|
|
const fileName = this.attachments_[index].name;
|
|
- chrome.fileSystem.chooseEntry(
|
|
- {type: 'saveFile', suggestedName: fileName},
|
|
- (entry?: FileSystemFileEntry) => {
|
|
- if (chrome.runtime.lastError) {
|
|
- if (chrome.runtime.lastError.message !== 'User cancelled') {
|
|
- console.error(
|
|
- 'chrome.fileSystem.chooseEntry failed: ' +
|
|
- chrome.runtime.lastError.message);
|
|
- }
|
|
- return;
|
|
- }
|
|
- entry!.createWriter((writer: FileWriter) => {
|
|
- writer.write(blob);
|
|
- // <if expr="enable_ink">
|
|
- // Unblock closing the window now that the user has saved
|
|
- // successfully.
|
|
- this.setShowBeforeUnloadDialog_(false);
|
|
- // </if>
|
|
- });
|
|
- });
|
|
+ const blob = new Blob(dataArray);
|
|
+
|
|
+ try {
|
|
+ const fileHandle = await window.showSaveFilePicker({
|
|
+ suggestedName: fileName,
|
|
+ });
|
|
+
|
|
+ const writable = await fileHandle.createWritable();
|
|
+ await writable.write(blob);
|
|
+ await writable.close();
|
|
+ // <if expr="enable_ink">
|
|
+ // Unblock closing the window now that the user has saved
|
|
+ // successfully.
|
|
+ this.setShowBeforeUnloadDialog_(false);
|
|
+ // </if>
|
|
+ } catch (error: any) {
|
|
+ if (error.name !== 'AbortError') {
|
|
+ console.error('window.showSaveFilePicker failed: ' + error);
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
/**
|
|
@@ -1301,36 +1300,33 @@ export class PdfViewerElement extends PdfViewerBaseElement {
|
|
fileName = fileName + '.pdf';
|
|
}
|
|
|
|
- // Create blob before callback to avoid race condition.
|
|
const blob = new Blob([result.dataToSave], {type: 'application/pdf'});
|
|
- chrome.fileSystem.chooseEntry(
|
|
- {
|
|
- type: 'saveFile',
|
|
- accepts: [{description: '*.pdf', extensions: ['pdf']}],
|
|
- suggestedName: fileName,
|
|
- },
|
|
- (entry?: FileSystemFileEntry) => {
|
|
- if (chrome.runtime.lastError) {
|
|
- if (chrome.runtime.lastError.message !== 'User cancelled') {
|
|
- console.error(
|
|
- 'chrome.fileSystem.chooseEntry failed: ' +
|
|
- chrome.runtime.lastError.message);
|
|
- }
|
|
- return;
|
|
- }
|
|
- entry!.createWriter((writer: FileWriter) => {
|
|
- writer.write(blob);
|
|
- // <if expr="enable_ink or enable_pdf_ink2">
|
|
- // Unblock closing the window now that the user has saved
|
|
- // successfully.
|
|
- this.setShowBeforeUnloadDialog_(false);
|
|
- // </if>
|
|
- // <if expr="enable_pdf_ink2">
|
|
- this.hasSavedEdits_ =
|
|
- this.hasSavedEdits_ || requestType === SaveRequestType.EDITED;
|
|
- // </if>
|
|
- });
|
|
- });
|
|
+ try {
|
|
+ const fileHandle = await window.showSaveFilePicker({
|
|
+ suggestedName: fileName,
|
|
+ types: [{
|
|
+ description: 'PDF Files',
|
|
+ accept: { 'application/pdf': ['.pdf'] },
|
|
+ }],
|
|
+ });
|
|
+
|
|
+ const writable = await fileHandle.createWritable();
|
|
+ await writable.write(blob);
|
|
+ await writable.close();
|
|
+ // <if expr="enable_ink or enable_pdf_ink2">
|
|
+ // Unblock closing the window now that the user has saved
|
|
+ // successfully.
|
|
+ this.setShowBeforeUnloadDialog_(false);
|
|
+ // </if>
|
|
+ // <if expr="enable_pdf_ink2">
|
|
+ this.hasSavedEdits_ =
|
|
+ this.hasSavedEdits_ || requestType === SaveRequestType.EDITED;
|
|
+ // </if>
|
|
+ } catch (error: any) {
|
|
+ if (error.name !== 'AbortError') {
|
|
+ console.error('window.showSaveFilePicker failed: ' + error);
|
|
+ }
|
|
+ }
|
|
|
|
// <if expr="enable_pdf_ink2">
|
|
// Ink2 doesn't need to exit annotation mode after save.
|
|
@@ -1476,6 +1472,9 @@ declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'pdf-viewer': PdfViewerElement;
|
|
}
|
|
+ interface Window {
|
|
+ showSaveFilePicker(opts: unknown): Promise<FileSystemFileHandle>;
|
|
+ }
|
|
}
|
|
|
|
customElements.define(PdfViewerElement.is, PdfViewerElement);
|