12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: Shelley Vohr <[email protected]>
- 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 26391c1965a83aa646db3ef9dbb6cb72fd564933..a3480ba54553406dc3576caefc814d854a9db21d 100644
- --- a/chrome/browser/resources/pdf/pdf_viewer.ts
- +++ b/chrome/browser/resources/pdf/pdf_viewer.ts
- @@ -1108,29 +1108,27 @@ export class PdfViewerElement extends PdfViewerBaseElement {
- dataArray = [result.dataToSave];
- }
-
- - const blob = new Blob(dataArray);
- const fileName = this.attachments_[index].name;
- - // TODO(crbug.com/373852607): Update to `showSaveFilePicker`.
- - 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);
- + }
- + }
- }
-
- /**
- @@ -1340,7 +1338,6 @@ 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'});
- // TODO(crbug.com/373852607): When OOPIF PDF is enabled, cross origin
- // checks block the request for `showSaveFilePicker`. Fix the issue by
|