コード例 #1
0
ファイル: FrmHomePage.cs プロジェクト: isliulin/HNWN_Applet
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "OpenTruckWeighter")
            {
                SelfVars.MainFrameForm.OpenTruckWeighter();
            }
            else if (message.Name == "OpenTruckMachinerySampler")
            {
                SelfVars.MainFrameForm.OpenTruckMachinerySampler();
            }
            else if (message.Name == "OpenAssayManage")
            {
                SelfVars.MainFrameForm.OpenAssayManage();
            }
            else if (message.Name == "CarSamplerChangeSelected")
            {
                SelfVars.CarSamplerForm.CurrentMachineCode = MonitorCommon.GetInstance().GetCarSamplerMachineCodeBySelected(message.Arguments.GetString(0));
            }
            else if (message.Name == "TruckWeighterChangeSelected")
            {
                SelfVars.TruckWeighterForm.CurrentMachineCode = MonitorCommon.GetInstance().GetTruckWeighterMachineCodeBySelected(message.Arguments.GetString(0));
            }
            else if (message.Name == "ChangeSelected")
            {
                SelfVars.CurrentSelectedCell = message.Arguments.GetString(0);
            }
            else if (message.Name == "OpenHikVideo")
            {
                //视频预览
                SelfVars.MainFrameForm.OpenHikVideo(message.Arguments.GetString(0));
            }

            return(true);
        }
コード例 #2
0
            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);
            }
コード例 #3
0
        public bool OnProcessMessageReceived(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message)
        {
            var ea = new CefProcessMessageReceivedEventArgs(browser, frame, sourceProcess, message);

            _application.OnCefProcessMessageReceived(ea);
            return(ea.Handled);
        }
コード例 #4
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            Console.WriteLine("Client::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" || message.Name == "myMessage3")
            {
                return(true);
            }

            return(false);
        }
コード例 #5
0
        public bool ProcessMessage(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage processMessage)
        {
            if (processMessage == null)
            {
                throw new ArgumentNullException("processMessage");
            }

            if (string.IsNullOrWhiteSpace(processMessage.Name))
            {
                throw new ArgumentException("ProcessMessage.Name is null or white space.");
            }

            Logger.Debug(string.Format("Process message: {0}", processMessage.Name));

            ProcessMessageDelegate handler;

            ProcessMessageDelegates.TryGetValue(processMessage.Name, out handler);

            if (handler != null)
            {
                handler(browser, sourceProcess, processMessage);

                return(true);
            }

            return(false);
        }
コード例 #6
0
        internal bool OnBrowserProcessMessage(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == PROCESS_MESSAGE_BRIDGE_MESSAGE)
            {
                var buff = message.Arguments.GetBinary(0);
                var json = Encoding.UTF8.GetString(buff.ToArray());



                var msg = BridgeMessage.FromJson(json);
                buff.Dispose();



                foreach (var handler in MessageHandlers)
                {
                    handler.OnBrowserSideMessageReceived(msg.Name, frame, msg.Arguments);
                }
                //if (ProcessMessageHandlers.ContainsKey(msg.Name))
                //{
                //    ProcessMessageHandlers[msg.Name].Invoke(this, frame, msg.Arguments);
                //}

                return(true);
            }

            return(false);
        }
コード例 #7
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (!this.loggingService.IsDebugEnabled)
            {
                return false;
            }

            this.loggingService.Debug("Client::OnProcessMessageReceived: SourceProcess={0}", sourceProcess);
            this.loggingService.Debug("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;
                }

                this.loggingService.Debug("  [{0}] ({1}) = {2}", i, type, value);
            }

            return false;
        }
コード例 #8
0
ファイル: LVCefClient.cs プロジェクト: mstroehle/lvcef
 internal OnProcessMessageReceivedEventArgs(CefBrowser _browser, CefProcessId _sourceProcess, CefProcessMessage _message)
 {
     browser       = _browser;
     sourceProcess = _sourceProcess;
     message       = _message;
     Handled       = false; //default return value
 }
コード例 #9
0
 public unsafe void SendProcessMessage(CefProcessId target_process, cef_process_message_t *message)
 {
     fixed(cef_frame_t *self = &this)
     {
         ((delegate * unmanaged[Stdcall] < cef_frame_t *, CefProcessId, cef_process_message_t *, void >)send_process_message)(self, target_process, message);
     }
 }
