Bug 1611133 - Fix print preview close handler. r=bgrins
authorBrendan Dahl <bdahl@mozilla.com>
Wed, 12 Feb 2020 18:48:46 +0000
changeset 513631 ea46ceb69962a6b56809935450f753fcd0751071
parent 513630 1b1452a5440dec1e9a6b73dba5ec07bc9f01bbc8
child 513632 934d8e7932174d263041b41dc561a0b8e3827fae
push id107150
push userbdahl@mozilla.com
push dateWed, 12 Feb 2020 21:08:24 +0000
treeherderautoland@ea46ceb69962 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1611133
milestone75.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1611133 - Fix print preview close handler. r=bgrins For HTML documents the onclose event is not dispatched to the root <html> element. Differential Revision: https://phabricator.services.mozilla.com/D62605
toolkit/components/printing/content/printUtils.js
--- a/toolkit/components/printing/content/printUtils.js
+++ b/toolkit/components/printing/content/printUtils.js
@@ -633,25 +633,25 @@ var PrintUtils = {
       if (this._sourceBrowser.isArticle) {
         printPreviewTB.enableSimplifyPage();
       } else {
         this.logTelemetry("PRINT_PREVIEW_SIMPLIFY_PAGE_UNAVAILABLE_COUNT");
         printPreviewTB.disableSimplifyPage();
       }
 
       // copy the window close handler
-      if (document.documentElement.hasAttribute("onclose")) {
-        this._closeHandlerPP = document.documentElement.getAttribute("onclose");
+      if (window.onclose) {
+        this._closeHandlerPP = window.onclose;
       } else {
         this._closeHandlerPP = null;
       }
-      document.documentElement.setAttribute(
-        "onclose",
-        "PrintUtils.exitPrintPreview(); return false;"
-      );
+      window.onclose = function() {
+        PrintUtils.exitPrintPreview();
+        return false;
+      };
 
       // disable chrome shortcuts...
       window.addEventListener("keydown", this.onKeyDownPP, true);
       window.addEventListener("keypress", this.onKeyPressPP, true);
 
       ppBrowser.collapsed = false;
       ppBrowser.focus();
       // on Enter PP Call back
@@ -668,19 +668,19 @@ var PrintUtils = {
     }
     this._ppBrowsers.clear();
     this._currentPPBrowser = null;
     window.removeEventListener("keydown", this.onKeyDownPP, true);
     window.removeEventListener("keypress", this.onKeyPressPP, true);
 
     // restore the old close handler
     if (this._closeHandlerPP) {
-      document.documentElement.setAttribute("onclose", this._closeHandlerPP);
+      window.onclose = this._closeHandlerPP;
     } else {
-      document.documentElement.removeAttribute("onclose");
+      window.onclose = null;
     }
     this._closeHandlerPP = null;
 
     // remove the print preview toolbar
     let printPreviewTB = document.getElementById("print-preview-toolbar");
     printPreviewTB.destroy();
     printPreviewTB.remove();