Files
cefsharp/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp
T
amaitland 73a156fdc5 Initial version 75 upgrade and NetworkService changes
Compiles, that's about it at this point, there are major CEF breaking changes, and lots to be addressed.

Browser Process (main process)
- Removed IResourceHandlerFactory as it no longer fits with the structure that CEF provides
- New IResourceRequestHandler interface added, not plumbed in yet
- CefSettings - Add RootCachePath and ApplicationClientIdForFileScanning

BrowserSubprocess (render process)
- SendProcessMessage was moved from CefBrowser to CefFrame
- OnBrowserCreated added extraInfo param

The BrowserSubprocess changes for this upgrade should be complete
2019-06-25 19:24:57 +10:00

75 lines
3.0 KiB
C++

// Copyright © 2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "stdafx.h"
#include "JavascriptAsyncMethodHandler.h"
#include "../CefSharp.Core/Internals/Messaging/Messages.h"
#include "../CefSharp.Core/Internals/Serialization/Primitives.h"
#include "Serialization/V8Serialization.h"
#include "CefAppUnmanagedWrapper.h"
using namespace CefSharp::Internals::Messaging;
using namespace CefSharp::Internals::Serialization;
namespace CefSharp
{
namespace Internals
{
namespace Async
{
bool JavascriptAsyncMethodHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
auto context = CefV8Context::GetCurrentContext();
auto frame = context->GetFrame();
CefRefPtr<CefV8Value> promiseData;
CefRefPtr<CefV8Exception> promiseException;
//this will create a promise and give us the reject/resolve functions {p: Promise, res: resolve(), rej: reject()}
if (!context->Eval(CefAppUnmanagedWrapper::kPromiseCreatorScript, CefString(), 0, promiseData, promiseException))
{
LOG(WARNING) << "JavascriptAsyncMethodHandler::Execute promiseData returned exception: " + promiseException->GetMessage().ToString();
exception = promiseException->GetMessage();
return true;
}
//when refreshing the browser this is sometimes null, in this case return true and log message
//https://github.com/cefsharp/CefSharp/pull/2446
if (promiseData == NULL)
{
LOG(WARNING) << "JavascriptAsyncMethodHandler::Execute promiseData returned NULL";
return true;
}
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(kJavascriptAsyncMethodCallRequest);
auto argList = request->GetArgumentList();
auto params = CefListValue::Create();
for (auto i = 0; i < arguments.size(); i++)
{
SerializeV8Object(arguments[i], params, i, _callbackRegistry);
}
SetInt64(argList, 0, frame->GetIdentifier());
SetInt64(argList, 1, _objectId);
SetInt64(argList, 2, callbackId);
argList->SetString(3, name);
argList->SetList(4, params);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, request);
return true;
}
}
}
}