1From d72c6d7f59aaf74d7ba64664fad3acc774e50324 Mon Sep 17 00:00:00 2001 2From: Tom Anderson <thomasanderson@chromium.org> 3Date: Sat, 21 May 2022 00:39:44 +0000 4Subject: [PATCH 14/14] Fix build with use_gtk=false 5 6shell_dialog_linux still needs to get built even for non-gtk builds. It 7was originally changed in [1] to fix a build with use_dbus=false. This 8CL unconditionally includes shell_dialog_linux on Linux, but adds a 9check for use_dbus before including select_file_dialog_linux_portal.cc. 10 11[1] https://chromium-review.googlesource.com/c/chromium/src/+/3462233 12 13R=sky 14 15Bug: None 16Change-Id: I54c39f52175e0c4b0784d15822e0fc4125f9e47d 17Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3656243 18Commit-Queue: Thomas Anderson <thomasanderson@chromium.org> 19Reviewed-by: Scott Violet <sky@chromium.org> 20Auto-Submit: Thomas Anderson <thomasanderson@chromium.org> 21Commit-Queue: Scott Violet <sky@chromium.org> 22Cr-Commit-Position: refs/heads/main@{#1006054} 23--- 24 ui/shell_dialogs/BUILD.gn | 23 ++++--- 25 ui/shell_dialogs/shell_dialog_linux.cc | 88 ++++++++++++++++---------- 26 2 files changed, 67 insertions(+), 44 deletions(-) 27 28diff --git a/ui/shell_dialogs/BUILD.gn b/ui/shell_dialogs/BUILD.gn 29index e1b3041dc..192251bad 100644 30--- a/ui/shell_dialogs/BUILD.gn 31+++ b/ui/shell_dialogs/BUILD.gn 32@@ -3,7 +3,7 @@ 33 # found in the LICENSE file. 34 35 import("//build/config/chromeos/ui_mode.gni") 36-import("//build/config/linux/gtk/gtk.gni") 37+import("//build/config/features.gni") 38 import("//build/config/ui.gni") 39 import("//testing/test.gni") 40 41@@ -41,23 +41,28 @@ component("shell_dialogs") { 42 "//url", 43 ] 44 45- if (is_chromeos || (is_linux && !use_gtk)) { 46+ if (is_chromeos || is_chromecast) { 47 sources += [ "shell_dialog_stub.cc" ] 48- } else if (is_linux) { 49+ } 50+ 51+ if (is_linux && !is_chromecast) { 52 sources += [ 53 "select_file_dialog_linux.cc", 54 "select_file_dialog_linux.h", 55 "select_file_dialog_linux_kde.cc", 56 "select_file_dialog_linux_kde.h", 57- "select_file_dialog_linux_portal.cc", 58- "select_file_dialog_linux_portal.h", 59 "shell_dialog_linux.cc", 60 "shell_dialog_linux.h", 61 ] 62- deps += [ 63- "//components/dbus/thread_linux", 64- "//dbus", 65- ] 66+ deps += [ "//components/dbus/thread_linux" ] 67+ if (use_dbus) { 68+ defines += [ "USE_DBUS" ] 69+ sources += [ 70+ "select_file_dialog_linux_portal.cc", 71+ "select_file_dialog_linux_portal.h", 72+ ] 73+ deps += [ "//dbus" ] 74+ } 75 } 76 77 if (is_mac) { 78diff --git a/ui/shell_dialogs/shell_dialog_linux.cc b/ui/shell_dialogs/shell_dialog_linux.cc 79index 0f5fa2e55..078fd3b1b 100644 80--- a/ui/shell_dialogs/shell_dialog_linux.cc 81+++ b/ui/shell_dialogs/shell_dialog_linux.cc 82@@ -10,14 +10,26 @@ 83 #include "build/chromeos_buildflags.h" 84 #include "ui/shell_dialogs/select_file_dialog_linux.h" 85 #include "ui/shell_dialogs/select_file_dialog_linux_kde.h" 86-#include "ui/shell_dialogs/select_file_dialog_linux_portal.h" 87 #include "ui/shell_dialogs/select_file_policy.h" 88 89+#if defined(USE_DBUS) 90+#include "ui/shell_dialogs/select_file_dialog_linux_portal.h" 91+#endif 92+ 93+namespace ui { 94+ 95 namespace { 96 97-ui::ShellDialogLinux* g_shell_dialog_linux = nullptr; 98+ShellDialogLinux* g_shell_dialog_linux = nullptr; 99 100-enum FileDialogChoice { kUnknown, kToolkit, kKde, kPortal }; 101+enum FileDialogChoice { 102+ kUnknown, 103+ kToolkit, 104+ kKde, 105+#if defined(USE_DBUS) 106+ kPortal, 107+#endif 108+}; 109 110 FileDialogChoice dialog_choice_ = kUnknown; 111 112@@ -26,14 +38,43 @@ std::string& KDialogVersion() { 113 return *version; 114 } 115 116-} // namespace 117+FileDialogChoice GetFileDialogChoice() { 118+#if defined(USE_DBUS) 119+ // Check to see if the portal is available. 120+ if (SelectFileDialogLinuxPortal::IsPortalAvailable()) 121+ return kPortal; 122+ // Make sure to kill the portal connection. 123+ SelectFileDialogLinuxPortal::DestroyPortalConnection(); 124+#endif 125+ 126+ // Check to see if KDE is the desktop environment. 127+ std::unique_ptr<base::Environment> env(base::Environment::Create()); 128+ base::nix::DesktopEnvironment desktop = 129+ base::nix::GetDesktopEnvironment(env.get()); 130+ if (desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 || 131+ desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4 || 132+ desktop == base::nix::DESKTOP_ENVIRONMENT_KDE5) { 133+ // Check to see if the user dislikes the KDE file dialog. 134+ if (!env->HasVar("NO_CHROME_KDE_FILE_DIALOG")) { 135+ // Check to see if the KDE dialog works. 136+ if (SelectFileDialogLinux::CheckKDEDialogWorksOnUIThread( 137+ KDialogVersion())) { 138+ return kKde; 139+ } 140+ } 141+ } 142 143-namespace ui { 144+ return kToolkit; 145+} 146+ 147+} // namespace 148 149 ShellDialogLinux::ShellDialogLinux() = default; 150 151 ShellDialogLinux::~ShellDialogLinux() { 152+#if defined(USE_DBUS) 153 SelectFileDialogLinuxPortal::DestroyPortalConnection(); 154+#endif 155 } 156 157 void ShellDialogLinux::SetInstance(ShellDialogLinux* instance) { 158@@ -45,50 +86,27 @@ const ShellDialogLinux* ShellDialogLinux::instance() { 159 } 160 161 void ShellDialogLinux::Initialize() { 162+#if defined(USE_DBUS) 163 SelectFileDialogLinuxPortal::StartAvailabilityTestInBackground(); 164+#endif 165 } 166 167 SelectFileDialog* CreateSelectFileDialog( 168 SelectFileDialog::Listener* listener, 169 std::unique_ptr<SelectFilePolicy> policy) { 170- if (dialog_choice_ == kUnknown) { 171- // Start out assuming we are going to use dialogs from the toolkit. 172- dialog_choice_ = kToolkit; 173- 174- // Check to see if the portal is available. 175- if (SelectFileDialogLinuxPortal::IsPortalAvailable()) { 176- dialog_choice_ = kPortal; 177- } else { 178- // Make sure to kill the portal connection. 179- SelectFileDialogLinuxPortal::DestroyPortalConnection(); 180- 181- // Check to see if KDE is the desktop environment. 182- std::unique_ptr<base::Environment> env(base::Environment::Create()); 183- base::nix::DesktopEnvironment desktop = 184- base::nix::GetDesktopEnvironment(env.get()); 185- if (desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 || 186- desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4 || 187- desktop == base::nix::DESKTOP_ENVIRONMENT_KDE5) { 188- // Check to see if the user dislikes the KDE file dialog. 189- if (!env->HasVar("NO_CHROME_KDE_FILE_DIALOG")) { 190- // Check to see if the KDE dialog works. 191- if (SelectFileDialogLinux::CheckKDEDialogWorksOnUIThread( 192- KDialogVersion())) { 193- dialog_choice_ = kKde; 194- } 195- } 196- } 197- } 198- } 199+ if (dialog_choice_ == kUnknown) 200+ dialog_choice_ = GetFileDialogChoice(); 201 202- const ui::ShellDialogLinux* shell_dialogs = ui::ShellDialogLinux::instance(); 203+ const ShellDialogLinux* shell_dialogs = ShellDialogLinux::instance(); 204 switch (dialog_choice_) { 205 case kToolkit: 206 if (!shell_dialogs) 207 break; 208 return shell_dialogs->CreateSelectFileDialog(listener, std::move(policy)); 209+#if defined(USE_DBUS) 210 case kPortal: 211 return new SelectFileDialogLinuxPortal(listener, std::move(policy)); 212+#endif 213 case kKde: { 214 std::unique_ptr<base::Environment> env(base::Environment::Create()); 215 base::nix::DesktopEnvironment desktop = 216-- 2172.20.1 218 219