Bug 1959052 - Ensure JS execution is blocked during window.print() when we're using the system UI (rather than printing via the Firefox preview panel). a=pascalc
The patch in bug 1898184 made reasonable sense, inasmuch as when the print.prefer_system_dialog option is set, we don't show our window-modal preview panel. However, as noted in comment 6 here, we do still need to block JS while window.print() is presenting the system dialog, otherwise the document may be changed or even closed by script behind the dialog's back. Prior to bug 1898184, the IsPreview::Yes flag caused us to block, but the issue was that without the preview panel taking care of cleaning up the cloned document, the block got cleared. It looks like we can solve this by setting the closeWindowAfterPrint flag in this case. In local testing, this seems to work for the various examples here, and does not regress bug 1898184. Original Revision: https://phabricator.services.mozilla.com/D253655 Differential Revision: https://phabricator.services.mozilla.com/D253944
This commit is contained in:
committed by
pchevrel@mozilla.com
parent
fff97f3ade
commit
c6ed7347ee
@@ -4937,9 +4937,8 @@ void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) {
|
||||
}
|
||||
});
|
||||
|
||||
const bool forPreview =
|
||||
!StaticPrefs::print_always_print_silent() &&
|
||||
!Preferences::GetBool("print.prefer_system_dialog", false);
|
||||
const bool forPreview = !StaticPrefs::print_always_print_silent() &&
|
||||
!StaticPrefs::print_prefer_system_dialog();
|
||||
Print(nullptr, nullptr, nullptr, nullptr, IsPreview(forPreview),
|
||||
IsForWindowDotPrint::Yes, nullptr, nullptr, aError);
|
||||
#endif
|
||||
@@ -5136,8 +5135,11 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
|
||||
// The exception is if we're using the passed-in aCachedBrowsingContext, in
|
||||
// which case this is the second print with this static document clone that
|
||||
// we created the first time through, and we are responsible for cleaning it
|
||||
// up.
|
||||
closeWindowAfterPrint = usingCachedBrowsingContext;
|
||||
// up. There's also an exception if we're directly using the system print
|
||||
// dialog rather than our preview panel, because in this case the preview
|
||||
// will not take care of cleaning up the cloned doc.
|
||||
closeWindowAfterPrint =
|
||||
usingCachedBrowsingContext || StaticPrefs::print_prefer_system_dialog();
|
||||
} else {
|
||||
// In this case the document was not a static clone, so we made a static
|
||||
// clone for printing purposes and must clean it up after the print is done.
|
||||
@@ -5179,6 +5181,9 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
|
||||
if (aIsPreview == IsPreview::Yes) {
|
||||
return !hasPrintCallbacks;
|
||||
}
|
||||
if (StaticPrefs::print_prefer_system_dialog()) {
|
||||
return true;
|
||||
}
|
||||
return StaticPrefs::dom_window_print_fuzzing_block_while_printing();
|
||||
}();
|
||||
|
||||
|
||||
@@ -15589,6 +15589,14 @@
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether we directly use the system print dialog to collect the user's print
|
||||
# settings rather than using the tab-modal print preview dialog.
|
||||
# Note: `print.always_print_silent` overrides this.
|
||||
- name: print.prefer_system_dialog
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether we attempt to generate links in Save As PDF output.
|
||||
- name: print.save_as_pdf.links.enabled
|
||||
type: RelaxedAtomicBool
|
||||
|
||||
@@ -725,11 +725,6 @@ pref("browser.fixup.fallback-to-https", true);
|
||||
// used in this case. See nsPrintSettingsService::InitPrintSettingsFromPrefs
|
||||
// for the restrictions on which prefs can act as defaults.
|
||||
|
||||
// Whether we directly use the system print dialog to collect the user's print
|
||||
// settings rather than using the tab-modal print preview dialog.
|
||||
// Note: `print.always_print_silent` overrides this.
|
||||
pref("print.prefer_system_dialog", false);
|
||||
|
||||
// Print/Preview Shrink-To-Fit won't shrink below 20% for text-ish documents.
|
||||
pref("print.shrink-to-fit.scale-limit-percent", 20);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user