diff --git a/patches/chromium/.patches b/patches/chromium/.patches index fb4fd6d099115..657061f4fb2f3 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -131,3 +131,4 @@ cherry-pick-109fde1088be.patch m96_fileapi_move_origin_checks_in_bloburlstore_sooner.patch cherry-pick-f781748dcb3c.patch cherry-pick-c5571653d932.patch +fix_crash_when_saving_edited_pdf_files.patch diff --git a/patches/chromium/fix_crash_when_saving_edited_pdf_files.patch b/patches/chromium/fix_crash_when_saving_edited_pdf_files.patch new file mode 100644 index 0000000000000..a55507bee60f7 --- /dev/null +++ b/patches/chromium/fix_crash_when_saving_edited_pdf_files.patch @@ -0,0 +1,85 @@ +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.js b/chrome/browser/resources/pdf/pdf_viewer.js +index 7b1e50624df15f4d77cbe5d014e4f57c7499a999..f3b8dcd32369e9f954a0791588ba4955c6cdae7e 100644 +--- a/chrome/browser/resources/pdf/pdf_viewer.js ++++ b/chrome/browser/resources/pdf/pdf_viewer.js +@@ -974,25 +974,12 @@ export class PDFViewerElement extends PDFViewerBaseElement { + dataArray = [result.dataToSave]; + } + ++ const a = document.createElement('a'); ++ a.download = this.attachments_[index].name; + const blob = new Blob(dataArray); +- const fileName = this.attachments_[index].name; +- chrome.fileSystem.chooseEntry( +- {type: 'saveFile', suggestedName: fileName}, entry => { +- 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 => { +- writer.write(blob); +- // Unblock closing the window now that the user has saved +- // successfully. +- chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(false); +- }); +- }); ++ a.href = URL.createObjectURL(blob); ++ a.click(); ++ URL.revokeObjectURL(a.href); + } + + /** +@@ -1120,29 +1107,12 @@ export class PDFViewerElement extends PDFViewerBaseElement { + fileName = fileName + '.pdf'; + } + +- chrome.fileSystem.chooseEntry( +- { +- type: 'saveFile', +- accepts: [{description: '*.pdf', extensions: ['pdf']}], +- suggestedName: fileName +- }, +- entry => { +- 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 => { +- writer.write( +- new Blob([result.dataToSave], {type: 'application/pdf'})); +- // Unblock closing the window now that the user has saved +- // successfully. +- chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(false); +- }); +- }); ++ 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); + + // + // Saving in Annotation mode is destructive: crbug.com/919364