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

Side by Side Diff: chrome/browser/ui/cocoa/applescript/apple_event_util.mm

Issue 11742028: Suspend Apple Events during their processing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 7 years, 11 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/applescript/apple_event_util.h"
6
7 #import <Carbon/Carbon.h>
8
9 #include "base/logging.h"
10 #include "base/sys_string_conversions.h"
11 #include "base/values.h"
12
13 namespace chrome {
14 namespace mac {
15
16 NSAppleEventDescriptor* ValueToAppleEventDescriptor(const base::Value* value) {
17 NSAppleEventDescriptor* descriptor = nil;
18
19 switch (value->GetType()) {
20 case base::Value::TYPE_NULL:
21 descriptor = [NSAppleEventDescriptor
22 descriptorWithTypeCode:cMissingValue];
23 break;
24
25 case base::Value::TYPE_BOOLEAN: {
26 bool bool_value;
27 value->GetAsBoolean(&bool_value);
28 descriptor = [NSAppleEventDescriptor descriptorWithBoolean:bool_value];
29 break;
30 }
31
32 case base::Value::TYPE_INTEGER: {
33 int int_value;
34 value->GetAsInteger(&int_value);
35 descriptor = [NSAppleEventDescriptor descriptorWithInt32:int_value];
36 break;
37 }
38
39 case base::Value::TYPE_DOUBLE: {
40 double double_value;
41 value->GetAsDouble(&double_value);
42 descriptor = [NSAppleEventDescriptor
43 descriptorWithDescriptorType:typeIEEE64BitFloatingPoint
44 bytes:&double_value
45 length:sizeof(double_value)];
46 break;
47 }
48
49 case base::Value::TYPE_STRING: {
50 std::string string_value;
51 value->GetAsString(&string_value);
52 descriptor = [NSAppleEventDescriptor descriptorWithString:
53 base::SysUTF8ToNSString(string_value)];
54 break;
55 }
56
57 case base::Value::TYPE_BINARY:
58 NOTREACHED();
59 break;
60
61 case base::Value::TYPE_DICTIONARY: {
62 const base::DictionaryValue* dictionary_value;
63 value->GetAsDictionary(&dictionary_value);
64 descriptor = [NSAppleEventDescriptor recordDescriptor];
65 NSAppleEventDescriptor* userRecord = [NSAppleEventDescriptor
66 listDescriptor];
67 for (DictionaryValue::key_iterator iter(dictionary_value->begin_keys());
68 iter != dictionary_value->end_keys(); ++iter) {
69 const base::Value* item;
70 if (dictionary_value->Get(*iter, &item)) {
71 [userRecord insertDescriptor:[NSAppleEventDescriptor
72 descriptorWithString:base::SysUTF8ToNSString(*iter)]
73 atIndex:0];
74 [userRecord insertDescriptor:ValueToAppleEventDescriptor(item)
75 atIndex:0];
76 }
77 }
78 // Description of what keyASUserRecordFields does.
79 // http://lists.apple.com/archives/cocoa-dev/2009/Jul/msg01216.html
80 [descriptor setDescriptor:userRecord forKeyword:keyASUserRecordFields];
81 break;
82 }
83
84 case base::Value::TYPE_LIST: {
85 const base::ListValue* list_value;
86 value->GetAsList(&list_value);
87 descriptor = [NSAppleEventDescriptor listDescriptor];
88 for (size_t i = 0; i < list_value->GetSize(); ++i) {
89 const base::Value* item;
90 list_value->Get(i, &item);
91 [descriptor insertDescriptor:ValueToAppleEventDescriptor(item)
92 atIndex:0];
93 }
94 break;
95 }
96 }
97
98 return descriptor;
99 }
100
101 } // namespace mac
102 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698