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

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

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 #import "chrome/browser/ui/cocoa/applescript/apple_event_util.h" 5 #import "chrome/browser/ui/cocoa/applescript/apple_event_util.h"
6 6
7 #import <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 13
14 namespace chrome { 14 namespace chrome {
15 namespace mac { 15 namespace mac {
16 16
17 NSAppleEventDescriptor* ValueToAppleEventDescriptor(const base::Value* value) { 17 NSAppleEventDescriptor* ValueToAppleEventDescriptor(const base::Value* value) {
18 NSAppleEventDescriptor* descriptor = nil; 18 NSAppleEventDescriptor* descriptor = nil;
19 19
20 switch (value->GetType()) { 20 switch (value->GetType()) {
21 case base::Value::TYPE_NULL: 21 case base::Value::Type::NONE:
22 descriptor = [NSAppleEventDescriptor 22 descriptor = [NSAppleEventDescriptor
23 descriptorWithTypeCode:cMissingValue]; 23 descriptorWithTypeCode:cMissingValue];
24 break; 24 break;
25 25
26 case base::Value::TYPE_BOOLEAN: { 26 case base::Value::Type::BOOLEAN: {
27 bool bool_value; 27 bool bool_value;
28 value->GetAsBoolean(&bool_value); 28 value->GetAsBoolean(&bool_value);
29 descriptor = [NSAppleEventDescriptor descriptorWithBoolean:bool_value]; 29 descriptor = [NSAppleEventDescriptor descriptorWithBoolean:bool_value];
30 break; 30 break;
31 } 31 }
32 32
33 case base::Value::TYPE_INTEGER: { 33 case base::Value::Type::INTEGER: {
34 int int_value; 34 int int_value;
35 value->GetAsInteger(&int_value); 35 value->GetAsInteger(&int_value);
36 descriptor = [NSAppleEventDescriptor descriptorWithInt32:int_value]; 36 descriptor = [NSAppleEventDescriptor descriptorWithInt32:int_value];
37 break; 37 break;
38 } 38 }
39 39
40 case base::Value::TYPE_DOUBLE: { 40 case base::Value::Type::DOUBLE: {
41 double double_value; 41 double double_value;
42 value->GetAsDouble(&double_value); 42 value->GetAsDouble(&double_value);
43 descriptor = [NSAppleEventDescriptor 43 descriptor = [NSAppleEventDescriptor
44 descriptorWithDescriptorType:typeIEEE64BitFloatingPoint 44 descriptorWithDescriptorType:typeIEEE64BitFloatingPoint
45 bytes:&double_value 45 bytes:&double_value
46 length:sizeof(double_value)]; 46 length:sizeof(double_value)];
47 break; 47 break;
48 } 48 }
49 49
50 case base::Value::TYPE_STRING: { 50 case base::Value::Type::STRING: {
51 std::string string_value; 51 std::string string_value;
52 value->GetAsString(&string_value); 52 value->GetAsString(&string_value);
53 descriptor = [NSAppleEventDescriptor descriptorWithString: 53 descriptor = [NSAppleEventDescriptor descriptorWithString:
54 base::SysUTF8ToNSString(string_value)]; 54 base::SysUTF8ToNSString(string_value)];
55 break; 55 break;
56 } 56 }
57 57
58 case base::Value::TYPE_BINARY: 58 case base::Value::Type::BINARY:
59 NOTREACHED(); 59 NOTREACHED();
60 break; 60 break;
61 61
62 case base::Value::TYPE_DICTIONARY: { 62 case base::Value::Type::DICTIONARY: {
63 const base::DictionaryValue* dictionary_value; 63 const base::DictionaryValue* dictionary_value;
64 value->GetAsDictionary(&dictionary_value); 64 value->GetAsDictionary(&dictionary_value);
65 descriptor = [NSAppleEventDescriptor recordDescriptor]; 65 descriptor = [NSAppleEventDescriptor recordDescriptor];
66 NSAppleEventDescriptor* userRecord = [NSAppleEventDescriptor 66 NSAppleEventDescriptor* userRecord = [NSAppleEventDescriptor
67 listDescriptor]; 67 listDescriptor];
68 for (base::DictionaryValue::Iterator iter(*dictionary_value); 68 for (base::DictionaryValue::Iterator iter(*dictionary_value);
69 !iter.IsAtEnd(); 69 !iter.IsAtEnd();
70 iter.Advance()) { 70 iter.Advance()) {
71 [userRecord insertDescriptor:[NSAppleEventDescriptor 71 [userRecord insertDescriptor:[NSAppleEventDescriptor
72 descriptorWithString:base::SysUTF8ToNSString(iter.key())] 72 descriptorWithString:base::SysUTF8ToNSString(iter.key())]
73 atIndex:0]; 73 atIndex:0];
74 [userRecord insertDescriptor:ValueToAppleEventDescriptor(&iter.value()) 74 [userRecord insertDescriptor:ValueToAppleEventDescriptor(&iter.value())
75 atIndex:0]; 75 atIndex:0];
76 } 76 }
77 // Description of what keyASUserRecordFields does. 77 // Description of what keyASUserRecordFields does.
78 // http://lists.apple.com/archives/cocoa-dev/2009/Jul/msg01216.html 78 // http://lists.apple.com/archives/cocoa-dev/2009/Jul/msg01216.html
79 [descriptor setDescriptor:userRecord forKeyword:keyASUserRecordFields]; 79 [descriptor setDescriptor:userRecord forKeyword:keyASUserRecordFields];
80 break; 80 break;
81 } 81 }
82 82
83 case base::Value::TYPE_LIST: { 83 case base::Value::Type::LIST: {
84 const base::ListValue* list_value; 84 const base::ListValue* list_value;
85 value->GetAsList(&list_value); 85 value->GetAsList(&list_value);
86 descriptor = [NSAppleEventDescriptor listDescriptor]; 86 descriptor = [NSAppleEventDescriptor listDescriptor];
87 for (size_t i = 0; i < list_value->GetSize(); ++i) { 87 for (size_t i = 0; i < list_value->GetSize(); ++i) {
88 const base::Value* item; 88 const base::Value* item;
89 list_value->Get(i, &item); 89 list_value->Get(i, &item);
90 [descriptor insertDescriptor:ValueToAppleEventDescriptor(item) 90 [descriptor insertDescriptor:ValueToAppleEventDescriptor(item)
91 atIndex:0]; 91 atIndex:0];
92 } 92 }
93 break; 93 break;
94 } 94 }
95 } 95 }
96 96
97 return descriptor; 97 return descriptor;
98 } 98 }
99 99
100 } // namespace mac 100 } // namespace mac
101 } // namespace chrome 101 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698