Bug 1552880 p1. Pass a document to nsPrintJob::PrintPreview instead of a window. r=bobowen
authorJonathan Watt <jwatt@jwatt.org>
Thu, 09 May 2019 10:40:12 +0100
changeset 474725 6030ebc07cd2c5348ba0a2364ca7ad18111cdd22
parent 474724 7c884ec3dbd7a8d712d899640bed07d8dc2768b2
child 474726 a42daaa44f8846936526459b8b97e7206902d4ec
push id36045
push userrmaries@mozilla.com
push dateTue, 21 May 2019 16:30:25 +0000
treeherdermozilla-central@3c0f78074b72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1552880
milestone69.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 1552880 p1. Pass a document to nsPrintJob::PrintPreview instead of a window. r=bobowen This stops nsPrintJob::PrintPreview from duplicating work done in nsDocumentViewer::PrintPreview. Differential Revision: https://phabricator.services.mozilla.com/D31811
layout/base/nsDocumentViewer.cpp
layout/printing/nsPrintJob.cpp
layout/printing/nsPrintJob.h
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3618,18 +3618,17 @@ nsDocumentViewer::PrintPreview(nsIPrintS
     mAutoBeforeAndAfterPrint = std::move(autoBeforeAndAfterPrint);
   }
   dom::Element* root = doc->GetRootElement();
   if (root &&
       root->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdisallowselectionprint)) {
     PR_PL(("PrintPreview: found mozdisallowselectionprint"));
     printJob->SetDisallowSelectionPrint(true);
   }
-  rv = printJob->PrintPreview(aPrintSettings, aChildDOMWin,
-                              aWebProgressListener);
+  rv = printJob->PrintPreview(doc, aPrintSettings, aWebProgressListener);
   mPrintPreviewZoomed = false;
   if (NS_FAILED(rv)) {
     OnDonePrinting();
   }
   return rv;
 #  else
   return NS_ERROR_FAILURE;
 #  endif
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -1036,37 +1036,32 @@ nsresult nsPrintJob::Print(nsIPrintSetti
   Document* doc = mPrtPreview && mPrtPreview->mPrintObject
                       ? mPrtPreview->mPrintObject->mDocument
                       : mDocument;
 
   return CommonPrint(false, aPrintSettings, aWebProgressListener, doc);
 }
 
 nsresult nsPrintJob::PrintPreview(
-    nsIPrintSettings* aPrintSettings, mozIDOMWindowProxy* aChildDOMWin,
+    Document* aSourceDoc, nsIPrintSettings* aPrintSettings,
     nsIWebProgressListener* aWebProgressListener) {
   // Get the DocShell and see if it is busy
   // (We can't Print Preview this document if it is still busy)
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
   NS_ENSURE_STATE(docShell);
 
   auto busyFlags = docShell->GetBusyFlags();
   if (busyFlags != nsIDocShell::BUSY_FLAGS_NONE) {
     CloseProgressDialog(aWebProgressListener);
     FirePrintingErrorEvent(NS_ERROR_GFX_PRINTER_DOC_IS_BUSY);
     return NS_ERROR_FAILURE;
   }
 
-  auto* window = nsPIDOMWindowOuter::From(aChildDOMWin);
-  NS_ENSURE_STATE(window);
-  nsCOMPtr<Document> doc = window->GetDoc();
-  NS_ENSURE_STATE(doc);
-
   // Document is not busy -- go ahead with the Print Preview
-  return CommonPrint(true, aPrintSettings, aWebProgressListener, doc);
+  return CommonPrint(true, aPrintSettings, aWebProgressListener, aSourceDoc);
 }
 
 //----------------------------------------------------------------------------------
 bool nsPrintJob::IsFramesetDocument() const {
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
   return IsParentAFrameSet(docShell);
 }
 
--- a/layout/printing/nsPrintJob.h
+++ b/layout/printing/nsPrintJob.h
@@ -57,18 +57,18 @@ class nsPrintJob final : public nsIObser
   // nsIObserver
   NS_DECL_NSIOBSERVER
 
   NS_DECL_NSIWEBPROGRESSLISTENER
 
   // Our nsIWebBrowserPrint implementation defers to these methods.
   nsresult Print(nsIPrintSettings* aPrintSettings,
                  nsIWebProgressListener* aWebProgressListener);
-  nsresult PrintPreview(nsIPrintSettings* aPrintSettings,
-                        mozIDOMWindowProxy* aChildDOMWin,
+  nsresult PrintPreview(mozilla::dom::Document* aSourceDoc,
+                        nsIPrintSettings* aPrintSettings,
                         nsIWebProgressListener* aWebProgressListener);
   bool IsDoingPrint() const { return mIsDoingPrinting; }
   bool IsDoingPrintPreview() const { return mIsDoingPrintPreview; }
   bool IsFramesetDocument() const;
   bool IsIFrameSelected();
   bool IsRangeSelection();
   bool IsFramesetFrameSelected() const;
   /// If the returned value is not greater than zero, an error occurred.