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

Side by Side Diff: base/mac/launch_services_util.mm

Issue 2390953003: [Mac Fix-It] Changed OpenApplicationWithPath to use NSWorkspace. (Closed)
Patch Set: Addressed review comments 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 unified diff | Download patch
« no previous file with comments | « base/mac/launch_services_util.cc ('k') | chrome/app_shim/app_mode_loader_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "base/mac/launch_services_util.h"
6
7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h"
9
10 namespace base {
11 namespace mac {
12
13 Process OpenApplicationWithPath(const base::FilePath& bundle_path,
14 const CommandLine& command_line,
15 NSWorkspaceLaunchOptions launch_options) {
16 NSString* bundle_url_spec = base::SysUTF8ToNSString(bundle_path.value());
17 NSURL* bundle_url = [NSURL fileURLWithPath:bundle_url_spec isDirectory:YES];
18 DCHECK(bundle_url);
19 if (!bundle_url) {
20 return Process();
21 }
22
23 // NSWorkspace automatically adds the binary path as the first argument and
24 // it should not be included into the list.
25 std::vector<std::string> argv = command_line.argv();
26 int argc = argv.size();
27 NSMutableArray* launch_args = [NSMutableArray arrayWithCapacity:argc - 1];
28 for (int i = 1; i < argc; ++i) {
29 [launch_args addObject:base::SysUTF8ToNSString(argv[i])];
30 }
31
32 NSDictionary* configuration = @{
33 NSWorkspaceLaunchConfigurationArguments : launch_args,
34 };
35 NSError* launch_error = nil;
36 // TODO(jeremya): this opens a new browser window if Chrome is already
37 // running without any windows open.
38 NSRunningApplication* app =
39 [[NSWorkspace sharedWorkspace] launchApplicationAtURL:bundle_url
40 options:launch_options
41 configuration:configuration
42 error:&launch_error];
43 if (launch_error) {
44 LOG(ERROR) << base::SysNSStringToUTF8([launch_error localizedDescription]);
45 return Process();
46 }
47 DCHECK(app);
48 return Process([app processIdentifier]);
49 }
50
51 } // namespace mac
52 } // namespace base
OLDNEW
« no previous file with comments | « base/mac/launch_services_util.cc ('k') | chrome/app_shim/app_mode_loader_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698