Backed out changeset 45df7207f4e1 (bug 1663140) for bc failure on browser_window_print.js

This commit is contained in:
Narcis Beleuzu
2020-09-06 05:43:56 +03:00
parent e33681205b
commit 02671e992c
7 changed files with 7 additions and 136 deletions

View File

@@ -1264,7 +1264,6 @@ Document::Document(const char* aContentType)
mAllowDNSPrefetch(true),
mIsStaticDocument(false),
mCreatingStaticClone(false),
mHasPrintCallbacks(false),
mInUnlinkOrDeletion(false),
mHasHadScriptHandlingObject(false),
mIsBeingUsedAsImage(false),

View File

@@ -2637,13 +2637,6 @@ class Document : public nsINode,
IsStaticDocument();
}
void SetHasPrintCallbacks() {
MOZ_DIAGNOSTIC_ASSERT(IsStaticDocument());
mHasPrintCallbacks = true;
}
bool HasPrintCallbacks() const { return mHasPrintCallbacks; }
/**
* Register/Unregister the ActivityObserver into mActivityObservers to listen
* the document's activity changes such as OnPageHide, visibility, activity.
@@ -4394,10 +4387,6 @@ class Document : public nsINode,
// True while this document is being cloned to a static document.
bool mCreatingStaticClone : 1;
// True if this static document has any <canvas> element with a
// mozPrintCallback property at the time of the clone.
bool mHasPrintCallbacks : 1;
// True iff the document is being unlinked or deleted.
bool mInUnlinkOrDeletion : 1;

View File

@@ -5312,9 +5312,7 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
nsCOMPtr<nsIContentViewer> cv;
RefPtr<BrowsingContext> bc;
bool hasPrintCallbacks = false;
if (docToPrint->IsStaticDocument() && aIsPreview == IsPreview::Yes) {
MOZ_DIAGNOSTIC_ASSERT(aBlockUntilDone == BlockUntilDone::No);
if (docToPrint->IsStaticDocument() && bool(aIsPreview)) {
// We're already a print preview window, just reuse our browsing context /
// content viewer.
//
@@ -5341,8 +5339,8 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
bc = aDocShellToCloneInto->GetBrowsingContext();
} else {
AutoNoJSAPI nojsapi;
auto printKind = aIsPreview == IsPreview::Yes ? PrintKind::PrintPreview
: PrintKind::Print;
auto printKind =
bool(aIsPreview) ? PrintKind::PrintPreview : PrintKind::Print;
aError = OpenInternal(EmptyString(), EmptyString(), EmptyString(),
false, // aDialog
false, // aContentModal
@@ -5405,8 +5403,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);
@@ -5434,8 +5430,6 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
hasPrintCallbacks |= doc && doc->HasPrintCallbacks();
}
}
}
@@ -5447,7 +5441,7 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
return nullptr;
}
if (aIsPreview == IsPreview::Yes) {
if (bool(aIsPreview)) {
aError = webBrowserPrint->PrintPreview(aPrintSettings, aListener,
std::move(aPrintPreviewCallback));
if (aError.Failed()) {
@@ -5458,13 +5452,8 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
webBrowserPrint->Print(aPrintSettings, aListener);
}
// When aBlockUntilDone is true, we usually want to block until the print
// dialog is hidden. But we can't really do that if we have print callbacks,
// because we are inside a sync operation, and we want to run microtasks / etc
// that the print callbacks may create.
//
// It is really awkward to have this subtle behavior difference...
if (aBlockUntilDone == BlockUntilDone::Yes && !hasPrintCallbacks) {
if (bool(aBlockUntilDone)) {
// Wait until print document is closed.
SpinEventLoopUntil([&] { return bc->IsDiscarded(); });
}

View File

@@ -529,16 +529,11 @@ HTMLCanvasElement* HTMLCanvasElement::GetOriginalCanvas() {
nsresult HTMLCanvasElement::CopyInnerTo(HTMLCanvasElement* aDest) {
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
NS_ENSURE_SUCCESS(rv, rv);
Document* destDoc = aDest->OwnerDoc();
if (destDoc->IsStaticDocument()) {
if (aDest->OwnerDoc()->IsStaticDocument()) {
// The Firefox print preview code can create a static clone from an
// existing static clone, so we may not be the original 'canvas' element.
aDest->mOriginalCanvas = GetOriginalCanvas();
if (GetMozPrintCallback()) {
destDoc->SetHasPrintCallbacks();
}
// We make sure that the canvas is not zero sized since that would cause
// the DrawImage call below to return an error, which would cause printing
// to fail.

View File

@@ -13,10 +13,6 @@ support-files =
file_page_change_print_original_2.html
skip-if = os == "mac"
[browser_window_print.js]
support-files =
file_window_print.html
[browser_preview_in_container.js]
support-files =
file_print.html

View File

@@ -1,76 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://example.com"
);
add_task(async function test() {
// window.print() only shows print preview when print.tab_modal.enabled is
// true.
await SpecialPowers.pushPrefEnv({
set: [["print.tab_modal.enabled", true]],
});
await BrowserTestUtils.withNewTab(
`${TEST_PATH}file_window_print.html`,
async function(browser) {
is(
document.querySelector(".printPreviewBrowser"),
null,
"There shouldn't be any print preview browser"
);
info(
"Waiting for the first window.print() to run and ensure we're showing the preview..."
);
await BrowserTestUtils.waitForCondition(
() => !!document.querySelector(".printPreviewBrowser")
);
{
let [before, afterFirst] = await SpecialPowers.spawn(
browser,
[],
() => {
return [
!!content.document.getElementById("before-print"),
!!content.document.getElementById("after-first-print"),
];
}
);
ok(before, "Content before printing should be in the DOM");
ok(!afterFirst, "Shouldn't have returned yet from window.print()");
}
gBrowser.getTabDialogBox(browser).abortAllDialogs();
await BrowserTestUtils.waitForCondition(
() => !!document.querySelector(".printPreviewBrowser")
);
{
let [before, afterFirst, afterSecond] = await SpecialPowers.spawn(
browser,
[],
() => {
return [
!!content.document.getElementById("before-print"),
!!content.document.getElementById("after-first-print"),
!!content.document.getElementById("after-second-print"),
];
}
);
ok(before, "Content before printing should be in the DOM");
ok(afterFirst, "Should be in the second print already");
ok(afterSecond, "Shouldn't have blocked if we have mozPrintCallbacks");
}
}
);
});

View File

@@ -1,21 +0,0 @@
<!doctype html>
<div id="before-print">Before print</div>
<canvas id="canvas" width="100" height="100"></canvas>
<script>
onload = function() {
// window.print() is special until after the load event is finished firing.
setTimeout(function() {
// This one should block until we're done printing.
window.print();
document.body.insertAdjacentHTML('beforeend', `<div id="after-first-print">After first print</div>`);
let canvas = document.getElementById("canvas");
canvas.mozPrintCallback = function() {};
// This one shouldn't, because the print callbacks need to run.
window.print();
document.body.insertAdjacentHTML('beforeend', `<div id="after-second-print">After second print</div>`);
}, 0);
}
</script>