コード例 #10
0
        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);

            return false;
        }
コード例 #11
0
ファイル: WebClient.cs プロジェクト: rajsite/lvcef
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (DumpProcessMessages)
            {
                Console.WriteLine("Client::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 = DemoApp.BrowserMessageRouter.OnProcessMessageReceived(browser, sourceProcess, message);
            if (handled) return true;

            if (message.Name == "myMessage2" || message.Name == "myMessage3") return true;

            return false;
        }
コード例 #12
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (!this.loggingService.IsDebugEnabled)
            {
                return(false);
            }

            this.loggingService.Debug("Client::OnProcessMessageReceived: SourceProcess={0}", sourceProcess);
            this.loggingService.Debug("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;
                }

                this.loggingService.Debug("  [{0}] ({1}) = {2}", i, type, value);
            }

            return(false);
        }
コード例 #13
0
 protected override bool OnProcessMessageReceived(
     CefBrowser browser,
     CefProcessId sourceProcess,
     CefProcessMessage message)
 {
     this.myCefV8Handler.OnProcessMessageReceived(message);
     return(base.OnProcessMessageReceived(browser, sourceProcess, message));
 }
コード例 #14
0
 private bool ProcessMessage(CefProcessId pid, CefProcessMessage msg)
 {
     if (OnIPC != null)
     {
         OnIPC(msg.Arguments.GetString(4));
     }
     return(true);
 }
コード例 #15
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess,
            CefProcessMessage message)
        {
            var handled = MessageRouter.OnProcessMessageReceived(browser, sourceProcess, message);
            if (handled) return true;

            return false;
        }
コード例 #16
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            var args = new ProcessMessageReceivedArgs(browser, message);

            OnProcessMessageReceived(args);

            return(args.Handled);
        }
コード例 #17
0
ファイル: MessageClient.cs プロジェクト: rpc-bindings/cefglue
        bool ICefClient.OnProcessMessageReceived(ICefBrowser browser, CefProcessId sourceProcess, ICefProcessMessage message)
        {
            var args = new ProcessMessageReceivedArgs(browser, message);

            OnProcessMessageReceived(args);

            return(args.Handled);
        }
コード例 #18
0
        //public void SendProcessMessage(CefProcessId processId, CefFrame frame, BridgeMessage message)
        //{
        //    var msg = CefProcessMessage.Create(PROCESS_MESSAGE_BRIDGE_MESSAGE);
        //    var json = message.ToJson();

        //    msg.Arguments.SetBinary(0, CefBinaryValue.Create(Encoding.UTF8.GetBytes(json)));
        //    frame.SendProcessMessage(processId, msg);
        //    msg.Dispose();
        //}

        public static void SendProcessMessage(CefProcessId processId, CefFrame frame, BridgeMessage message)
        {
            var msg  = CefProcessMessage.Create(PROCESS_MESSAGE_BRIDGE_MESSAGE);
            var json = message.ToJson();

            msg.Arguments.SetBinary(0, CefBinaryValue.Create(Encoding.UTF8.GetBytes(json)));
            frame.SendProcessMessage(processId, msg);
            msg.Dispose();
        }
コード例 #19
0
        /// <summary>
        /// Called when process message received.
        /// </summary>
        /// <param name="browser">The browser.</param>
        /// <param name="sourceProcess">The source process.</param>
        /// <param name="message">The process message.</param>
        /// <returns></returns>
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            return(NativeMessageHandler.ProcessMessage(browser, sourceProcess, message));
        }
