Commit 196a43c4 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1663283 - Fix printing of nested iframes. r=smaug, a=RyanVM

Cloning of the nested documents should be recursive, I am dum dum.

Differential Revision: https://phabricator.services.mozilla.com/D89313
parent 3222cb94
......@@ -5262,6 +5262,37 @@ void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) {
#endif
}
// Returns whether there's any print callback.
static bool BuildNestedClones(Document& aJustClonedDoc) {
bool hasPrintCallbacks = aJustClonedDoc.HasPrintCallbacks();
auto pendingFrameClones = aJustClonedDoc.TakePendingFrameStaticClones();
for (const auto& clone : pendingFrameClones) {
RefPtr<Element> element = do_QueryObject(clone.mElement);
RefPtr<nsFrameLoader> frameLoader =
nsFrameLoader::Create(element, /* aNetworkCreated */ false);
if (NS_WARN_IF(!frameLoader)) {
continue;
}
clone.mElement->SetFrameLoader(frameLoader);
nsCOMPtr<nsIDocShell> docshell;
RefPtr<Document> doc;
nsresult rv = frameLoader->FinishStaticClone(clone.mStaticCloneOf,
getter_AddRefs(docshell),
getter_AddRefs(doc));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
if (doc) {
hasPrintCallbacks |= BuildNestedClones(*doc);
}
}
return hasPrintCallbacks;
}
Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
nsIPrintSettings* aPrintSettings, nsIWebProgressListener* aListener,
nsIDocShell* aDocShellToCloneInto, IsPreview aIsPreview,
......@@ -5388,8 +5419,6 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
return nullptr;
}
hasPrintCallbacks |= clone->HasPrintCallbacks();
// Do this now so that we get a script handling object, and thus can
// create our clones.
aError = cv->SetDocument(clone);
......@@ -5397,29 +5426,7 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
return nullptr;
}
auto pendingFrameClones = clone->TakePendingFrameStaticClones();
for (const auto& clone : pendingFrameClones) {
RefPtr<Element> element = do_QueryObject(clone.mElement);
RefPtr<nsFrameLoader> frameLoader =
nsFrameLoader::Create(element, /* aNetworkCreated */ false);
if (NS_WARN_IF(!frameLoader)) {
continue;
}
clone.mElement->SetFrameLoader(frameLoader);
nsCOMPtr<nsIDocShell> docshell;
RefPtr<Document> doc;
nsresult rv = frameLoader->FinishStaticClone(clone.mStaticCloneOf,
getter_AddRefs(docshell),
getter_AddRefs(doc));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
hasPrintCallbacks |= doc && doc->HasPrintCallbacks();
}
hasPrintCallbacks |= BuildNestedClones(*clone);
}
}
......
<!doctype html>
<style>
body { margin: 0 }
p {
/* 2 times the default margin of <body>, to account for the doubly-nested document */
margin: 16px;
}
</style>
<p>PASS
<!doctype html>
<link rel=match href="iframe-nested-print-ref.html">
<style>
body { margin: 0 }
</style>
<iframe frameborder=0 scrolling=no srcdoc="<iframe scrolling=no frameborder=0 srcdoc='PASS'></iframe>"></iframe>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment