mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
// Copyright © 2010-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 "TypeUtils.h"
|
|
#include "JavascriptCallbackWrapper.h"
|
|
#include "Serialization/V8Serialization.h"
|
|
|
|
namespace CefSharp
|
|
{
|
|
namespace Internals
|
|
{
|
|
using namespace Serialization;
|
|
|
|
JavascriptCallbackWrapper::!JavascriptCallbackWrapper()
|
|
{
|
|
value = nullptr;
|
|
context = nullptr;
|
|
}
|
|
|
|
JavascriptCallbackWrapper::~JavascriptCallbackWrapper()
|
|
{
|
|
this->!JavascriptCallbackWrapper();
|
|
}
|
|
|
|
JavascriptResponse^ JavascriptCallbackWrapper::Execute(array<Object^>^ parms)
|
|
{
|
|
JavascriptResponse^ response = nullptr;
|
|
if (context->Enter())
|
|
{
|
|
response = gcnew JavascriptResponse();
|
|
try
|
|
{
|
|
CefV8ValueList args;
|
|
for each (auto parm in parms)
|
|
{
|
|
auto cefParm = TypeUtils::ConvertToCef(parm, nullptr);
|
|
args.push_back(cefParm);
|
|
}
|
|
|
|
auto retval = value->ExecuteFunctionWithContext(context.get(), nullptr, args);
|
|
response->Success = retval != nullptr;
|
|
if (response->Success)
|
|
{
|
|
response->Result = TypeUtils::ConvertFromCef(retval);
|
|
}
|
|
else
|
|
{
|
|
auto exception = value->GetException();
|
|
if (exception.get())
|
|
{
|
|
response->Message = StringUtils::ToClr(exception->GetMessage());
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
context->Exit();
|
|
}
|
|
}
|
|
return response;
|
|
}
|
|
|
|
CefRefPtr<CefV8Value> JavascriptCallbackWrapper::GetValue()
|
|
{
|
|
return value.get();
|
|
}
|
|
|
|
CefRefPtr<CefV8Context> JavascriptCallbackWrapper::GetContext()
|
|
{
|
|
return context.get();
|
|
}
|
|
}
|
|
}
|