Commit Graph

323 Commits

Author SHA1 Message Date
Daniel Holbert
039f2d8510 Bug 1776289 part 2: Merge nsPrintJob::Initialize into the constructor. r=emilio
This patch doesn't change behavior; it's just collapsing logic from
nsPrintJob's Initialize method (which is now de-facto infallible) into the
constructor.

I'm also removing the "Methods needed by the DocViewer" header-comment since
it's clearly innacurate at this point. It's only surrounding this constructor
and GetSeqFrameAndCountSheets, which is silly since nsDocumentViewer uses more
of our API than that.

(I also placed TODO(dholbert) comments for a few things that looked odd, to
follow up on later. In particular, I noticed that nsDocumentViewer holds a
dedicated stack-owned RefPtr reference to nsPrintJob after creating it, which
superficially looks unnecessary. I don't want to risk changing behvior or
introducing a crash by removing that reference in this refactoring patch, so
I'm leaving that as-is and simply flagging it as suspicious.)

Depends on D150194

Differential Revision: https://phabricator.services.mozilla.com/D150195
2022-06-23 22:57:01 +00:00
Daniel Holbert
34f45933df Bug 1776289 part 1: Change nsPrintJob::Initialize to take references instead of pointers, to avoid the need for unnecessary null-checks. r=emilio
This patch doesn't change behavior.

Depends on D150177

Differential Revision: https://phabricator.services.mozilla.com/D150194
2022-06-23 22:57:00 +00:00
Daniel Holbert
2cb6d8f464 Bug 1776074 part 7: Remove mFrameType member (and PrintObjectType in general) from nsPrintObject.h. r=emilio
This patch does not change behavior (other than a minor correctness fix in some
off-by-default logging; see below).

As shown in the removed line of the init list, this mFrameType member-var's
semantics are equivalent to a null-check of the mParent member-var.  So: rather
than encoding that same information twice, this patch simplifies to just
directly null-check the mParent pointer at all the usage sites.

Before this patch, nsPrintJob.cpp had two different patterns for logging
mFrameType; sometimes with a global `gFrameTypesStr` array, and other times
with a local `types` array (with shorter 2-character strings).  I've converted
both of these to helper-functions.

In the case of the `types` array, the old code used a 4-value array, which was
interesting since the enum type only had 2 possible values. This discrepancy is
just due to an oversight in bug 1769508, where we recently condensed the enum
from 4 values to 2; that bug technically should've condensed these arrays as
well (but didn't do so).  This left these arrays' enum-to-string mapping being
wrong (since eIFrame changed its numeric value from 2 to 1 in bug 1769508), but
probably nobody has used this logging code in a while, so nobody
noticed. Anyway: in this patch, I'm restoring the mappings that we had before
that change (so we'll log "DC" for root print objects and "IF" for non-root
i.e. iframe-flavored print objects).

Differential Revision: https://phabricator.services.mozilla.com/D150177
2022-06-23 22:57:00 +00:00
Daniel Holbert
8ec0a8475a Bug 1776074 part 5: Merge nsPrintObject's effectively-infallible Init function into constructor. r=emilio
This patch doesn't change behavior; it's just refactoring.

The pre-existing Init code is now clearly infallible, now that earlier patches
have removed all of Init's NS_ENSURE_STATE arg-null-checks (which were Init's
only failure-returning codepaths).

So: now that it's infallible, we can just merge the Init() code directly into
the constructor.

This lets us promote some member-variables to be 'const' as well, since they
will now be initialized in the init list and are never modified after that.

Differential Revision: https://phabricator.services.mozilla.com/D150079
2022-06-23 22:56:59 +00:00
Daniel Holbert
574940c643 Bug 1776074 part 4: Use references instead of pointers for nsPrintObject::Init's Document and nsDocShell args (and in callers). r=emilio
This patch doesn't change behavior. It just changes to c++ reference types and
code-comments to indicate where we know that pointers have been null-checked
(and removes some null-checks that now become trivially-unnecessary).

I've added code-comments to justify why we know these args are non-null.
Generally, `nsPrintObject::Init`'s args are null-checked by the caller, except
in one case (in `nsPrintJob::DoCommonPrint`) where the Document* pointer in
question was _not_ directly null-checked by the caller. But fortunately, it is
null-checked earlier, higher up in the call-stack.  So, this patch simply
propagates the C++ reference type-conversion up to that point for additional
clarity.

Differential Revision: https://phabricator.services.mozilla.com/D150078
2022-06-23 22:56:59 +00:00
Daniel Holbert
2578254c73 Bug 1776074 part 3: Merge nsPrintObject's Init methods into one method. r=emilio
This patch doesn't change behavior.

The two init functions were already pretty similar.  This patch merges them,
and uses the "aParent" arg as a signal for which variant we're handling (with
the "root" variant being signalled via a null value).

