1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_MAC_LAUNCH_APPLICATION_H_ 6 #define BASE_MAC_LAUNCH_APPLICATION_H_ 7 8 #import <AppKit/AppKit.h> 9 10 #include <string> 11 #include <vector> 12 13 #include "base/base_export.h" 14 #include "base/command_line.h" 15 #include "base/files/file_path.h" 16 #include "base/functional/callback_forward.h" 17 #include "base/types/expected.h" 18 #include "third_party/abseil-cpp/absl/types/variant.h" 19 20 // Launches an application. 21 // 22 // What makes this different from `LaunchProcess()` in /base/process/launch.h? 23 // That code creates a sub-process, which is useful for utility processes and 24 // the like, but inappropriate for independent applications. 25 // `LaunchApplication()` below, on the other hand, launches an app in the way 26 // that the Finder or Dock would launch an app. 27 28 namespace base::mac { 29 30 struct LaunchApplicationOptions { 31 bool activate = true; 32 bool create_new_instance = false; 33 bool prompt_user_if_needed = false; 34 }; 35 36 using LaunchApplicationCallback = 37 base::OnceCallback<void(base::expected<NSRunningApplication*, NSError*>)>; 38 39 using CommandLineArgs = 40 absl::variant<absl::monostate, CommandLine, std::vector<std::string>>; 41 42 // Launches the specified application. 43 // - `app_bundle_path`: the location of the application to launch 44 // - `command_line_args`: the command line arguments to pass to the 45 // application if the app isn't already running (the default-constructed 46 // monostate alternative means no arguments) 47 // - Note: The application to launch is specified as `app_bundle_path`, so 48 // if `base::CommandLine` is used to provide command line arguments, its 49 // first argument will be ignored 50 // - `url_specs`: the URLs for the application to open (an empty vector is OK) 51 // - `options`: options to modify the launch 52 // - `callback`: the result callback 53 // 54 // When the launch is complete, `callback` is called on the main thread. If the 55 // launch succeeded, it will be called with an `NSRunningApplication*`. If the 56 // launch failed, it will be called with an `NSError*`. 57 BASE_EXPORT void LaunchApplication(const FilePath& app_bundle_path, 58 const CommandLineArgs& command_line_args, 59 const std::vector<std::string>& url_specs, 60 LaunchApplicationOptions options, 61 LaunchApplicationCallback callback); 62 63 } // namespace base::mac 64 65 #endif // BASE_MAC_LAUNCH_APPLICATION_H_ 66