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

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

Issue 2390953003: [Mac Fix-It] Changed OpenApplicationWithPath to use NSWorkspace. (Closed)
Patch Set: Self review 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
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 bool OpenApplicationWithPath(const base::FilePath& bundle_path,
14 const CommandLine& command_line,
15 NSWorkspaceLaunchOptions launch_options,
16 pid_t* out_pid) {
17 NSString* bundle_url_spec = base::SysUTF8ToNSString(bundle_path.value());
18 NSURL* bundle_url = [NSURL fileURLWithPath:bundle_url_spec isDirectory:YES];
19 if (!bundle_url) {
tapted 2016/10/04 05:54:08 apart from OOM, can this fail? Perhaps just DCHECK
Eugene But (OOO till 7-30) 2016/10/04 07:02:49 It can if bundle_path.value() is an empty string.
20 LOG(ERROR) << "Cannot create NSURL for " << bundle_path.value();
21 }
22
23 std::vector<std::string> argv = command_line.argv();
24 int argc = argv.size();
25 NSMutableArray* launch_args = [NSMutableArray arrayWithCapacity:argc - 1];
tapted 2016/10/04 05:54:08 NSWorkspaceLaunchConfigurationArguments says it's
Eugene But (OOO till 7-30) 2016/10/04 07:02:49 argv[0] is a binary path, which automatically adde
26 for (int i = 1; i < argc; ++i) {
27 const std::string& arg(argv[i]);
28 [launch_args addObject:base::SysUTF8ToNSString(arg)];
29 }
30
31 NSDictionary* configuration = @{
32 NSWorkspaceLaunchConfigurationArguments : launch_args,
33 };
tapted 2016/10/04 05:54:08 That // TODO(jeremya): this opens a new browser wi
Eugene But (OOO till 7-30) 2016/10/04 07:02:49 Added back TODO.
34 NSError* launch_error = nil;
35 NSRunningApplication* app =
36 [[NSWorkspace sharedWorkspace] launchApplicationAtURL:bundle_url
37 options:launch_options
38 configuration:configuration
39 error:&launch_error];
40
41 if (out_pid) {
42 *out_pid = app.processIdentifier;
tapted 2016/10/04 05:54:08 [app processIdentifier] But also launchApplicatio
Eugene But (OOO till 7-30) 2016/10/04 07:02:49 Done. New code now correctly handles nil case.
43 }
44
45 if (launch_error) {
46 NSString* error_description =
47 [[launch_error userInfo] objectForKey:NSLocalizedDescriptionKey];
48 DLOG(ERROR) << base::SysNSStringToUTF8(error_description);
tapted 2016/10/04 05:54:08 There's probably a good argument for making this a
Eugene But (OOO till 7-30) 2016/10/04 07:02:49 Localized description prints this: The applicati
tapted 2016/10/05 01:40:47 The localized description should be OK - I agree i
49 return false;
50 }
51 return true;
52 }
53
54 } // namespace mac
55 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698