OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 ValueConversions_h | 5 #ifndef ValueConversions_h |
6 #define ValueConversions_h | 6 #define ValueConversions_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/inspector_protocol/ErrorSupport.h" | 9 #include "platform/inspector_protocol/ErrorSupport.h" |
| 10 #include "platform/inspector_protocol/String16.h" |
10 #include "platform/inspector_protocol/Values.h" | 11 #include "platform/inspector_protocol/Values.h" |
11 #include "wtf/text/WTFString.h" | |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 namespace protocol { | 14 namespace protocol { |
15 | 15 |
16 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(int value); | 16 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(int value); |
17 | 17 |
18 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(double value); | 18 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(double value); |
19 | 19 |
20 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(bool value); | 20 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(bool value); |
21 | 21 |
| 22 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(const String16& param); |
| 23 |
22 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(const String& param); | 24 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(const String& param); |
23 | 25 |
24 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::Value* param); | 26 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::Value* param); |
25 | 27 |
26 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::DictionaryValue* p
aram); | 28 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::DictionaryValue* p
aram); |
27 | 29 |
28 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::ListValue* param); | 30 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::ListValue* param); |
29 | 31 |
30 template<typename T> PassOwnPtr<protocol::Value> toValue(T* param) | 32 template<typename T> PassOwnPtr<protocol::Value> toValue(T* param) |
31 { | 33 { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (!success) | 87 if (!success) |
86 errors->addError("double value expected"); | 88 errors->addError("double value expected"); |
87 return result; | 89 return result; |
88 } | 90 } |
89 }; | 91 }; |
90 | 92 |
91 template<> | 93 template<> |
92 struct FromValue<String> { | 94 struct FromValue<String> { |
93 static String parse(protocol::Value* value, ErrorSupport* errors) | 95 static String parse(protocol::Value* value, ErrorSupport* errors) |
94 { | 96 { |
95 String result; | 97 String16 result; |
96 bool success = value ? value->asString(&result) : false; | 98 bool success = value ? value->asString(&result) : false; |
97 if (!success) | 99 if (!success) |
98 errors->addError("string value expected"); | 100 errors->addError("string value expected"); |
| 101 return result; |
| 102 } |
| 103 }; |
| 104 |
| 105 template<> |
| 106 struct FromValue<String16> { |
| 107 static String16 parse(protocol::Value* value, ErrorSupport* errors) |
| 108 { |
| 109 String16 result; |
| 110 bool success = value ? value->asString(&result) : false; |
| 111 if (!success) |
| 112 errors->addError("string value expected"); |
99 return result; | 113 return result; |
100 } | 114 } |
101 }; | 115 }; |
102 | 116 |
103 template<> | 117 template<> |
104 struct FromValue<Value> { | 118 struct FromValue<Value> { |
105 static PassOwnPtr<Value> parse(protocol::Value* value, ErrorSupport* errors) | 119 static PassOwnPtr<Value> parse(protocol::Value* value, ErrorSupport* errors) |
106 { | 120 { |
107 String result; | |
108 bool success = !!value; | 121 bool success = !!value; |
109 if (!success) | 122 if (!success) |
110 errors->addError("value expected"); | 123 errors->addError("value expected"); |
111 return value->clone(); | 124 return value->clone(); |
112 } | 125 } |
113 }; | 126 }; |
114 | 127 |
115 template<> | 128 template<> |
116 struct FromValue<DictionaryValue> { | 129 struct FromValue<DictionaryValue> { |
117 static PassOwnPtr<DictionaryValue> parse(protocol::Value* value, ErrorSuppor
t* errors) | 130 static PassOwnPtr<DictionaryValue> parse(protocol::Value* value, ErrorSuppor
t* errors) |
118 { | 131 { |
119 String result; | |
120 bool success = value && value->type() == protocol::Value::TypeObject; | 132 bool success = value && value->type() == protocol::Value::TypeObject; |
121 if (!success) | 133 if (!success) |
122 errors->addError("object expected"); | 134 errors->addError("object expected"); |
123 return DictionaryValue::cast(value->clone()); | 135 return DictionaryValue::cast(value->clone()); |
124 } | 136 } |
125 }; | 137 }; |
126 | 138 |
127 template<> | 139 template<> |
128 struct FromValue<ListValue> { | 140 struct FromValue<ListValue> { |
129 static PassOwnPtr<ListValue> parse(protocol::Value* value, ErrorSupport* err
ors) | 141 static PassOwnPtr<ListValue> parse(protocol::Value* value, ErrorSupport* err
ors) |
130 { | 142 { |
131 String result; | |
132 bool success = value && value->type() == protocol::Value::TypeArray; | 143 bool success = value && value->type() == protocol::Value::TypeArray; |
133 if (!success) | 144 if (!success) |
134 errors->addError("list expected"); | 145 errors->addError("list expected"); |
135 return ListValue::cast(value->clone()); | 146 return ListValue::cast(value->clone()); |
136 } | 147 } |
137 }; | 148 }; |
138 | 149 |
139 template<typename T> class Array; | 150 template<typename T> class Array; |
140 | 151 |
141 template<typename T> | 152 template<typename T> |
142 struct FromValue<protocol::Array<T>> { | 153 struct FromValue<protocol::Array<T>> { |
143 static PassOwnPtr<protocol::Array<T>> parse(protocol::Value* value, ErrorSup
port* errors) | 154 static PassOwnPtr<protocol::Array<T>> parse(protocol::Value* value, ErrorSup
port* errors) |
144 { | 155 { |
145 return protocol::Array<T>::parse(value, errors); | 156 return protocol::Array<T>::parse(value, errors); |
146 } | 157 } |
147 }; | 158 }; |
148 | 159 |
149 } // namespace platform | 160 } // namespace platform |
150 } // namespace blink | 161 } // namespace blink |
151 | 162 |
152 #endif // !defined(ValueConversions_h) | 163 #endif // !defined(ValueConversions_h) |
OLD | NEW |