Exemplo n.º 1
0
bool V8FunctionHandler::Execute(const CefString& functionName,
                        CefRefPtr<CefV8Value> thisObject,
                        const CefV8ValueList& v8Arguments,
                        CefRefPtr<CefV8Value>& returnValue,
                        CefString& exception) {
    if (!CefV8Context::InContext()) {
        // CefV8Context::GetCurrentContext may not be called when
        // not in a V8 context.
        DebugLog("Renderer: V8FunctionHandler::Execute() FAILED:"\
                " not inside a V8 context");
        return false;
    }
    CefRefPtr<CefV8Context> context =  CefV8Context::GetCurrentContext();
    CefRefPtr<CefBrowser> browser = context.get()->GetBrowser();
    CefRefPtr<CefFrame> frame = context.get()->GetFrame();
    if (pythonCallbackId_) {
        DebugLog("Renderer: V8FunctionHandler::Execute(): python callback");
        CefRefPtr<CefListValue> functionArguments = V8ValueListToCefListValue(
                v8Arguments);
        CefRefPtr<CefProcessMessage> processMessage = \
                CefProcessMessage::Create("ExecutePythonCallback");
        CefRefPtr<CefListValue> messageArguments = \
                processMessage->GetArgumentList();
        messageArguments->SetInt(0, pythonCallbackId_);
        messageArguments->SetList(1, functionArguments);
        browser->SendProcessMessage(PID_BROWSER, processMessage);
        returnValue = CefV8Value::CreateNull();
        return true;
    } else {
        DebugLog("Renderer: V8FunctionHandler::Execute(): js binding");
        if (!(cefPythonApp_.get() \
                && cefPythonApp_->BindedFunctionExists( \
                        browser, functionName))) {
            exception = std::string("[CEF Python] " \
                    "V8FunctionHandler::Execute() FAILED: " \
                    "function does not exist: ").append(functionName) \
                    .append("()");
            // Must return true for the exception to be thrown.
            return true;
        }
        CefRefPtr<CefListValue> functionArguments = V8ValueListToCefListValue(
                v8Arguments);
        // TODO: losing int64 precision here.
        int frameId = (int)frame->GetIdentifier();
        CefRefPtr<CefProcessMessage> processMessage = \
                CefProcessMessage::Create("V8FunctionHandler::Execute");
        CefRefPtr<CefListValue> messageArguments = \
                processMessage->GetArgumentList();
        messageArguments->SetInt(0, frameId);
        messageArguments->SetString(1, functionName);
        messageArguments->SetList(2, functionArguments);
        browser->SendProcessMessage(PID_BROWSER, processMessage);
        returnValue = CefV8Value::CreateNull();
        return true;
    }
}
Exemplo n.º 2
0
bool ClientApp::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
	CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create(name);
	CefRefPtr<CefListValue> par = message->GetArgumentList();
	V8ValueListToCefListValue(arguments, par);
	CefRefPtr<CefBrowser> browser = CefV8Context::GetCurrentContext()->GetBrowser();
	if (browser) browser->SendProcessMessage(PID_BROWSER, message);	
	return true;
}