public static V8PluginAdapter FromCefObject(CefV8Value value) { if (value == null || !value.IsObject) { return(null); } return(value.GetUserData() as V8PluginAdapter); }
/// <summary> /// 创建JavaScript方法 /// </summary> /// <param name="handler">处理程序</param> /// <param name="javascriptObject">经过V8 JS引擎处理后的对象</param> /// <param name="methodNames">方法键值对集合</param> public static void CreateJavascriptMethods(CefV8Handler handler, CefV8Value javascriptWrapper, IList <String> methodNames) { var unmanagedWrapper = (UnmanagedWrapper)(javascriptWrapper.GetUserData()); foreach (string methodName in methodNames) { string jsMethodName = LowercaseFirst(methodName); //unmanagedWrapper.AddMethodMapping(methodName, jsMethodName); javascriptWrapper.SetValue(jsMethodName, CefV8Value.CreateFunction(jsMethodName, handler), CefV8PropertyAttribute.None); } }
/// <summary> /// 创建JavaScript属性 /// </summary> /// <param name="javascriptWrapper">经过V8 JS引擎处理后的对象</param> /// <param name="properties">属性键值对集合</param> private static void CreateJavascriptProperties(CefV8Value javascriptWrapper, IList <string> properties) { var unmanagedWrapper = (UnmanagedWrapper)(javascriptWrapper.GetUserData()); foreach (string property in properties) { string jsPropertyName = LowercaseFirst(property); var PropertyInfo = unmanagedWrapper.ClrObject.GetType().GetProperty(property, BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.DeclaredOnly); var v8Value = V8ValueClrMap.ConvertToV8Value(PropertyInfo.GetValue(unmanagedWrapper.ClrObject, null)); javascriptWrapper.SetValue(jsPropertyName, v8Value, CefV8PropertyAttribute.None); } }
protected override bool Set(string name, CefV8Value obj, CefV8Value value, out string exception) { var objectUserData = obj.GetUserData() as V8PluginAdapter; var scriptObject = objectUserData != null ? objectUserData.Plugin : null; if (scriptObject != null) { return(scriptObject.SetProperty(name, value, out exception)); } exception = null; return(false); }
protected override bool Get(string name, CefV8Value obj, out CefV8Value returnValue, out string exception) { var objectUserData = obj.GetUserData() as V8PluginAdapter; var scriptObject = objectUserData != null ? objectUserData.Plugin : null; if (scriptObject != null) { return(scriptObject.GetProperty(name, out returnValue, out exception)); } exception = null; returnValue = CefV8Value.CreateUndefined(); return(false); }
public static object GetClrValue(CefV8Value v) { if (v.IsArray) { int length = v.GetArrayLength(); object[] objs = new object[length]; for (int i = 0; i < length; i++) { var value = v.GetValue(i); objs[i] = GetClrValue(value); } return(objs); } if (v.IsBool) { return(v.GetBoolValue()); } if (v.IsDate) { return(v.GetDateValue()); } if (v.IsInt) { return(v.GetIntValue()); } if (v.IsDouble) { return(v.GetDoubleValue()); } if (v.IsFunction) { throw new NotSupportedException("IsFunction"); } if (v.IsNull) { return(null); } if (v.IsObject) { //throw new NotSupportedException("IsObject"); //todo:这里可能存在BUG var map = v.GetUserData() as UnmanagedWrapper; if (map != null) { return(map.ClrObject); } return(null); } if (v.IsString) { return(v.GetStringValue()); } if (v.IsUInt) { return(v.GetUIntValue()); } if (v.IsUndefined) { return(null); } if (v.IsUserCreated) { throw new NotSupportedException("IsUserCreated"); } throw new NotSupportedException("??"); }