コード例 #20
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "SetOverlayAPI")
            {
                // 対象のフレームを取得
                var frameName      = message.Arguments.GetString(0);
                var frame          = GetFrameByName(browser, frameName);
                var overlayName    = message.Arguments.GetString(1);
                var overlayVersion = message.Arguments.GetString(2);

                // API を設定
                if (frame != null && frame.V8Context.Enter())
                {
                    var apiObject = CefV8Value.CreateObject(null);

                    var broadcastMessageFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.BroadcastMessageFunctionName,
                        builtinFunctionHandler);
                    var sendMessageFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.SendMessageFunctionName,
                        builtinFunctionHandler);
                    var overlayMessageFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.OverlayMessageFunctionName,
                        builtinFunctionHandler);
                    var endEncounterFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.EndEncounterFunctionName,
                        builtinFunctionHandler);

                    apiObject.SetValue("version", CefV8Value.CreateString(overlayVersion), CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue("overlayName", CefV8Value.CreateString(overlayName), CefV8PropertyAttribute.ReadOnly);

                    apiObject.SetValue(
                        BuiltinFunctionHandler.BroadcastMessageFunctionName,
                        broadcastMessageFunction,
                        CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue(
                        BuiltinFunctionHandler.SendMessageFunctionName,
                        sendMessageFunction,
                        CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue(
                        BuiltinFunctionHandler.OverlayMessageFunctionName,
                        overlayMessageFunction,
                        CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue(
                        BuiltinFunctionHandler.EndEncounterFunctionName,
                        endEncounterFunction,
                        CefV8PropertyAttribute.ReadOnly);

                    frame.V8Context.GetGlobal().SetValue("OverlayPluginApi", apiObject, CefV8PropertyAttribute.ReadOnly);

                    frame.V8Context.Exit();
                }
                return(true);
            }

            return(base.OnProcessMessageReceived(browser, sourceProcess, message));
        }
コード例 #21
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            MessageReceived?.Invoke(this, new MessageReceivedEventArgs()
            {
                Browser = browser, ProcessId = sourceProcess, Message = message
            });

            return(base.OnProcessMessageReceived(browser, sourceProcess, message));
        }
コード例 #22
0
ファイル: CefFrame.cs プロジェクト: tokyokamera/Chromely
        /// <summary>
        /// Send a message to the specified |target_process|. Message delivery is not
        /// guaranteed in all cases (for example, if the browser is closing,
        /// navigating, or if the target process crashes). Send an ACK message back
        /// from the target process if confirmation is required.
        /// </summary>
        public void SendProcessMessage(CefProcessId targetProcess, CefProcessMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            cef_frame_t.send_process_message(_self, targetProcess, message.ToNative());
        }
        /// <summary>
        /// Send a message to the specified |target_process|. Returns true if the
        /// message was sent successfully.
        /// </summary>
        public bool SendProcessMessage(CefProcessId target, CefProcessMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            return(cef_browser_t.send_process_message(_self, target, message.ToNative()) != 0);
        }
コード例 #24
0
        /// <summary>
        /// Called when a new message is received from a different process. Return true
        /// if the message was handled or false otherwise. Do not keep a reference to
        /// or attempt to access the message outside of this callback.
        /// </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)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            return(V8NativeBrowserHandler.ProcessMessage(browser, sourceProcess, message) ||
                   BaseMainApplication.Current.BrowserMessageRouter.OnProcessMessageReceived(browser, sourceProcess, message));
        }
コード例 #25
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);
            }
コード例 #26
0
        public bool ProcessMessage(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage processMessage)
        {
            if (processMessage == null)
            {
                throw new ArgumentNullException("processMessage");
            }

            // native
            if (processMessage.Name == "native")
            {
                var message = MessageUtility.DeserializeMessage <string>(processMessage);

                if (message.CallbackId != null)
                {
                    var returnJson = message.Data;
                    var callback   = GetCallback(message.CallbackId.Value);

                    if (callback != null)
                    {
                        callback.Execute(returnJson);
                    }
                }

                return(true);
            }

            // call function
            else if (processMessage.Name == "callFunction")
            {
                var message      = MessageUtility.DeserializeMessage <CallFunction>(processMessage);
                var functionName = message.Data.Name;
                var data         = message.Data.Data;

                if (Functions.ContainsKey(functionName))
                {
                    if (data != Undefined.Value)
                    {
                        Functions[functionName].Execute(data);
                    }
                    else
                    {
                        Functions[functionName].Execute();
                    }
                }
                else
                {
                    GeneralLog.Error(string.Format("Call function - function {0} is not registered.", functionName));
                }

                return(true);
            }

            return(false);
        }
コード例 #27
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;
            }
コード例 #28
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);
        }
コード例 #29
0
        /// <summary>
        /// The on process message received.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="sourceProcess">
        /// The source process.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            var handled = this.MessageRouter.OnProcessMessageReceived(browser, sourceProcess, message);

            if (handled)
            {
                return(true);
            }

            return(false);
        }
コード例 #30
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            // var handled = DemoApp.BrowserMessageRouter.OnProcessMessageReceived(browser, sourceProcess, message);
            // if (handled) return true;

            if (OnProcessMessage != null)
            {
                return(OnProcessMessage(sourceProcess, message));
            }

            return(false);
        }
