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

Side by Side Diff: webrtc/base/macutils.cc

Issue 2321493002: Reland of move all reference to carbon api (Closed)
Patch Set: fix chromium build issues Created 4 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 unified diff | Download patch
« no previous file with comments | « webrtc/base/macutils.h ('k') | webrtc/base/macutils_unittest.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 /* 1 /*
2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 #include <sstream> 12 #include <sstream>
13 13
14 #include <CoreServices/CoreServices.h>
15
14 #include "webrtc/base/common.h" 16 #include "webrtc/base/common.h"
15 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
16 #include "webrtc/base/macutils.h" 18 #include "webrtc/base/macutils.h"
17 #include "webrtc/base/stringutils.h" 19 #include "webrtc/base/stringutils.h"
18 20
19 namespace rtc { 21 namespace rtc {
20 22
21 /////////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////////
22 24
23 bool ToUtf8(const CFStringRef str16, std::string* str8) { 25 bool ToUtf8(const CFStringRef str16, std::string* str8) {
(...skipping 15 matching lines...) Expand all
39 if (NULL == str16) { 41 if (NULL == str16) {
40 return false; 42 return false;
41 } 43 }
42 *str16 = CFStringCreateWithBytes(kCFAllocatorDefault, 44 *str16 = CFStringCreateWithBytes(kCFAllocatorDefault,
43 reinterpret_cast<const UInt8*>(str8.data()), 45 reinterpret_cast<const UInt8*>(str8.data()),
44 str8.length(), kCFStringEncodingUTF8, 46 str8.length(), kCFStringEncodingUTF8,
45 false); 47 false);
46 return NULL != *str16; 48 return NULL != *str16;
47 } 49 }
48 50
49 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
50 void DecodeFourChar(UInt32 fc, std::string* out) { 51 void DecodeFourChar(UInt32 fc, std::string* out) {
51 std::stringstream ss; 52 std::stringstream ss;
52 ss << '\''; 53 ss << '\'';
53 bool printable = true; 54 bool printable = true;
54 for (int i = 3; i >= 0; --i) { 55 for (int i = 3; i >= 0; --i) {
55 char ch = (fc >> (8 * i)) & 0xFF; 56 char ch = (fc >> (8 * i)) & 0xFF;
56 if (isprint(static_cast<unsigned char>(ch))) { 57 if (isprint(static_cast<unsigned char>(ch))) {
57 ss << ch; 58 ss << ch;
58 } else { 59 } else {
59 printable = false; 60 printable = false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return kMacOSSnowLeopard; 122 return kMacOSSnowLeopard;
122 case 7: 123 case 7:
123 return kMacOSLion; 124 return kMacOSLion;
124 case 8: 125 case 8:
125 return kMacOSMountainLion; 126 return kMacOSMountainLion;
126 case 9: 127 case 9:
127 return kMacOSMavericks; 128 return kMacOSMavericks;
128 } 129 }
129 return kMacOSNewer; 130 return kMacOSNewer;
130 } 131 }
131
132 bool RunAppleScript(const std::string& script) {
133 // TODO(thaloun): Add a .mm file that contains something like this:
134 // NSString source from script
135 // NSAppleScript* appleScript = [[NSAppleScript alloc] initWithSource:&source]
136 // if (appleScript != nil) {
137 // [appleScript executeAndReturnError:nil]
138 // [appleScript release]
139 #ifndef CARBON_DEPRECATED
140 ComponentInstance component = NULL;
141 AEDesc script_desc;
142 AEDesc result_data;
143 OSStatus err;
144 OSAID script_id, result_id;
145
146 AECreateDesc(typeNull, NULL, 0, &script_desc);
147 AECreateDesc(typeNull, NULL, 0, &result_data);
148 script_id = kOSANullScript;
149 result_id = kOSANullScript;
150
151 component = OpenDefaultComponent(kOSAComponentType, typeAppleScript);
152 if (component == NULL) {
153 LOG(LS_ERROR) << "Failed opening Apple Script component";
154 return false;
155 }
156 err = AECreateDesc(typeUTF8Text, script.data(), script.size(), &script_desc);
157 if (err != noErr) {
158 CloseComponent(component);
159 LOG(LS_ERROR) << "Failed creating Apple Script description";
160 return false;
161 }
162
163 err = OSACompile(component, &script_desc, kOSAModeCanInteract, &script_id);
164 if (err != noErr) {
165 AEDisposeDesc(&script_desc);
166 if (script_id != kOSANullScript) {
167 OSADispose(component, script_id);
168 }
169 CloseComponent(component);
170 LOG(LS_ERROR) << "Error compiling Apple Script";
171 return false;
172 }
173
174 err = OSAExecute(component, script_id, kOSANullScript, kOSAModeCanInteract,
175 &result_id);
176
177 if (err == errOSAScriptError) {
178 LOG(LS_ERROR) << "Error when executing Apple Script: " << script;
179 AECreateDesc(typeNull, NULL, 0, &result_data);
180 OSAScriptError(component, kOSAErrorMessage, typeChar, &result_data);
181 int len = AEGetDescDataSize(&result_data);
182 char* data = (char*)malloc(len);
183 if (data != NULL) {
184 err = AEGetDescData(&result_data, data, len);
185 LOG(LS_ERROR) << "Script error: " << std::string(data, len);
186 }
187 AEDisposeDesc(&script_desc);
188 AEDisposeDesc(&result_data);
189 return false;
190 }
191 AEDisposeDesc(&script_desc);
192 if (script_id != kOSANullScript) {
193 OSADispose(component, script_id);
194 }
195 if (result_id != kOSANullScript) {
196 OSADispose(component, result_id);
197 }
198 CloseComponent(component);
199 return true;
200 #else
201 // TODO(thaloun): Support applescripts with the NSAppleScript API.
202 return false;
203 #endif // CARBON_DEPRECATED
204 }
205 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
206
207 ///////////////////////////////////////////////////////////////////////////////
208
209 } // namespace rtc 132 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/macutils.h ('k') | webrtc/base/macutils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698