Propagate LinuxUi state to print utility subprocess
This is required to prevent loading a different version of GTK in the print utility process which may cause printer enumeration to differ. R=thestig Bug: 414635403, 411336538 Change-Id: I01df9fcf0f04a8259d7fa50e7fabe34b0a914d31 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6514352 Commit-Queue: Colin Blundell <blundell@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Auto-Submit: Thomas Anderson <thomasanderson@chromium.org> Reviewed-by: Colin Blundell <blundell@chromium.org> Cr-Commit-Position: refs/heads/main@{#1456790}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
fd829ced2b
commit
4d44e5915a
@ -38,6 +38,7 @@
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "ui/linux/linux_ui.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
@ -878,14 +879,19 @@ PrintBackendServiceManager::GetServiceFromBundle(
|
||||
<< (sandboxed ? "sandboxed" : "unsandboxed") << " for `"
|
||||
<< remote_id << "`";
|
||||
|
||||
std::vector<std::string> extra_switches;
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
if (auto* linux_ui = ui::LinuxUi::instance()) {
|
||||
extra_switches = linux_ui->GetCmdLineFlagsForCopy();
|
||||
}
|
||||
extra_switches.push_back(switches::kMessageLoopTypeUi);
|
||||
#endif
|
||||
mojo::Remote<T>& host = bundle->host;
|
||||
content::ServiceProcessHost::Launch(
|
||||
host.BindNewPipeAndPassReceiver(),
|
||||
content::ServiceProcessHost::Options()
|
||||
.WithDisplayName(IDS_UTILITY_PROCESS_PRINT_BACKEND_SERVICE_NAME)
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
.WithExtraCommandLineSwitches({switches::kMessageLoopTypeUi})
|
||||
#endif
|
||||
.WithExtraCommandLineSwitches(std::move(extra_switches))
|
||||
.Pass());
|
||||
host->BindBackend(service.BindNewPipeAndPassReceiver());
|
||||
|
||||
|
@ -33,6 +33,10 @@ const char kSystemFontFamily[] = "system-font-family";
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
// Specify the toolkit used to construct the Linux GUI.
|
||||
const char kUiToolkitFlag[] = "ui-toolkit";
|
||||
// Specify the GTK version to be loaded.
|
||||
const char kGtkVersionFlag[] = "gtk-version";
|
||||
// Specify the QT version to be loaded.
|
||||
const char kQtVersionFlag[] = "qt-version";
|
||||
// Disables GTK IME integration.
|
||||
const char kDisableGtkIme[] = "disable-gtk-ime";
|
||||
#endif
|
||||
|
@ -28,6 +28,8 @@ COMPONENT_EXPORT(UI_BASE) extern const char kSystemFontFamily[];
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
COMPONENT_EXPORT(UI_BASE) extern const char kUiToolkitFlag[];
|
||||
COMPONENT_EXPORT(UI_BASE) extern const char kGtkVersionFlag[];
|
||||
COMPONENT_EXPORT(UI_BASE) extern const char kQtVersionFlag[];
|
||||
COMPONENT_EXPORT(UI_BASE) extern const char kDisableGtkIme[];
|
||||
#endif
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "base/nix/xdg_util.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
#include "ui/gfx/color_palette.h"
|
||||
#include "ui/gtk/gtk_stubs.h"
|
||||
#include "ui/gtk/ime_compat_check.h"
|
||||
@ -26,8 +27,6 @@ namespace gtk {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kGtkVersionFlag[] = "gtk-version";
|
||||
|
||||
struct Gdk3Rgba {
|
||||
gdouble r;
|
||||
gdouble g;
|
||||
@ -136,7 +135,7 @@ bool LoadGtkImpl() {
|
||||
|
||||
auto* cmd = base::CommandLine::ForCurrentProcess();
|
||||
unsigned int gtk_version;
|
||||
if (!base::StringToUint(cmd->GetSwitchValueASCII(kGtkVersionFlag),
|
||||
if (!base::StringToUint(cmd->GetSwitchValueASCII(switches::kGtkVersionFlag),
|
||||
>k_version)) {
|
||||
gtk_version = 0;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "base/nix/xdg_util.h"
|
||||
#include "base/numerics/safe_conversions.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "chrome/browser/themes/theme_properties.h" // nogncheck
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
@ -552,6 +553,15 @@ bool GtkUi::PreferDarkTheme() const {
|
||||
return dark;
|
||||
}
|
||||
|
||||
std::vector<std::string> GtkUi::GetCmdLineFlagsForCopy() const {
|
||||
const auto& gtk_version = GtkVersion();
|
||||
uint32_t major_version =
|
||||
gtk_version.IsValid() ? gtk_version.components()[0] : 0;
|
||||
return {std::string(switches::kUiToolkitFlag) + "=gtk",
|
||||
std::string(switches::kGtkVersionFlag) + "=" +
|
||||
base::NumberToString(major_version)};
|
||||
}
|
||||
|
||||
void GtkUi::SetDarkTheme(bool dark) {
|
||||
auto* settings = gtk_settings_get_default();
|
||||
g_object_set(settings, "gtk-application-prefer-dark-theme", dark, nullptr);
|
||||
|
@ -94,6 +94,7 @@ class GtkUi : public ui::LinuxUiAndTheme {
|
||||
ui::WindowButtonOrderObserver* observer) override;
|
||||
WindowFrameAction GetWindowFrameAction(
|
||||
WindowFrameActionSource source) override;
|
||||
std::vector<std::string> GetCmdLineFlagsForCopy() const override;
|
||||
|
||||
// ui::LinuxUiTheme:
|
||||
ui::NativeTheme* GetNativeTheme() const override;
|
||||
|
@ -89,6 +89,10 @@ LinuxUi::WindowFrameAction FakeLinuxUi::GetWindowFrameAction(
|
||||
return WindowFrameAction::kNone;
|
||||
}
|
||||
|
||||
std::vector<std::string> FakeLinuxUi::GetCmdLineFlagsForCopy() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool FakeLinuxUi::PreferDarkTheme() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ class FakeLinuxUi : public LinuxUiAndTheme {
|
||||
ui::WindowButtonOrderObserver* observer) override;
|
||||
WindowFrameAction GetWindowFrameAction(
|
||||
WindowFrameActionSource source) override;
|
||||
std::vector<std::string> GetCmdLineFlagsForCopy() const override;
|
||||
|
||||
// ui::LinuxUiTheme:
|
||||
ui::NativeTheme* GetNativeTheme() const override;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "base/time/time.h"
|
||||
#include "ui/base/ime/linux/linux_input_method_context.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
#include "ui/events/keycodes/dom/dom_keyboard_layout_map.h"
|
||||
#include "ui/gfx/font_render_params.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
@ -116,6 +117,10 @@ LinuxUi::WindowFrameAction FallbackLinuxUi::GetWindowFrameAction(
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> FallbackLinuxUi::GetCmdLineFlagsForCopy() const {
|
||||
return {std::string(switches::kUiToolkitFlag) + "=fallback"};
|
||||
}
|
||||
|
||||
bool FallbackLinuxUi::PreferDarkTheme() const {
|
||||
return theme_is_dark_;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ class FallbackLinuxUi : public LinuxUiAndTheme {
|
||||
ui::WindowButtonOrderObserver* observer) override;
|
||||
WindowFrameAction GetWindowFrameAction(
|
||||
WindowFrameActionSource source) override;
|
||||
std::vector<std::string> GetCmdLineFlagsForCopy() const override;
|
||||
|
||||
// ui::LinuxUiTheme:
|
||||
ui::NativeTheme* GetNativeTheme() const override;
|
||||
|
@ -205,6 +205,10 @@ class COMPONENT_EXPORT(LINUX_UI) LinuxUi {
|
||||
virtual WindowFrameAction GetWindowFrameAction(
|
||||
WindowFrameActionSource source) = 0;
|
||||
|
||||
// Returns the command line flags that should be copied to subprocesses
|
||||
// to have the same toolkit and version as this process.
|
||||
virtual std::vector<std::string> GetCmdLineFlagsForCopy() const = 0;
|
||||
|
||||
protected:
|
||||
struct CmdLineArgs {
|
||||
CmdLineArgs();
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/base/ime/linux/linux_input_method_context.h"
|
||||
#include "ui/base/ime/text_edit_commands.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
#include "ui/color/color_mixer.h"
|
||||
#include "ui/color/color_provider.h"
|
||||
#include "ui/color/color_provider_manager.h"
|
||||
@ -61,16 +62,15 @@ namespace qt {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kQtVersionFlag[] = "qt-version";
|
||||
|
||||
void* LoadLibrary(const base::FilePath& path) {
|
||||
return dlopen(path.value().c_str(), RTLD_NOW | RTLD_GLOBAL);
|
||||
}
|
||||
|
||||
bool PreferQt6() {
|
||||
auto* cmd = base::CommandLine::ForCurrentProcess();
|
||||
if (cmd->HasSwitch(kQtVersionFlag)) {
|
||||
std::string qt_version_string = cmd->GetSwitchValueASCII(kQtVersionFlag);
|
||||
if (cmd->HasSwitch(switches::kQtVersionFlag)) {
|
||||
std::string qt_version_string =
|
||||
cmd->GetSwitchValueASCII(switches::kQtVersionFlag);
|
||||
unsigned int qt_version = 0;
|
||||
if (base::StringToUint(qt_version_string, &qt_version)) {
|
||||
switch (qt_version) {
|
||||
@ -395,6 +395,12 @@ QtUi::WindowFrameAction QtUi::GetWindowFrameAction(
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> QtUi::GetCmdLineFlagsForCopy() const {
|
||||
return {std::string(switches::kUiToolkitFlag) + "=qt",
|
||||
std::string(switches::kQtVersionFlag) + "=" +
|
||||
base::NumberToString(qt_version_)};
|
||||
}
|
||||
|
||||
DISABLE_CFI_VCALL
|
||||
bool QtUi::PreferDarkTheme() const {
|
||||
return color_utils::IsDark(
|
||||
|
@ -65,6 +65,7 @@ class QtUi : public ui::LinuxUiAndTheme, QtInterface::Delegate {
|
||||
ui::WindowButtonOrderObserver* observer) override;
|
||||
WindowFrameAction GetWindowFrameAction(
|
||||
WindowFrameActionSource source) override;
|
||||
std::vector<std::string> GetCmdLineFlagsForCopy() const override;
|
||||
|
||||
// ui::LinuxUiTheme:
|
||||
ui::NativeTheme* GetNativeTheme() const override;
|
||||
|
Reference in New Issue
Block a user