コード例 #31
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (browser != null)
            {
                // Clone the browser as CEFGlue will dispose the reference passed to this function when it returns
                browser = browser.Clone();
            }
            // Use local variable to guard against client being disposed on different thread (assignment is atomic)
            var core = _core;

            return(core != null && core.OnProcessMessageReceived(browser, message));
        }
コード例 #32
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "Send Message To Browser")
            {
                this.cefWebBrowser.Invoke((Action)(() =>
                {
                    MessageBoxEx.Show("这是从HTML页面传递回来的消息!");
                }));
            }

            //return base.OnProcessMessageReceived(browser, sourceProcess, message);
            return(true);
        }
コード例 #33
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);
        }
コード例 #34
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "renderProcessIdResponse")
            {
                int            renderProcessId = message.Arguments.GetInt(0);
                BrowserWrapper browserWrapper;
                if (BrowserManager.Instance.TryGetBrowser(
                        browser.Identifier, out browserWrapper))
                {
                    browserWrapper.UpdateRenderProcessId(renderProcessId);
                }
            }

            return(false);
        }
コード例 #35
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "renderProcessIdResponse")
            {
                int renderProcessId = message.Arguments.GetInt(0);
                BrowserWrapper browserWrapper;
                if (BrowserManager.Instance.TryGetBrowser(
                    browser.Identifier, out browserWrapper))
                {
                    browserWrapper.UpdateRenderProcessId(renderProcessId);
                }
            }

            return false;
        }
コード例 #36
0
ファイル: LVCefClient.cs プロジェクト: rajsite/lvcef
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            Debug.WriteLine(DBGPREFIX + "OnProcessMessageReceived: " + message.ToString());
            var isHandled = _messageRouter.OnProcessMessageReceived(browser, sourceProcess, message);
            if (isHandled)
                return true;

	        var handler = OnProcessMessageReceivedEvent;
            if (handler != null)
            {
                Debug.WriteLine(DBGPREFIX + "OnProcessMessageReceived Delegate");
                var e = new OnProcessMessageReceivedEventArgs(browser, sourceProcess, message);
                handler(this, e);
                return e.Handled;
            }
            return false;
        }
コード例 #37
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "SetOverlayAPI")
            {
                // 対象のフレームを取得
                var frameName = message.Arguments.GetString(0);
                var frame = GetFrameByName(browser, frameName);

                // API を設定
                if (frame != null && frame.V8Context.Enter())
                {
                    var apiObject = CefV8Value.CreateObject(null);

                    var broadcastMessageFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.BroadcastMessageFunctionName,
                        builtinFunctionHandler);
                    var sendMessageFunction = CefV8Value.CreateFunction(
                         BuiltinFunctionHandler.SendMessageFunctionName,
                         builtinFunctionHandler);

                    apiObject.SetValue(
                        BuiltinFunctionHandler.BroadcastMessageFunctionName,
                        broadcastMessageFunction,
                        CefV8PropertyAttribute.None);
                    apiObject.SetValue(
                        BuiltinFunctionHandler.SendMessageFunctionName,
                        sendMessageFunction,
                        CefV8PropertyAttribute.None);

                    frame.V8Context.GetGlobal().SetValue("OverlayPluginApi", apiObject, CefV8PropertyAttribute.None);

                    frame.V8Context.Exit();
                }
                return true;
            }

            return base.OnProcessMessageReceived(browser, sourceProcess, message);
        }
コード例 #38
0
ファイル: CefBrowser.cs プロジェクト: whztt07/SDK
        /// <summary>
        /// Send a message to the specified |target_process|. Returns true if the
        /// message was sent successfully.
        /// </summary>
        public bool SendProcessMessage(CefProcessId target, CefProcessMessage message)
        {
            if (message == null) throw new ArgumentNullException("message");

            return cef_browser_t.send_process_message(_self, target, message.ToNative()) != 0;
        }
