How to convert CefValue to CefV8Value
Posted: Fri Dec 30, 2016 10:10 pm
I retrive CefValue (by CefParseJSON) in CefUrlRequestClient.OnRequestComplete. I want to convert it to CefV8Value, then pass it into JS Function Callback (CefV8Value). Is there some conversion could do that ?
Thank you.
[main.html]
[myapp.cc]
[myrequest.cc]
Thank you.
[main.html]
- Code: Select all
mycefobj.GetHttpJson(function (res) {
alert(res.ip);
});
[myapp.cc]
- Code: Select all
bool V8Handler::Execute(...) {
...
if (name == "GetHttpJson") {
CefRefPtr<CefV8Value> onrequestcomplete = arguments[0].get();
CefRefPtr<CefRequestContext> context = CefRequestContext::GetGlobalContext();
CefRefPtr<CefRequest> req = CefRequest::Create();
req->SetMethod("GET");
req->SetURL("http://ip.jsontest.com/");
CefRefPtr<POSURLRequestClient> client = new POSURLRequestClient ();
client->SetRequestCompleteCallback(onrequestcomplete, CefV8Context::GetCurrentContext());
CefURLRequest::Create(req, client, NULL);
retval = CefV8Value::CreateNull();
return true;
...
}
[myrequest.cc]
- Code: Select all
void URLRequestClient::OnRequestComplete(CefRefPtr<CefURLRequest> request) {
CEF_REQUIRE_UI_THREAD();
CefRefPtr<CefValue> json = CefParseJSON(buffer.data(), JSON_PARSER_ALLOW_TRAILING_COMMAS);
if (json->IsValid()) {
OnRequestCompleteCallbackContext->Enter();
CefV8ValueList args;
args.push_back(json); // I want to make conversion here
OnRequestCompleteCallback->ExecuteFunctionWithContext(OnRequestCompleteCallbackContext, NULL, args);
OnRequestCompleteCallbackContext->Exit();
}
}