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

Side by Side Diff: chrome/browser/platform_util_mac.mm

Issue 613673003: [Mac] On Mavericks or later, use NSWorkspace to open download items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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/sdk_forward_declarations.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/platform_util.h" 5 #include "chrome/browser/platform_util.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <CoreServices/CoreServices.h> 9 #include <CoreServices/CoreServices.h>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/mac_logging.h" 13 #include "base/mac/mac_logging.h"
14 #import "base/mac/mac_util.h"
15 #import "base/mac/sdk_forward_declarations.h"
14 #include "base/mac/scoped_aedesc.h" 16 #include "base/mac/scoped_aedesc.h"
15 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
18 namespace platform_util { 20 namespace platform_util {
19 21
20 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { 22 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
21 DCHECK([NSThread isMainThread]); 23 DCHECK([NSThread isMainThread]);
22 NSString* path_string = base::SysUTF8ToNSString(full_path.value()); 24 NSString* path_string = base::SysUTF8ToNSString(full_path.value());
23 if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string 25 if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string
24 inFileViewerRootedAtPath:nil]) 26 inFileViewerRootedAtPath:nil])
25 LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value(); 27 LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value();
26 } 28 }
27 29
28 // This function opens a file. This doesn't use LaunchServices or NSWorkspace 30 // This function opens a file. This doesn't use LaunchServices or NSWorkspace
29 // because of two bugs: 31 // because of two bugs:
30 // 1. Incorrect app activation with com.apple.quarantine: 32 // 1. Incorrect app activation with com.apple.quarantine:
31 // http://crbug.com/32921 33 // http://crbug.com/32921
32 // 2. Silent no-op for unassociated file types: http://crbug.com/50263 34 // 2. Silent no-op for unassociated file types: http://crbug.com/50263
33 // Instead, an AppleEvent is constructed to tell the Finder to open the 35 // Instead, an AppleEvent is constructed to tell the Finder to open the
34 // document. 36 // document.
35 void OpenItem(Profile* profile, const base::FilePath& full_path) { 37 void OpenItem(Profile* profile, const base::FilePath& full_path) {
36 DCHECK([NSThread isMainThread]); 38 DCHECK([NSThread isMainThread]);
37 NSString* path_string = base::SysUTF8ToNSString(full_path.value()); 39 NSString* path_string = base::SysUTF8ToNSString(full_path.value());
38 if (!path_string) 40 if (!path_string)
39 return; 41 return;
40 42
43 if (base::mac::IsOSMavericksOrLater()) {
Avi (use Gerrit) 2014/09/29 15:36:00 Fix the comment at the top of the function ("This
Robert Sesek 2014/09/29 15:41:16 Done.
44 NSURL* url = [NSURL fileURLWithPath:path_string];
45 if (!url)
46 return;
47
48 const NSWorkspaceLaunchOptions launch_options =
49 NSWorkspaceLaunchAsync | NSWorkspaceLaunchWithErrorPresentation;
50 [[NSWorkspace sharedWorkspace] openURLs:@[ url ]
51 withAppBundleIdentifier:nil
52 options:launch_options
53 additionalEventParamDescriptor:nil
54 launchIdentifiers:NULL]) {
55 return;
56 }
57
41 // Create the target of this AppleEvent, the Finder. 58 // Create the target of this AppleEvent, the Finder.
42 base::mac::ScopedAEDesc<AEAddressDesc> address; 59 base::mac::ScopedAEDesc<AEAddressDesc> address;
43 const OSType finderCreatorCode = 'MACS'; 60 const OSType finderCreatorCode = 'MACS';
44 OSErr status = AECreateDesc(typeApplSignature, // type 61 OSErr status = AECreateDesc(typeApplSignature, // type
45 &finderCreatorCode, // data 62 &finderCreatorCode, // data
46 sizeof(finderCreatorCode), // dataSize 63 sizeof(finderCreatorCode), // dataSize
47 address.OutPointer()); // result 64 address.OutPointer()); // result
48 if (status != noErr) { 65 if (status != noErr) {
49 OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE target"; 66 OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE target";
50 return; 67 return;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 [[view window] isVisible]); 168 [[view window] isVisible]);
152 } 169 }
153 170
154 bool IsSwipeTrackingFromScrollEventsEnabled() { 171 bool IsSwipeTrackingFromScrollEventsEnabled() {
155 SEL selector = @selector(isSwipeTrackingFromScrollEventsEnabled); 172 SEL selector = @selector(isSwipeTrackingFromScrollEventsEnabled);
156 return [NSEvent respondsToSelector:selector] 173 return [NSEvent respondsToSelector:selector]
157 && [NSEvent performSelector:selector]; 174 && [NSEvent performSelector:selector];
158 } 175 }
159 176
160 } // namespace platform_util 177 } // namespace platform_util
OLDNEW
« no previous file with comments | « base/mac/sdk_forward_declarations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698