Beispiel #1
0
        private void UpdateDom(CefFrame frame)
        {
            var request = CefProcessMessage.Create("dom-request");

            request.SetFrameIdentifier(frame.Identifier);
            FBrowser.SendProcessMessage(CefProcessId.Renderer, request);
        }
 public string GetElementValueById(string id)
 {
     Global.flag = false;
     browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("GetElementValue|" + id));
     while (!Global.flag)
     {
     }
     return(Global.Result);
 }
Beispiel #3
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (DumpProcessMessages)
            {
                Console.WriteLine("Render::OnProcessMessageReceived: SourceProcess={0}", sourceProcess);
                Console.WriteLine("Message Name={0} IsValid={1} IsReadOnly={2}", message.Name, message.IsValid, message.IsReadOnly);
                var arguments = message.Arguments;
                for (var i = 0; i < arguments.Count; i++)
                {
                    var    type = arguments.GetValueType(i);
                    object value;
                    switch (type)
                    {
                    case CefValueType.Null: value = null; break;

                    case CefValueType.String: value = arguments.GetString(i); break;

                    case CefValueType.Int: value = arguments.GetInt(i); break;

                    case CefValueType.Double: value = arguments.GetDouble(i); break;

                    case CefValueType.Bool: value = arguments.GetBool(i); break;

                    default: value = null; break;
                    }

                    Console.WriteLine("  [{0}] ({1}) = {2}", i, type, value);
                }
            }

            var handled = MessageRouter.OnProcessMessageReceived(browser, sourceProcess, message);

            if (handled)
            {
                return(true);
            }

            if (message.Name == "myMessage2")
            {
                return(true);
            }

            var message2 = CefProcessMessage.Create("myMessage2");
            var success  = browser.SendProcessMessage(CefProcessId.Renderer, message2);

            Console.WriteLine("Sending myMessage2 to renderer process = {0}", success);

            var message3 = CefProcessMessage.Create("myMessage3");
            var success2 = browser.SendProcessMessage(CefProcessId.Browser, message3);

            Console.WriteLine("Sending myMessage3 to browser process = {0}", success);

            return(false);
        }
            private void HandleDomRequest(CefBrowser browser, CefProcessId sourceProcess, long frameIdentifier)
            {
                var scheduler = GetTaskScheduler(CefThreadId.Renderer);

                Task.Factory.StartNew(
                    () =>
                {
                    var frame = browser.GetFrame(frameIdentifier);
                    if (frame != null)
                    {
                        var visitor = new DomVisitor();
                        frame.VisitDom(visitor);
                        var response = CefProcessMessage.Create("dom-response");
                        response.SetFrameIdentifier(frame.Identifier);
                        if (visitor.Result != null)
                        {
                            response.Arguments.SetBool(2, true);
                            response.Arguments.SetString(3, visitor.Result.ToString());
                        }
                        else
                        {
                            response.Arguments.SetBool(2, false);
                            response.Arguments.SetString(3, visitor.Exception.ToString());
                        }
                        browser.SendProcessMessage(sourceProcess, response);
                    }
                },
                    CancellationToken.None,
                    TaskCreationOptions.None,
                    scheduler);
            }
Beispiel #5
0
        // Returns the new request ID.
        private int SendQuery(CefBrowser browser, long frameId, int contextId, string request, bool persistent, CefV8Value successCallback, CefV8Value failureCallback)
        {
            Helpers.RequireRendererThread();

            var requestId = _requestIdGenerator.GetNextId();

            var info = new RequestInfo
            {
                Persistent      = persistent,
                SuccessCallback = successCallback,
                FailureCallback = failureCallback,
            };

            _browserRequestInfoMap.Add(browser.Identifier, new KeyValuePair <int, int>(contextId, requestId), info);

            var message = CefProcessMessage.Create(_queryMessageName);
            var args    = message.Arguments;

            args.SetInt(0, Helpers.Int64GetLow(frameId));
            args.SetInt(1, Helpers.Int64GetHigh(frameId));
            args.SetInt(2, contextId);
            args.SetInt(3, requestId);
            args.SetString(4, request);
            args.SetBool(5, persistent);

            browser.SendProcessMessage(CefProcessId.Browser, message);

            args.Dispose();
            message.Dispose();

            return(requestId);
        }
