From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Shelley Vohr 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 7e9c031b514bc59c4648587677dc5af0d1156a6e..6abb8e9d9c2ed8a87202aff9794cc4045db31ea7 100644 --- a/chrome/browser/resources/pdf/pdf_viewer.ts +++ b/chrome/browser/resources/pdf/pdf_viewer.ts @@ -1029,7 +1029,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); + // + a.href = URL.createObjectURL(blob); + a.click(); + URL.revokeObjectURL(a.href); + // + // const fileName = this.attachments_[index].name; chrome.fileSystem.chooseEntry( {type: 'saveFile', suggestedName: fileName}, @@ -1051,6 +1059,7 @@ export class PdfViewerElement extends PdfViewerBaseElement { // }); }); + // } /** @@ -1174,7 +1183,15 @@ export class PdfViewerElement extends PdfViewerBaseElement { } // 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'}); + // + a.href = URL.createObjectURL(blob); + a.click(); + URL.revokeObjectURL(a.href); + // + // chrome.fileSystem.chooseEntry( { type: 'saveFile', @@ -1199,6 +1216,7 @@ export class PdfViewerElement extends PdfViewerBaseElement { // }); }); + // // // Ink2 doesn't need to exit annotation mode after save.