Bug 1323987 - Set document URI after content viewer is created to host preview. r?mconley draft
authorMatheus Longaray <mlongaray@hp.com>
Thu, 16 Feb 2017 16:50:15 +0100
changeset 485511 a3fbbd4a42cec194bd791a1babb0aa89265c3749
parent 485510 6765c3feee5ba40662bbc5ae96264f17fb27afce
child 546037 7bb5f6099d7d839106aecddc0bd956a7d6f64a96
push id45752
push userbmo:mlongaray@hp.com
push dateThu, 16 Feb 2017 20:15:57 +0000
reviewersmconley
bugs1323987
milestone54.0a1
Bug 1323987 - Set document URI after content viewer is created to host preview. r?mconley This patch sets document URI to about:printpreview after content viewer is created to host preview. MozReview-Commit-ID: GD5x70cwXck
docshell/base/nsDocShell.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -14335,20 +14335,29 @@ nsDocShell::StopDocumentLoad(void)
 
 NS_IMETHODIMP
 nsDocShell::GetPrintPreview(nsIWebBrowserPrint** aPrintPreview)
 {
   *aPrintPreview = nullptr;
 #if NS_PRINT_PREVIEW
   nsCOMPtr<nsIDocumentViewerPrint> print = do_QueryInterface(mContentViewer);
   if (!print || !print->IsInitializedForPrintPreview()) {
+    // XXX: Creating a brand new content viewer to host preview every
+    // time we enter here seems overwork. We could skip ahead to where
+    // we QI the mContentViewer if the current URI is either about:blank
+    // or about:printpreview.
     Stop(nsIWebNavigation::STOP_ALL);
     nsCOMPtr<nsIPrincipal> principal = nsNullPrincipal::CreateWithInheritedAttributes(this);
-    nsresult rv = CreateAboutBlankContentViewer(principal, nullptr);
+    nsCOMPtr<nsIURI> uri;
+    NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:printpreview"));
+    nsresult rv = CreateAboutBlankContentViewer(principal, uri);
     NS_ENSURE_SUCCESS(rv, rv);
+    // Here we manually set current URI since we have just created a
+    // brand new content viewer (about:blank) to host preview.
+    SetCurrentURI(uri, nullptr, true, 0);
     print = do_QueryInterface(mContentViewer);
     NS_ENSURE_STATE(print);
     print->InitializeForPrintPreview();
   }
   nsCOMPtr<nsIWebBrowserPrint> result = do_QueryInterface(print);
   result.forget(aPrintPreview);
   return NS_OK;
 #else