Open Bug 1747997 Opened 6 months ago Updated 6 months ago

Print preview does not match pdf file for a specific link.

Categories

(Core :: Print Preview, defect)

Desktop
All
defect

Tracking

()

Tracking Status
firefox-esr91 --- wontfix
firefox95 --- wontfix
firefox96 --- wontfix
firefox97 --- fix-optional

People

(Reporter: monica.chiorean, Unassigned, NeedInfo)

References

(Regression)

Details

(Keywords: regression)

Attachments

(2 files)

Affected versions

  • Beta 96.0b10 (64-bit)
  • Nightly 97.0a1(20211230095735)
  • Release 95.0.2 (20211218203254)

Affected platforms

  • Win 10 x64
  • Win 7 x86
  • macOS 10.13
  • Ubuntu 20.04 x64

Steps to reproduce

  1. Open Mozilla FF.
  2. Open the following link https://bug1722890.bmoattachments.org/attachment.cgi?id=9234328.
  3. From Hamburger menu select Print.
  4. On print preview select “Save to pdf”.
  5. Compare the print preview and the pdf file.

Expected result
Same file should be displayed on both sides.
Actual result
Print preview is different from the pdf file, because on the print preview on the upper left side there is a link, while on the pdf file it is displayed Firefox text(check screenshot attached).

Suggested Severity

  • S4, since it is a display issue only this type of links.
    Issue is not reproducing on: OLD->Nightly build from 4th of May.

Regression range

Has Regression Range: --- → yes
Has STR: --- → yes
Component: PDF Viewer → Untriaged
Severity: -- → S4

The Bugbug bot thinks this bug should belong to the 'Core::Print Preview' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → Print Preview
Product: Firefox → Core

Set release status flags based on info from the regressing bug 1666247

Mark, can you take a look?

Flags: needinfo?(mstriemer)

This reproduces on any page without a <title>, I think.

It reproduces on this extremely-reduced testcase:

data:text/html,Hello

...but not on:

data:text/html,<title>TITLE</title>Hello

(For the former data URI here, print preview shows the URL at the top-left, whereas the printout shows the text "Nightly".)

(Given the regression range, I suspect this is a bug in the JS code that sets up the print-preview visualization, rather than in the platform code to support printing/print-preview. Given that, I'm reclassifying as Toolkit|Printing.)

Component: Print Preview → Printing
Product: Core → Toolkit
Attached file testcase 1

Poking around in gdb, it looks like we're asked to draw &T (title) for the left-header and &U (URL) for the right-header.

We expand &T to mPD->mDocTitle here, but unfortunately mPD->mDocTitle actually contains the page URL in this case.

mPD->mDocTitle is populated a bit earlier, and it looks like we use a different fallback flag for the print-preview vs. printing cases.

In nsPrintJob::SetupToPrintContent, we have:

  nsAutoString docTitleStr;
  nsAutoString docURLStr;
  GetDisplayTitleAndURL(
      *printData->mPrintObject->mDocument, printData->mPrintSettings,
      DocTitleDefault::eDocURLElseFallback, docTitleStr, docURLStr);

In nsPrintJob::DoPrint, we have:

    nsAutoString docTitleStr;
    nsAutoString docURLStr;
    GetDisplayTitleAndURL(*aPO->mDocument, mPrt->mPrintSettings,
                          DocTitleDefault::eFallback, docTitleStr, docURLStr);

The eDocURLElseFallback vs. eFallback seems to be the relevant thing here, with the former causing us to fall back to the URL, and the latter causing us to fall back to "Nightly" (or "Firefox") instead. And importantly, nsPrintJob::DoPrint is only executed for "actual" print operations (including print-to-PDF), at least in current builds. So that's why we're not getting a URL at the top-left in those actual print operations.

These GetDisplayTitleAndURL calls (with the disagreeing fallback flags) come most-recently from jwatt in bug 1619403, though the discrepancy predated that commit with older enum names -- they used to be eDocTitleDefURLDoc vs eDocTitleDefBlank:
https://hg.mozilla.org/mozilla-central/rev/885a99d3d16c#l1.210

So there's been some disagreement between these two code-paths for quite a while - it goes back at least to 2006 in bug 361844, with these two lines:

 GetDisplayTitleAndURL(mPrt->mPrintObject, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); 

vs.

GetDisplayTitleAndURL(aPO, &docTitleStr, &docURLStr, eDocTitleDefBlank); 

https://searchfox.org/mozilla-central/diff/01ccd95a112c5e9e5c64a66260e645839875fb21/layout/printing/nsPrintEngine.cpp#1956
https://searchfox.org/mozilla-central/diff/01ccd95a112c5e9e5c64a66260e645839875fb21/layout/printing/nsPrintEngine.cpp#2397

I don't immediately see why this only would have started causing trouble recently (maybe DoPrint was being called even for print-preview in some cases, and now it's not?)

jwatt, do you know why we make different choices for fallback enum in these two different code-paths? Given your refactoring in bug 1619403, I'm wondering if you have any insight into what's going on here.

Flags: needinfo?(jwatt)

And this probably does belong in Core|Print-Preview after all, given that the differing behavior seems to be hardcoded into the C++ code. (Even though it was somehow triggered by a non-C++ change, based on the regression analysis, which is... odd.)

--> Reclassifying back.

Component: Printing → Print Preview
Product: Toolkit → Core

I tested this in an old build just before bug 1666247's patches, to see why this "regressed" there.

It looks like the relevant difference is: before bug 1666247, when SetupToPrintContent calls GetDisplayTitleAndURL for print-preview, it finds that aSettings->GetDocURL() is empty; and that causes GetDisplayTitleAndURL to fall back to the branded name for its aTitle outparam, even though it was passed the fallback-to-URL enum eDocURLElseFallback. (Ironically, GetDisplayTitleAndURL then just proceeds to figure out the URL for itself, to populate its aURLStr outparam; it doesn't use that dynamically-determined page-URL as the fallback title.)

Whereas after bug 1666247, aSettings->GetDocURL() is nonempty -- it's got the document URL already, presumably provided by JS via one of the changes in bug 1666247 -- and that causes GetDisplayTitleAndURL to be able to fall back to that as the page-title (when given eDocURLElseFallback).

So, tl;dr: bug 1666247 probably caused this visible behavior-change by virtue of helpfully providing the page URI in the settings object, which inadvertently exposed the fact that our missing-page-title fallback behavior is somewhat dependent on the presence/absence of that URI, specifically in the codepath that we take for print preview.

So, two takeaways:
(1) It seems odd/cobwebby that we have these two different fallback modes, and we use one for print-preview (and for early stages of actual printing), vs. the other for the final stage of actual-printing. Perhaps we should drop eDocURLElseFallback, and/or make our usage consistent between the two callsites?

(2) If needed/simpler, we could also probably massage the JS to avoid providing the page's URL to the aSettings object, to restore our old behavior without needing to mess with the C++ here. (But ideally it would be good to have a coherent story around how the underlying codepaths behave, too.)

[I'm curious for jwatt's thoughts on both of these points; leaving ni open for his feedback on these when he's around.]

Flags: needinfo?(mstriemer)
You need to log in before you can comment on or make changes to this bug.