From 222d260b2185ace4c0027da36e76a6d74d68fdfd Mon Sep 17 00:00:00 2001 From: Butkovits Atila Date: Sat, 11 Jul 2020 12:11:20 +0300 Subject: [PATCH] Backed out changeset f91e5fbb9520 (bug 1557983) as requested by dev. --- layout/printing/nsPrintJob.cpp | 33 +++++++++++++++++++++++++++++++++ layout/printing/nsPrintJob.h | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index add10bf555bf..b5cae9d83fbe 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -381,6 +381,37 @@ static nsresult EnsureSettingsHasPrinterNameSet( #endif } +static bool DocHasPrintCallbackCanvas(Document& aDoc) { + Element* root = aDoc.GetRootElement(); + if (!root) { + return false; + } + // FIXME(emilio): This doesn't account for shadow dom and it's unnecessarily + // inefficient. Though I guess it doesn't really matter. + RefPtr canvases = + NS_GetContentList(root, kNameSpaceID_XHTML, u"canvas"_ns); + uint32_t canvasCount = canvases->Length(true); + for (uint32_t i = 0; i < canvasCount; ++i) { + auto* canvas = HTMLCanvasElement::FromNodeOrNull(canvases->Item(i, false)); + if (canvas && canvas->GetMozPrintCallback()) { + return true; + } + } + + bool result = false; + + auto checkSubDoc = [&result](Document& aSubDoc) { + if (DocHasPrintCallbackCanvas(aSubDoc)) { + result = true; + return CallState::Stop; + } + return CallState::Continue; + }; + + aDoc.EnumerateSubDocuments(checkSubDoc); + return result; +} + //------------------------------------------------------- NS_IMPL_ISUPPORTS(nsPrintJob, nsIWebProgressListener, nsISupportsWeakReference, @@ -450,6 +481,8 @@ nsresult nsPrintJob::Initialize(nsIDocumentViewerPrint* aDocViewerPrint, } } + mHasMozPrintCallback = DocHasPrintCallbackCanvas(*aOriginalDoc); + return NS_OK; } diff --git a/layout/printing/nsPrintJob.h b/layout/printing/nsPrintJob.h index 62bead2898b6..456e34516eb5 100644 --- a/layout/printing/nsPrintJob.h +++ b/layout/printing/nsPrintJob.h @@ -131,6 +131,12 @@ class nsPrintJob final : public nsIObserver, void TurnScriptingOn(bool aDoTurnOn); + /** + * Checks to see if the document this print engine is associated with has any + * canvases that have a mozPrintCallback. + * https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement#Properties + */ + bool HasPrintCallbackCanvas() { return mHasMozPrintCallback; } bool PrePrintPage(); bool PrintPage(nsPrintObject* aPOect, bool& aInRange); bool DonePrintingPages(nsPrintObject* aPO, nsresult aResult);