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
--- 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