Browse Source

fix: Launch apps with XDG_ACTIVATION_TOKEN in ozone/wayland (#43578)

* fix: Launch apps with XDG_ACTIVATION_TOKEN in ozone/wayland

Ensure apps are launched with the activation token received from
xdg_activation_v1 protocol.

Co-authored-by: Orko Garai <[email protected]>

* add focus_launched_process option

Co-authored-by: Orko Garai <[email protected]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Orko Garai <[email protected]>
trop[bot] 7 months ago
parent
commit
722bc116f8
1 changed files with 18 additions and 2 deletions
  1. 18 2
      shell/common/platform_util_linux.cc

+ 18 - 2
shell/common/platform_util_linux.cc

@@ -22,6 +22,7 @@
 #include "base/posix/eintr_wrapper.h"
 #include "base/process/kill.h"
 #include "base/process/launch.h"
+#include "base/run_loop.h"
 #include "base/strings/escape.h"
 #include "base/strings/string_util.h"
 #include "base/threading/thread_restrictions.h"
@@ -269,8 +270,21 @@ std::string GetErrorDescription(int error_code) {
 bool XDGUtil(const std::vector<std::string>& argv,
              const base::FilePath& working_directory,
              const bool wait_for_exit,
+             const bool focus_launched_process,
              platform_util::OpenCallback callback) {
   base::LaunchOptions options;
+  if (focus_launched_process) {
+    base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
+    base::RepeatingClosure quit_loop = run_loop.QuitClosure();
+    base::nix::CreateLaunchOptionsWithXdgActivation(base::BindOnce(
+        [](base::RepeatingClosure quit_loop, base::LaunchOptions* options_out,
+           base::LaunchOptions options) {
+          *options_out = std::move(options);
+          std::move(quit_loop).Run();
+        },
+        std::move(quit_loop), &options));
+    run_loop.Run();
+  }
   options.current_directory = working_directory;
   options.allow_new_privs = true;
   // xdg-open can fall back on mailcap which eventually might plumb through
@@ -302,11 +316,12 @@ bool XDGOpen(const base::FilePath& working_directory,
              const bool wait_for_exit,
              platform_util::OpenCallback callback) {
   return XDGUtil({"xdg-open", path}, working_directory, wait_for_exit,
-                 std::move(callback));
+                 /*focus_launched_process=*/true, std::move(callback));
 }
 
 bool XDGEmail(const std::string& email, const bool wait_for_exit) {
   return XDGUtil({"xdg-email", email}, base::FilePath(), wait_for_exit,
+                 /*focus_launched_process=*/true,
                  platform_util::OpenCallback());
 }
 
@@ -375,7 +390,8 @@ bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail) {
     argv = {"gio", "trash", filename};
   }
 
-  return XDGUtil(argv, base::FilePath(), true, platform_util::OpenCallback());
+  return XDGUtil(argv, base::FilePath(), true, /*focus_launched_process=*/false,
+                 platform_util::OpenCallback());
 }
 
 namespace internal {