Beispiel #6
0
        private void CallbackDone(PromiseResult promiseResult, CefBrowser browser, long executionId)
        {
            var callbackResult = new CallbackResult <CefValue>
            {
                ExecutionId = executionId,
                Success     = promiseResult.Success
            };

            if (promiseResult.Success)
            {
                callbackResult.Result = v8Serializer.Serialize(promiseResult.Result, new HashSet <object>());
            }
            else if (!string.IsNullOrWhiteSpace(promiseResult.Error))
            {
                callbackResult.Error = promiseResult.Error;
            }

            var response = new RpcResponse <CefValue>
            {
                CallbackResult = callbackResult
            };
            var msg        = CefProcessMessage.Create(Messages.RpcResponseMessage);
            var serialized = v8Serializer.Serialize(response, new HashSet <object>());

            msg.Arguments.SetValue(0, serialized);

            browser.SendProcessMessage(CefProcessId.Browser, msg);
        }
Beispiel #7
0
        private void SendResponse(RpcResponse <CefValue> response)
        {
            var msg        = CefProcessMessage.Create(Messages.RpcResponseMessage);
            var serialized = objectSerializer.Serialize(response, new HashSet <object>());

            msg.Arguments.SetValue(0, serialized);

            browser.SendProcessMessage(CefProcessId.Browser, msg);
        }
Beispiel #8
0
        protected override void OnLoadStart(CefBrowser browser, CefFrame frame)
        {
            base.OnLoadStart(browser, frame);

            var message = CefProcessMessage.Create("SetOverlayAPI");

            message.Arguments.SetString(0, frame.Name);
            browser.SendProcessMessage(CefProcessId.Renderer, message);
        }
 public void showdetails(string url)
 {
     using (CefBrowser browser = CefV8Context.GetCurrentContext().GetBrowser())
     {
         CefProcessMessage message = CefProcessMessage.Create(url);
         browser.SendProcessMessage(CefProcessId.Browser, message);
         message.Dispose();
     }
 }
Beispiel #10
0
        /// <summary>
        /// Send a message across the CEF boundary.
        /// </summary>
        /// <param name="browser">The browser instance to send the mesage to.</param>
        /// <param name="pluginMessage">The message to send.</param>
        protected void SendMessage(CefBrowser browser, PluginMessage pluginMessage)
        {
            if (browser == null)
            {
                throw new ArgumentNullException("browser");
            }
            var message = CefProcessMessage.Create(CallInfo.Call);

            SerializeProcessMessage(pluginMessage, message.Arguments);
            browser.SendProcessMessage(_remotePluginProcess, message);
        }
Beispiel #11
0
        protected override void OnLoadStart(CefBrowser browser, CefFrame frame, CefTransitionType transitionType)
        {
            base.OnLoadStart(browser, frame, transitionType);

            var message = CefProcessMessage.Create("SetOverlayAPI");

            message.Arguments.SetString(0, frame.Name);
            message.Arguments.SetString(1, this.renderer.OverlayName);
            message.Arguments.SetString(2, this.renderer.OverlayVersion);
            browser.SendProcessMessage(CefProcessId.Renderer, message);
        }
Beispiel #12
0
            protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
            {
                if (message.Name == "renderProcessIdRequest")
                {
                    CefProcessMessage response = CefProcessMessage.Create("renderProcessIdResponse");
                    response.Arguments.SetInt(0, Process.GetCurrentProcess().Id);
                    browser.SendProcessMessage(CefProcessId.Browser, response);
                }

                return(false);
            }
Beispiel #13
0
        public void Send(RpcRequest <CefValue> rpcRequest)
        {
            var message = rpcRequest.ToCefProcessMessage();

            if (message != null)
            {
                browser.SendProcessMessage(CefProcessId.Renderer, message);
            }
            else
            {
                throw new Exception();
            }
        }
        private void SendQuerySuccess(CefBrowser browser, int contextId, int requestId, string response)
        {
            var message = CefProcessMessage.Create(_queryMessageName);
            var args    = message.Arguments;

            args.SetInt(0, contextId);
            args.SetInt(1, requestId);
            args.SetBool(2, true);  // Indicates a success result.
            args.SetString(3, response);
            browser.SendProcessMessage(CefProcessId.Renderer, message);
            args.Dispose();
            message.Dispose();
        }
