Bug 1747997 Comment 8 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

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](https://searchfox.org/mozilla-central/rev/855814f769ac55bbb6a00e2170a6a876ab4cff3a/layout/generic/nsPageFrame.cpp#230-232), 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.  And importantly, `nsPrintJob::DoPrint` is only executed for "actual" print operations (including print-to-PDF).
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](https://searchfox.org/mozilla-central/rev/855814f769ac55bbb6a00e2170a6a876ab4cff3a/layout/generic/nsPageFrame.cpp#230-232), 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:](https://searchfox.org/mozilla-central/rev/855814f769ac55bbb6a00e2170a6a876ab4cff3a/layout/printing/nsPrintJob.cpp#1279-1283)
```c++
  nsAutoString docTitleStr;
  nsAutoString docURLStr;
  GetDisplayTitleAndURL(
      *printData->mPrintObject->mDocument, printData->mPrintSettings,
      DocTitleDefault::eDocURLElseFallback, docTitleStr, docURLStr);
```

[In `nsPrintJob::DoPrint`, we have:](https://searchfox.org/mozilla-central/rev/855814f769ac55bbb6a00e2170a6a876ab4cff3a/layout/printing/nsPrintJob.cpp#2083-2086)
```c++
    nsAutoString docTitleStr;
    nsAutoString docURLStr;
    GetDisplayTitleAndURL(*aPO->mDocument, mPrt->mPrintSettings,
                          DocTitleDefault::eFallback, docTitleStr, docURLStr);
```

The `eDocURLElseFallback` vs. `eFallback` seems to be the relevant thing here.  And importantly, `nsPrintJob::DoPrint` is only executed for "actual" print operations (including print-to-PDF).
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](https://searchfox.org/mozilla-central/rev/855814f769ac55bbb6a00e2170a6a876ab4cff3a/layout/generic/nsPageFrame.cpp#230-232), 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:](https://searchfox.org/mozilla-central/rev/855814f769ac55bbb6a00e2170a6a876ab4cff3a/layout/printing/nsPrintJob.cpp#1279-1283)
```c++
  nsAutoString docTitleStr;
  nsAutoString docURLStr;
  GetDisplayTitleAndURL(
      *printData->mPrintObject->mDocument, printData->mPrintSettings,
      DocTitleDefault::eDocURLElseFallback, docTitleStr, docURLStr);
```

[In `nsPrintJob::DoPrint`, we have:](https://searchfox.org/mozilla-central/rev/855814f769ac55bbb6a00e2170a6a876ab4cff3a/layout/printing/nsPrintJob.cpp#2083-2086)
```c++
    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.

Back to Bug 1747997 Comment 8