| 307 | } |
| 308 | |
| 309 | CefRefPtr<CefV8Value> CefDictionaryValueToV8Value( |
| 310 | CefRefPtr<CefDictionaryValue> dictValue, |
| 311 | int nestingLevel) { |
| 312 | if (!dictValue->IsValid()) { |
| 313 | LOG(ERROR) << "[Renderer process] CefDictionaryValueToV8Value():" |
| 314 | " CefDictionaryValue is invalid"; |
| 315 | return CefV8Value::CreateNull(); |
| 316 | } |
| 317 | if (nestingLevel > 8) { |
| 318 | LOG(ERROR) << "[Renderer process] CefDictionaryValueToV8Value():" |
| 319 | " max nesting level (8) exceeded"; |
| 320 | return CefV8Value::CreateNull(); |
| 321 | } |
| 322 | std::vector<CefString> keys; |
| 323 | if (!dictValue->GetKeys(keys)) { |
| 324 | LOG(ERROR) << "[Renderer process] CefDictionaryValueToV8Value():" |
| 325 | " dictValue->GetKeys() failed"; |
| 326 | return CefV8Value::CreateNull(); |
| 327 | } |
| 328 | CefRefPtr<CefV8Value> ret = CefV8Value::CreateObject(NULL, NULL); |
| 329 | CefRefPtr<CefBinaryValue> binaryValue; |
| 330 | PythonCallback pyCallback; |
| 331 | CefRefPtr<CefV8Handler> v8FunctionHandler; |
| 332 | for (std::vector<CefString>::iterator it = keys.begin(); \ |
| 333 | it != keys.end(); ++it) { |
| 334 | CefString key = *it; |
| 335 | cef_value_type_t valueType = dictValue->GetType(key); |
| 336 | bool success; |
| 337 | std::string callbackName = "python_callback_"; |
| 338 | if (valueType == VTYPE_NULL) { |
| 339 | success = ret->SetValue(key, |
| 340 | CefV8Value::CreateNull(), |
| 341 | V8_PROPERTY_ATTRIBUTE_NONE); |
| 342 | } else if (valueType == VTYPE_BOOL) { |
| 343 | success = ret->SetValue(key, |
| 344 | CefV8Value::CreateBool(dictValue->GetBool(key)), |
| 345 | V8_PROPERTY_ATTRIBUTE_NONE); |
| 346 | } else if (valueType == VTYPE_INT) { |
| 347 | success = ret->SetValue(key, |
| 348 | CefV8Value::CreateInt(dictValue->GetInt(key)), |
| 349 | V8_PROPERTY_ATTRIBUTE_NONE); |
| 350 | } else if (valueType == VTYPE_DOUBLE) { |
| 351 | success = ret->SetValue(key, |
| 352 | CefV8Value::CreateDouble(dictValue->GetDouble(key)), |
| 353 | V8_PROPERTY_ATTRIBUTE_NONE); |
| 354 | } else if (valueType == VTYPE_STRING) { |
| 355 | success = ret->SetValue(key, |
| 356 | CefV8Value::CreateString(dictValue->GetString(key)), |
| 357 | V8_PROPERTY_ATTRIBUTE_NONE); |
| 358 | } else if (valueType == VTYPE_BINARY) { |
| 359 | binaryValue = dictValue->GetBinary(key); |
| 360 | if (binaryValue->GetSize() == sizeof(pyCallback)) { |
| 361 | binaryValue->GetData(&pyCallback, sizeof(pyCallback), 0); |
| 362 | v8FunctionHandler = new V8FunctionHandler( |
| 363 | NULL, pyCallback.callbackId); |
| 364 | // You must provide a function name to |
| 365 | // CefV8Value::CreateFunction(), otherwise it fails. |
| 366 | callbackName.append(AnyToString(pyCallback.callbackId)); |
no test coverage detected