mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
Make wrapper objects contain references to the Properties/Methods they represent
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Stdafx.h"
|
||||
#include "include/cef_app.h"
|
||||
#include "include/cef_base.h"
|
||||
#include "include/cef_v8.h"
|
||||
|
||||
#include "JavascriptObjectWrapper.h"
|
||||
#include "JavascriptMethodHandler.h"
|
||||
|
||||
@@ -12,28 +16,30 @@ using namespace System::Runtime::Serialization;
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
private ref class JavascriptMethodWrapper : IBindableJavascriptMember
|
||||
public ref class JavascriptMethodWrapper
|
||||
{
|
||||
private:
|
||||
MCefRefPtr<JavascriptMethodHandler> _javascriptMethodHandler;
|
||||
JavascriptObjectWrapper^ _owner;
|
||||
JavascriptMethod^ _method;
|
||||
JavascriptMethod^ _javascriptMethod;
|
||||
int _ownerId;
|
||||
|
||||
internal:
|
||||
MCefRefPtr<CefV8Value> V8Value;
|
||||
|
||||
public:
|
||||
JavascriptMethodWrapper(JavascriptMethod^ method)
|
||||
JavascriptMethodWrapper(JavascriptMethod^ javascriptMethod, int ownerId)
|
||||
{
|
||||
_method = method;
|
||||
_javascriptMethod = javascriptMethod;
|
||||
_ownerId = ownerId;
|
||||
_javascriptMethodHandler = new JavascriptMethodHandler(gcnew Func<array<Object^>^, Object^>(this, &JavascriptMethodWrapper::Execute));
|
||||
}
|
||||
|
||||
virtual void Bind(JavascriptObject^ owner)
|
||||
virtual void Bind()
|
||||
{
|
||||
_owner = static_cast<JavascriptObjectWrapper^>(owner);
|
||||
|
||||
auto methodName = StringUtils::ToNative(_method->JavascriptName);
|
||||
auto methodName = StringUtils::ToNative(_javascriptMethod->JavascriptName);
|
||||
auto v8Value = CefV8Value::CreateFunction(methodName, _javascriptMethodHandler.get());
|
||||
|
||||
_owner->V8Value->SetValue(methodName, v8Value, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
V8Value->SetValue(methodName, v8Value, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
};
|
||||
|
||||
Object^ Execute(array<Object^>^ parameters);
|
||||
|
||||
Reference in New Issue
Block a user