Пример #1
0
        /// <summary>
        /// Visit the DOM in the remote browser's main frame.
        /// 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 according to the InvokeMode setting.
        ///
        /// The document object passed to the callback represents a snapshot
        /// of the DOM at the time the callback is executed.
        /// DOM objects are only valid for the scope of the callback. Do not
        /// keep references to or attempt to access any DOM objects outside the scope
        /// of the callback.
        /// Use with care:
        /// The callback may never be called if the render process gets killed prematurely.
        /// Do not keep a reference to the remote DOM or remote browser object after returning from the callback.
        /// Do not block the callback since it blocks the renderer thread.
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public bool VisitDom(Action <CfrDomDocument, CfrBrowser> 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 VisitDomTask(this, callback);
                    taskRunner.PostTask(task);
                    return(true);
                }
                finally
                {
                    ctx.Exit();
                }
            }
            catch (CfxRemotingException)
            {
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Visit the DOM in the remote browser's main frame.
 /// 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 according to the InvokeMode setting.
 /// 
 /// The document object passed to the callback represents a snapshot 
 /// of the DOM at the time the callback is executed.
 /// DOM objects are only valid for the scope of the callback. Do not
 /// keep references to or attempt to access any DOM objects outside the scope
 /// of the callback.
 /// Use with care:
 /// The callback may never be called if the render process gets killed prematurely.
 /// Do not keep a reference to the remote DOM or remote browser object after returning from the callback.
 /// Do not block the callback since it blocks the renderer thread.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public bool VisitDom(Action<CfrDomDocument, CfrBrowser> 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 VisitDomTask(this, callback);
             taskRunner.PostTask(task);
             return true;
         }
         finally
         {
             ctx.Exit();
         }
     }
     catch (CfxRemotingException)
     {
         return false;
     }
 }