| 48 | } |
| 49 | |
| 50 | bool ExecuteJavascriptCallback(int callbackId, CefRefPtr<CefListValue> args) { |
| 51 | if (g_jsCallbackMap.empty()) { |
| 52 | LOG(ERROR) << "[Renderer process] ExecuteJavascriptCallback():" |
| 53 | " callback map is empty"; |
| 54 | return false; |
| 55 | } |
| 56 | JavascriptCallbackMap::const_iterator it = g_jsCallbackMap.find( |
| 57 | callbackId); |
| 58 | if (it == g_jsCallbackMap.end()) { |
| 59 | std::string logMessage = "[Renderer process]" |
| 60 | " ExecuteJavascriptCallback():" |
| 61 | " callback not found, id="; |
| 62 | logMessage.append(AnyToString(callbackId)); |
| 63 | LOG(ERROR) << logMessage.c_str(); |
| 64 | return false; |
| 65 | } |
| 66 | CefRefPtr<CefFrame> frame = it->second.first; |
| 67 | CefRefPtr<CefV8Value> callback = it->second.second; |
| 68 | CefRefPtr<CefV8Context> context = frame->GetV8Context(); |
| 69 | context->Enter(); |
| 70 | CefV8ValueList v8Arguments = CefListValueToCefV8ValueList(args); |
| 71 | CefRefPtr<CefV8Value> v8ReturnValue = callback->ExecuteFunction( |
| 72 | NULL, v8Arguments); |
| 73 | if (v8ReturnValue.get()) { |
| 74 | context->Exit(); |
| 75 | return true; |
| 76 | } else { |
| 77 | context->Exit(); |
| 78 | LOG(ERROR) << "[Renderer process] ExecuteJavascriptCallback():" |
| 79 | " callback->ExecuteFunction() failed"; |
| 80 | return false; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void RemoveJavascriptCallbacksForFrame(CefRefPtr<CefFrame> frame) { |
| 85 | if (g_jsCallbackMap.empty()) { |
no test coverage detected