@@ -142,6 +142,134 @@ bool MCCefListToV8List(CefRefPtr<CefV8Context> p_context, CefRefPtr<CefListValue
142142 return t_success;
143143}
144144
145+ bool MCCefV8ArrayToList (CefRefPtr<CefV8Context> p_context, CefRefPtr<CefV8Value> p_array, CefRefPtr<CefListValue> &r_list);
146+ bool MCCefV8ObjectToDictionary (CefRefPtr<CefV8Context> p_context, CefRefPtr<CefV8Value> p_obj, CefRefPtr<CefDictionaryValue> &r_dict);
147+
148+ bool MCCefV8ArrayToList (CefRefPtr<CefV8Context> p_context, CefRefPtr<CefV8Value> p_array, CefRefPtr<CefListValue> &r_list)
149+ {
150+ bool t_success;
151+ t_success = true ;
152+
153+ p_context->Enter ();
154+
155+ CefRefPtr<CefListValue> t_list;
156+ if (t_success)
157+ t_list = CefListValue::Create ();
158+
159+ uint32_t t_length;
160+ t_length = p_array->GetArrayLength ();
161+
162+ if (t_success)
163+ t_success = t_list->SetSize (t_length);
164+
165+ for (uint32_t i = 0 ; i < t_length; i++)
166+ {
167+ CefRefPtr<CefV8Value> t_val;
168+ t_val = p_array->GetValue (i);
169+
170+ if (t_val->IsBool ())
171+ t_success = t_list->SetBool (i, t_val->GetBoolValue ());
172+ else if (t_val->IsInt ())
173+ t_success = t_list->SetInt (i, t_val->GetIntValue ());
174+ else if (t_val->IsUInt ())
175+ t_success = t_list->SetInt (i, t_val->GetUIntValue ());
176+ else if (t_val->IsDouble ())
177+ t_success = t_list->SetDouble (i, t_val->GetDoubleValue ());
178+ else if (t_val->IsString ())
179+ t_success = t_list->SetString (i, t_val->GetStringValue ());
180+ else if (t_val->IsArray ())
181+ {
182+ CefRefPtr<CefListValue> t_list_val;
183+ t_success = MCCefV8ArrayToList (p_context, t_val, t_list_val);
184+ if (t_success)
185+ t_success = t_list->SetList (i, t_list_val);
186+ }
187+ else if (t_val->IsObject ())
188+ {
189+ CefRefPtr<CefDictionaryValue> t_dict_val;
190+ t_success = MCCefV8ObjectToDictionary (p_context, t_val, t_dict_val);
191+ if (t_success)
192+ t_success = t_list->SetDictionary (i, t_dict_val);
193+ }
194+ else
195+ {
196+ t_success = MCCefV8ValueConvertToString (p_context, t_val);
197+ if (t_success)
198+ t_success = t_list->SetString (i, t_val->GetStringValue ());
199+ }
200+ }
201+
202+ p_context->Exit ();
203+
204+ if (t_success)
205+ r_list = t_list;
206+
207+ return t_success;
208+ }
209+
210+ bool MCCefV8ObjectToDictionary (CefRefPtr<CefV8Context> p_context, CefRefPtr<CefV8Value> p_obj, CefRefPtr<CefDictionaryValue> &r_dict)
211+ {
212+ bool t_success;
213+ t_success = true ;
214+
215+ p_context->Enter ();
216+
217+ CefRefPtr<CefDictionaryValue> t_dict;
218+ if (t_success)
219+ t_dict = CefDictionaryValue::Create ();
220+
221+ std::vector<CefString> t_keys;
222+ if (t_success)
223+ t_success = p_obj->GetKeys (t_keys);
224+
225+ for (std::vector<CefString>::const_iterator i = t_keys.begin (); t_success && i != t_keys.end (); i++)
226+ {
227+ CefRefPtr<CefV8Value> t_val;
228+ t_val = p_obj->GetValue (*i);
229+
230+ uint32_t t_index;
231+ t_index = i - t_keys.begin ();
232+
233+ if (t_val->IsBool ())
234+ t_success = t_dict->SetBool (*i, t_val->GetBoolValue ());
235+ else if (t_val->IsInt ())
236+ t_success = t_dict->SetInt (*i, t_val->GetIntValue ());
237+ else if (t_val->IsUInt ())
238+ t_success = t_dict->SetInt (*i, t_val->GetUIntValue ());
239+ else if (t_val->IsDouble ())
240+ t_success = t_dict->SetDouble (*i, t_val->GetDoubleValue ());
241+ else if (t_val->IsString ())
242+ t_success = t_dict->SetString (*i, t_val->GetStringValue ());
243+ else if (t_val->IsArray ())
244+ {
245+ CefRefPtr<CefListValue> t_list_val;
246+ t_success = MCCefV8ArrayToList (p_context, t_val, t_list_val);
247+ if (t_success)
248+ t_success = t_dict->SetList (*i, t_list_val);
249+ }
250+ else if (t_val->IsObject ())
251+ {
252+ CefRefPtr<CefDictionaryValue> t_dict_val;
253+ t_success = MCCefV8ObjectToDictionary (p_context, t_val, t_dict_val);
254+ if (t_success)
255+ t_success = t_dict->SetDictionary (*i, t_dict_val);
256+ }
257+ else
258+ {
259+ t_success = MCCefV8ValueConvertToString (p_context, t_val);
260+ if (t_success)
261+ t_success = t_dict->SetString (*i, t_val->GetStringValue ());
262+ }
263+ }
264+
265+ p_context->Exit ();
266+
267+ if (t_success)
268+ r_dict = t_dict;
269+
270+ return t_success;
271+ }
272+
145273bool MCCefV8ListToList (CefRefPtr<CefV8Context> p_context, const CefV8ValueList &p_list, CefRefPtr<CefListValue> &r_list)
146274{
147275 bool t_success;
@@ -174,6 +302,20 @@ bool MCCefV8ListToList(CefRefPtr<CefV8Context> p_context, const CefV8ValueList &
174302 t_success = t_list->SetDouble (t_index, t_val->GetDoubleValue ());
175303 else if (t_val->IsString ())
176304 t_success = t_list->SetString (t_index, t_val->GetStringValue ());
305+ else if (t_val->IsArray ())
306+ {
307+ CefRefPtr<CefListValue> t_list_val;
308+ t_success = MCCefV8ArrayToList (p_context, t_val, t_list_val);
309+ if (t_success)
310+ t_success = t_list->SetList (t_index, t_list_val);
311+ }
312+ else if (t_val->IsObject ())
313+ {
314+ CefRefPtr<CefDictionaryValue> t_dict_val;
315+ t_success = MCCefV8ObjectToDictionary (p_context, t_val, t_dict_val);
316+ if (t_success)
317+ t_success = t_list->SetDictionary (t_index, t_dict_val);
318+ }
177319 else
178320 {
179321 t_success = MCCefV8ValueConvertToString (p_context, t_val);
0 commit comments