Ejemplo n.º 1
0
 internal EvaluateTask(IChromiumWebBrowser wb, string code, JSInvokeMode invokeMode, Action<CfrV8Value, CfrV8Exception> callback)
 {
     this.wb = wb;
     this.code = code;
     this.invokeMode = invokeMode;
     this.callback = callback;
     lock (tasks) tasks.Add(this);
     Execute += (s, e) => {
         if (invokeMode == JSInvokeMode.Invoke || (invokeMode == JSInvokeMode.Inherit && wb.RemoteCallbacksWillInvoke))
             wb.RenderThreadInvoke(() => Task_Execute(e));
         else
             Task_Execute(e);
         lock (tasks) tasks.Remove(this);
     };
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Evaluate a string of javascript code in the browser's main frame.
 /// Evaluation is done asynchronously in the render process.
 /// Returns false if the remote browser is currently unavailable.
 /// If this function returns false, then |callback| will not be called. Otherwise,
 /// |callback| will be called asynchronously in the context of the render thread.
 /// 
 /// If |invokeMode| is set to Invoke, |callback| will be called on the thread that 
 /// owns the browser's underlying window handle. If |invokeMode| is set to Inherit,
 /// |callback| will be called according to RemoteCallbackInvokeMode.
 /// 
 /// Use with care:
 /// The callback may never be called if the render process gets killed prematurely.
 /// On success the CfrV8Value argument of the callback will be set to the return value
 /// of the evaluated script, if any. On failure the CfrV8Exception argument of the callback
 /// will be set to the exception thrown by the evaluated script, if any.
 /// Do not block the callback since it blocks the render thread.
 /// </summary>
 public bool EvaluateJavascript(string code, JSInvokeMode invokeMode, Action<CfrV8Value, CfrV8Exception> callback)
 {
     var rb = remoteBrowser;
     if (rb == null) return false;
     try
     {
         var ctx = rb.CreateRemoteCallContext();
         ctx.Enter();
         try
         {
             var taskRunner = CfrTaskRunner.GetForThread(CfxThreadId.Renderer);
             var task = new EvaluateTask(this, code, invokeMode, callback);
             taskRunner.PostTask(task);
             return true;
         }
         finally
         {
             ctx.Exit();
         }
     }
     catch (CfxRemotingException)
     {
         return false;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new javascript object to be added as a property
 /// to a browser frame's global object or a child object.
 /// </summary>
 public JSObject(JSInvokeMode invokeMode)
     : base(JSPropertyType.Object, invokeMode)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new javascript function to be added as a property
 /// to a browser frame's global object or to a child object.
 /// </summary>
 public JSFunction(JSInvokeMode invokeMode)
     : base(JSPropertyType.Function, invokeMode)
 {
 }
Ejemplo n.º 5
0
 public bool EvaluateJavascript(string code, JSInvokeMode invokeMode, Action <CfrV8Value, CfrV8Exception> callback)
 {
     return(((IChromiumWebBrowser)browser).EvaluateJavascript(code, invokeMode, callback));
 }
Ejemplo n.º 6
0
 public bool EvaluateJavascript(string code, JSInvokeMode invokeMode, Action <CfrV8Value, CfrV8Exception> callback) => Chromium.EvaluateJavascript(code, invokeMode, callback);