| 7 | #include "include/base/cef_logging.h" |
| 8 | |
| 9 | bool V8FunctionHandler::Execute(const CefString& functionName, |
| 10 | CefRefPtr<CefV8Value> thisObject, |
| 11 | const CefV8ValueList& v8Arguments, |
| 12 | CefRefPtr<CefV8Value>& returnValue, |
| 13 | CefString& exception) { |
| 14 | if (!CefV8Context::InContext()) { |
| 15 | // CefV8Context::GetCurrentContext may not be called when |
| 16 | // not in a V8 context. |
| 17 | LOG(ERROR) << "[Renderer process] V8FunctionHandler::Execute():" |
| 18 | " not inside a V8 context"; |
| 19 | return false; |
| 20 | } |
| 21 | CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext(); |
| 22 | CefRefPtr<CefBrowser> browser = context.get()->GetBrowser(); |
| 23 | CefRefPtr<CefFrame> frame = context.get()->GetFrame(); |
| 24 | if (pythonCallbackId_) { |
| 25 | LOG(INFO) << "[Renderer process] V8FunctionHandler::Execute():" |
| 26 | " python callback"; |
| 27 | CefRefPtr<CefListValue> functionArguments = V8ValueListToCefListValue( |
| 28 | v8Arguments); |
| 29 | CefRefPtr<CefProcessMessage> processMessage = \ |
| 30 | CefProcessMessage::Create("ExecutePythonCallback"); |
| 31 | CefRefPtr<CefListValue> messageArguments = \ |
| 32 | processMessage->GetArgumentList(); |
| 33 | messageArguments->SetInt(0, pythonCallbackId_); |
| 34 | messageArguments->SetList(1, functionArguments); |
| 35 | browser->SendProcessMessage(PID_BROWSER, processMessage); |
| 36 | returnValue = CefV8Value::CreateNull(); |
| 37 | return true; |
| 38 | } else { |
| 39 | LOG(INFO) << "[Renderer process] V8FunctionHandler::Execute():" |
| 40 | " js binding"; |
| 41 | if (!(cefPythonApp_.get() \ |
| 42 | && cefPythonApp_->BindedFunctionExists( \ |
| 43 | browser, functionName))) { |
| 44 | exception = std::string("[CEF Python] " \ |
| 45 | "V8FunctionHandler::Execute() FAILED: " \ |
| 46 | "function does not exist: ").append(functionName) \ |
| 47 | .append("()"); |
| 48 | // Must return true for the exception to be thrown. |
| 49 | return true; |
| 50 | } |
| 51 | CefRefPtr<CefListValue> functionArguments = V8ValueListToCefListValue( |
| 52 | v8Arguments); |
| 53 | // TODO: losing int64 precision here. |
| 54 | int frameId = (int)frame->GetIdentifier(); |
| 55 | CefRefPtr<CefProcessMessage> processMessage = \ |
| 56 | CefProcessMessage::Create("V8FunctionHandler::Execute"); |
| 57 | CefRefPtr<CefListValue> messageArguments = \ |
| 58 | processMessage->GetArgumentList(); |
| 59 | messageArguments->SetInt(0, frameId); |
| 60 | messageArguments->SetString(1, functionName); |
| 61 | messageArguments->SetList(2, functionArguments); |
| 62 | browser->SendProcessMessage(PID_BROWSER, processMessage); |
| 63 | returnValue = CefV8Value::CreateNull(); |
| 64 | return true; |
| 65 | } |
| 66 | } |
nothing calls this directly
no test coverage detected