From 309413115f8c30cbc7fb0e9d897c9a3e5bac4f83 Mon Sep 17 00:00:00 2001 From: Matheus Longaray Date: Wed, 25 Jan 2017 17:19:12 +0100 Subject: [PATCH] Bug 1323987 - Avoid creation of a blank content viewer when current viewer is already blank. r=mconley This patch checks if current content viewer is blank. If so, we skip ahead to where we QI the mContentViewer using it to host print preview, instead of creating a brand new one for no reason. MozReview-Commit-ID: 8WY33x2nCYA --HG-- extra : rebase_source : 3173fb87b3743059d9d1eff5d54229f1d3a94874 --- docshell/base/nsDocShell.cpp | 26 +++++++++++++++++++++++--- docshell/base/nsDocShell.h | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 7bcde6d8243a..6ff0a2c5239d 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -14300,9 +14300,16 @@ nsDocShell::GetPrintPreview(nsIWebBrowserPrint** aPrintPreview) nsCOMPtr print = do_QueryInterface(mContentViewer); if (!print || !print->IsInitializedForPrintPreview()) { Stop(nsIWebNavigation::STOP_ALL); - nsCOMPtr principal = nsNullPrincipal::CreateWithInheritedAttributes(this); - nsresult rv = CreateAboutBlankContentViewer(principal, nullptr); - NS_ENSURE_SUCCESS(rv, rv); + // Check if current content viewer is blank. If so, we skip ahead to where + // we QI the mContentViewer using it to host print preview, instead of + // creating a brand new one. + if (!IsContentViewerBlankForPrintPreview()) { + nsCOMPtr principal = nsNullPrincipal::CreateWithInheritedAttributes(this); + nsCOMPtr uri; + NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:printpreview")); + nsresult rv = CreateAboutBlankContentViewer(principal, uri); + NS_ENSURE_SUCCESS(rv, rv); + } print = do_QueryInterface(mContentViewer); NS_ENSURE_STATE(print); print->InitializeForPrintPreview(); @@ -14427,6 +14434,19 @@ nsDocShell::GetOriginAttributes(JSContext* aCx, return NS_OK; } +bool +nsDocShell::IsContentViewerBlankForPrintPreview() +{ + MOZ_ASSERT(mCurrentURI); + if (!mCurrentURI) { + return false; + } + + nsCString spec = mCurrentURI->GetSpecOrDefault(); + return (spec.EqualsLiteral("about:printpreview") || + spec.EqualsLiteral("about:blank")); +} + bool nsDocShell::CanSetOriginAttributes() { diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 22029b4675f3..820799513c9d 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -273,6 +273,7 @@ public: bool InFrameSwap(); private: + bool IsContentViewerBlankForPrintPreview(); bool CanSetOriginAttributes(); public: