2014-04-05 19:47:42 +03:00
|
|
|
// 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.
|
2014-05-08 22:21:06 +02:00
|
|
|
#pragma once
|
2014-04-05 19:47:42 +03:00
|
|
|
|
|
|
|
|
#include "Stdafx.h"
|
|
|
|
|
|
2014-04-08 18:56:11 +01:00
|
|
|
#include "include/cef_v8.h"
|
2014-05-08 22:21:06 +02:00
|
|
|
#include "TypeUtils.h"
|
2014-04-08 18:56:11 +01:00
|
|
|
|
2014-09-02 11:25:39 +10:00
|
|
|
using namespace CefSharp::Internals;
|
|
|
|
|
|
2014-04-05 19:47:42 +03:00
|
|
|
namespace CefSharp
|
|
|
|
|
{
|
2014-04-08 17:47:22 +03:00
|
|
|
private class JavascriptMethodHandler : public CefV8Handler
|
2014-04-05 19:47:42 +03:00
|
|
|
{
|
2014-05-08 22:21:06 +02:00
|
|
|
private:
|
2014-09-02 11:25:39 +10:00
|
|
|
gcroot<Func<array<Object^>^, BrowserProcessResponse^>^> _method;
|
2014-05-08 22:21:06 +02:00
|
|
|
|
|
|
|
|
public:
|
2014-09-02 11:25:39 +10:00
|
|
|
JavascriptMethodHandler(Func<array<Object^>^, BrowserProcessResponse^>^ method)
|
2014-05-08 22:21:06 +02:00
|
|
|
{
|
|
|
|
|
_method = method;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-16 16:34:07 +10:00
|
|
|
~JavascriptMethodHandler()
|
|
|
|
|
{
|
|
|
|
|
delete _method;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 19:47:42 +03:00
|
|
|
virtual bool Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
|
|
|
|
|
{
|
2014-05-08 22:21:06 +02:00
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-06 20:44:19 +10:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
auto response = _method->Invoke(parameter);
|
2014-05-08 22:21:06 +02:00
|
|
|
|
2015-01-06 20:44:19 +10:00
|
|
|
retval = TypeUtils::ConvertToCef(response->Result, nullptr);
|
|
|
|
|
if (!response->Success)
|
|
|
|
|
{
|
|
|
|
|
exception = StringUtils::ToNative(response->Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception^ ex)
|
2014-09-02 11:25:39 +10:00
|
|
|
{
|
2015-01-06 20:44:19 +10:00
|
|
|
exception = StringUtils::ToNative(ex->Message);
|
2014-09-02 11:25:39 +10:00
|
|
|
}
|
2015-01-06 20:44:19 +10:00
|
|
|
|
2014-09-02 12:02:32 +10:00
|
|
|
//NOTE: Return true otherwise exception is ignored
|
|
|
|
|
return true;
|
2014-04-05 19:47:42 +03:00
|
|
|
}
|
|
|
|
|
|
2014-04-08 18:56:29 +01:00
|
|
|
IMPLEMENT_REFCOUNTING(JavascriptMethodHandler)
|
2014-04-05 19:47:42 +03:00
|
|
|
};
|
|
|
|
|
}
|