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

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

Issue 11734035: Add unit test for Value > AEDesc conversion. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/values.h"
11 #include "base/sys_string_conversions.h"
12
13 NSAppleEventDescriptor* ValueToAppleEventDescriptor(const base::Value* value) {
14 NSAppleEventDescriptor* descriptor = nil;
15
16 switch (value->GetType()) {
17 case base::Value::TYPE_NULL:
18 descriptor = [NSAppleEventDescriptor
19 descriptorWithTypeCode:cMissingValue];
20 break;
21
22 case base::Value::TYPE_BOOLEAN: {
23 bool bool_value;
24 value->GetAsBoolean(&bool_value);
25 descriptor = [NSAppleEventDescriptor descriptorWithBoolean:bool_value];
26 break;
27 }
28
29 case base::Value::TYPE_INTEGER: {
30 int int_value;
31 value->GetAsInteger(&int_value);
32 descriptor = [NSAppleEventDescriptor descriptorWithInt32:int_value];
33 break;
34 }
35
36 case base::Value::TYPE_DOUBLE: {
37 double double_value;
38 value->GetAsDouble(&double_value);
39 descriptor = [NSAppleEventDescriptor
40 descriptorWithDescriptorType:typeIEEE64BitFloatingPoint
41 bytes:&double_value
42 length:sizeof(double_value)];
43 break;
44 }
45
46 case base::Value::TYPE_STRING: {
47 std::string string_value;
48 value->GetAsString(&string_value);
49 descriptor = [NSAppleEventDescriptor descriptorWithString:
50 base::SysUTF8ToNSString(string_value)];
51 break;
52 }
53
54 case base::Value::TYPE_BINARY:
55 NOTREACHED();
56 break;
57
58 case base::Value::TYPE_DICTIONARY: {
59 const base::DictionaryValue* dictionary_value =
60 static_cast<const base::DictionaryValue*>(value);
61 descriptor = [NSAppleEventDescriptor recordDescriptor];
62 NSAppleEventDescriptor* userRecord = [NSAppleEventDescriptor
63 listDescriptor];
64 for (DictionaryValue::key_iterator iter(dictionary_value->begin_keys());
65 iter != dictionary_value->end_keys(); ++iter) {
66 const base::Value* item;
67 if (dictionary_value->Get(*iter, &item)) {
68 [userRecord insertDescriptor:[NSAppleEventDescriptor
69 descriptorWithString:base::SysUTF8ToNSString(*iter)]
70 atIndex:0];
71 [userRecord insertDescriptor:ValueToAppleEventDescriptor(item)
72 atIndex:0];
73 }
74 }
75 // Description of what keyASUserRecordFields does.
76 // http://lists.apple.com/archives/cocoa-dev/2009/Jul/msg01216.html
77 [descriptor setDescriptor:userRecord forKeyword:keyASUserRecordFields];
78 break;
79 }
80
81 case base::Value::TYPE_LIST: {
82 const base::ListValue* list_value;
83 value->GetAsList(&list_value);
84 descriptor = [NSAppleEventDescriptor listDescriptor];
85 for (unsigned i = 0; i < list_value->GetSize(); ++i) {
86 const base::Value* item;
87 list_value->Get(i, &item);
88 [descriptor insertDescriptor:ValueToAppleEventDescriptor(item)
89 atIndex:0];
90 }
91 break;
92 }
93 }
94
95 return descriptor;
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698