This usage of aParent (to distinguish between variants) is valid, as long as we
can assume that the old `InitAsNestedObject` variant was always guaranteed to
receive a non-null value for its aParent arg.  (That would mean that we're OK to
use that arg's nullness as a way to distinguish between the two variants in
their new merged form.)

And indeed, we're safe to make this assumption, since there's only one callsite
for the `InitAsNestedObject` version (which is in
`nsPrintJob::BuildNestedPrintObjects`), and it dereferences the pointer before
calling into this init function.  So, the pointer has to be non-null, or else
we would have crashed at the earlier dereference.

Therefore, this conversion (and usage of aParent to distinguish between
variants) is valid.

(Spoiler alert: a later patch in this series will merge this Init() method
into the constructor. I'm doing this as a multi-step process with this
intermediate state, in order to hopefully make it easier to reason about the
conversion and confirm that it's valid.)

Differential Revision: https://phabricator.services.mozilla.com/D150077
2022-06-23 22:56:59 +00:00
Daniel Holbert
3bd26a8479 Bug 1776074 part 2: Remove redundant assignment of mPrintObject->mFrameType. r=emilio
This patch doesn't change behavior.

The assignment here is working with a freshly-constructed `nsPrintObject`,
which was initialized via `InitAsRootObject`. Its `mFrameType` will have
already been assigned to `eDoc` in the constructor.  The only place in our
codebase where we might hypothetically reassign `mFrameType` is in
`InitAsNestedObject`, but that's the other init method -- not the one we're
calling here.

So: `mFrameType` will already be `eDoc` when we reach this assignment, and
the assignment is unnecessary.

Differential Revision: https://phabricator.services.mozilla.com/D150076
2022-06-23 22:56:58 +00:00
Daniel Holbert
da05d2045c Bug 1776074 part 1: Remove unused 'aForPrintPreview' param from nsPrintObject::InitAsRootObject. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D150075
2022-06-23 22:56:58 +00:00
Andrew McCreight
95468ac0e3 Bug 1771383 - Null check mPrintObject in nsPrintJob::SetupToPrintContent(). r=emilio
We're seeing a lot of null crashes here. Maybe we're running script since
we last checked mPrintObject and the printer was disconnected or
something along those lines, so just add a null check.

Differential Revision: https://phabricator.services.mozilla.com/D149387
2022-06-15 13:34:11 +00:00
Dmitrij Feller
26d5b8b017 Bug 370035 - Remove the aWidget parameter from nsIDeviceContextSpec::Init.r=spohl
Differential Revision: https://phabricator.services.mozilla.com/D145841
2022-05-23 19:34:40 +00:00
Jonathan Watt
18f9de0375 Bug 1770539 p9 - Move nsPrintData::mPrintObject to nsPrintJob. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146980
2022-05-22 09:37:58 +00:00
Jonathan Watt
7e215396eb Bug 1770539 p8 - Centralize nulling out of nsPrintJob::mPrt. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146981
2022-05-22 09:37:58 +00:00
Jonathan Watt
7bcf36f927 Bug 1770539 p7 - Move nsPrintData::mSelectionRoot to nsPrintJob. r=emilio
Depends on D146978

Differential Revision: https://phabricator.services.mozilla.com/D146979
2022-05-22 09:37:57 +00:00
Jonathan Watt
a7f56c17cb Bug 1770539 p6 - Move nsPrintData::mPrintDocList to nsPrintJob. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146978
2022-05-22 09:37:57 +00:00
Jonathan Watt
edff04bc59 Bug 1770539 p5 - Move nsPrintData::mPreparingForPrint to nsPrintJob. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146977
2022-05-22 09:37:57 +00:00
Jonathan Watt
98f8acc7e1 Bug 1770539 p4 - Move nsPrintData::mNumPrintablePages to nsPrintJob. r=emilio
Depends on D146975

Differential Revision: https://phabricator.services.mozilla.com/D146976
2022-05-22 09:37:56 +00:00
Jonathan Watt
f652606f33 Bug 1770539 p3 - Move nsPrintData::mShrinkRatio to nsPrintJob::mShrinkToFitFactor. r=emilio
Depends on D146974

Differential Revision: https://phabricator.services.mozilla.com/D146975
2022-05-22 09:37:56 +00:00
Jonathan Watt
d819eeffe6 Bug 1770539 p2 - Move nsPrintData::mShrinkToFit to nsPrintJob. r=emilio
Depends on D146973

Differential Revision: https://phabricator.services.mozilla.com/D146974
2022-05-22 09:37:56 +00:00
Jonathan Watt
1a78e7e81c Bug 1770539 p1 - Move nsPrintData::mPrintSettings to nsPrintJob. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146973
2022-05-22 09:37:55 +00:00
Jonathan Watt
da7ad9ef25 Bug 1754308 p2 - Stop sending nsIPrintSettings.printerName to content processes. r=bobowen
This avoids exposing printer names to potentially compromised content processes.

The changes in bug 1770211 mean that we no longer create platform specific
nsIDeviceContextSpec instances in the content process, so we no longer need
the printer name to instantiate an nsDeviceContextSpecWin there.

Differential Revision: https://phabricator.services.mozilla.com/D146868
2022-05-20 22:51:00 +00:00
Jonathan Watt
2ea24a6cfb Bug 1769999 - Remove the last of the nsPrintJob::mPrtPreview code. r=emilio
Since bug 1659432 landed, we no longer keep the nsPrintJob around across print
settings changes, only replacing the nsPrintData. Now that we throw away
everything on a settings change it doesn't make sense to have code that was
written for juggling nsPrintData objects. That code was just making things
difficult to understand.

Differential Revision: https://phabricator.services.mozilla.com/D146718
2022-05-19 09:38:19 +00:00
Jonathan Watt
34b623a4cf Bug 1769993 - Bring some sanity to nsPrintJob's scaling/shrink-to-fit logic. r=emilio
The comments and structure of this code no longer made much sense after the
last 20 years of churn, including those made in bug 1659432 and bug 1552785.

Differential Revision: https://phabricator.services.mozilla.com/D146717
2022-05-19 07:08:16 +00:00
Iulian Moraru
14625b6760 Backed out changeset 9273652dbd01 (bug 1769993) for causing mochitest-chrome failures on test_printpreview.xhtml. CLOSED TREE 2022-05-18 20:42:02 +03:00
Jonathan Watt
4aff27e443 Bug 1769993 - Bring some sanity to nsPrintJob's scaling/shrink-to-fit logic. r=emilio
The comments and structure of this code no longer made much sense after the
last 20 years of churn, including those made in bug 1659432 and bug 1552785.

Differential Revision: https://phabricator.services.mozilla.com/D146717
2022-05-18 16:45:59 +00:00
Jonathan Watt
59e9bab8e9 Bug 1769756 - Remove nsIWebBrowserPrint.currentPrintSettings. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D146569
2022-05-17 15:04:24 +00:00
Jonathan Watt
ad725ddcb6 Bug 1769746 - Stop using mPrtPreview in nsPrintJob::Print. r=emilio
We create a new nsPrintJob every time Print() or PrintPreview() is invoked
now ( https://phabricator.services.mozilla.com/D87417 ), so the mPrtPreview
member is never set this early on.

This also renames aSourceDoc to just aDoc since the document that is passed is
nowadays the actual document we're going to print from (the static clone,
which nowadays is created before these methods are invoked rather than being
created by them).

Differential Revision: https://phabricator.services.mozilla.com/D146563
2022-05-17 15:04:00 +00:00
Jonathan Watt
1f5693261e Bug 1769717 - Remove nsPrintJob::GetPrintPreviewPresShell(). r=emilio
Long ago we used to play switcheroo with PresShells in order to print a
document, but for over a decade we've been cloning the document that is
to be printed (bug 487667). Since then we've had no need for this method.

Differential Revision: https://phabricator.services.mozilla.com/D146545
2022-05-17 11:36:20 +00:00
Jonathan Watt
d65361fde9 Bug 1769508 - Remove the special case code for frameset shrink-to-fit. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146417
2022-05-16 12:27:49 +00:00
Jonathan Watt
1592fc4878 Bug 1432651 p2 - Remove nsIPrintSession and all the code that uses it. r=emilio,geckoview-reviewers,m_kato
Lately nsIPrintSession was only used to pass around RemotePrintJobChild objects.
Now that we pass those objects explicitly where needed (part 1), this class
serves no purpose.

Another reason to want to get rid of this class is that having it as a member
of nsIPrintSettings made no sense and was confusing.

Differential Revision: https://phabricator.services.mozilla.com/D146381
2022-05-16 08:38:02 +00:00
Jonathan Watt
e5a8eb1650 Bug 1432651 p1 - Pass RemotePrintJobChild through to the places where it's needed. r=emilio
Given how nsIPrintSettings is passed around, stored and copied all over the
place, it's very hard to reason about where and when a RemotePrintJobChild is
needed or valid. This patch avoids all that by explicitly passing a
RemotePrintJobChild when it's needed.

Another reason to make this change is because RemotePrintJobChild really does
not belong on nsIPrintSettings. That interface is supposed to represent a
collection of settings for laying out the document that is to be printed.

Differential Revision: https://phabricator.services.mozilla.com/D146380
2022-05-16 08:38:01 +00:00
Jonathan Watt
e336997b9a Bug 1769129. Remove nsIPrintSettings.isPrintSelectionRBEnabled. r=emilio
nsIPrintSettings is supposed to be a collection of settings passed to the
platform code to determine how the document prints. The
isPrintSelectionRBEnabled member doesn't belong here since it is a flag that
is passed to the OS native print settings dialog to tell it whether to
display a "Print selection only" radio button.

Depends on D146232

Differential Revision: https://phabricator.services.mozilla.com/D146251
2022-05-13 15:26:07 +00:00
Cristian Tuns
cebb65e9b3 Backed out changeset 00ef44ea9e3f (bug 1769129) for causing build bustages on nsPrintDialogX.mm CLOSED TREE 2022-05-13 08:20:12 -04:00
Jonathan Watt
7509ece9d9 Bug 1769129. Remove nsIPrintSettings.isPrintSelectionRBEnabled. r=emilio
nsIPrintSettings is supposed to be a collection of settings passed to the
platform code to determine how the document prints. The
isPrintSelectionRBEnabled member doesn't belong here since it is a flag that
is passed to the OS native print settings dialog to tell it whether to
display a "Print selection only" radio button.

Differential Revision: https://phabricator.services.mozilla.com/D146251
2022-05-13 11:57:08 +00:00
Jonathan Watt
a334fa1923 Bug 1768919 - Avoid checking the original document for focus in nsPrintJob. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146110
2022-05-12 12:06:57 +00:00
Jonathan Watt
9bc99a50ee Bug 1768741 - Remove nsPrintJob::HasEverPrinted. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146016
2022-05-11 18:08:45 +00:00
Iulian Moraru
471eb9ff50 Backed out changeset cb6bcb4d91d4 (bug 1768741) for causing build bustages on nsPrintJob.cpp. CLOSED TREE 2022-05-11 19:49:47 +03:00
Jonathan Watt
8d6776344b Bug 1768741 - Remove nsPrintJob::HasEverPrinted. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146016
2022-05-11 16:02:40 +00:00
Jonathan Watt
c41dff7855 Bug 1766651 - Remove nsIPrintSettings.isCancelled and nsIPrintSettings.saveOnCancel. r=bobowen
nsIPrintSettings.isCancelled was only being set to true by the Windows widget
code ShowNativePrintDialog nowadays. That seems pointless since that widget
code is only invoked under the _showPrintDialog call in print.js, and in the
case that the widget code throws, the print is never invoked and the
nsIPrintSettings object isn't used.

nsIPrintSettings.saveOnCancel was set in some places but never read.

Differential Revision: https://phabricator.services.mozilla.com/D144830
2022-04-27 17:55:24 +00:00
Jonathan Watt
77085a0558 Bug 1766640 - Remove nsIWebBrowserPrint.cancel(). r=emilio
It seems the new tab-modal printing code doesn't actually use this. Instead it
relies on the window being closed (see cancelPrint() in
toolkit/components/printing/content/print.js ).

Differential Revision: https://phabricator.services.mozilla.com/D144821
2022-04-27 14:37:25 +00:00
Emilio Cobos Álvarez
7966ccdd67 Bug 1766020 - Add support for parsing container-query-specific features. r=firefox-style-system-reviewers,layout-reviewers,boris
There are some mediaqueries-5 features that we still don't support and
explain the remaining failures in at-container-{parsing,serialization}.

Differential Revision: https://phabricator.services.mozilla.com/D144446
2022-04-27 10:52:32 +00:00
Emilio Cobos Álvarez
202fcd0999 Bug 1760836 - Support printing to an nsIOutputStream. r=jfkthame,jrmuizel,webdriver-reviewers,geckoview-reviewers,agi
The trickiest bits are the PrintTargetCG ones, the rest is just plumbing
and cleanups and tests, but let me know if you want those to be split
out, can do.

The GTK change to nsPrintSettingsGTK::GetResolution is a no-op (we only
read resolution on windows), but I did that because we assume that it
doesn't fail and GTK returns a sane default anyways.

Differential Revision: https://phabricator.services.mozilla.com/D142199
2022-03-30 18:51:58 +00:00
Iulian Moraru
7106f0368c Backed out changeset d42d7505c9cf (bug 1760836) for causing mochitest failures on browser_print_stream.js. CLOSED TREE 2022-03-29 23:32:39 +03:00
Emilio Cobos Álvarez
2ee3ba7653 Bug 1760836 - Support printing to an nsIOutputStream. r=jfkthame,jrmuizel,webdriver-reviewers,geckoview-reviewers,agi
The trickiest bits are the PrintTargetCG ones, the rest is just plumbing
and cleanups and tests, but let me know if you want those to be split
out, can do.

The GTK change to nsPrintSettingsGTK::GetResolution is a no-op (we only
read resolution on windows), but I did that because we assume that it
doesn't fail and GTK returns a sane default anyways.

Differential Revision: https://phabricator.services.mozilla.com/D142199
2022-03-29 17:50:58 +00:00
Emilio Cobos Álvarez
d3a9df63c5 Bug 1759494 - Remove some dead code introduced for PDFium. r=dholbert
IsSyncPagePrinting() only had one implementation which unconditionally
returned true.

So, any code that was conditioned on !IsSyncPagePrinting() is necessarily
dead/unreachable.

These are also crashing due to a null deref in mPrintTarget which might
happen if print is aborted.

Differential Revision: https://phabricator.services.mozilla.com/D140988
2022-03-14 23:18:22 +00:00
Jonathan Watt
09499fe3c0 Bug 1756445 - Stop saving print settings in platform code after printing. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D139291
2022-02-27 21:12:08 +00:00
Daniel Holbert
f14236634f Bug 1754111 part 3: Remove nsPrintJob.cpp's unused variable 'kPrintingPromptService', and a bunch of unused headers. r=emilio
This removal fixes the following non-fatal warning which (like some categories of warnings) only appears when you build in non-unified mode:
layout/printing/nsPrintJob.cpp:61:19: warning: unused variable 'kPrintingPromptService' [-Wunused-const-variable]

(Indeed, this variable was entirely unused.)

This patch also removes a bunch of surrounding #includes that looked
likely-unused to me as well. I did some spot-checks to be pretty-sure the
removed headers are all unused at this point, and (most importantly) I made
sure we still successfully build in non-unified mode.  This means that, if we
do actually depend on any of these removed includes, we're still getting them
indirectly via some other header, so these removals shouldn't really cause
trouble.

Depends on D138097

Differential Revision: https://phabricator.services.mozilla.com/D138098
2022-02-08 05:17:31 +00:00
Daniel Holbert
8f2220610d Bug 1754111 part 2: Fix non-unified build errors in layout/printing, and mark it as safe to build in non-unified mode. r=emilio
The previous patch in this series fixed some sources of non-unified build errors for this directory, and this patch here fixes the only remaining one, which is:

layout/printing/nsPrintJob.cpp:584:22: error: use of undeclared identifier 'do_CreateInstance'

This API is provided by nsComponentManagerUtils.h, which is the include I'm adding here.

Depends on D138096

Differential Revision: https://phabricator.services.mozilla.com/D138097
2022-02-08 05:17:30 +00:00
Jonathan Watt
1757bcbadb Bug 1704178. Remove platform print.tab_modal.enabled=false code. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D136736
2022-01-28 15:52:51 +00:00
Jonathan Watt
0c215eb942 Bug 1749003 - Remove unnecessary includes and other mentions of nsIWebBrowserPrint. r=jfkthame
Differential Revision: https://phabricator.services.mozilla.com/D135339
2022-01-07 14:46:30 +00:00
Jonathan Watt
79109555b9 Bug 1702501 - Remove print.tab_modal.enabled pref and old frontend print preview code. r=mstriemer
Differential Revision: https://phabricator.services.mozilla.com/D134699
2022-01-06 18:55:38 +00:00