internal Callback(CefMessageRouterBrowserSide router, int browserId, long queryId, bool persistent)
 {
     _router     = router;
     _browserId  = browserId;
     _queryId    = queryId;
     _persistent = persistent;
 }
            /// <summary>
            /// Notify the associated JavaScript onFailure callback that the query has
            /// failed with the specified |error_code| and |error_message|.
            /// </summary>
            public void Failure(int errorCode, string errorMessage)
            {
                if (!CefRuntime.CurrentlyOn(CefThreadId.UI))
                {
                    // Must execute on the UI thread to access member variables.
                    Helpers.PostTask(CefThreadId.UI,
                                     Helpers.Apply(this.Failure, errorCode, errorMessage)
                                     );
                    return;
                }

                if (_router != null)
                {
                    Helpers.PostTaskUncertainty(CefThreadId.UI,
                                                Helpers.Apply(_router.OnCallbackFailure, _browserId, _queryId, errorCode, errorMessage)
                                                );

                    // Failure always invalidates the callback.
                    _router = null;
                }
            }
            /// <summary>
            /// Notify the associated JavaScript onSuccess callback that the query has
            /// completed successfully with the specified |response|.
            /// </summary>
            public void Success(string response)
            {
                if (!CefRuntime.CurrentlyOn(CefThreadId.UI))
                {
                    Helpers.PostTask(CefThreadId.UI,
                                     Helpers.Apply(this.Success, response)
                                     );
                    return;
                }

                if (_router != null)
                {
                    Helpers.PostTaskUncertainty(CefThreadId.UI,
                                                Helpers.Apply(_router.OnCallbackSuccess, _browserId, _queryId, response)
                                                );

                    if (!_persistent)
                    {
                        // Non-persistent callbacks are only good for a single use.
                        _router = null;
                    }
                }
            }
 internal void Detach()
 {
     Helpers.RequireUIThread();
     _router = null;
 }