コード例 #39
0
        /// <summary>
        /// Call from CefClient::OnProcessMessageReceived. Returns true if the message
        /// is handled by this router or false otherwise.
        /// </summary>
        public bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            Helpers.RequireUIThread();

            var messageName = message.Name;
            if (messageName == _queryMessageName)
            {
                var args = message.Arguments;
                Debug.Assert(args.Count == 6);

                var frameId = Helpers.Int64Set(args.GetInt(0), args.GetInt(1));
                var contextId = args.GetInt(2);
                var requestId = args.GetInt(3);
                var request = args.GetString(4);
                var persistent = args.GetBool(5);

                if (_handlerSet.Count == 0)
                {
                    // No handlers so cancel the query.
                    CancelUnhandledQuery(browser, contextId, requestId);
                    return true;
                }

                var browserId = browser.Identifier;
                var queryId = _queryIdGenerator.GetNextId();

                var frame = browser.GetFrame(frameId);
                var callback = new Callback(this, browserId, queryId, persistent);

                // Make a copy of the handler list in case the user adds or removes a
                // handler while we're iterating.
                var handlers = _handlerSet.ToArray();

                var handled = false;
                Handler handler = null;
                foreach (var x in handlers)
                {
                    handled = x.OnQuery(browser, frame, queryId, request, persistent, callback);
                    if (handled)
                    {
                        handler = x;
                        break;
                    }
                }

                // If the query isn't handled nothing should be keeping a reference to
                // the callback.
                // DCHECK(handled || callback->GetRefCt() == 1);
                // Debug.Assert(handled && handler != null);
                // We don't need this assertion, in GC environment.
                // There is client responsibility to do not reference callback, if request is not handled.

                if (handled)
                {
                    // Persist the query information until the callback executes.
                    // It's safe to do this here because the callback will execute
                    // asynchronously.
                    var info = new QueryInfo
                    {
                        Browser = browser,
                        FrameId = frameId,
                        ContextId = contextId,
                        RequestId = requestId,
                        Persistent = persistent,
                        Callback = callback,
                        Handler = handler,
                    };
                    _browserQueryInfoMap.Add(browserId, queryId, info);
                }
                else
                {
                    // Invalidate the callback.
                    callback.Detach();

                    // No one chose to handle the query so cancel it.
                    CancelUnhandledQuery(browser, contextId, requestId);
                }

                return true;
            }
            else if (messageName == _cancelMessageName)
            {
                var args = message.Arguments;
                Debug.Assert(args.Count == 2);

                var browserId = browser.Identifier;
                var contextId = args.GetInt(0);
                var requestId = args.GetInt(1);

                CancelPendingRequest(browserId, contextId, requestId);
                return true;
            }

            return false;
        }
コード例 #40
0
        /// <summary>
        /// Call from CefRenderProcessHandler::OnProcessMessageReceived. Returns true
        /// if the message is handled by this router or false otherwise.
        /// </summary>
        public bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            Helpers.RequireRendererThread();

            var messageName = message.Name;
            if (messageName == _queryMessageName)
            {
                var args = message.Arguments;
                Debug.Assert(args.Count > 3);

                var contextId = args.GetInt(0);
                var requestId = args.GetInt(1);
                var isSuccess = args.GetBool(2);

                if (isSuccess)
                {
                    Debug.Assert(args.Count == 4);
                    string response = args.GetString(3);
                    Helpers.PostTaskUncertainty(CefThreadId.Renderer,
                        Helpers.Apply(this.ExecuteSuccessCallback, browser.Identifier, contextId, requestId, response)
                        );
                }
                else
                {
                    Debug.Assert(args.Count == 5);
                    var errorCode = args.GetInt(3);
                    string errorMessage = args.GetString(4);
                    Helpers.PostTaskUncertainty(CefThreadId.Renderer,
                        Helpers.Apply(this.ExecuteFailureCallback, browser.Identifier, contextId, requestId, errorCode, errorMessage)
                        );
                }

                return true;
            }

            return false;
        }
コード例 #41
0
 /// <summary>
 /// Called when a new message is received from a different process. Return true
 /// if the message was handled or false otherwise. Do not keep a reference to
 /// or attempt to access the message outside of this callback.
 /// </summary>
 protected virtual bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
 {
     return false;
 }
コード例 #42
0
        private int on_process_message_received(cef_client_t* self, cef_browser_t* browser, CefProcessId source_process, cef_process_message_t* message)
        {
            CheckSelf(self);

            var m_browser = CefBrowser.FromNative(browser);
            var m_message = CefProcessMessage.FromNative(message);

            var result = OnProcessMessageReceived(m_browser, source_process, m_message);

            m_browser.Dispose();
            m_message.Dispose();

            return result ? 1 : 0;
        }
