Ejemplo n.º 1
0
        public bool BindObject(JsBinding binding)
        {
            if (Closed)
            {
                return(false);
            }
            if (RemoteBrowser == null)
            {
                return(false);
            }
            try
            {
                var jsBinding = binding;
                if (JsBindings.ContainsKey(binding.Name))
                {
                    jsBinding = JsBindings[binding.Name];
                    jsBinding.MigrateFunctions(binding);
                }
                else
                {
                    JsBindings.Add(binding.Name, binding);
                }

                var remoteCallContext = RemoteBrowser.CreateRemoteCallContext();
                remoteCallContext.Enter();
                try
                {
                    V8Handler = new CfrV8Handler();
                    jsBinding.Bind(this, V8Handler);
                    var taskrunner = CfrTaskRunner.GetForThread((CfxThreadId)6);
                    if (taskrunner == null)
                    {
                        LogError("Unsuccessful Binding, TaskRunner is null");
                        remoteCallContext.Exit();
                        return(false);
                    }
                    taskrunner.PostTask(new BindFunctionsTask(RemoteBrowser, jsBinding.Name, jsBinding.Functions.Keys.ToArray(), V8Handler));
                    remoteCallContext.Exit();
                    return(true);
                }
                catch (Exception ex)
                {
                    remoteCallContext.Exit();
                    LogError(ex.Message);
                    VvvvLogger?.Log(ex);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                LogError(ex.Message);
                VvvvLogger?.Log(ex);
                return(false);
            }
        }
Ejemplo n.º 2
0
 public bool EvaluateJavascript(string code, Action <CfrV8Value, CfrV8Exception> callback)
 {
     if (Closed)
     {
         return(false);
     }
     if (RemoteBrowser == null)
     {
         return(false);
     }
     try
     {
         var remoteCallContext = RemoteBrowser.CreateRemoteCallContext();
         remoteCallContext.Enter();
         try
         {
             var taskrunner = CfrTaskRunner.GetForThread((CfxThreadId)6);
             if (taskrunner == null)
             {
                 LogError("Not evaluating javascript, TaskRunner is null, wrong CEF thread ID?");
                 return(false);
             }
             taskrunner.PostTask(new EvaluateTask(RemoteBrowser, code, callback));
             return(true);
         }
         finally
         {
             remoteCallContext.Exit();
         }
     }
     catch (IOException ex)
     {
         LogError(ex.Message);
         VvvvLogger?.Log(ex);
         return(false);
     }
 }