Commit graph

101 commits

Author SHA1 Message Date
Daniel Holbert
49e37dc76e 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
e7ce1d2a70 Bug 1776074 part 6: Simplify nsPrintObject init list. r=emilio
Move two assignments to the declaration site, and remove an unnecessary
nullptr assignment (for a nsCOMPtr which is nullptr by default).

Depends on D150079

Differential Revision: https://phabricator.services.mozilla.com/D150176
2022-06-23 22:57:00 +00:00
Daniel Holbert
63c1d9f029 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
4685a0aa28 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
dddd82e118 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
a7c7dfb8cd 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
Jonathan Watt
45fd50ca0f 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
7bc6abbc6e 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
b60432d3eb 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
7ea23646b7 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
Nika Layzell
66e5b6b669 Bug 1729092 - Remove dead nsPrintObject::mDidCreateDocShell, r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D124511
2021-09-07 14:22:42 +00:00
Emilio Cobos Álvarez
044b3c4332 Bug 1636728 - Centralize printing entry points in nsGlobalWindowOuter, and move cloning out of nsPrintJob. r=jwatt,geckoview-reviewers,smaug,agi
This centralizes our print and preview setup in nsGlobalWindowOuter so
that we never re-clone a clone, and so that we reuse the window.open()
codepath to create the browsing context to clone into.

For window.print, for both old print dialog / silent printing and new
print preview UI, we now create a hidden browser (as in with visibility:
collapse, which takes no space but still gets a layout box).

 * In the modern UI case, this browser is swapped with the actual print
   preview clone, and the UI takes care of removing the browser.

 * In the print dialog / silent printing case, the printing code calls
   window.close() from nsDocumentViewer::OnDonePrinting().

 * We don't need to care about the old print preview UI for this case
   because it can't be open from window.print().

We need to fall back to an actual window when there's no
nsIBrowserDOMWindow around for WPT print tests and the like, which don't
have one. That seems fine, we could special-case this code path more if
needed but it doesn't seem worth it.

Differential Revision: https://phabricator.services.mozilla.com/D87063
2020-08-25 17:45:12 +00:00
Emilio Cobos Álvarez
3cc8263836 Bug 1658894 - Move selection range caching to Document::CreateStaticClone(). r=jwatt
This is needed to eventually make the print process able to process the
same static document twice.

Differential Revision: https://phabricator.services.mozilla.com/D86937
2020-08-13 11:11:35 +00:00
Tom Tung
002102679d Bug 1654935 - Copy over COOP header from new document to the docshell in nsPrintObject; r=nika
The COOP header is set to BrowsingContext only in Document::StartDocumentLoad.
If the replaced document has a different COOP header from one in its docshell.
Then, we can crash while creating a window global child for a new inner window.

Differential Revision: https://phabricator.services.mozilla.com/D85127
2020-08-05 17:14:38 +00:00
Bogdan Tara
ebb07c5b3a Backed out changeset b5a3e838eaec (bug 1654935) for nsPrintObject.cpp related bustage CLOSED TREE 2020-08-04 22:21:45 +03:00
Tom Tung
cd5124ffd5 Bug 1654935 - Copy over COOP header from new document to the docshell in nsPrintObject; r=nika
The COOP header is set to BrowsingContext only in Document::StartDocumentLoad.
If the replaced document has a different COOP header from one in its docshell.
Then, we can crash while creating a window global child for a new inner window.

Differential Revision: https://phabricator.services.mozilla.com/D85127
2020-08-04 19:05:04 +00:00
Bob Owen
ada89eea81 Bug 1653334 part 2: Cache the selection ranges on subdocuments as we build the nsPrintObject tree. r=jwatt
This also refactors the selection printing code, so that as we build the tree we
record which nsPrintObject should be used if printing a Selection is chosen.

Differential Revision: https://phabricator.services.mozilla.com/D85600
2020-08-03 14:23:56 +00:00
Butkovits Atila
076d3aa7ed Backed out 2 changesets (bug 1653334) for reftest failures at test-print-selection.html. CLOSED TREE
Backed out changeset 6cc6bbaa91f0 (bug 1653334)
Backed out changeset 75a5873f02a4 (bug 1653334)
2020-08-03 15:35:37 +03:00
Bob Owen
ac5872bd35 Bug 1653334 part 2: Cache the selection ranges on subdocuments as we build the nsPrintObject tree. r=jwatt
This also refactors the selection printing code, so that as we build the tree we
record which nsPrintObject should be used if printing a Selection is chosen.

