fix_crash_when_saving_edited_pdf_files.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Mon, 17 Jan 2022 23:47:54 +0100
  4. Subject: fix: crash when saving edited PDF files
  5. This commit fixes a crash that persists any time a user attempts to
  6. download an edited PDF. This was happening because the logic flow for
  7. downloading of any edited PDF triggers a call to
  8. chrome.fileSystem.chooseEntry, which we do not support and which
  9. therefore causes unmapped page access crashes.
  10. This patch can be removed should we choose to support chrome.fileSystem
  11. or support it enough to fix the crash.
  12. diff --git a/chrome/browser/resources/pdf/pdf_viewer.ts b/chrome/browser/resources/pdf/pdf_viewer.ts
  13. index f291ca720095ad1d079135539fb0a7421cae0be9..b967868063402572d9410c1725188e9c9caa5455 100644
  14. --- a/chrome/browser/resources/pdf/pdf_viewer.ts
  15. +++ b/chrome/browser/resources/pdf/pdf_viewer.ts
  16. @@ -1010,7 +1010,15 @@ export class PdfViewerElement extends PdfViewerBaseElement {
  17. dataArray = [result.dataToSave];
  18. }
  19. + const a = document.createElement('a');
  20. + a.download = this.attachments_[index].name;
  21. const blob = new Blob(dataArray);
  22. + // <if expr="not _google_chrome">
  23. + a.href = URL.createObjectURL(blob);
  24. + a.click();
  25. + URL.revokeObjectURL(a.href);
  26. + // </if>
  27. + // <if expr="_google_chrome">
  28. const fileName = this.attachments_[index].name;
  29. chrome.fileSystem.chooseEntry(
  30. {type: 'saveFile', suggestedName: fileName},
  31. @@ -1032,6 +1040,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
  32. // </if>
  33. });
  34. });
  35. + // </if>
  36. }
  37. /**
  38. @@ -1160,7 +1169,15 @@ export class PdfViewerElement extends PdfViewerBaseElement {
  39. }
  40. // Create blob before callback to avoid race condition.
  41. + const a = document.createElement('a');
  42. + a.download = fileName;
  43. const blob = new Blob([result.dataToSave], {type: 'application/pdf'});
  44. + // <if expr="not _google_chrome">
  45. + a.href = URL.createObjectURL(blob);
  46. + a.click();
  47. + URL.revokeObjectURL(a.href);
  48. + // </if>
  49. + // <if expr="_google_chrome">
  50. chrome.fileSystem.chooseEntry(
  51. {
  52. type: 'saveFile',
  53. @@ -1189,6 +1206,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
  54. // </if>
  55. });
  56. });
  57. + // </if>
  58. // <if expr="enable_pdf_ink2">
  59. // Ink2 doesn't need to exit annotation mode after save.