Beispiel #15
0
        // If |requestId| is kReservedId all requests associated with |contextId|
        // will be canceled, otherwise only the specified |requestId| will be
        // canceled. Returns true if any request was canceled.
        private bool SendCancel(CefBrowser browser, long frameId, int contextId, int requestId)
        {
            Helpers.RequireRendererThread();

            var browserId = browser.Identifier;

            int cancelCount = 0;

            if (requestId != CefMessageRouter.ReservedId)
            {
                // Cancel a single request.
                bool removed = false;
                var  info    = GetRequestInfo(browserId, contextId, requestId, true, ref removed);
                if (info != null)
                {
                    Debug.Assert(removed);
                    info.Dispose();
                    cancelCount = 1;
                }
            }
            else
            {
                // Cancel all requests with the specified context ID.
                BrowserRequestInfoMap.Visitor visitor = (int vBrowserId, KeyValuePair <int, int> vInfoId, RequestInfo vInfo, ref bool vRemove) =>
                {
                    if (vInfoId.Key == contextId)
                    {
                        vRemove = true;
                        vInfo.Dispose();
                        cancelCount++;
                    }
                    return(true);
                };

                _browserRequestInfoMap.FindAll(browserId, visitor);
            }

            if (cancelCount > 0)
            {
                var message = CefProcessMessage.Create(_cancelMessageName);

                var args = message.Arguments;
                args.SetInt(0, contextId);
                args.SetInt(1, requestId);

                browser.SendProcessMessage(CefProcessId.Browser, message);
                return(true);
            }

            return(false);
        }
Beispiel #16
0
        /// <summary>
        /// 从其对应的render 进程中接收过来的消息过滤处理
        /// </summary>
        /// <param name="browser"></param>
        /// <param name="sourceProcess"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            Console.WriteLine("Render::OnProcessMessageReceived: SourceProcess={0}", sourceProcess);
            Console.WriteLine("Message Name={0} IsValid={1} IsReadOnly={2}", message.Name, message.IsValid, message.IsReadOnly);
            var arguments = message.Arguments;

            for (var i = 0; i < arguments.Count; i++)
            {
                var    type = arguments.GetValueType(i);
                object value;
                switch (type)
                {
                case CefValueType.Null: value = null; break;

                case CefValueType.String: value = arguments.GetString(i); break;

                case CefValueType.Int: value = arguments.GetInt(i); break;

                case CefValueType.Double: value = arguments.GetDouble(i); break;

                case CefValueType.Bool: value = arguments.GetBool(i); break;

                default: value = null; break;
                }

                Console.WriteLine("  [{0}] ({1}) = {2}", i, type, value);
            }
            //filters
            if (message.Name.Equals(IPCCommand.CommandType.GET_COOKIE_FROM_BROWSER_PROCESS.ToString()))
            {
                var    argumentsInMsg = message.Arguments;
                string domainName     = argumentsInMsg.GetString(0);
                if (!string.IsNullOrEmpty(domainName))
                {
                    //获取指定域名的cookie
                    var cks = new LazyCookieVistor().LoadNativCookies(domainName);
                    if (cks.IsNotEmpty())
                    {
                        var cookieString    = cks.ToJson();
                        var message_cookies = CefProcessMessage.Create(IPCCommand.CommandType.GET_COOKIE_FROM_BROWSER_PROCESS.ToString());
                        message_cookies.Arguments.SetString(0, domainName);
                        message_cookies.Arguments.SetString(1, cookieString);
                        var success = browser.SendProcessMessage(CefProcessId.Renderer, message_cookies);
                        Console.WriteLine("Sending myMessage3 to browser process = {0}", success);
                    }
                }
            }
            return(true);
            //return base.OnProcessMessageReceived(browser, sourceProcess, message);
        }
        private void SendQueryFailure(CefBrowser browser, int contextId, int requestId, int errorCode, string errorMessage)
        {
            var message = CefProcessMessage.Create(_queryMessageName);
            var args    = message.Arguments;

            args.SetInt(0, contextId);
            args.SetInt(1, requestId);
            args.SetBool(2, false);  // Indicates a failure result.
            args.SetInt(3, errorCode);
            args.SetString(4, errorMessage);
            browser.SendProcessMessage(CefProcessId.Renderer, message);
            args.Dispose();
            message.Dispose();
        }
