#include "ClientApp.h" static const char * const func_names[]={ "JSExample1" }; ClientApp::ClientApp() { } void ClientApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr command_line) { //Extra command line switches command_line->AppendSwitch("enable-media-stream"); command_line->AppendSwitch("no-sandbox"); } void ClientApp::OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) { //Register our JS functions CefRefPtr object = context->GetGlobal(); for(int f = 0; f < __countof(func_names); f++){ CefRefPtr func = CefV8Value::CreateFunction(func_names[f], this); object->SetValue(func_names[f], func, V8_PROPERTY_ATTRIBUTE_NONE); } } void ClientApp::OnFocusedNodeChanged(CefRefPtr browser, CefRefPtr frame, CefRefPtr node) { bool is_editable = (node.get() && node->IsEditable()); browser->SendProcessMessage(PID_BROWSER, CefProcessMessage::Create(is_editable ? "show_keyboard" : "hide_keyboard")); } bool ClientApp::Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) { CefRefPtr message = CefProcessMessage::Create(name); CefRefPtr par = message->GetArgumentList(); V8ValueListToCefListValue(arguments, par); CefRefPtr browser = CefV8Context::GetCurrentContext()->GetBrowser(); if (browser) browser->SendProcessMessage(PID_BROWSER, message); return true; } void ClientApp::V8ValueListToCefListValue(const CefV8ValueList& src, CefRefPtr & dst) { for (unsigned i = 0; i < src.size(); i++) { if (!src[i]->IsValid()) { dst->SetString(dst->GetSize(),"Invalid V8Value"); continue;} if (src[i]->IsUndefined() || src[i]->IsNull()) { dst->SetNull(dst->GetSize()); continue;} if (src[i]->IsBool()) { dst->SetBool(dst->GetSize(), src[i]->GetBoolValue()); continue;} if (src[i]->IsInt()) { dst->SetInt(dst->GetSize(), src[i]->GetIntValue()); continue;} if (src[i]->IsDouble()) { dst->SetDouble(dst->GetSize(),src[i]->GetDoubleValue()); continue;} if (src[i]->IsString()) { dst->SetString(dst->GetSize(),src[i]->GetStringValue()); continue;} dst->SetString(dst->GetSize(), "Unimplemented V8Value conversion"); } }