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 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 5 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 template <typename T> | 45 template <typename T> |
46 struct ValueConversionTraits<std::vector<T> > { | 46 struct ValueConversionTraits<std::vector<T> > { |
47 static Value* CreateValueFrom(const std::vector<T>& t) { | 47 static Value* CreateValueFrom(const std::vector<T>& t) { |
48 ListValue* value = new ListValue(); | 48 ListValue* value = new ListValue(); |
49 for (size_t i = 0; i < t.size(); i++) { | 49 for (size_t i = 0; i < t.size(); i++) { |
50 value->Append(ValueConversionTraits<T>::CreateValueFrom(t[i])); | 50 value->Append(ValueConversionTraits<T>::CreateValueFrom(t[i])); |
51 } | 51 } |
52 return value; | 52 return value; |
53 } | 53 } |
54 static bool SetFromValue(Value* value, std::vector<T>* t) { | 54 static bool SetFromValue(const Value* value, std::vector<T>* t) { |
55 ListValue* list_value = value->AsList(); | 55 if (!value->IsType(Value::TYPE_LIST)) |
56 if (!list_value) | |
57 return false; | 56 return false; |
58 | 57 |
| 58 const ListValue* list_value = static_cast<const ListValue*>(value); |
59 ListValue::const_iterator iter; | 59 ListValue::const_iterator iter; |
60 for (iter = list_value->begin(); iter != list_value->end(); ++iter) { | 60 for (iter = list_value->begin(); iter != list_value->end(); ++iter) { |
61 if (!ValueConversionTraits<T>::CanConvert(*iter)) | 61 if (!ValueConversionTraits<T>::CanConvert(*iter)) |
62 return false; | 62 return false; |
63 } | 63 } |
64 for (iter = list_value->begin(); iter != list_value->end(); ++iter) { | 64 for (iter = list_value->begin(); iter != list_value->end(); ++iter) { |
65 T inner_value; | 65 T inner_value; |
66 ValueConversionTraits<T>::SetFromValue(*iter, &inner_value); | 66 ValueConversionTraits<T>::SetFromValue(*iter, &inner_value); |
67 t->push_back(inner_value); | 67 t->push_back(inner_value); |
68 } | 68 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 const T2& arg2, const T3& arg3) { | 103 const T2& arg2, const T3& arg3) { |
104 return base::StringPrintf(format.c_str(), | 104 return base::StringPrintf(format.c_str(), |
105 JSONStringify(arg1).c_str(), | 105 JSONStringify(arg1).c_str(), |
106 JSONStringify(arg2).c_str(), | 106 JSONStringify(arg2).c_str(), |
107 JSONStringify(arg3).c_str()); | 107 JSONStringify(arg3).c_str()); |
108 } | 108 } |
109 | 109 |
110 } // namespace javascript_utils | 110 } // namespace javascript_utils |
111 | 111 |
112 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 112 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
OLD | NEW |