linux: Fix callbacks to CefPrintHandler (fixes #4130)#4210
Conversation
Since M145 the Linux print dialog is created via a PrintingContextLinux::PrintDialogFactory instead of directly through ui::LinuxUi/PrintingContextLinuxDelegate. The default factory routes to the GTK/XDG portal dialog and never consults CefPrintingContextLinuxDelegate, so CefPrintHandler callbacks stopped firing (they worked on CEF143/144). Register a CefPrintDialogFactory via the public PrintingContextLinux::SetPrintDialogFactory() so dialog creation routes back through CefPrintingContextLinuxDelegate and the CefPrintHandler. M145 also changed PrintingContextLinux to own the dialog via a std::unique_ptr and delete it on teardown, which is incompatible with the reference-counted CefPrintDialogLinux (it must outlive the context until an asynchronous print job completes). Wrap it in a thin CefPrintDialogLinuxProxy that is owned by the unique_ptr and calls ReleaseDialog() on destruction, restoring the previous lifetime handshake. As with chromiumembedded#3729, out-of-process printing must be disabled (--disable-features=EnableOopPrintDrivers) for the handler callbacks to fire.
|
I can confirm this patch allows CefPrintHandler to work on Linux on branch 7299 (CEF151). |
| // CefPrintHandler is used. The delegate falls back to the default (GTK) | ||
| // implementation when no handler is provided. | ||
| if (auto* delegate = ui::PrintingContextLinuxDelegate::instance()) { | ||
| return delegate->CreatePrintDialog(context); |
There was a problem hiding this comment.
[P1] Please preserve Chromium’s default dialog-factory behavior when no CefPrintHandler is configured. This factory replaces PrintDialogLinuxFactory globally, ignores show_system_dialog, and always routes through the legacy LinuxUi delegate. That fallback cannot reproduce Chromium’s default-enabled XDG portal branch (and FallbackLinuxUi::CreatePrintDialog() returns null), so handler-less Chrome/Alloy printing can lose the portal dialog or fail entirely. Please select the CEF dialog only when the associated browser has a print handler; otherwise forward to equivalent default-factory behavior, preserving show_system_dialog and the settings-based portal selection.
CefPrintDialogFactory derives from PrintDialogLinuxFactory and only routes browsers that have a CefPrintHandler through the delegate; otherwise it falls back to the base implementation, preserving show_system_dialog and the portal/LinuxUi dialog selection. The delegate and factory are owned and unregistered at shutdown rather than leaked.
Fixes #4130.
Summary:
moved print dialog creation to a PrintingContextLinux::PrintDialogFactory
whose default implementation bypasses CefPrintingContextLinuxDelegate.
PrintingContextLinux::SetPrintDialogFactory() so dialog creation routes back
through the delegate and CefPrintHandler.
owned by the context's unique_ptr; the proxy calls ReleaseDialog() on
destruction so the dialog can outlive the PrintingContext until an async
print job completes (M145 changed the dialog to be owned via unique_ptr).
(--disable-features=EnableOopPrintDrivers) for the callbacks to fire.