Bug 1580565 - Part 2: Delay creating nsFrameLoader in static clone until embedder has window, r=smaug

Follow-up parts in this bug depend on being able to read the `nsGlobalWindow`
which embeds a `nsFrameLoader` within `CreateBrowsingContext`, which is called
from the `nsFrameLoader` constructor. Unfortunately, we depend on creating the
`nsFrameLoader` and `BrowsingContext` before we have the window as part of the
fix to bug 1577711.

This patch changes `BuildNestedPrintObjects` to instead use a list of pending
clones stored on the parent `Document` object, and delays creation of the
`nsFrameLoader`, and thus the inner `BrowsingContext`, until after the document
has an owner global.

Due to the low number of automated tests for printing, I manually tested
print-previewing both the reduced test case from bug 1577711, a wikipedia
article, and 'data:text/html,<object data="data:text/html,hi">' to avoid
regressions.

Differential Revision: https://phabricator.services.mozilla.com/D71236
This commit is contained in:
Nika Layzell
2020-04-24 18:32:59 +00:00
parent b218c9e7a7
commit e4b5167f9b
7 changed files with 106 additions and 74 deletions

View File

@@ -121,7 +121,7 @@ Nullable<WindowProxyHolder> nsGenericHTMLFrameElement::GetContentWindow() {
}
void nsGenericHTMLFrameElement::EnsureFrameLoader() {
if (!IsInComposedDoc() || mFrameLoader) {
if (!IsInComposedDoc() || mFrameLoader || OwnerDoc()->IsStaticDocument()) {
// If frame loader is there, we just keep it around, cached
return;
}
@@ -320,10 +320,7 @@ nsresult nsGenericHTMLFrameElement::CopyInnerTo(Element* aDest) {
if (doc->IsStaticDocument() && mFrameLoader) {
nsGenericHTMLFrameElement* dest =
static_cast<nsGenericHTMLFrameElement*>(aDest);
RefPtr<nsFrameLoader> fl = nsFrameLoader::Create(dest, false);
NS_ENSURE_STATE(fl);
dest->mFrameLoader = fl;
mFrameLoader->CreateStaticClone(fl);
doc->AddPendingFrameStaticClone(dest, mFrameLoader);
}
return rv;