OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/test/automation/value_conversion_traits.h" | 5 #include "chrome/test/automation/value_conversion_traits.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 | 8 |
9 using base::DictionaryValue; | 9 using base::DictionaryValue; |
10 using base::ListValue; | 10 using base::ListValue; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 bool ValueConversionTraits<Value*>::CanConvert(const Value* value) { | 64 bool ValueConversionTraits<Value*>::CanConvert(const Value* value) { |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 Value* ValueConversionTraits<ListValue*>::CreateValueFrom(const ListValue* t) { | 68 Value* ValueConversionTraits<ListValue*>::CreateValueFrom(const ListValue* t) { |
69 return t->DeepCopy(); | 69 return t->DeepCopy(); |
70 } | 70 } |
71 | 71 |
72 bool ValueConversionTraits<ListValue*>::SetFromValue(const Value* value, | 72 bool ValueConversionTraits<ListValue*>::SetFromValue(const Value* value, |
73 ListValue** t) { | 73 ListValue** t) { |
74 if (!value->IsType(Value::TYPE_LIST)) | 74 ListValue* list = const_cast<Value*>(value)->AsList(); |
| 75 if (!list) |
75 return false; | 76 return false; |
76 *t = static_cast<const ListValue*>(value)->DeepCopy(); | 77 *t = list->DeepCopy(); |
77 return true; | 78 return true; |
78 } | 79 } |
79 | 80 |
80 bool ValueConversionTraits<ListValue*>::CanConvert(const Value* value) { | 81 bool ValueConversionTraits<ListValue*>::CanConvert(const Value* value) { |
81 return value->IsType(Value::TYPE_LIST); | 82 return const_cast<Value*>(value)->AsList(); |
82 } | 83 } |
83 | 84 |
84 Value* ValueConversionTraits<DictionaryValue*>::CreateValueFrom( | 85 Value* ValueConversionTraits<DictionaryValue*>::CreateValueFrom( |
85 const DictionaryValue* t) { | 86 const DictionaryValue* t) { |
86 return t->DeepCopy(); | 87 return t->DeepCopy(); |
87 } | 88 } |
88 | 89 |
89 bool ValueConversionTraits<DictionaryValue*>::SetFromValue( | 90 bool ValueConversionTraits<DictionaryValue*>::SetFromValue( |
90 const Value* value, DictionaryValue** t) { | 91 const Value* value, DictionaryValue** t) { |
91 if (!value->IsType(Value::TYPE_DICTIONARY)) | 92 if (!value->IsType(Value::TYPE_DICTIONARY)) |
92 return false; | 93 return false; |
93 *t = static_cast<const DictionaryValue*>(value)->DeepCopy(); | 94 *t = static_cast<const DictionaryValue*>(value)->DeepCopy(); |
94 return true; | 95 return true; |
95 } | 96 } |
96 | 97 |
97 bool ValueConversionTraits<DictionaryValue*>::CanConvert(const Value* value) { | 98 bool ValueConversionTraits<DictionaryValue*>::CanConvert(const Value* value) { |
98 return value->IsType(Value::TYPE_DICTIONARY); | 99 return value->IsType(Value::TYPE_DICTIONARY); |
99 } | 100 } |
OLD | NEW |