electron/patches/chromium/fix_crash_when_saving_edite...

68 lines
2.4 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 be4c3c82787ac575320c0f3363027a1b8fb32a0e..8e2862e25f748254b006746be4fb93b9b89c5f50 100644
--- a/chrome/browser/resources/pdf/pdf_viewer.ts
+++ b/chrome/browser/resources/pdf/pdf_viewer.ts
@@ -964,7 +964,15 @@ export class PdfViewerElement extends PdfViewerBaseElement {
dataArray = [result.dataToSave];
}
+ const a = document.createElement('a');
+ a.download = this.attachments_[index].name;
const blob = new Blob(dataArray);
+ // <if expr="not _google_chrome">
+ a.href = URL.createObjectURL(blob);
+ a.click();
+ URL.revokeObjectURL(a.href);
+ // </if>
+ // <if expr="_google_chrome">
const fileName = this.attachments_[index].name;
chrome.fileSystem.chooseEntry(
{type: 'saveFile', suggestedName: fileName},
@@ -988,6 +996,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
}
});
});
+ // </if>
}
/**
@@ -1095,8 +1104,15 @@ export class PdfViewerElement extends PdfViewerBaseElement {
fileName = fileName + '.pdf';
}
- // Create blob before callback to avoid race condition.
+ const a = document.createElement('a');
+ a.download = fileName;
const blob = new Blob([result.dataToSave], {type: 'application/pdf'});
+ // <if expr="not _google_chrome">
+ a.href = URL.createObjectURL(blob);
+ a.click();
+ URL.revokeObjectURL(a.href);
+ // </if>
+ // <if expr="_google_chrome">
chrome.fileSystem.chooseEntry(
{
type: 'saveFile',
@@ -1123,6 +1139,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
}
});
});
+ // </if>
// <if expr="enable_ink">
// Saving in Annotation mode is destructive: crbug.com/919364