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

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

Issue 8457004: platform_util::OpenItem fixes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/platform_util_linux.cc ('k') | chrome/browser/platform_util_win.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_path.h" 11 #include "base/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/scoped_aedesc.h" 13 #include "base/mac/scoped_aedesc.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/l10n/l10n_util_mac.h" 18 #include "ui/base/l10n/l10n_util_mac.h"
19 19
20 namespace platform_util { 20 namespace platform_util {
21 21
22 void ShowItemInFolder(const FilePath& full_path) { 22 void ShowItemInFolder(const FilePath& full_path) {
23 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); 23 DCHECK([NSThread isMainThread]);
24 NSString* path_string = base::SysUTF8ToNSString(full_path.value()); 24 NSString* path_string = base::SysUTF8ToNSString(full_path.value());
25 if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string 25 if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string
26 inFileViewerRootedAtPath:nil]) 26 inFileViewerRootedAtPath:nil])
27 LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value(); 27 LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value();
28 } 28 }
29 29
30 // 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
31 // because of two bugs: 31 // because of two bugs:
32 // 1. Incorrect app activation with com.apple.quarantine: 32 // 1. Incorrect app activation with com.apple.quarantine:
33 // http://crbug.com/32921 33 // http://crbug.com/32921
34 // 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
35 // 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
36 // document. 36 // document.
37 void OpenItem(const FilePath& full_path) { 37 void OpenItem(const FilePath& full_path) {
38 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); 38 DCHECK([NSThread isMainThread]);
39 NSString* path_string = base::SysUTF8ToNSString(full_path.value()); 39 NSString* path_string = base::SysUTF8ToNSString(full_path.value());
40 if (!path_string) 40 if (!path_string)
41 return; 41 return;
42 42
43 OSErr status; 43 OSErr status;
44 44
45 // Create the target of this AppleEvent, the Finder. 45 // Create the target of this AppleEvent, the Finder.
46 base::mac::ScopedAEDesc<AEAddressDesc> address; 46 base::mac::ScopedAEDesc<AEAddressDesc> address;
47 const OSType finderCreatorCode = 'MACS'; 47 const OSType finderCreatorCode = 'MACS';
48 status = AECreateDesc(typeApplSignature, // type 48 status = AECreateDesc(typeApplSignature, // type
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 kAENormalPriority, // sendPriority 114 kAENormalPriority, // sendPriority
115 kAEDefaultTimeout, // timeOutInTicks 115 kAEDefaultTimeout, // timeOutInTicks
116 NULL, // idleProc 116 NULL, // idleProc
117 NULL); // filterProc 117 NULL); // filterProc
118 if (status != noErr) { 118 if (status != noErr) {
119 LOG(WARNING) << "Could not send AE to Finder in OpenItem()"; 119 LOG(WARNING) << "Could not send AE to Finder in OpenItem()";
120 } 120 }
121 } 121 }
122 122
123 void OpenExternal(const GURL& url) { 123 void OpenExternal(const GURL& url) {
124 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); 124 DCHECK([NSThread isMainThread]);
125 NSString* url_string = base::SysUTF8ToNSString(url.spec()); 125 NSString* url_string = base::SysUTF8ToNSString(url.spec());
126 NSURL* ns_url = [NSURL URLWithString:url_string]; 126 NSURL* ns_url = [NSURL URLWithString:url_string];
127 if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url]) 127 if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url])
128 LOG(WARNING) << "NSWorkspace failed to open URL " << url; 128 LOG(WARNING) << "NSWorkspace failed to open URL " << url;
129 } 129 }
130 130
131 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { 131 gfx::NativeWindow GetTopLevel(gfx::NativeView view) {
132 return [view window]; 132 return [view window];
133 } 133 }
134 134
(...skipping 11 matching lines...) Expand all
146 146
147 bool IsVisible(gfx::NativeView view) { 147 bool IsVisible(gfx::NativeView view) {
148 // A reasonable approximation of how you'd expect this to behave. 148 // A reasonable approximation of how you'd expect this to behave.
149 return (view && 149 return (view &&
150 ![view isHiddenOrHasHiddenAncestor] && 150 ![view isHiddenOrHasHiddenAncestor] &&
151 [view window] && 151 [view window] &&
152 [[view window] isVisible]); 152 [[view window] isVisible]);
153 } 153 }
154 154
155 } // namespace platform_util 155 } // namespace platform_util
OLDNEW
« no previous file with comments | « chrome/browser/platform_util_linux.cc ('k') | chrome/browser/platform_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698