#include "ChromiumBrowser.h" #include "ClientApp.h" 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"); command_line->AppendSwitch("disable-pinch"); #ifdef PLATFORM_LINUX Upp::String fp = Upp::GetExeDirFile("libpepflashplayer.so"); if (Upp::FileExists(fp)) command_line->AppendSwitchWithValue("ppapi-flash-path", ~fp); #elif defined(PLATFORM_WIN32) Upp::String fp = Upp::GetExeDirFile("pepflashplayer.dll"); if (Upp::FileExists(fp)) command_line->AppendSwitchWithValue("ppapi-flash-path", ~fp); #endif } void ClientApp::OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) { //Register our JS functions CefRefPtr object = context->GetGlobal(); for(int f = 0; Upp::ChromiumBrowser::JSFunctions[f] != nullptr; f++){ CefRefPtr func = CefV8Value::CreateFunction(Upp::ChromiumBrowser::JSFunctions[f], this); object->SetValue(Upp::ChromiumBrowser::JSFunctions[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 (const auto & s: src){ if (!s->IsValid()) { dst->SetString(dst->GetSize(),"Invalid V8Value"); continue;} if (s->IsUndefined() || s->IsNull()) { dst->SetNull(dst->GetSize()); continue;} if (s->IsBool()) { dst->SetBool(dst->GetSize(), s->GetBoolValue()); continue;} if (s->IsInt()) { dst->SetInt(dst->GetSize(), s->GetIntValue()); continue;} if (s->IsDouble()) { dst->SetDouble(dst->GetSize(),s->GetDoubleValue()); continue;} if (s->IsString()) { dst->SetString(dst->GetSize(),s->GetStringValue()); continue;} dst->SetString(dst->GetSize(), "Unimplemented V8Value conversion"); } }