| 360 | } |
| 361 | |
| 362 | bool CefPythonApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, |
| 363 | CefProcessId source_process, |
| 364 | CefRefPtr<CefProcessMessage> message) { |
| 365 | std::string messageName = message->GetName().ToString(); |
| 366 | std::string logMessage = "[Renderer process] OnProcessMessageReceived(): "; |
| 367 | logMessage.append(messageName.c_str()); |
| 368 | LOG(INFO) << logMessage.c_str(); |
| 369 | CefRefPtr<CefListValue> args = message->GetArgumentList(); |
| 370 | if (messageName == "DoJavascriptBindings") { |
| 371 | if (args->GetSize() == 1 |
| 372 | && args->GetType(0) == VTYPE_DICTIONARY |
| 373 | && args->GetDictionary(0)->IsValid()) { |
| 374 | // Is it necessary to make a copy? It won't harm. |
| 375 | SetJavascriptBindings(browser, |
| 376 | args->GetDictionary(0)->Copy(false)); |
| 377 | DoJavascriptBindingsForBrowser(browser); |
| 378 | } else { |
| 379 | LOG(ERROR) << "[Renderer process] OnProcessMessageReceived():" |
| 380 | " invalid arguments," |
| 381 | " messageName=DoJavascriptBindings"; |
| 382 | return false; |
| 383 | } |
| 384 | } else if (messageName == "ExecuteJavascriptCallback") { |
| 385 | if (args->GetType(0) == VTYPE_INT) { |
| 386 | int jsCallbackId = args->GetInt(0); |
| 387 | CefRefPtr<CefListValue> jsArgs; |
| 388 | if (args->IsReadOnly()) { |
| 389 | jsArgs = args->Copy(); |
| 390 | } else { |
| 391 | jsArgs = args; |
| 392 | } |
| 393 | // Remove jsCallbackId. |
| 394 | jsArgs->Remove(0); |
| 395 | ExecuteJavascriptCallback(jsCallbackId, jsArgs); |
| 396 | } else { |
| 397 | LOG(ERROR) << "[Renderer process] OnProcessMessageReceived:" |
| 398 | " invalid arguments, expected first argument to be" |
| 399 | " a javascript callback (int)"; |
| 400 | return false; |
| 401 | } |
| 402 | } |
| 403 | return true; |
| 404 | } |
| 405 | |
| 406 | void CefPythonApp::SetJavascriptBindings(CefRefPtr<CefBrowser> browser, |
| 407 | CefRefPtr<CefDictionaryValue> data) { |
nothing calls this directly
no test coverage detected