Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(982)

Unified Diff: base/mac/launch_services_util.mm

Issue 2398853002: Remove deprecated APIs from OpenApplicationWithPath. (Closed)
Patch Set: More cleanup. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/mac/launch_services_util.cc ('k') | chrome/app_shim/chrome_main_app_mode_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/launch_services_util.mm
diff --git a/base/mac/launch_services_util.mm b/base/mac/launch_services_util.mm
new file mode 100644
index 0000000000000000000000000000000000000000..0ae4262cefc6bd3adfd89ab0b15dd196a647f7d6
--- /dev/null
+++ b/base/mac/launch_services_util.mm
@@ -0,0 +1,63 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/mac/launch_services_util.h"
+
+#import <AppKit/AppKit.h>
+
+#include "base/logging.h"
+#include "base/mac/mac_logging.h"
+#include "base/mac/mac_util.h"
+#include "base/mac/scoped_cftyperef.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+
+namespace base {
+namespace mac {
+
+bool OpenApplicationWithPath(const base::FilePath& bundle_path,
+ const CommandLine& command_line,
+ NSWorkspaceLaunchOptions launch_flags,
+ NSAppleEventDescriptor* descriptor,
+ pid_t* pid) {
+ const std::vector<std::string>& argv = command_line.argv();
+ int argc = argv.size();
+ base::scoped_nsobject<NSMutableArray> launch_args(
+ [[NSMutableArray alloc] initWithCapacity:argc - 1]);
+
+ for (int i = 1; i < argc; ++i) {
+ const std::string& arg(argv[i]);
+ [launch_args addObject:base::SysUTF8ToNSString(arg)];
+ }
+
+ NSURL* url =
+ [NSURL fileURLWithPath:base::SysUTF8ToNSString(bundle_path.value())];
+ base::scoped_nsobject<NSMutableDictionary> configuration(
+ [[NSMutableDictionary alloc] init]);
+ [configuration setObject:launch_args
+ forKey:NSWorkspaceLaunchConfigurationArguments];
+ if (descriptor)
+ [configuration setObject:descriptor
+ forKey:NSWorkspaceLaunchConfigurationAppleEvent];
+
+ NSError* error = nil;
+ NSRunningApplication* application =
+ [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url
+ options:launch_flags
+ configuration:configuration
+ error:&error];
+
+ if (error) {
+ const char* error_description = [[error description] UTF8String];
+ LOG(ERROR) << "Failed to launch application: "
+ << (error_description ? error_description : "");
+ return false;
+ }
+ if (pid)
+ *pid = [application processIdentifier];
+ return true;
+}
+
+} // namespace mac
+} // namespace base
« no previous file with comments | « base/mac/launch_services_util.cc ('k') | chrome/app_shim/chrome_main_app_mode_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698