Bug 1716655 - Prevent creating print presentation for a destroyed content viewer. r=nika

nsDocumentViewer::mDocument ends up null because Destroy() is called
as a result of nsGlobalWindowOuter::SetNewDocument failing because of
the AncestorsAreCurrent check:

    https://searchfox.org/mozilla-central/rev/d6188c9ce02efeea309e7177fc14c9eb2f09db37/dom/base/Document.cpp#13026-13030
    https://searchfox.org/mozilla-central/rev/d6188c9ce02efeea309e7177fc14c9eb2f09db37/layout/base/nsDocumentViewer.cpp#1888
    https://searchfox.org/mozilla-central/rev/d6188c9ce02efeea309e7177fc14c9eb2f09db37/dom/base/nsGlobalWindowOuter.cpp#2089-2091

Just bail out if we don't have a document when creating the print
presentation, as that presentation won't be shown either way.

Differential Revision: https://phabricator.services.mozilla.com/D124742
This commit is contained in:
Emilio Cobos Álvarez 2021-09-07 15:55:56 +00:00
Родитель d1bcbded65
Коммит b2a2efeffa
1 изменённых файлов: 4 добавлений и 0 удалений

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

@ -3518,6 +3518,10 @@ NS_IMETHODIMP nsDocumentViewer::SetPrintSettingsForSubdocument(
MOZ_ASSERT(!mPresContext);
MOZ_ASSERT(!mPresShell);
if (MOZ_UNLIKELY(!mDocument)) {
return NS_ERROR_NOT_AVAILABLE;
}
RefPtr<nsIDeviceContextSpec> devspec = new nsDeviceContextSpecProxy();
nsresult rv =
devspec->Init(nullptr, aPrintSettings, /* aIsPrintPreview = */ true);