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 8f516ab1d3772b27f4568b36d3f87dddcdd57ed7..cf82067ba9ff479dd3c9fb213fae9f9993e9cf35 100644
  14. --- a/chrome/browser/resources/pdf/pdf_viewer.ts
  15. +++ b/chrome/browser/resources/pdf/pdf_viewer.ts
  16. @@ -1012,7 +1012,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. @@ -1034,6 +1042,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
  32. // </if>
  33. });
  34. });
  35. + // </if>
  36. }
  37. /**
  38. @@ -1157,7 +1166,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. @@ -1182,6 +1199,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.