コード例 #43
0
 protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
 {
     Debug.WriteLine(DBGPREFIX + "OnProcessMessageReceived called");
     return _messageRouter.OnProcessMessageReceived(browser, sourceProcess, message);
 }
コード例 #44
0
ファイル: cef_browser_t.g.cs プロジェクト: rajsite/lvcef
 public static int send_process_message(cef_browser_t* self, CefProcessId target_process, cef_process_message_t* message)
 {
     send_process_message_delegate d;
     var p = self->_send_process_message;
     if (p == _p17) { d = _d17; }
     else
     {
         d = (send_process_message_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(send_process_message_delegate));
         if (_p17 == IntPtr.Zero) { _d17 = d; _p17 = p; }
     }
     return d(self, target_process, message);
 }
コード例 #45
0
ファイル: LVCefClient.cs プロジェクト: rajsite/lvcef
            internal OnProcessMessageReceivedEventArgs(CefBrowser _browser, CefProcessId _sourceProcess, CefProcessMessage _message)
	        {
                browser = _browser;
                sourceProcess = _sourceProcess;
                message = _message;
                Handled = false; //default return value
	        }
コード例 #46
0
ファイル: ClientHandler.cs プロジェクト: kaagati/spectre
 private int OnProcessMessageReceived(IntPtr self, IntPtr browser, CefProcessId sourceprocess, IntPtr message)
 {
     var e = new IpcMessageReceivedEventArgs {
         Browser = Browser.FromHandle(browser),
         SourceProcess = (ProcessType) sourceprocess,
         Message = IpcMessage.FromHandle(message)
     };
     _delegate.OnIpcMessageReceived(e);
     return e.IsHandled ? 1 : 0;
 }
コード例 #47
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            string[] items = message.Name.Split(new char[] {'|'} );
            if (items.Length == 0) return false;

            switch (items[0])
            {
                case "GetElementValue":
                {
                    string elementID = items[1];
                    long[] frameIDs = browser.GetFrameIdentifiers();
                    foreach (long frameID in frameIDs)
                    {
                        CefFrame frame = browser.GetFrame(frameID);
                        if (frame == null) continue;
                        frame.VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID));
                    }
                    browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID));
                    return true;
                }
                case "SetElementValue":
                {
                    string elementID = items[1];
                    string elementValue = items[2];
                    long[] frameIDs = browser.GetFrameIdentifiers();
                    foreach (long frameID in frameIDs)
                    {
                        CefFrame frame = browser.GetFrame(frameID);
                        if (frame == null) continue;
                        frame.VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID, elementValue));
                    }
                    browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsSetElementValue, elementID, elementValue));
                    return true;
                }
                case "EvaluateScript":
                {
                    CefV8Value value = CefV8Value.CreateString("t");
                    CefV8Exception exp;
                    browser.GetMainFrame().V8Context.TryEval(items[1], out value, out exp);
                    Global.JsEvaResult = null;
                    if (value.IsString)
                    {
                        Global.JsEvaResult = value.GetStringValue();
                    }
                    if (value.IsInt)
                    {
                        Global.JsEvaResult = value.GetIntValue();
                    }
                    if (value.IsDouble)
                    {
                        Global.JsEvaResult = value.GetDoubleValue();
                    }
                    if (value.IsBool)
                    {
                        Global.JsEvaResult = value.GetBoolValue();
                    }
                    if (value.IsDate)
                    {
                        Global.JsEvaResult = value.GetDateValue();
                    }
                    Global.flag = true;
                    return true;
                }
                case "AppendListener":
                {
                    CwbBusinStyle cbStyle = CwbBusinStyle.bsAddElementEvent;
                    if (items.Length > 2)
                        cbStyle = CwbBusinStyle.bsAttachElementEvent;
                    string elementID = items[1];
                    long[] frameIDs = browser.GetFrameIdentifiers();
                    foreach (long frameID in frameIDs)
                    {
                        CefFrame frame = browser.GetFrame(frameID);
                        if (frame == null) continue;
                        frame.VisitDom(new CwbDOMVisitor(browser, cbStyle, webBrowser.getEventListener(elementID)));
                    }
                    browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, cbStyle, webBrowser.getEventListener(elementID)));
                    return true;
                }
                case "GetDocument":
                {
                    browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsVisitDocument, ""));
                    return true;
                }
            }
            return false;
        }