-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Copy pathJavascriptObjectWrapper.cpp
57 lines (45 loc) · 2.34 KB
/
JavascriptObjectWrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright © 2014 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.
#pragma once
#include "Stdafx.h"
#include "JavascriptObjectWrapper.h"
namespace CefSharp
{
namespace BrowserSubprocess
{
void JavascriptObjectWrapper::Bind(JavascriptObject^ object, const CefRefPtr<CefV8Value>& v8Value, JavascriptCallbackRegistry^ callbackRegistry)
{
_objectId = object->Id;
//Create property handler for get and set of Properties of this object
_jsPropertyHandler = new JavascriptPropertyHandler(
gcnew Func<String^, BrowserProcessResponse^>(this, &JavascriptObjectWrapper::GetProperty),
gcnew Func<String^, Object^, BrowserProcessResponse^>(this, &JavascriptObjectWrapper::SetProperty)
);
//V8Value that represents this javascript object - only one per complex type
auto javascriptObject = CefV8Value::CreateObject(_jsPropertyHandler.get(), nullptr);
auto objectName = StringUtils::ToNative(object->JavascriptName);
v8Value->SetValue(objectName, javascriptObject, V8_PROPERTY_ATTRIBUTE_NONE);
for each (JavascriptMethod ^ method in Enumerable::OfType<JavascriptMethod^>(object->Methods))
{
auto wrappedMethod = gcnew JavascriptMethodWrapper(object->Id, _browserProcess, callbackRegistry);
wrappedMethod->Bind(method, javascriptObject);
_wrappedMethods->Add(wrappedMethod);
}
for each (JavascriptProperty ^ prop in Enumerable::OfType<JavascriptProperty^>(object->Properties))
{
auto wrappedproperty = gcnew JavascriptPropertyWrapper(object->Id, _browserProcess);
wrappedproperty->Bind(prop, javascriptObject, callbackRegistry);
_wrappedProperties->Add(wrappedproperty);
}
}
BrowserProcessResponse^ JavascriptObjectWrapper::GetProperty(String^ memberName)
{
return _browserProcess->GetProperty(_objectId, memberName);
};
BrowserProcessResponse^ JavascriptObjectWrapper::SetProperty(String^ memberName, Object^ value)
{
return _browserProcess->SetProperty(_objectId, memberName, value);
};
}
}