| 425 | } |
| 426 | |
| 427 | bool CefPythonApp::BindedFunctionExists(CefRefPtr<CefBrowser> browser, |
| 428 | const CefString& functionName) { |
| 429 | CefRefPtr<CefDictionaryValue> jsBindings = GetJavascriptBindings(browser); |
| 430 | if (!jsBindings.get()) { |
| 431 | return false; |
| 432 | } |
| 433 | std::string strFunctionName = functionName.ToString(); |
| 434 | size_t dotPosition = strFunctionName.find("."); |
| 435 | if (std::string::npos != dotPosition) { |
| 436 | // This is a method call, functionName == "object.method". |
| 437 | CefString objectName(strFunctionName.substr(0, dotPosition)); |
| 438 | CefString methodName(strFunctionName.substr(dotPosition + 1, |
| 439 | std::string::npos)); |
| 440 | if (!(jsBindings->HasKey("objects") |
| 441 | && jsBindings->GetType("objects") == VTYPE_DICTIONARY)) { |
| 442 | LOG(ERROR) << "[Renderer process] BindedFunctionExists():" |
| 443 | " objects dictionary not found"; |
| 444 | return false; |
| 445 | } |
| 446 | CefRefPtr<CefDictionaryValue> objects = \ |
| 447 | jsBindings->GetDictionary("objects"); |
| 448 | if (objects->HasKey(objectName)) { |
| 449 | if (!(objects->GetType(objectName) == VTYPE_DICTIONARY)) { |
| 450 | LOG(ERROR) << "[Renderer process] BindedFunctionExists():" |
| 451 | " objects dictionary has invalid type"; |
| 452 | return false; |
| 453 | } |
| 454 | CefRefPtr<CefDictionaryValue> methods = \ |
| 455 | objects->GetDictionary(objectName); |
| 456 | return methods->HasKey(methodName); |
| 457 | } else { |
| 458 | return false; |
| 459 | } |
| 460 | } else { |
| 461 | // This is a function call. |
| 462 | if (!(jsBindings->HasKey("functions") |
| 463 | && jsBindings->GetType("functions") == VTYPE_DICTIONARY)) { |
| 464 | LOG(ERROR) << "[Renderer process] BindedFunctionExists():" |
| 465 | " functions dictionary not found"; |
| 466 | return false; |
| 467 | } |
| 468 | CefRefPtr<CefDictionaryValue> functions = \ |
| 469 | jsBindings->GetDictionary("functions"); |
| 470 | return functions->HasKey(functionName); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void CefPythonApp::DoJavascriptBindingsForBrowser( |
| 475 | CefRefPtr<CefBrowser> browser) { |