Beispiel #18
0
 public void Load()
 {
     Global.flag = false;
     if (Root != null)
     {
         Root.ChildElements.Clear();
     }
     browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("GetDocument"));
     while (!Global.flag)
     {
     }
     _root = Global.RootList[browser.Identifier];
     CefCookieManager.Global.VisitUrlCookies(browser.GetMainFrame().Url, true, new CwbCookieVisitor(CwbCookieStyle.csVisitUrlCookie, this));
 }
Beispiel #19
0
 protected override void OnBrowserCreated(CefBrowser browser)
 {
     Logger.Info("Created Browser {0}", browser.Identifier);
     try
     {
         var msg = CefProcessMessage.Create(RENDER_PROC_ID_MESSAGE);
         msg.Arguments.SetInt(0, Process.GetCurrentProcess().Id);
         browser.SendProcessMessage(CefProcessId.Browser, msg);
     }
     catch (Exception ex)
     {
         Logger.Error(string.Format("Error notifying the browser {0} it's corresponding render process Id", browser.Identifier), ex);
     }
     base.OnBrowserCreated(browser);
 }
Beispiel #20
0
        /// <summary>
        /// Sends the binary message.
        /// </summary>
        /// <param name="cefBrowser">The cef browser.</param>
        /// <param name="name">The name.</param>
        /// <param name="message">The message.</param>
        private static void SendBinaryMessage(CefBrowser cefBrowser, string name, byte[] message)
        {
            using (var processMessage = CefProcessMessage.Create(name))
            {
                try
                {
                    using (var binaryValue = CefBinaryValue.Create(message))
                    {
                        processMessage.Arguments.SetBinary(0, binaryValue);

                        cefBrowser.SendProcessMessage(CefProcessId.Browser, processMessage);
                    }
                }
                finally
                {
                    processMessage.Arguments.Dispose();
                }
            }
        }
Beispiel #21
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "executeJs")
            {
                var context = browser.GetMainFrame().V8Context;

                context.TryEval(message.Arguments.GetString(0), message.Arguments.GetString(1), 1, out CefV8Value value, out CefV8Exception exception);

                var response = CefProcessMessage.Create("executeJsResult");

                if (value.IsString)
                {
                    response.Arguments.SetString(0, value.GetStringValue());
                }
                browser.SendProcessMessage(CefProcessId.Browser, response);
                return(true);
            }

            return(false);
        }
                protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
                {
                    switch (name)
                    {
                    case ReportDocumentSize:
                        var message = CefProcessMessage.Create("document-size-response");
                        message.SetFrameIdentifier(Frame.Identifier);
                        message.Arguments.SetInt(2, arguments[0].GetIntValue());
                        message.Arguments.SetInt(3, arguments[1].GetIntValue());
                        Browser.SendProcessMessage(CefProcessId.Browser, message);
                        returnValue = null;
                        exception   = null;
                        return(true);

                    default:
                        returnValue = null;
                        exception   = null;
                        return(false);
                    }
                }
Beispiel #23
0
        public void Send(RpcRequest <CefValue> rpcRequest)
        {
            if (browserDisposed == 1)
            {
                return;
            }

            var message = CefProcessMessage.Create(Messages.RpcRequestMessage);

            try
            {
                message.Arguments.SetValue(0, objectSerializer.Serialize(rpcRequest, new HashSet <object>()));

                browser.SendProcessMessage(CefProcessId.Renderer, message);
            }
            catch (NullReferenceException)
            {
                //when the browser is already disposed
                //this can happen from a finalized callback for example
                message.Dispose();
            }
        }
