Beispiel #1
0
        private void JavascriptFunctionLoadInternalScript(CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            if (arguments.Length < 1 || !arguments[0].IsString)
            {
                throw new ArgumentException("Invalid arguments.", "arguments");
            }

            returnValue = null;

            var scriptName = "Scripts/" + arguments[0].GetStringValue();

            if (!ResourceUtility.ResourceExists(scriptName))
            {
                throw new InvalidOperationException(string.Format("Script '{0}' not found.", scriptName));
            }

            CefV8Value     evalReturnValue = null;
            CefV8Exception evalException   = null;

            string script  = ResourceUtility.GetResourceAsString(scriptName);
            var    context = CefV8Context.GetCurrentContext();

            if (!context.TryEval(script, out evalReturnValue, out evalException))
            {
                throw new InvalidOperationException(string.Format("Javascript exception: {0}.", JsonConvert.SerializeObject(evalException)));
            }
        }
Beispiel #2
0
        public void Execute(CallbackExecution <CefValue> execution)
        {
            CefV8Exception exception = null;

            using (new ContextHelper(context))
            {
                var cefV8Values = execution.Parameters.Select(s => (CefV8Value)v8Serializer.Deserialize(s, typeof(CefV8Value))).ToArray();
                var result      = function.ExecuteFunction(null, cefV8Values);


                var browser = context.GetBrowser();

                if (result == null && function.HasException)
                {
                    exception = function.GetException();
                    function.ClearException();
                }

                if (promiseService.IsPromise(result, context))
                {
                    promiseService.Then(result, context, a => CallbackDone(a, browser, execution.ExecutionId));
                }
                else
                {
                    CallbackDone(new PromiseResult
                    {
                        Success = result != null,
                        Result  = result,
                        Error   = exception?.Message
                    }, browser, execution.ExecutionId);
                }
            }
        }
 public CefUncaughtExceptionEventArgs(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     this.browser = browser;
     this.frame = frame;
     this.context = context;
     this.exception = exception;
     this.stackTrace = stackTrace;
 }
Beispiel #4
0
 public CefUncaughtExceptionEventArgs(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     this.browser    = browser;
     this.frame      = frame;
     this.context    = context;
     this.exception  = exception;
     this.stackTrace = stackTrace;
 }
Beispiel #5
0
        public bool Eval(string code, out IJavascriptObject res)
        {
            CefV8Exception exp  = null;
            CefV8Value     val  = null;
            bool           bres = Context.TryEval(code, out val, out exp);

            res = (val == null) ? null : new CefV8_JavascriptObject(val);
            return(bres);
        }
Beispiel #6
0
        /// <summary>
        /// Evals the HTML UI script.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="context">The context.</param>
        private void EvalHtmlUiScript(string name, CefV8Context context, bool mapping)
        {
            CefV8Value     returnValue = null;
            CefV8Exception exception   = null;

            if (!context.TryEval(GetHtmlUiScript(name, mapping), out returnValue, out exception))
            {
                Logger.Error(string.Format("Register html ui script exception: {0}.", JsonConvert.SerializeObject(exception)));
            }
        }
Beispiel #7
0
        /// <summary>
        /// create
        /// </summary>
        /// <param name="userJsCode"></param>
        /// <returns></returns>
        protected static bool CreateFromJsCode(CefV8Context ownerContext,
                                               string userJsCode,
                                               out IntPtr nativeFunc)
        {
            IntPtr ret       = IntPtr.Zero;
            IntPtr exception = IntPtr.Zero;

            //eval in js side

            if (ownerContext.Eval(userJsCode, "", 1, ref ret, ref exception))
            {
                nativeFunc = ret;
                return(true);
            }
            else
            {
                //dispose
                nativeFunc = IntPtr.Zero;
                CefV8Exception v8Exception = new CefV8Exception(exception);
                v8Exception.Dispose();
                return(false);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Called for global uncaught exceptions in a frame. Execution of this
        /// callback is disabled by default. To enable set
        /// CefSettings.uncaught_exception_stack_size &gt; 0.
        /// </summary>
        /// <param name="browser"></param>
        /// <param name="frame"></param>
        /// <param name="context"></param>
        /// <param name="exception"></param>
        /// <param name="stackTrace"></param>
        protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            GeneralLog.Error("Render process unhandled exception: " + exception.Message);
        }
Beispiel #9
0
 protected internal unsafe override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     _implementation.OnUncaughtException(browser, frame, context, exception, stackTrace);
 }
