protected void AppendArgs(CefListValue argList, int start, IEnumerable <object> args) { foreach (object value in args) { int index = start; start++; if (value is V8Undefined) { argList.SetBinary(index, new byte[1]); continue; } if (value is null) { argList.SetNull(index); continue; } switch (value) { case string v: argList.SetString(index, v); continue; case int v: argList.SetInt(index, v); continue; case double v: argList.SetDouble(index, v); continue; case bool v: argList.SetBool(index, v); continue; case DateTime v: argList.SetBinary(index, XrayHandle.FromDateTime(v).ToCfxBinaryValue()); continue; case XrayHandle v: argList.SetBinary(index, ValidateXrayHandle(v).ToCfxBinaryValue()); continue; case ScriptableObject v: argList.SetBinary(index, ValidateXrayHandle((XrayHandle)v).ToCfxBinaryValue()); continue; } throw new NotImplementedException("Type: " + value.GetType().Name); } }
public object SendRequest(XrayAction action, XrayHandle thisArg, params object[] args) { var sqi = new ScriptableRequestInfo(); CefProcessMessage msg = null; try { msg = new CefProcessMessage(CefNetApplication.XrayRequestKey); CefListValue argList = msg.ArgumentList; if (!argList.SetSize(3 + args.Length)) { throw new InvalidOperationException(); } argList.SetInt(0, sqi.RequestId); argList.SetInt(1, (int)action); argList.SetBinary(2, ValidateXrayHandle(thisArg).ToCfxBinaryValue()); AppendArgs(argList, 3, args); CefFrame frame = this.Frame; if (!frame.IsValid || frame.Identifier != _frameId) { throw new ObjectDeadException(); } frame.SendProcessMessage(CefProcessId.Renderer, msg); sqi.Wait(); return(sqi.GetResult()); } finally { msg?.Dispose(); sqi.Dispose(); } }
public void ReleaseObject(XrayHandle handle) { if (CefNetApplication.ProcessType == ProcessType.Renderer) { if (CefApi.CurrentlyOn(CefThreadId.Renderer)) { handle.Release(); } else { CefApi.PostTask(CefThreadId.Renderer, new V8CallTask(handle.Release)); } return; } CefBinaryValue obj = null; CefProcessMessage msg = null; try { if (_frameId != handle.frame) { return; } obj = handle.ToCfxBinaryValue(); msg = new CefProcessMessage(CefNetApplication.XrayReleaseKey); using (CefListValue args = msg.ArgumentList) { if (!args.SetSize(1)) { return; } args.SetBinary(0, obj); } _frame.SendProcessMessage(CefProcessId.Renderer, msg); } finally { if (msg != null) { msg.Dispose(); } if (obj != null) { obj.Dispose(); } } }
public static void SetTime(this CefListValue @this, int index, DateTime value) { SetTime(_ => @this.SetBinary(index, _), value); }
public static void SetInt64(this CefListValue @this, int index, long value) { SetInt64(_ => @this.SetBinary(index, _), value); }