Beispiel #24
0
        internal object TryEval(string code, CefBrowser browser)
        {
            if (browser != null)
            {
                var message   = CefProcessMessage.Create("JavascriptEval");
                var arguments = message.Arguments;
                arguments.SetString(0, code);

                browser.SendProcessMessage(CefProcessId.Renderer, message);
                JavascriptException = null;
                JavascriptResult    = null;
                mrevent.Reset();
                mrevent.WaitOne();
            }

            if (JavascriptException != null)
            {
                throw new Exception(JavascriptException);
            }

            return(JavascriptResult);
        }
Beispiel #25
0
        public bool CreateBrowser(BrowserSource browserSource,
                                  BrowserConfig browserConfig)
        {
            if (browserClient == null)
            {
                InitClient(browserSource);
            }

            Debug.Assert(browserClient != null);
            Debug.Assert(browserConfig != null);

            BrowserConfig = browserConfig;

            CefWindowInfo windowInfo = CefWindowInfo.Create();

            windowInfo.Width  = (int)browserConfig.BrowserSourceSettings.Width;
            windowInfo.Height = (int)browserConfig.BrowserSourceSettings.Height;
            windowInfo.SetAsWindowless(IntPtr.Zero, true);

            BrowserInstanceSettings settings = AbstractSettings.DeepClone(
                BrowserSettings.Instance.InstanceSettings);

            settings.MergeWith(browserConfig.BrowserInstanceSettings);

            CefBrowserSettings browserSettings = new CefBrowserSettings
            {
                WindowlessFrameRate        = browserConfig.BrowserSourceSettings.Fps,
                ApplicationCache           = settings.ApplicationCache,
                CaretBrowsing              = settings.CaretBrowsing,
                CursiveFontFamily          = settings.CursiveFontFamily,
                Databases                  = settings.Databases,
                DefaultEncoding            = settings.DefaultEncoding,
                DefaultFixedFontSize       = settings.DefaultFixedFontSize,
                DefaultFontSize            = settings.DefaultFontSize,
                FantasyFontFamily          = settings.FantasyFontFamily,
                FileAccessFromFileUrls     = settings.FileAccessFromFileUrls,
                FixedFontFamily            = settings.FixedFontFamily,
                ImageLoading               = settings.ImageLoading,
                ImageShrinkStandaloneToFit = settings.ImageShrinkStandaloneToFit,
                Java       = settings.Java,
                JavaScript = settings.JavaScript,
                JavaScriptAccessClipboard = settings.JavaScriptAccessClipboard,
                JavaScriptCloseWindows    = settings.JavaScriptCloseWindows,
                JavaScriptDomPaste        = settings.JavaScriptDomPaste,
                JavaScriptOpenWindows     = settings.JavaScriptOpenWindows,
                LocalStorage           = settings.LocalStorage,
                MinimumFontSize        = settings.MinimumFontSize,
                MinimumLogicalFontSize = settings.MinimumLogicalFontSize,
                Plugins             = settings.Plugins,
                RemoteFonts         = settings.RemoteFonts,
                SansSerifFontFamily = settings.SansSerifFontFamily,
                SerifFontFamily     = settings.SerifFontFamily,
                StandardFontFamily  = settings.StandardFontFamily,
                //TabToLinks = settings.TabToLinks,
                //TextAreaResize = settings.TextAreaResize,
                UniversalAccessFromFileUrls =
                    settings.UniversalAccessFromFileUrls,
                WebGL       = settings.WebGL,
                WebSecurity = settings.WebSecurity
            };

            String url = browserConfig.BrowserSourceSettings.Url;

            if (browserConfig.BrowserSourceSettings.IsApplyingTemplate)
            {
                url = "http://absolute";
            }

            lock (browserLock)
            {
                ManualResetEventSlim createdBrowserEvent =
                    new ManualResetEventSlim();
                CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() =>
                {
                    try
                    {
                        browser = CefBrowserHost.CreateBrowserSync(windowInfo,
                                                                   browserClient, browserSettings, new Uri(url));
                        BrowserManager.Instance.RegisterBrowser(browser.Identifier,
                                                                this);

                        // request the render process id for volume control
                        browser.SendProcessMessage(CefProcessId.Renderer,
                                                   CefProcessMessage.Create("renderProcessIdRequest"));
                    }
                    catch (Exception)
                    {
                        browser = null;
                    }
                    finally
                    {
                        createdBrowserEvent.Set();
                    }
                }));
                createdBrowserEvent.Wait();
            }

            return(browser != null);
        }
        // If |requestId| is kReservedId all requests associated with |contextId|
        // will be canceled, otherwise only the specified |requestId| will be
        // canceled. Returns true if any request was canceled.
        private bool SendCancel(CefBrowser browser, long frameId, int contextId, int requestId)
        {
            Helpers.RequireRendererThread();

            var browserId = browser.Identifier;

            int cancelCount = 0;
            if (requestId != CefMessageRouter.ReservedId)
            {
                // Cancel a single request.
                bool removed = false;
                var info = GetRequestInfo(browserId, contextId, requestId, true, ref removed);
                if (info != null)
                {
                    Debug.Assert(removed);
                    info.Dispose();
                    cancelCount = 1;
                }
            }
            else
            {
                // Cancel all requests with the specified context ID.
                BrowserRequestInfoMap.Visitor visitor = (int vBrowserId, KeyValuePair<int, int> vInfoId, RequestInfo vInfo, ref bool vRemove) =>
                {
                    if (vInfoId.Key == contextId)
                    {
                        vRemove = true;
                        vInfo.Dispose();
                        cancelCount++;
                    }
                    return true;
                };

                _browserRequestInfoMap.FindAll(browserId, visitor);
            }

            if (cancelCount > 0)
            {
                var message = CefProcessMessage.Create(_cancelMessageName);

                var args = message.Arguments;
                args.SetInt(0, contextId);
                args.SetInt(1, requestId);

                browser.SendProcessMessage(CefProcessId.Browser, message);
                return true;
            }

            return false;
        }
