mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* chore: bump chromium in DEPS to 131.0.6778.4 * chore: bump chromium to 131.0.6778.0 (main) (#44251) * chore: bump chromium in DEPS to 131.0.6778.0 * 5803393: [UI] Add alias for mojo version of `MenuSourceType` https://chromium-review.googlesource.com/c/chromium/src/+/5803393 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> (cherry picked from commitef84f13650) * chore: bump chromium in DEPS to 132.0.6779.0 (cherry picked from commit77f17523f2) * chore: update patches (cherry picked from commitfed9888232) * 5904951: controlledframe: Disable File System Access for <controlledframe> https://chromium-review.googlesource.com/c/chromium/src/+/5904951 (cherry picked from commit289a2fb86a) --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
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 020e31e04887008cba6ed04407124c034b9565a2..8a8a7eb411dc6946254d0d92e043a22bdd2053f9 100644
|
|
--- a/chrome/browser/resources/pdf/pdf_viewer.ts
|
|
+++ b/chrome/browser/resources/pdf/pdf_viewer.ts
|
|
@@ -1020,28 +1020,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);
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
/**
|
|
@@ -1169,36 +1168,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.
|
|
@@ -1308,6 +1304,9 @@ declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'pdf-viewer': PdfViewerElement;
|
|
}
|
|
+ interface Window {
|
|
+ showSaveFilePicker(opts: unknown): Promise<FileSystemFileHandle>;
|
|
+ }
|
|
}
|
|
|
|
customElements.define(PdfViewerElement.is, PdfViewerElement);
|