Ensure Linux UI is initialized for OOP printing
PrintingContextLinux::UpdatePrinterSettings() exits early for updating
settings when there is no LinuxUI instance present. This reports
success, even though some print settings do not get updated further by
PrintDialogGtk.
Since a full LinuxUI is not supported for Linux services at this time,
utilize a stub version for the UI. This enables printing to proceed
farther without skipping to fill in some information and unblocks the
rest of the OOP print pipeline.
This only unblocks the OOP portions of the print pipeline which do not
need to display a system UI dialog.
Bug: 809738, 1361982
Change-Id: I188b4b8a819618dd5ff35e06a5f7150d028b3655
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3906648
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1050907}
diff --git a/chrome/services/printing/BUILD.gn b/chrome/services/printing/BUILD.gn
index 45d8e48..6e56fa4f 100644
--- a/chrome/services/printing/BUILD.gn
+++ b/chrome/services/printing/BUILD.gn
@@ -92,6 +92,13 @@
"//components/crash/core/common",
"//ui/gfx",
]
+
+ if (is_linux) {
+ deps += [
+ "//ui/linux:linux_ui",
+ "//ui/linux:linux_ui_factory",
+ ]
+ }
}
}
diff --git a/chrome/services/printing/print_backend_service_impl.cc b/chrome/services/printing/print_backend_service_impl.cc
index fae88c6c..91d396b 100644
--- a/chrome/services/printing/print_backend_service_impl.cc
+++ b/chrome/services/printing/print_backend_service_impl.cc
@@ -41,6 +41,13 @@
#include "printing/backend/cups_connection_pool.h"
#endif
+#if BUILDFLAG(IS_LINUX)
+#include "base/no_destructor.h"
+#include "ui/linux/linux_ui.h"
+#include "ui/linux/linux_ui_delegate_stub.h"
+#include "ui/linux/linux_ui_factory.h"
+#endif
+
#if BUILDFLAG(IS_WIN)
#include "base/containers/queue.h"
#include "base/win/win_util.h"
@@ -55,6 +62,14 @@
namespace {
+#if BUILDFLAG(IS_LINUX)
+void InstantiateLinuxUiDelegate() {
+ // TODO(crbug.com/809738) Until a real UI can be used in a utility process,
+ // need to use the stub version.
+ static base::NoDestructor<ui::LinuxUiDelegateStub> linux_ui_delegate;
+}
+#endif
+
scoped_refptr<base::SequencedTaskRunner> GetPrintingTaskRunner() {
static constexpr base::TaskTraits kTraits = {
base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN};
@@ -407,6 +422,13 @@
// `InitCommon()`.
InitializeProcessForPrinting();
print_backend_ = PrintBackend::CreateInstance(locale);
+#if BUILDFLAG(IS_LINUX)
+ // Test framework already initializes the UI, so this should not go in
+ // `InitCommon()`. Additionally, low-level Linux UI is not needed when tests
+ // are using `TestPrintingContext`.
+ InstantiateLinuxUiDelegate();
+ ui::LinuxUi::SetInstance(ui::GetDefaultLinuxUi());
+#endif
InitCommon(locale);
}
diff --git a/ui/gtk/printing/print_dialog_gtk.cc b/ui/gtk/printing/print_dialog_gtk.cc
index 1207e8e9..98985bc 100644
--- a/ui/gtk/printing/print_dialog_gtk.cc
+++ b/ui/gtk/printing/print_dialog_gtk.cc
@@ -12,6 +12,7 @@
#include <vector>
#include "base/bind.h"
+#include "base/check_op.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
@@ -25,6 +26,7 @@
#include "printing/mojom/print.mojom.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings.h"
+#include "printing/printing_features.h"
#include "ui/aura/window.h"
#include "ui/gtk/gtk_compat.h"
#include "ui/gtk/gtk_ui.h"
@@ -417,8 +419,11 @@
void PrintDialogGtk::PrintDocument(const printing::MetafilePlayer& metafile,
const std::u16string& document_name) {
- // This runs on the print worker thread, does not block the UI thread.
- DCHECK(!owning_task_runner()->RunsTasksInCurrentSequence());
+ // For in-browser printing, this runs on the print worker thread, so it does
+ // not block the UI thread. For OOP it runs on the service document task
+ // runner.
+ DCHECK_EQ(owning_task_runner()->RunsTasksInCurrentSequence(),
+ printing::features::kEnableOopPrintDriversJobPrint.Get());
// The document printing tasks can outlive the PrintingContext that created
// this dialog.