Beispiel #27
0
                protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
                {
                    var message = default(CefProcessMessage);

                    try
                    {
                        CefListValue args;
                        switch (name)
                        {
                        case ReportDocumentSize:
                            message = CefProcessMessage.Create("document-size-response");
                            message.SetFrameIdentifier(Frame.Identifier);
                            using (args = message.Arguments)
                            {
                                args.SetInt(2, arguments[0].GetIntValue());
                                args.SetInt(3, arguments[1].GetIntValue());
                                Browser.SendProcessMessage(CefProcessId.Browser, message);
                            }
                            returnValue = null;
                            exception   = null;
                            return(true);

                        case Send:
                            if (arguments.Length != 1)
                            {
                                exception   = "Invalid argument; expecting a single dictionary";
                                returnValue = null;
                                return(true);
                            }
                            var arg = arguments[0];
                            if (!arg.IsObject)
                            {
                                exception   = "Argument is not an object";
                                returnValue = null;
                                return(true);
                            }
                            message = CefProcessMessage.Create("receive-data");
                            message.SetFrameIdentifier(Frame.Identifier);
                            using (var disposable = new CompositeDisposable())
                                using (args = message.Arguments)
                                {
                                    if (arg.IsArray)
                                    {
                                        var value = ToListValue(arg, disposable);
                                        args.SetString(2, "list");
                                        args.SetList(3, value);
                                    }
                                    else
                                    {
                                        var value = ToDictionaryValue(arg, disposable);
                                        args.SetString(2, "dict");
                                        args.SetDictionary(3, value);
                                    }
                                    Browser.SendProcessMessage(CefProcessId.Browser, message);
                                }
                            returnValue = null;
                            exception   = null;
                            return(true);

                        default:
                            returnValue = null;
                            exception   = null;
                            return(false);
                        }
                    }
                    finally
                    {
                        message?.Dispose();
                    }
                }
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            //Console.WriteLine("Render::OnProcessMessageReceived: SourceProcess={0}", sourceProcess);
            //Console.WriteLine("Message Name={0} IsValid={1} IsReadOnly={2}", message.Name, message.IsValid, message.IsReadOnly);
            //var arguments = message.Arguments;
            //for (var i = 0; i < arguments.Count; i++)
            //{
            //    var type = arguments.GetValueType(i);
            //    object value;
            //    switch (type)
            //    {
            //        case CefValueType.Null: value = null; break;
            //        case CefValueType.String: value = arguments.GetString(i); break;
            //        case CefValueType.Int: value = arguments.GetInt(i); break;
            //        case CefValueType.Double: value = arguments.GetDouble(i); break;
            //        case CefValueType.Bool: value = arguments.GetBool(i); break;
            //        default: value = null; break;
            //    }

            //    Console.WriteLine("  [{0}] ({1}) = {2}", i, type, value);
            //}
            //if (message.Name == "myMessage2") return true;

            //var message2 = CefProcessMessage.Create("myMessage2");
            //var success = browser.SendProcessMessage(CefProcessId.Renderer, message2);
            //Console.WriteLine("Sending myMessage2 to renderer process = {0}", success);

            //var message3 = CefProcessMessage.Create("myMessage3");
            //var success2 = browser.SendProcessMessage(CefProcessId.Browser, message3);
            //Console.WriteLine("Sending myMessage3 to browser process = {0}", success);

            if (message.Name == "ExecuteJavaScript")
            {
                string code    = message.Arguments.GetString(0);
                var    context = browser.GetMainFrame().V8Context;
                context.Enter();
                try
                {
                    var        global   = context.GetGlobal();
                    var        evalFunc = global.GetValue("eval");
                    CefV8Value arg0     = CefV8Value.CreateString(code);

                    var rtn = evalFunc.ExecuteFunctionWithContext(context, evalFunc,
                                                                  new CefV8Value[] { arg0 });
                    if (evalFunc.HasException)
                    {
                        var exception = evalFunc.GetException();
                        var message3  = CefProcessMessage.Create("Exception");
                        var arguments = message3.Arguments;
                        arguments.SetString(0, exception.Message + " At Line" + exception.LineNumber);
                        var success2 = browser.SendProcessMessage(CefProcessId.Browser, message3);
                    }
                    else
                    {
                        var message3  = CefProcessMessage.Create("JavascriptExecutedResult");
                        var arguments = message3.Arguments;
                        arguments.SetString(0, rtn.GetStringValue());
                        var success2 = browser.SendProcessMessage(CefProcessId.Browser, message3);
                    }
                }

                finally
                {
                    context.Exit();
                }
            }

            return(false);
        }
 private void SendQueryFailure(CefBrowser browser, int contextId, int requestId, int errorCode, string errorMessage)
 {
     var message = CefProcessMessage.Create(_queryMessageName);
     var args = message.Arguments;
     args.SetInt(0, contextId);
     args.SetInt(1, requestId);
     args.SetBool(2, false);  // Indicates a failure result.
     args.SetInt(3, errorCode);
     args.SetString(4, errorMessage);
     browser.SendProcessMessage(CefProcessId.Renderer, message);
     args.Dispose();
     message.Dispose();
 }
 private void SendQuerySuccess(CefBrowser browser, int contextId, int requestId, string response)
 {
     var message = CefProcessMessage.Create(_queryMessageName);
     var args = message.Arguments;
     args.SetInt(0, contextId);
     args.SetInt(1, requestId);
     args.SetBool(2, true);  // Indicates a success result.
     args.SetString(3, response);
     browser.SendProcessMessage(CefProcessId.Renderer, message);
     args.Dispose();
     message.Dispose();
 }
        // Returns the new request ID.
        private int SendQuery(CefBrowser browser, long frameId, int contextId, string request, bool persistent, CefV8Value successCallback, CefV8Value failureCallback)
        {
            Helpers.RequireRendererThread();

            var requestId = _requestIdGenerator.GetNextId();

            var info = new RequestInfo
            {
                Persistent = persistent,
                SuccessCallback = successCallback,
                FailureCallback = failureCallback,
            };
            _browserRequestInfoMap.Add(browser.Identifier, new KeyValuePair<int, int>(contextId, requestId), info);

            var message = CefProcessMessage.Create(_queryMessageName);
            var args = message.Arguments;
            args.SetInt(0, Helpers.Int64GetLow(frameId));
            args.SetInt(1, Helpers.Int64GetHigh(frameId));
            args.SetInt(2, contextId);
            args.SetInt(3, requestId);
            args.SetString(4, request);
            args.SetBool(5, persistent);

            browser.SendProcessMessage(CefProcessId.Browser, message);

            args.Dispose();
            message.Dispose();

            return requestId;
        }