Bug 1568055 - Part 1: SetDocument earlier in the clone operation for print, r=farre

This should ensure that the inner window for each document is set up correctly
before iframe elements are created in them during a static clone. Other,
non-static-clone cases are not affected because they cannot load subframes.

Differential Revision: https://phabricator.services.mozilla.com/D38931

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nika Layzell 2019-07-23 12:26:31 +00:00
parent 7cd712008e
commit d75c40bc90
3 changed files with 11 additions and 8 deletions

View File

@ -11084,11 +11084,13 @@ nsresult Document::CloneDocHelper(Document* clone) const {
GetScriptHandlingObject(hasHadScriptObject);
NS_ENSURE_STATE(scriptObject || !hasHadScriptObject);
if (mCreatingStaticClone) {
// If we're doing a static clone (print, print preview), then we're going to
// be setting a scope object after the clone. It's better to set it only
// once, so we don't do that here. However, we do want to act as if there is
// a script handling object. So we set mHasHadScriptHandlingObject.
clone->mHasHadScriptHandlingObject = true;
// If we're doing a static clone (print, print preview), then immediately
// embed this newly created document into our container. This will set our
// script handling object for us.
nsCOMPtr<nsIContentViewer> contentViewer;
mDocumentContainer->GetContentViewer(getter_AddRefs(contentViewer));
MOZ_ASSERT(contentViewer);
contentViewer->SetDocument(clone);
} else if (scriptObject) {
clone->SetScriptHandlingObject(scriptObject);
} else {

View File

@ -2857,7 +2857,7 @@ nsresult nsFrameLoader::CreateStaticClone(nsFrameLoader* aDest) {
nsCOMPtr<Document> clonedDoc = doc->CreateStaticClone(aDest->GetDocShell());
viewer->SetDocument(clonedDoc);
MOZ_ASSERT(viewer->GetDocument() == clonedDoc);
return NS_OK;
}

View File

@ -102,10 +102,11 @@ nsresult nsPrintObject::InitAsRootObject(nsIDocShell* aDocShell, Document* aDoc,
mDocument = aDoc->CreateStaticClone(mDocShell);
NS_ENSURE_STATE(mDocument);
#ifdef DEBUG
nsCOMPtr<nsIContentViewer> viewer;
mDocShell->GetContentViewer(getter_AddRefs(viewer));
NS_ENSURE_STATE(viewer);
viewer->SetDocument(mDocument);
MOZ_ASSERT(viewer && viewer->GetDocument() == mDocument);
#endif
return NS_OK;
}