2019-04-19 17:19:57 +08:00
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "js_handler.h"
|
|
|
|
|
#include "cef_control/util/util.h"
|
|
|
|
|
#include "cef_control/app/ipc_string_define.h"
|
|
|
|
|
#include "cef_control/app/cef_js_bridge.h"
|
|
|
|
|
|
2019-09-22 11:08:20 +08:00
|
|
|
|
namespace nim_comp
|
2019-04-19 17:19:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
bool CefJSHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
|
|
|
|
|
{
|
|
|
|
|
// <20><>Web<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>"NimCefWebFunction"<22><><EFBFBD><EFBFBD><EFBFBD>ᴥ<F3A3ACBB><E1B4A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFA3AC><C8BB><EFBFBD>Ѳ<EFBFBD><D1B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>棬ת<E6A3AC><D7AA><EFBFBD><EFBFBD>Broswer<65><72><EFBFBD><EFBFBD>
|
|
|
|
|
// Broswer<65><72><EFBFBD>̵<EFBFBD>BrowserHandler<65><72><EFBFBD><EFBFBD>OnProcessMessageReceived<65>ӿ<EFBFBD><D3BF>д<EFBFBD><D0B4><EFBFBD>kJsCallbackMessage<67><65>Ϣ<EFBFBD><CFA2><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
|
{
|
|
|
|
|
exception = "Invalid arguments.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
|
|
|
|
CefRefPtr<CefFrame> frame = context->GetFrame();
|
|
|
|
|
CefRefPtr<CefBrowser> browser = context->GetBrowser();
|
|
|
|
|
|
|
|
|
|
int64_t browser_id = browser->GetIdentifier();
|
|
|
|
|
int64_t frame_id = frame->GetIdentifier();
|
|
|
|
|
|
|
|
|
|
if (name == "call")
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>û<EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD>б<EFBFBD><D0B1>ĵ<EFBFBD><C4B5>ã<EFBFBD><C3A3>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ص<EFBFBD>
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD>ص<EFBFBD><D8B5>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CefString function_name = arguments[0]->GetStringValue();
|
|
|
|
|
CefString params = "{}";
|
|
|
|
|
CefRefPtr<CefV8Value> callback;
|
|
|
|
|
if (arguments[0]->IsString() && arguments[1]->IsFunction())
|
|
|
|
|
{
|
|
|
|
|
callback = arguments[1];
|
|
|
|
|
}
|
|
|
|
|
else if (arguments[0]->IsString() && arguments[1]->IsString() && arguments[2]->IsFunction())
|
|
|
|
|
{
|
|
|
|
|
params = arguments[1]->GetStringValue();
|
|
|
|
|
callback = arguments[2];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
exception = "Invalid arguments.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ִ<><D6B4> C++ <20><><EFBFBD><EFBFBD>
|
|
|
|
|
if (!js_bridge_->CallCppFunction(function_name, params, callback))
|
|
|
|
|
{
|
|
|
|
|
exception = nbase::StringPrintf("Failed to call function %s.", function_name).c_str();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (name == "register")
|
|
|
|
|
{
|
|
|
|
|
if (arguments[0]->IsString() && arguments[1]->IsFunction())
|
|
|
|
|
{
|
|
|
|
|
std::string function_name = arguments[0]->GetStringValue();
|
|
|
|
|
CefRefPtr<CefV8Value> callback = arguments[1];
|
|
|
|
|
if (!js_bridge_->RegisterJSFunc(function_name, callback))
|
|
|
|
|
{
|
|
|
|
|
exception = "Failed to register function.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
exception = "Invalid arguments.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|