コード例 #1
0
ファイル: ClientAppRenderer.cs プロジェクト: 2php/kneadium
        /// <summary>
        /// handle native reqiest , this is called by native side.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="argsPtr"></param>

        void HandleNativeReq(int met_id, IntPtr argsPtr)
        {
            if (renderProcessHandler == null)
            {
                //check if the render process handler is create or not
                //this method is called from native side
                //must check here!
                renderProcessHandler = new RenderProcessHandler();
            }

            //main raw msg switch table
            if ((met_id >> 16) > 0)
            {
                //built in object
                CefNativeRequestHandlers.HandleNativeReq_I0(renderProcessHandler, met_id, argsPtr);
                return;
            }

            //this is custom msg
            dbugRenderProcessLog.WriteLine("custom_msg");
            switch ((MyCefMsg)met_id)
            {
            default:

                break;

            case MyCefMsg.CEF_MSG_CefSettings_Init:
            {
                InitCefSettings(new CefSettings(argsPtr));
            }
            break;

            case MyCefMsg.CEF_MSG_MainContext_GetConsoleLogPath:
            {
                NativeCallArgs nat1 = new NativeCallArgs(argsPtr);
                nat1.SetOutputAsAsciiString(0, ReferencePaths.LOG_PATH);
            }
            break;

            case MyCefMsg.CEF_MSG_OSR_Render:
            {
            }
            break;
            }
        }
コード例 #2
0
        public override void OnRequestForBinaryResource(NativeCallArgs args)
        {
            string url = args.GetArgAsString(0);

            if (url == "http://localhost/hello_img" && File.Exists("prepare.jpg"))
            {
                //load sample image and the send to client
                byte[] img    = File.ReadAllBytes("prepare.jpg");
                int    imgLen = img.Length;
                //TODO: review here, who will destroy this mem
                IntPtr unmanagedPtr = Marshal.AllocHGlobal(imgLen);
                Marshal.Copy(img, 0, unmanagedPtr, imgLen);
                args.SetOutput(0, 1);
                args.UnsafeSetOutput(1, unmanagedPtr, imgLen);
                args.SetOutputAsAsciiString(2, "image/jpeg");
            }
            else
            {
                //intercept any request
                //args.SetOutput(0, 1);
                //args.SetOutputAsAsciiString(1, "OKOK!!!!");
                //args.SetOutputAsAsciiString(2, "text/plain");
            }
        }
コード例 #3
0
ファイル: ClientApp.cs プロジェクト: jaswgq/CefBridge
        void MxCallBack(int id, IntPtr argsPtr)
        {
            switch ((MyCefMsg)id)
            {
            case MyCefMsg.CEF_MSG_ClientHandler_OnBeforePopup:
            {
                NativeCallArgs args = new NativeCallArgs(argsPtr);
                string         url  = args.GetArgAsString(0);
                Cef3Binder.SafeUIInvoke(() =>
                    {
                        IWindowForm popupWin = Cef3Binder.CreateNewBrowserWindow(600, 450);
                        popupWin.Show();
                    });
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_BeforeDownload:
            {
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_ShowDevTools:
            {
                //show dev tools
                Cef3Binder.SafeUIInvoke(() =>
                    {
                        IWindowForm newPopupForm = Cef3Binder.CreateNewBrowserWindow(800, 600);
                        newPopupForm.Show();
                    });
            }
            break;

            case MyCefMsg.CEF_MSG_CefSettings_Init:
            {
                InitCefSettings(new CefSettings(argsPtr));
            }
            break;

            case MyCefMsg.CEF_MSG_MainContext_GetConsoleLogPath:
            {
                NativeCallArgs nat1 = new NativeCallArgs(argsPtr);
                nat1.SetOutputAsAsciiString(0, "d:\\WImageTest\\cef_console.log");
            }
            break;

            case MyCefMsg.CEF_MSG_OSR_Render:
            {
                //not visit here?
            } break;

            case MyCefMsg.CEF_MSG_RenderDelegate_OnContextCreated:
            {
                //client app callback
                //eg. from RenderClientApp
                //in render process ***
                //we can register external methods  for window object here.
                //NativeMethods.MessageBox(IntPtr.Zero, id.ToString(), "NN2", 0);

                if (renderProcessListener != null)
                {
                    NativeCallArgs   args           = new NativeCallArgs(argsPtr);
                    MyCefContextArgs cefContextArgs = new MyCefContextArgs(args);
                    //var clientRenderApp = new NativeRendererApp(args.GetArgAsNativePtr(0));
                    //var browser = new NativeBrowser(args.GetArgAsNativePtr(1));
                    //var context = new NativeJsContext(args.GetArgAsNativePtr(2));

                    renderProcessListener.OnContextCreated(cefContextArgs);
                }
            }
            break;

            case MyCefMsg.CEF_MSG_RenderDelegate_OnContextReleased:
            {
                if (renderProcessListener != null)
                {
                    NativeCallArgs   args           = new NativeCallArgs(argsPtr);
                    MyCefContextArgs cefContextArgs = new MyCefContextArgs(args);
                    //var clientRenderApp = new NativeRendererApp(args.GetArgAsNativePtr(0));
                    //var browser = new NativeBrowser(args.GetArgAsNativePtr(1));
                    //var context = new NativeJsContext(args.GetArgAsNativePtr(2));
                    renderProcessListener.OnContextReleased(cefContextArgs);
                }
            }
            break;

            case MyCefMsg.CEF_MSG_RenderDelegate_OnWebKitInitialized:
            {
                if (renderProcessListener != null)
                {
                    NativeCallArgs args = new NativeCallArgs(argsPtr);
                    renderProcessListener.OnWebKitInitialized(args);
                }
            }
            break;
            }
        }