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

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

Issue 3828009: Move scoped_nsdisable_screen_update from base to app/mac... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #import <CoreServices/CoreServices.h> 8 #import <CoreServices/CoreServices.h>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/l10n_util_mac.h" 11 #include "app/l10n_util_mac.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/mac_util.h" 14 #include "base/mac_util.h"
15 #include "base/scoped_aedesc.h" 15 #include "base/mac/scoped_aedesc.h"
16 #include "base/sys_string_conversions.h" 16 #include "base/sys_string_conversions.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.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_EQ([NSThread currentThread], [NSThread mainThread]);
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
(...skipping 10 matching lines...) Expand all
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_EQ([NSThread currentThread], [NSThread mainThread]);
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 scoped_aedesc<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
49 &finderCreatorCode, // data 49 &finderCreatorCode, // data
50 sizeof(finderCreatorCode), // dataSize 50 sizeof(finderCreatorCode), // dataSize
51 address.OutPointer()); // result 51 address.OutPointer()); // result
52 if (status != noErr) { 52 if (status != noErr) {
53 LOG(WARNING) << "Could not create OpenItem() AE target"; 53 LOG(WARNING) << "Could not create OpenItem() AE target";
54 return; 54 return;
55 } 55 }
56 56
57 // Build the AppleEvent data structure that instructs Finder to open files. 57 // Build the AppleEvent data structure that instructs Finder to open files.
58 scoped_aedesc<AppleEvent> theEvent; 58 base::mac::ScopedAEDesc<AppleEvent> theEvent;
59 status = AECreateAppleEvent(kCoreEventClass, // theAEEventClass 59 status = AECreateAppleEvent(kCoreEventClass, // theAEEventClass
60 kAEOpenDocuments, // theAEEventID 60 kAEOpenDocuments, // theAEEventID
61 address, // target 61 address, // target
62 kAutoGenerateReturnID, // returnID 62 kAutoGenerateReturnID, // returnID
63 kAnyTransactionID, // transactionID 63 kAnyTransactionID, // transactionID
64 theEvent.OutPointer()); // result 64 theEvent.OutPointer()); // result
65 if (status != noErr) { 65 if (status != noErr) {
66 LOG(WARNING) << "Could not create OpenItem() AE event"; 66 LOG(WARNING) << "Could not create OpenItem() AE event";
67 return; 67 return;
68 } 68 }
69 69
70 // Create the list of files (only ever one) to open. 70 // Create the list of files (only ever one) to open.
71 scoped_aedesc<AEDescList> fileList; 71 base::mac::ScopedAEDesc<AEDescList> fileList;
72 status = AECreateList(NULL, // factoringPtr 72 status = AECreateList(NULL, // factoringPtr
73 0, // factoredSize 73 0, // factoredSize
74 false, // isRecord 74 false, // isRecord
75 fileList.OutPointer()); // resultList 75 fileList.OutPointer()); // resultList
76 if (status != noErr) { 76 if (status != noErr) {
77 LOG(WARNING) << "Could not create OpenItem() AE file list"; 77 LOG(WARNING) << "Could not create OpenItem() AE file list";
78 return; 78 return;
79 } 79 }
80 80
81 // Add the single path to the file list. C-style cast to avoid both a 81 // Add the single path to the file list. C-style cast to avoid both a
(...skipping 18 matching lines...) Expand all
100 // Attach the file list to the AppleEvent. 100 // Attach the file list to the AppleEvent.
101 status = AEPutParamDesc(theEvent.OutPointer(), // theAppleEvent 101 status = AEPutParamDesc(theEvent.OutPointer(), // theAppleEvent
102 keyDirectObject, // theAEKeyword 102 keyDirectObject, // theAEKeyword
103 fileList); // theAEDesc 103 fileList); // theAEDesc
104 if (status != noErr) { 104 if (status != noErr) {
105 LOG(WARNING) << "Could not put the AE file list the path in OpenItem()"; 105 LOG(WARNING) << "Could not put the AE file list the path in OpenItem()";
106 return; 106 return;
107 } 107 }
108 108
109 // Send the actual event. Do not care about the reply. 109 // Send the actual event. Do not care about the reply.
110 scoped_aedesc<AppleEvent> reply; 110 base::mac::ScopedAEDesc<AppleEvent> reply;
111 status = AESend(theEvent, // theAppleEvent 111 status = AESend(theEvent, // theAppleEvent
112 reply.OutPointer(), // reply 112 reply.OutPointer(), // reply
113 kAENoReply + kAEAlwaysInteract, // sendMode 113 kAENoReply + kAEAlwaysInteract, // sendMode
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 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 channel = @"unknown"; 196 channel = @"unknown";
197 } 197 }
198 198
199 return base::SysNSStringToUTF8(channel); 199 return base::SysNSStringToUTF8(channel);
200 #else 200 #else
201 return std::string(); 201 return std::string();
202 #endif 202 #endif
203 } 203 }
204 204
205 } // namespace platform_util 205 } // namespace platform_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698