Beispiel #10
0
        protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
        {
            base.OnUncaughtException(browser, frame, context, exception, stackTrace);

            System.Collections.Generic.List <string> data = new System.Collections.Generic.List <string>();
            data.Add(string.Format("Url: {0}", frame.Url));
            data.Add(string.Format("ScriptResourceName: {0}", exception.ScriptResourceName));
            data.Add(string.Format("Message: {0}", exception.Message));
            data.Add(string.Format("LineNumber: {0}", exception.LineNumber));
            data.Add(string.Format("SourceLine: {0}", exception.SourceLine));
            data.Add(string.Format("StartColumn: {0}", exception.StartColumn));
            data.Add(string.Format("EndColumn: {0}", exception.EndColumn));
            System.Windows.Forms.MessageBox.Show(string.Join(Environment.NewLine, data));
        }
 protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     Log.Warn("RenderProcessHandler.OnUncaughtException( browser: {0}, frame: {1}, exception: {2} )",
              browser.Identifier,
              frame.Identifier,
              "\"" + exception.Message + "\" at line " + exception.LineNumber + " in script \"" + exception.ScriptResourceName + "\"");
     base.OnUncaughtException(browser, frame, context, exception, stackTrace);
 }
 protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     _context.OnUncaughtException(browser, frame, context, exception, stackTrace);
 }
Beispiel #13
0
        /// <summary>
        /// Called for global uncaught exceptions in a frame. Execution of this
        /// callback is disabled by default. To enable set
        /// CefSettings.uncaught_exception_stack_size &gt; 0.
        /// </summary>
        /// <param name="browser"></param>
        /// <param name="frame"></param>
        /// <param name="context"></param>
        /// <param name="exception"></param>
        /// <param name="stackTrace"></param>
        protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            Logger.Error(string.Format("Unhandled exception: {0}", JsonConvert.SerializeObject(exception)));
        }
 protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     _context.OnUncaughtException(browser, frame, context, exception, stackTrace);
 }
Beispiel #15
0
        /// <summary>
        /// Sends the request to the browser process.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="obj"></param>
        /// <param name="arguments"></param>
        /// <param name="returnValue"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            returnValue = null;
            exception   = null;

            // native
            if (name == "native")
            {
                var functionName     = arguments[0].GetStringValue();
                var jsonData         = arguments[1].GetStringValue();
                var callbackFunction = arguments.Length > 2 && arguments[2].IsFunction ? arguments[2] : null;

                var callbackId = AddCallback(callbackFunction, CefV8Context.GetCurrentContext());

                MessageUtility.SendMessage(CefBrowser, "native", callbackId, new CallNative {
                    Name = functionName, Json = jsonData
                });

                return(true);
            }

            // register function
            else if (name == "registerFunction")
            {
                var functionName = arguments[0].GetStringValue();
                var function     = arguments[1];

                if (!Functions.ContainsKey(functionName))
                {
                    Functions.Add(functionName, new JavascriptFunction(function, CefV8Context.GetCurrentContext()));
                }
                else
                {
                    exception = string.Format("Function '{0}' is already registered.", functionName);
                }

                return(true);
            }

            // load internal script
            else if (name == "loadInternalScript")
            {
                if (arguments.Length > 0 && arguments[0].IsString)
                {
                    var scriptName = "Scripts/" + arguments[0].GetStringValue();

                    if (ResourceUtility.ResourceExists(scriptName))
                    {
                        CefV8Value     evalReturnValue = null;
                        CefV8Exception evalException   = null;

                        string script  = ResourceUtility.GetResourceAsString(scriptName);
                        var    context = CefV8Context.GetCurrentContext();

                        if (!context.TryEval(script, out evalReturnValue, out evalException))
                        {
                            exception = string.Format("Exception: {0}.", JsonConvert.SerializeObject(exception));
                        }
                    }
                    else
                    {
                        exception = "Script not found.";
                    }
                }
                else
                {
                    exception = "Missing script name.";
                }

                return(true);
            }

            return(false);
        }
Beispiel #16
0
 protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     Logger.Info("UncaughtException in Renderer Browser {0} Frame {1}: {2}",
                 browser != null ? browser.Identifier : -1,
                 frame != null ? frame.Identifier : -1,
                 exception != null ? exception.Message : string.Empty);
     base.OnUncaughtException(browser, frame, context, exception, stackTrace);
 }
 protected override void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     Console.WriteLine($"BrowserException: Line: {exception.LineNumber}, Col: {exception.StartColumn}, Message: {exception.Message} \nSource: {exception.SourceLine} \nStacktrace:{stackTrace.ToString()}");
 }
 internal void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     var handler = this.UncaughtException;
     if (handler != null)
     {
         handler(this, new CefUncaughtExceptionEventArgs(browser, frame, context, exception, stackTrace));
     }
 }
Beispiel #19
0
        internal void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
        {
            var handler = this.UncaughtException;

            if (handler != null)
            {
                handler(this, new CefUncaughtExceptionEventArgs(browser, frame, context, exception, stackTrace));
            }
        }
 public void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     _application.OnUncaughtException(new CefUncaughtExceptionEventArgs(browser, frame, context, exception, stackTrace));
 }