SIGN IN SIGN UP
cefsharp / CefSharp UNCLAIMED

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework

0 0 119 C#
// Copyright © 2010-2013 The CefSharp Project. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#pragma once
#include "Stdafx.h"
2014-04-08 18:56:11 +01:00
#include "include/cef_v8.h"
#include "TypeUtils.h"
2014-04-08 18:56:11 +01:00
using namespace CefSharp::Internals;
namespace CefSharp
{
2014-04-08 17:47:22 +03:00
private class JavascriptMethodHandler : public CefV8Handler
{
private:
gcroot<Func<array<Object^>^, BrowserProcessResponse^>^> _method;
public:
JavascriptMethodHandler(Func<array<Object^>^, BrowserProcessResponse^>^ method)
{
_method = method;
}
2014-09-16 16:34:07 +10:00
~JavascriptMethodHandler()
{
delete _method;
}
virtual bool Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
auto parameter = gcnew array<Object^>(arguments.size());
for (std::vector<CefRefPtr<CefV8Value>>::size_type i = 0; i != arguments.size(); i++)
{
parameter[i] = TypeUtils::ConvertFromCef(arguments[i]);
}
try
{
auto response = _method->Invoke(parameter);
retval = TypeUtils::ConvertToCef(response->Result, nullptr);
if (!response->Success)
{
exception = StringUtils::ToNative(response->Message);
}
}
catch (Exception^ ex)
{
exception = StringUtils::ToNative(ex->Message);
}
//NOTE: Return true otherwise exception is ignored
return true;
}
IMPLEMENT_REFCOUNTING(JavascriptMethodHandler)
};
}