Commit b83907e0 authored by Robert Sesek's avatar Robert Sesek

[Mac] On Mavericks or later, use NSWorkspace to open download items.

With the NSWorkspaceLaunchWithErrorPresentation option, Finder no longer
silently fails opening the file.

BUG=32921
R=avi@chromium.org
TEST=Download a DMG file. Click the download shelf button to open/mount it. Finder activates the new disk image window as the topmost.
TEST=Download a file with an unassociated file extension type (e.g.  "test.foobar"). Click the download shelf button to open it. Finder presents the unknown file type dialog.

Review URL: https://codereview.chromium.org/613673003

Cr-Commit-Position: refs/heads/master@{#297239}
parent 5df63fb8
...@@ -285,6 +285,10 @@ typedef NSUInteger NSWindowOcclusionState; ...@@ -285,6 +285,10 @@ typedef NSUInteger NSWindowOcclusionState;
- (NSWindowOcclusionState)occlusionState; - (NSWindowOcclusionState)occlusionState;
@end @end
enum {
NSWorkspaceLaunchWithErrorPresentation = 0x00000040
};
#else // !MAC_OS_X_VERSION_10_9 #else // !MAC_OS_X_VERSION_10_9
typedef enum { typedef enum {
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mac_logging.h" #include "base/mac/mac_logging.h"
#import "base/mac/mac_util.h"
#import "base/mac/sdk_forward_declarations.h"
#include "base/mac/scoped_aedesc.h" #include "base/mac/scoped_aedesc.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -25,19 +27,35 @@ void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { ...@@ -25,19 +27,35 @@ void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value(); LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value();
} }
// This function opens a file. This doesn't use LaunchServices or NSWorkspace
// because of two bugs:
// 1. Incorrect app activation with com.apple.quarantine:
// http://crbug.com/32921
// 2. Silent no-op for unassociated file types: http://crbug.com/50263
// Instead, an AppleEvent is constructed to tell the Finder to open the
// document.
void OpenItem(Profile* profile, const base::FilePath& full_path) { void OpenItem(Profile* profile, const base::FilePath& full_path) {
DCHECK([NSThread isMainThread]); DCHECK([NSThread isMainThread]);
NSString* path_string = base::SysUTF8ToNSString(full_path.value()); NSString* path_string = base::SysUTF8ToNSString(full_path.value());
if (!path_string) if (!path_string)
return; return;
// On Mavericks or later, NSWorkspaceLaunchWithErrorPresentation will
// properly handle Finder activation for quarantined files
// (http://crbug.com/32921) and unassociated file types
// (http://crbug.com/50263).
if (base::mac::IsOSMavericksOrLater()) {
NSURL* url = [NSURL fileURLWithPath:path_string];
if (!url)
return;
const NSWorkspaceLaunchOptions launch_options =
NSWorkspaceLaunchAsync | NSWorkspaceLaunchWithErrorPresentation;
[[NSWorkspace sharedWorkspace] openURLs:@[ url ]
withAppBundleIdentifier:nil
options:launch_options
additionalEventParamDescriptor:nil
launchIdentifiers:NULL];
return;
}
// On older OSes, both LaunchServices and NSWorkspace will fail silently for
// the two cases described above. On those platforms, use an AppleEvent to
// instruct the Finder to open the file.
// Create the target of this AppleEvent, the Finder. // Create the target of this AppleEvent, the Finder.
base::mac::ScopedAEDesc<AEAddressDesc> address; base::mac::ScopedAEDesc<AEAddressDesc> address;
const OSType finderCreatorCode = 'MACS'; const OSType finderCreatorCode = 'MACS';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment