Skip to content

linux: Fix callbacks to CefPrintHandler (fixes #4130)#4210

Open
linesight wants to merge 2 commits into
chromiumembedded:masterfrom
linesight:fix-4130-linux-printhandler
Open

linux: Fix callbacks to CefPrintHandler (fixes #4130)#4210
linesight wants to merge 2 commits into
chromiumembedded:masterfrom
linesight:fix-4130-linux-printhandler

Conversation

@linesight

Copy link
Copy Markdown
Contributor

Fixes #4130.

Summary:

  • CefPrintHandler callbacks stopped firing on Linux in M145+ after upstream
    moved print dialog creation to a PrintingContextLinux::PrintDialogFactory
    whose default implementation bypasses CefPrintingContextLinuxDelegate.
  • Register a CefPrintDialogFactory via the public
    PrintingContextLinux::SetPrintDialogFactory() so dialog creation routes back
    through the delegate and CefPrintHandler.
  • Wrap the reference-counted CefPrintDialogLinux in a CefPrintDialogLinuxProxy
    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).
  • As with Support CefPrintHandler on Chrome-Runtime Linux #3729, out-of-process printing must be disabled
    (--disable-features=EnableOopPrintDrivers) for the callbacks to fire.

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.
@edgardogho

Copy link
Copy Markdown

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux: CefPrintHandler not used on CEF145 (worked on CEF143/144)

3 participants