#include "ClientApp.h" ClientApp::ClientApp() { //Add our own JS functions to the list functions.Add("JSExample1", Upp::callback(this, &ClientApp::JSExample1)); } 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 < functions.GetCount(); f++){ CefRefPtr func = CefV8Value::CreateFunction(~functions.GetKey(f), this); object->SetValue(~functions.GetKey(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) { int f = functions.Find(name.ToString()); if (f >= 0){ functions[f].Execute(arguments, retval, exception); return true; }else{ RLOG(Upp::String("ERROR: Unknown native function: ") + name.ToString()); } return false; } void ClientApp::JSExample1(const CefV8ValueList& args, CefRefPtr& retval, CefString& exc) { retval = CefV8Value::CreateString("Function that returns some string"); }