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

Unified 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: Fix bad upload Created 6 years, 3 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/sdk_forward_declarations.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/platform_util_mac.mm
diff --git a/chrome/browser/platform_util_mac.mm b/chrome/browser/platform_util_mac.mm
index 20afdcd498551dc62f38e74f641dbd444b5b4003..ef5fbe7f99849677c830763b36a5e4caf3d5d2c9 100644
--- a/chrome/browser/platform_util_mac.mm
+++ b/chrome/browser/platform_util_mac.mm
@@ -11,6 +11,8 @@
#include "base/files/file_path.h"
#include "base/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/strings/sys_string_conversions.h"
#include "url/gurl.h"
@@ -25,19 +27,35 @@ void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
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) {
DCHECK([NSThread isMainThread]);
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
if (!path_string)
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.
base::mac::ScopedAEDesc<AEAddressDesc> address;
const OSType finderCreatorCode = 'MACS';
« 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