OLD | NEW |
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 |
(...skipping 28 matching lines...) Expand all Loading... |
39 if (NULL == str16) { | 39 if (NULL == str16) { |
40 return false; | 40 return false; |
41 } | 41 } |
42 *str16 = CFStringCreateWithBytes(kCFAllocatorDefault, | 42 *str16 = CFStringCreateWithBytes(kCFAllocatorDefault, |
43 reinterpret_cast<const UInt8*>(str8.data()), | 43 reinterpret_cast<const UInt8*>(str8.data()), |
44 str8.length(), kCFStringEncodingUTF8, | 44 str8.length(), kCFStringEncodingUTF8, |
45 false); | 45 false); |
46 return NULL != *str16; | 46 return NULL != *str16; |
47 } | 47 } |
48 | 48 |
| 49 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
49 void DecodeFourChar(UInt32 fc, std::string* out) { | 50 void DecodeFourChar(UInt32 fc, std::string* out) { |
50 std::stringstream ss; | 51 std::stringstream ss; |
51 ss << '\''; | 52 ss << '\''; |
52 bool printable = true; | 53 bool printable = true; |
53 for (int i = 3; i >= 0; --i) { | 54 for (int i = 3; i >= 0; --i) { |
54 char ch = (fc >> (8 * i)) & 0xFF; | 55 char ch = (fc >> (8 * i)) & 0xFF; |
55 if (isprint(static_cast<unsigned char>(ch))) { | 56 if (isprint(static_cast<unsigned char>(ch))) { |
56 ss << ch; | 57 ss << ch; |
57 } else { | 58 } else { |
58 printable = false; | 59 printable = false; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return kMacOSSnowLeopard; | 121 return kMacOSSnowLeopard; |
121 case 7: | 122 case 7: |
122 return kMacOSLion; | 123 return kMacOSLion; |
123 case 8: | 124 case 8: |
124 return kMacOSMountainLion; | 125 return kMacOSMountainLion; |
125 case 9: | 126 case 9: |
126 return kMacOSMavericks; | 127 return kMacOSMavericks; |
127 } | 128 } |
128 return kMacOSNewer; | 129 return kMacOSNewer; |
129 } | 130 } |
| 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 |
130 } // namespace rtc | 209 } // namespace rtc |
OLD | NEW |