Differential Revision: https://phabricator.services.mozilla.com/D85600
2020-08-03 08:54:12 +00:00
Daniel Holbert
0df096b344 Bug 1652788: Preemptively fix unified build bustage in layout/{base,generic,printing}. r=TYLin
Differential Revision: https://phabricator.services.mozilla.com/D83534
2020-07-14 18:15:49 +00:00
Jonathan Watt
3e4c61adb7 Bug 1642236. Make all printing "print as is" printing. r=bobowen
nsPrintObject::InitAsNestedObject made sure that all nsPrintObjects were set to
print-as-is except for frameset documents and their sub-documents. (Note the
setting of mParent->mPrintAsIs, which would actually set the root nsPrintObject
to print-as-is if it wasn't a frameset document!).

The SetPrintAsIs() calls in nsPrintJob::EnablePOsForPrinting would then
subsequently also set those frameset and frame nsPrintObjects to be print-as-is
in all but one edge case, namely printing a selection when there isn't a focused
window (which I'm not sure is even be possible).

Differential Revision: https://phabricator.services.mozilla.com/D77621
2020-06-02 15:18:04 +00:00
Jonathan Watt
9ed4ac0f5d Bug 1642162. Remove nsPrintJob.cpp's MapContentToWebShells and MapContentForPO functions. r=bobowen
We nowadays already directly set nsPrintObject->mContent in
nsPrintObject::InitAsNestedObject.  This patch adds the setting of mFrameType
and PrintAsIs that MapContentForPO does, making MapContentToWebShells and
MapContentForPO redundant.

Differential Revision: https://phabricator.services.mozilla.com/D77597
2020-06-02 21:03:20 +00:00
Jonathan Watt
bbb1b84928 Bug 1642233. Rename nsPrintObject's mDontPrint and IsPrintable for consistency with its EnablePrinting. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D77616
2020-05-31 19:00:42 +00:00
Emilio Cobos Álvarez
89958b377a Bug 1640605 - Remove IsInAnonymousSubtree / IsRootOfAnonymousSubtree. r=edgar
In favor of the NativeAnonymous versions which they forward to.

Done automatically with:

  rg -l 'IsInAnonymousSubtree' | xargs sed -i 's/IsInAnonymousSubtree/IsInNativeAnonymousSubtree/g'

And removing the function definitions afterwards.

Differential Revision: https://phabricator.services.mozilla.com/D76681
2020-05-25 11:43:51 +00:00
Hiroyuki Ikezoe
45b7227266 Bug 1640108 - Move nsPrintJob::SetPrintPO into nsPrintObject class and rename it to EnablePrinting. r=jwatt
Differential Revision: https://phabricator.services.mozilla.com/D76456
2020-05-22 09:57:12 +00:00
Hiroyuki Ikezoe
28234785d1 Bug 1640108 - Move SetPrintAsIs in nsPrintObject. r=jwatt
Differential Revision: https://phabricator.services.mozilla.com/D76455
2020-05-22 09:56:55 +00:00
Mirko Brodesser
a060e2efd4 Bug 1634663: part 4) Declare callers of Selection::GetRangeAt const in layout code. r=masayuki
Depends on D73446

Differential Revision: https://phabricator.services.mozilla.com/D73447
2020-05-02 23:46:01 +00:00
Nika Layzell
4f3a5448c4 Bug 1580565 - Part 3: Simplify API for creating independent BCs, r=farre
There were previously a number of different APIs for creating BrowsingContext
instances. This simplifies them into two major cases: "CreateDetached", which
allows for creating BrowsingContexts which are related to other
BrowsingContexts, and "CreateIndependent" which creates new, fully unrelated,
browsing contexts.

Differential Revision: https://phabricator.services.mozilla.com/D71237
2020-04-24 18:33:01 +00:00
Narcis Beleuzu
fffdcb0203 Backed out 7 changesets (bug 1580565) for bustages on nsDocShell.cpp . CLOSED TREE
Backed out changeset 8237f9a307f8 (bug 1580565)
Backed out changeset 47f5698d6c72 (bug 1580565)
Backed out changeset e1802670dcc4 (bug 1580565)
Backed out changeset 0a44c410b59b (bug 1580565)
Backed out changeset 20dbcfc9eacc (bug 1580565)
Backed out changeset cdf2b600e779 (bug 1580565)
Backed out changeset a421d33d03ce (bug 1580565)
2020-04-24 05:31:55 +03:00
Nika Layzell
989454dc24 Bug 1580565 - Part 3: Simplify API for creating independent BCs, r=farre
There were previously a number of different APIs for creating BrowsingContext
instances. This simplifies them into two major cases: "CreateDetached", which
allows for creating BrowsingContexts which are related to other
BrowsingContexts, and "CreateIndependent" which creates new, fully unrelated,
browsing contexts.

Differential Revision: https://phabricator.services.mozilla.com/D71237
2020-04-23 21:52:44 +00:00
Erik Nordin
232bc61244 Bug 1620289 - Part 1 Clone Selection Ranges For Printing r=jwatt
- Clones selection ranges to the static document for printing
- Static docs can remove selections without referring to original doc

Differential Revision: https://phabricator.services.mozilla.com/D71110
2020-04-23 16:41:49 +00:00
Andreea Pavel
b74d860d87 Backed out 7 changesets (bug 1580565) for bc failures on a CLOSED TREE
Backed out changeset e44e0a6366f8 (bug 1580565)
Backed out changeset c0849928f934 (bug 1580565)
Backed out changeset 3d4f155096be (bug 1580565)
Backed out changeset 108d5fb4418e (bug 1580565)
Backed out changeset d8dea951a032 (bug 1580565)
Backed out changeset f9ab41f29552 (bug 1580565)
Backed out changeset fd5d76304c09 (bug 1580565)
2020-04-22 21:51:17 +03:00
Nika Layzell
6d700ff7a6 Bug 1580565 - Part 3: Simplify API for creating independent BCs, r=farre
There were previously a number of different APIs for creating BrowsingContext
instances. This simplifies them into two major cases: "CreateDetached", which
allows for creating BrowsingContexts which are related to other
BrowsingContexts, and "CreateIndependent" which creates new, fully unrelated,
browsing contexts.

Differential Revision: https://phabricator.services.mozilla.com/D71237
2020-04-22 15:48:20 +00:00
Dorel Luca
7daa9a6695 Backed out 7 changesets (bug 1580565) for Gecko-view failures in Test.crashParent. CLOSED TREE
Backed out changeset 7da9785ebb06 (bug 1580565)
Backed out changeset a80e177a91b2 (bug 1580565)
Backed out changeset 2cf821f2a6ea (bug 1580565)
Backed out changeset a30f158eba45 (bug 1580565)
Backed out changeset 276b131190a8 (bug 1580565)
Backed out changeset 3c15e4c600c4 (bug 1580565)
Backed out changeset bf8877cdb10f (bug 1580565)
2020-04-22 18:42:24 +03:00
Nika Layzell
01ad33304d Bug 1580565 - Part 3: Simplify API for creating independent BCs, r=farre
There were previously a number of different APIs for creating BrowsingContext
instances. This simplifies them into two major cases: "CreateDetached", which
allows for creating BrowsingContexts which are related to other
BrowsingContexts, and "CreateIndependent" which creates new, fully unrelated,
browsing contexts.

Differential Revision: https://phabricator.services.mozilla.com/D71237
2020-04-22 03:21:55 +00:00
Bogdan Tara
4bd759fa8e Backed out 7 changesets (bug 1580565) for browser_entry_point_telemetry.js failures CLOSED TREE
Backed out changeset 12a4f3de76a8 (bug 1580565)
Backed out changeset 81d537df2dc1 (bug 1580565)
Backed out changeset b182e872c9d4 (bug 1580565)
Backed out changeset 0b4595b2c153 (bug 1580565)
Backed out changeset 4363e3a3d799 (bug 1580565)
Backed out changeset cbb14b2c7b33 (bug 1580565)
Backed out changeset 46b251848297 (bug 1580565)
2020-04-22 06:15:43 +03:00
Nika Layzell
20e0c066e7 Bug 1580565 - Part 3: Simplify API for creating independent BCs, r=farre
There were previously a number of different APIs for creating BrowsingContext
instances. This simplifies them into two major cases: "CreateDetached", which
allows for creating BrowsingContexts which are related to other
BrowsingContexts, and "CreateIndependent" which creates new, fully unrelated,
browsing contexts.

Differential Revision: https://phabricator.services.mozilla.com/D71237
2020-04-22 01:37:52 +00:00
Jonathan Watt
a149392cbb Bug 1552966. Convert the printing code to stop using DocShellTree* classes. r=farre
Differential Revision: https://phabricator.services.mozilla.com/D56830

--HG--
extra : moz-landing-system : lando
2020-02-14 16:31:01 +00:00
Kris Maglione
6dfb63c750 Bug 1582832: Part 3 - Correctly handle windowless BCs created for printing. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D61006

--HG--
extra : moz-landing-system : lando
2020-02-06 19:08:06 +00:00
Kris Maglione
1722817403 Bug 1582832: Part 1 - Make FrameLoader owner rather than DocShell responsible for discarding a BC. r=nika
There are all sorts of lifecycle issues which arise from making DocShell
responsible for discarding BrowsingContexts. In this particular bug, we tend
to run into them in cases where we create a BrowsingContext for a FrameLoader,
and then never create a DocShell for it, leading to it never being destroyed.
But there are myriad other issues as well.

This patch moves the responsibility for BrowsingContext lifecycle management
to the FrameLoader/FrameLoaderOwner, rather than the DocShell, which makes
things more consistent, and more closely aligns with spec-defined behavior.

Differential Revision: https://phabricator.services.mozilla.com/D59008

--HG--
extra : moz-landing-system : lando
2020-02-06 19:07:56 +00:00
Ciure Andrei
4a058d35be Backed out changeset fd383a15ed4e (bug 1552966) for causing browser_printpreview.js to permafail CLOSED TREE 2019-12-14 17:45:23 +02:00
Jonathan Watt
5096a4a025 Bug 1552966. Convert the printing code to stop using DocShellTree* classes. r=farre
Differential Revision: https://phabricator.services.mozilla.com/D56830

--HG--
extra : moz-landing-system : lando
2019-12-13 14:16:15 +00:00
Nika Layzell
245b18cd39 Bug 1577711 - Part 1: Revert calling SetDocument earlier during clone from 1568055, r=smaug
This change was causing issues with images not displaying and iframes not
displaying correctly after multiple print preview calls.

Differential Revision: https://phabricator.services.mozilla.com/D44585

--HG--
extra : moz-landing-system : lando
2019-09-05 14:55:11 +00:00
Nika Layzell
d75c40bc90 Bug 1568055 - Part 1: SetDocument earlier in the clone operation for print, r=farre
This should ensure that the inner window for each document is set up correctly
before iframe elements are created in them during a static clone. Other,
non-static-clone cases are not affected because they cannot load subframes.

Differential Revision: https://phabricator.services.mozilla.com/D38931

--HG--
extra : moz-landing-system : lando
2019-07-23 12:26:31 +00:00
Jonathan Watt
88e7ba6db9 Bug 1558180. Comment the mysterious OnPageHide() call in nsPrintJob and move it somewhere that makes sense. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D34347

--HG--
extra : rebase_source : 4799985e94b29c2ef522d2d0ea69009fd72473ec
extra : amend_source : 5700597b2644267a6fecbd7e654e6162f3862bea
2019-06-04 16:01:33 +01:00
Jonathan Watt
4a0c9a9c7e Bug 1557434. Remove nsPrintObject::mPrintPreview. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D34134

--HG--
extra : rebase_source : b02b90a21ed16fce0189b0aa317743f01570f57a
extra : amend_source : ad608df1346b8ce0bd2ef43305764407008e8e5f
2019-05-28 15:26:59 +01:00
Jonathan Watt
47ed611600 Bug 1557434. Split nsPrintObject::Init into separate root-object and nested-object init methods. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D34006

--HG--
extra : rebase_source : cb246f4b1686d2e7634715b7cea657f762bbca58
extra : amend_source : 3de6ae30fa2156bd38cdea347a77d667c1d65581
2019-05-28 12:48:21 +01:00
Jonathan Watt
18dcb56a18 Bug 1552162. Fix unified build bustage in nsPrintObject.cpp. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D31446

--HG--
extra : rebase_source : b4ef894cfd919455788c82392d385a41b27c77be
extra : amend_source : d5c3542c4cb15185e65bf85872231a6e8e3055cd
2019-05-01 17:03:35 +01:00
Masayuki Nakano
f5737567dd Bug 1544343 - part 3: Make layout use mozilla::PresShell instead of nsIPresShell as far as possible r=emilio
This patch changes remaining things under `layout/`.  However, there are some
places which still need to use `nsIPresShell`.  That will be fixed in a
follow up bug.

Differential Revision: https://phabricator.services.mozilla.com/D27477

--HG--
extra : moz-landing-system : lando
2019-04-16 07:25:10 +00:00
Emilio Cobos Álvarez
d2ed260822 Bug 1517241 - Rename nsIDocument to mozilla::dom::Document. r=smaug
Summary: Really sorry for the size of the patch. It's mostly automatic
s/nsIDocument/Document/ but I had to fix up in a bunch of places manually to
add the right namespacing and such.

Overall it's not a very interesting patch I think.

nsDocument.cpp turns into Document.cpp, nsIDocument.h into Document.h and
nsIDocumentInlines.h into DocumentInlines.h.

I also changed a bunch of nsCOMPtr usage to RefPtr, but not all of it.

While fixing up some of the bits I also removed some unneeded OwnerDoc() null
checks and such, but I didn't do anything riskier than that.
2019-01-03 17:48:33 +01:00