diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 53d2e5874a21..c48a2a7dfa0f 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -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 contentViewer; + mDocumentContainer->GetContentViewer(getter_AddRefs(contentViewer)); + MOZ_ASSERT(contentViewer); + contentViewer->SetDocument(clone); } else if (scriptObject) { clone->SetScriptHandlingObject(scriptObject); } else { diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index ab17132f4c4e..cdaddda77cbb 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -2857,7 +2857,7 @@ nsresult nsFrameLoader::CreateStaticClone(nsFrameLoader* aDest) { nsCOMPtr clonedDoc = doc->CreateStaticClone(aDest->GetDocShell()); - viewer->SetDocument(clonedDoc); + MOZ_ASSERT(viewer->GetDocument() == clonedDoc); return NS_OK; } diff --git a/layout/printing/nsPrintObject.cpp b/layout/printing/nsPrintObject.cpp index ad3003e5f2f3..1ce266defe87 100644 --- a/layout/printing/nsPrintObject.cpp +++ b/layout/printing/nsPrintObject.cpp @@ -102,10 +102,11 @@ nsresult nsPrintObject::InitAsRootObject(nsIDocShell* aDocShell, Document* aDoc, mDocument = aDoc->CreateStaticClone(mDocShell); NS_ENSURE_STATE(mDocument); +#ifdef DEBUG nsCOMPtr viewer; mDocShell->GetContentViewer(getter_AddRefs(viewer)); - NS_ENSURE_STATE(viewer); - viewer->SetDocument(mDocument); + MOZ_ASSERT(viewer && viewer->GetDocument() == mDocument); +#endif return NS_OK; }