mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-03 23:12:42 +00:00
added callback capability for async bound method with promises
This commit is contained in:
committed by
cefsharp-ms cefsharp-github@morganstanley.com
parent
a8db666642
commit
fc85d90877
@@ -20,6 +20,17 @@ namespace CefSharp
|
||||
{
|
||||
bool JavascriptAsyncMethodHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
|
||||
{
|
||||
auto context = CefV8Context::GetCurrentContext();
|
||||
auto browser = context->GetBrowser();
|
||||
//this will create a promise and give us the reject/resolve functions {p: Promise, res: resolve(), rej: reject()}
|
||||
auto promiseData = _promiseCreator->ExecuteFunctionWithContext(context, nullptr, CefV8ValueList());
|
||||
retval = promiseData->GetValue("p");
|
||||
|
||||
auto resolve = promiseData->GetValue("res");
|
||||
auto reject = promiseData->GetValue("rej");
|
||||
auto callback = gcnew JavascriptAsyncMethodCallback(context, resolve, reject);
|
||||
auto callbackId = _methodCallbackSave->Invoke(callback);
|
||||
|
||||
auto request = CefProcessMessage::Create(kJavascriptMethodCallRequest);
|
||||
auto argList = request->GetArgumentList();
|
||||
auto params = CefListValue::Create();
|
||||
@@ -29,11 +40,11 @@ namespace CefSharp
|
||||
}
|
||||
|
||||
SetInt64(_objectId, argList, 0);
|
||||
SetInt64(0, argList, 1);
|
||||
argList->SetString(2, StringUtils::ToNative(_method->JavascriptName));
|
||||
SetInt64(callbackId, argList, 1);
|
||||
argList->SetString(2, name);
|
||||
argList->SetList(3, params);
|
||||
|
||||
_browser->SendProcessMessage(CefProcessId::PID_BROWSER, request);
|
||||
browser->SendProcessMessage(CefProcessId::PID_BROWSER, request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user