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
This commit is contained in:
Matheus Longaray 2017-01-25 17:19:12 +01:00
Родитель baf00beae5
Коммит 309413115f
2 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

@ -14300,9 +14300,16 @@ nsDocShell::GetPrintPreview(nsIWebBrowserPrint** aPrintPreview)
nsCOMPtr<nsIDocumentViewerPrint> print = do_QueryInterface(mContentViewer);
if (!print || !print->IsInitializedForPrintPreview()) {
Stop(nsIWebNavigation::STOP_ALL);
nsCOMPtr<nsIPrincipal> 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<nsIPrincipal> principal = nsNullPrincipal::CreateWithInheritedAttributes(this);
nsCOMPtr<nsIURI> 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()
{

Просмотреть файл

@ -273,6 +273,7 @@ public:
bool InFrameSwap();
private:
bool IsContentViewerBlankForPrintPreview();
bool CanSetOriginAttributes();
public: