/// <summary> /// To the javascript exception. /// </summary> /// <returns></returns> JavascriptException INativeException.ToJavascriptException() { return(new JavascriptException { Message = Message, Type = "SyncMaxDepthException", InnerException = InnerException != null?ExceptionUtility.CreateJavascriptException(InnerException) : null, AdditionalData = new Dictionary <string, object> { { "SyncMaxDepth", SyncMaxDepth } } }); }
/// <summary> /// To the javascript exception. /// </summary> /// <returns></returns> JavascriptException INativeException.ToJavascriptException() { return(new JavascriptException { Message = Message, Type = "NativeNotFoundException", InnerException = InnerException != null?ExceptionUtility.CreateJavascriptException(InnerException) : null, AdditionalData = new Dictionary <string, object> { { "NativeName", NativeName } } }); }
/// <summary> /// To the javascript exception. /// </summary> /// <returns></returns> JavascriptException INativeException.ToJavascriptException() { return(new JavascriptException { Message = Message, Type = "ParameterCountMismatchException", InnerException = InnerException != null?ExceptionUtility.CreateJavascriptException(InnerException) : null, AdditionalData = new Dictionary <string, object> { { "MethodName", MethodName }, { "ControllerName", ControllerName } } }); }
/// <summary> /// To the javascript exception. /// </summary> /// <returns></returns> JavascriptException INativeException.ToJavascriptException() { return(new JavascriptException { Message = Message, Type = "ReadOnlyPropertyException", InnerException = InnerException != null?ExceptionUtility.CreateJavascriptException(InnerException) : null, AdditionalData = new Dictionary <string, object> { { "ControllerName", ControllerName }, { "PropertyName", PropertyName } } }); }
/// <summary> /// Gets the response headers. /// </summary> /// <param name="response"></param> /// <param name="responseLength"></param> /// <param name="redirectUrl"></param> protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl) { if (response == null) { throw new ArgumentNullException("response"); } redirectUrl = null; response.Status = 200; response.StatusText = "OK"; response.MimeType = "application/json"; response.SetHeaderMap(new NameValueCollection { { "Access-Control-Allow-Origin", "*" } }); var nativeResponse = new NativeResponse(); // exception if (Exception != null) { nativeResponse.Type = NativeResponseType.Exception; nativeResponse.Value = null; nativeResponse.Exception = ExceptionUtility.CreateJavascriptException(Exception); } // ok else { if (ResponseValue == Undefined.Value) { nativeResponse.Type = NativeResponseType.Undefined; nativeResponse.Value = null; } else { nativeResponse.Type = NativeResponseType.Value; nativeResponse.Value = ResponseValue; } nativeResponse.Exception = null; } Data = JsonUtility.SerializeToByteJson(nativeResponse); responseLength = Data.Length; }
public bool ProcessMessage(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage processMessage) { if (processMessage.Name == "native") { var message = MessageUtility.DeserializeMessage <CallNative>(processMessage); BaseMainApplication.Current.InvokeOnMainAsync(() => { var returnData = (object)null; var exception = (Exception)null; // native found if (ProcessMessages.ContainsKey(message.Data.Name)) { try { returnData = ProcessMessages[message.Data.Name](message.Data.Json); } catch (Exception e) { exception = e; returnData = null; } } else { exception = new NativeNotFoundException(message.Data.Name); } // callback if (message.CallbackId != null) { var nativeResponse = new NativeResponse(); if (exception != null) { nativeResponse.Exception = ExceptionUtility.CreateJavascriptException(exception); nativeResponse.Type = NativeResponseType.Exception; nativeResponse.Value = null; } else { if (returnData == Undefined.Value) { nativeResponse.Exception = null; nativeResponse.Type = NativeResponseType.Undefined; nativeResponse.Value = null; } else { nativeResponse.Exception = null; nativeResponse.Type = NativeResponseType.Value; nativeResponse.Value = returnData; } } var returnJson = JsonUtility.SerializeToJson(nativeResponse); MessageUtility.SendMessage(browser, "native", message.CallbackId, returnJson); } }).ContinueWith(t => { GeneralLog.Error("Native call exception.", t.Exception); }, TaskContinuationOptions.OnlyOnFaulted); return(true); } return(false); }
private void ProcessMessageNative(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage processMessage) { var callNative = MessageUtility.DeserializeMessage <CallNative>(processMessage); Application.Current.InvokeOnMainAsync(() => { object returnData = null; Exception exception = null; NativeFunctionDelegate handler; NativeFunctionDelegates.TryGetValue(callNative.Name, out handler); // function call if (handler != null) { try { returnData = handler(callNative.Json); } catch (Exception e) { exception = e; } } else { exception = new NativeNotFoundException(callNative.Name); } // callback if (callNative.CallbackId != null) { var nativeResponse = new NativeResponse(); if (exception != null) { nativeResponse.Exception = ExceptionUtility.CreateJavascriptException(exception); nativeResponse.Type = NativeResponseType.Exception; nativeResponse.Value = null; } else { if (returnData == Value.Undefined) { nativeResponse.Exception = null; nativeResponse.Type = NativeResponseType.Undefined; nativeResponse.Value = null; } else { nativeResponse.Exception = null; nativeResponse.Type = NativeResponseType.Value; nativeResponse.Value = returnData; } } var returnJson = JsonUtility.SerializeToJson(nativeResponse); MessageUtility.SendMessage(CefProcessId.Renderer, browser, "native", new CallNativeResult { JsonResult = returnJson, CallbackId = callNative.CallbackId }); } }).ContinueWith(t => { Logger.Error("Native call exception.", t.Exception); }, TaskContinuationOptions.OnlyOnFaulted); }