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