diff --git printing/printing_context_linux.cc printing/printing_context_linux.cc index 83211e80d8270..9ce9b37375762 100644 --- printing/printing_context_linux.cc +++ printing/printing_context_linux.cc @@ -25,6 +25,12 @@ namespace printing { +namespace { + +static PrintingContextLinuxDelegate* g_delegate = nullptr; + +} // namespace + // static std::unique_ptr PrintingContext::CreateImpl( Delegate* delegate, @@ -47,6 +53,14 @@ PrintingContextLinux::~PrintingContextLinux() { print_dialog_->ReleaseDialog(); } +// static +PrintingContextLinuxDelegate* PrintingContextLinuxDelegate::SetInstance( + PrintingContextLinuxDelegate* delegate) { + auto old_delegate = g_delegate; + g_delegate = delegate; + return old_delegate; +} + void PrintingContextLinux::AskUserForSettings(int max_pages, bool has_selection, bool is_scripted, @@ -68,23 +82,19 @@ mojom::ResultCode PrintingContextLinux::UseDefaultSettings() { ResetSettings(); -#if BUILDFLAG(IS_LINUX) - if (!ui::LinuxUi::instance()) + if (!g_delegate) return mojom::ResultCode::kSuccess; if (!print_dialog_) - print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this); + print_dialog_ = g_delegate->CreatePrintDialog(this); print_dialog_->UseDefaultSettings(); -#endif return mojom::ResultCode::kSuccess; } gfx::Size PrintingContextLinux::GetPdfPaperSizeDeviceUnits() { -#if BUILDFLAG(IS_LINUX) - if (ui::LinuxUi::instance()) - return ui::LinuxUi::instance()->GetPdfPaperSize(this); -#endif + if (g_delegate) + return g_delegate->GetPdfPaperSize(this); return gfx::Size(); } @@ -94,18 +104,16 @@ mojom::ResultCode PrintingContextLinux::UpdatePrinterSettings( DCHECK(!printer_settings.show_system_dialog); DCHECK(!in_print_job_); -#if BUILDFLAG(IS_LINUX) - if (!ui::LinuxUi::instance()) + if (!g_delegate) return mojom::ResultCode::kSuccess; if (!print_dialog_) - print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this); + print_dialog_ = g_delegate->CreatePrintDialog(this); // PrintDialogGtk::UpdateSettings() calls InitWithSettings() so settings_ will // remain non-null after this line. print_dialog_->UpdateSettings(std::move(settings_)); DCHECK(settings_); -#endif return mojom::ResultCode::kSuccess; } diff --git printing/printing_context_linux.h printing/printing_context_linux.h index 6fb35248ec459..3be9c29c7ebf9 100644 --- printing/printing_context_linux.h +++ printing/printing_context_linux.h @@ -16,6 +16,20 @@ namespace printing { class MetafilePlayer; class PrintDialogLinuxInterface; +class PrintingContextLinux; + +class COMPONENT_EXPORT(PRINTING) PrintingContextLinuxDelegate { + public: + virtual ~PrintingContextLinuxDelegate() = default; + + virtual PrintDialogLinuxInterface* CreatePrintDialog( + PrintingContextLinux* context) = 0; + + virtual gfx::Size GetPdfPaperSize(PrintingContextLinux* context) = 0; + + static PrintingContextLinuxDelegate* SetInstance( + PrintingContextLinuxDelegate* delegate); +}; // PrintingContext with optional native UI for print dialog and pdf_paper_size. class COMPONENT_EXPORT(PRINTING) PrintingContextLinux : public PrintingContext { diff --git tools/v8_context_snapshot/BUILD.gn tools/v8_context_snapshot/BUILD.gn index 33a147bd79fd1..01f573e30395e 100644 --- tools/v8_context_snapshot/BUILD.gn +++ tools/v8_context_snapshot/BUILD.gn @@ -106,6 +106,7 @@ if (use_v8_context_snapshot) { deps = [ "//gin:gin", "//mojo/core/embedder", + "//printing", "//services/service_manager/public/cpp", "//third_party/blink/public:blink", "//v8", diff --git ui/linux/linux_ui.cc ui/linux/linux_ui.cc index fc0ab170837bf..3d8c437ee4733 100644 --- ui/linux/linux_ui.cc +++ ui/linux/linux_ui.cc @@ -23,6 +23,10 @@ LinuxUi* g_linux_ui = nullptr; // static LinuxUi* LinuxUi::SetInstance(LinuxUi* instance) { +#if BUILDFLAG(IS_LINUX) && BUILDFLAG(ENABLE_PRINTING) + printing::PrintingContextLinuxDelegate::SetInstance(instance); +#endif + return std::exchange(g_linux_ui, instance); } diff --git ui/linux/linux_ui.h ui/linux/linux_ui.h index 4c5e4e19fc94c..2bfcd7d11ea21 100644 --- ui/linux/linux_ui.h +++ ui/linux/linux_ui.h @@ -17,6 +17,10 @@ #include "build/chromecast_buildflags.h" #include "printing/buildflags/buildflags.h" +#if BUILDFLAG(ENABLE_PRINTING) +#include "printing/printing_context_linux.h" // nogncheck +#endif + // The main entrypoint into Linux toolkit specific code. GTK/QT code should only // be executed behind this interface. @@ -61,7 +65,11 @@ class WindowFrameProvider; // Adapter class with targets to render like different toolkits. Set by any // project that wants to do linux desktop native rendering. -class COMPONENT_EXPORT(LINUX_UI) LinuxUi { +class COMPONENT_EXPORT(LINUX_UI) LinuxUi +#if BUILDFLAG(ENABLE_PRINTING) + : public printing::PrintingContextLinuxDelegate +#endif + { public: LinuxUi(const LinuxUi&) = delete; LinuxUi& operator=(const LinuxUi&) = delete; @@ -111,14 +119,6 @@ class COMPONENT_EXPORT(LINUX_UI) LinuxUi { // Returns a map of KeyboardEvent code to KeyboardEvent key values. virtual base::flat_map GetKeyboardLayoutMap() = 0; -#if BUILDFLAG(ENABLE_PRINTING) - virtual printing::PrintDialogLinuxInterface* CreatePrintDialog( - printing::PrintingContextLinux* context) = 0; - - virtual gfx::Size GetPdfPaperSize( - printing::PrintingContextLinux* context) = 0; -#endif - // Returns a native file selection dialog. `listener` is of type // SelectFileDialog::Listener. TODO(thomasanderson): Move // SelectFileDialog::Listener to SelectFileDialogListener so that it can be