예제 #1
0
        public override void OnDownloadCompleted(NativeCallArgs args)
        {
            string downloadFullPath = args.GetArgAsString(2);

            Console.WriteLine("download complete :" + downloadFullPath);
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        void HandleNativeReq(int met_id, IntPtr argsPtr)
        {
            //main raw msg switch table

            if ((met_id >> 16) > 0)
            {
                //built in object
                CefNativeRequestHandlers.HandleNativeReq_I0(myBwHandler, met_id, argsPtr);
                return;
            }

            //else this is custom msg

            switch ((MyCefMsg)met_id)
            {
            default:

                break;

            case MyCefMsg.CEF_MSG_ClientHandler_NotifyBrowserCreated:
            {
                IsBrowserCreated = true;
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_NotifyBrowserClosing:
            {
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_NotifyBrowserClosed:
            {
                if (this.devForm != null)
                {
                    this.devForm.Close();
                    ((IDisposable)this.devForm).Dispose();
                    this.devForm = null;
                }
                if (this.BrowserDisposed != null)
                {
                    this.BrowserDisposed(this, EventArgs.Empty);
                }
            }
            break;
            //case MyCefMsg.CEF_MSG_ClientHandler_OnBeforeContextMenu:
            //    {
            //    }
            //    break;

            //case MyCefMsg.CEF_MSG_ClientHandler_DownloadUpdated:
            //    {
            //        //this version we notify back
            //        //when
            //        NativeCallArgs metArgs = new NativeCallArgs(argsPtr);
            //        if (browserProcessListener != null)
            //        {
            //            browserProcessListener.OnDownloadCompleted(metArgs);
            //        }
            //    }
            //    break;
            //case MyCefMsg.CEF_MSG_ClientHandler_OnBeforePopup:
            //    {
            //        NativeCallArgs args = new NativeCallArgs(argsPtr);
            //        //open new form with specific url
            //        string url = args.GetArgAsString(0);
            //        Cef3Binder.SafeUIInvoke(() =>
            //        {
            //            IWindowForm form = Cef3Binder.CreateNewBrowserWindow(800, 600);
            //            form.Show();
            //            //and navigate to a specific url
            //        });
            //    }
            //    break;
            //case MyCefMsg.CEF_MSG_ClientHandler_OnConsoleMessage:
            //    {
            //        //console.log ...

            //        if (browserProcessListener != null)
            //        {
            //            NativeCallArgs args = new NativeCallArgs(argsPtr);
            //            browserProcessListener.OnConsoleLog(args);
            //        }
            //    }
            //    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_ClientHandler_OnLoadError:
            //    {
            //        //load page error
            //        //ui process
            //        var args = new NativeCallArgs(argsPtr);
            //        IntPtr cefBrowser = args.GetArgAsNativePtr(0);
            //        IntPtr cefFrame = args.GetArgAsNativePtr(1);
            //        int errorCode = args.GetArgAsInt32(2);//error code
            //        string errorText = args.GetArgAsString(3);//errorText
            //        string failedUrl = args.GetArgAsString(4); //failedUrl
            //        //---------------------------
            //        //load error page
            //        LoadErrorPage(cefBrowser, cefFrame, errorCode, errorText, failedUrl);
            //    }
            //    break;
            //case MyCefMsg.CEF_MSG_ClientHandler_OnCertError:
            //    {
            //        var args = new NativeCallArgs(argsPtr);
            //        string certErrMsg = args.GetArgAsString(0);
            //        args.SetOutput(0, 1);//true
            //    }
            //    break;
            //case MyCefMsg.CEF_MSG_ClientHandler_ExecCustomProtocol:
            //    {
            //        //disable all protocol
            //        var args = new NativeCallArgs(argsPtr);
            //        if (browserProcessListener != null)
            //        {
            //            browserProcessListener.OnExecProtocol(args);
            //        }
            //        else
            //        {
            //            args.SetOutput(0, 0);//disable all protocol
            //        }
            //    }
            //    break;
            //----
            //TODO: review here again
            //case MyCefMsg.CEF_MSG_ClientHandler_SetResourceManager:
            //    {
            //        //setup resource mx
            //        if (browserProcessListener != null)
            //        {
            //            //INIT_MY_MET_ARGS(metArgs, 1)
            //            // MyCefSetVoidPtr2(&vargs[1], resource_manager_);

            //            var args = new NativeCallArgs(argsPtr);
            //            var resourceMx = new NativeResourceMx(args.GetArgAsNativePtr(1));
            //            browserProcessListener.OnAddResourceMx(resourceMx);
            //        }
            //    }
            //    break;
            //case MyCefMsg.CEF_MSG_RequestUrlFilter2:
            //    {
            //        //filter url name
            //        if (browserProcessListener != null)
            //        {
            //            var args = new NativeCallArgs(argsPtr);
            //            browserProcessListener.OnFilterUrl(args);
            //        }
            //    }
            //    break;
            //case MyCefMsg.CEF_MSG_BinaryResouceProvider_OnRequest:
            //    {
            //        //request for binary resource
            //        if (browserProcessListener != null)
            //        {
            //            var args = new NativeCallArgs(argsPtr);
            //            browserProcessListener.OnRequestForBinaryResource(args);
            //        }
            //    }
            //    break;
            //------------------------------
            //eg. from cefQuery -->
            case MyCefMsg.CEF_MSG_OnQuery:
            {
                //if (browserProcessListener != null)
                //{
                //    var args = new NativeCallArgs(argsPtr);
                //    QueryRequestArgs reqArgs = QueryRequestArgs.CreateRequest(args.GetArgAsNativePtr(0));
                //    browserProcessListener.OnCefQuery(args, reqArgs);
                //}


                //TODO: review here again
                //QueryRequestArgs queryReq;
                //memset(&queryReq, 0, sizeof(QueryRequestArgs));
                //queryReq.browser = browser.get();
                //queryReq.frame = frame.get();
                //queryReq.query_id = query_id;


                //MyCefStringHolder mystr;
                //mystr.value = request;
                //queryReq.request = &mystr;
                //queryReq.persistent = persistent;
                //queryReq.callback = callback.get();

                //MethodArgs args;
                //memset(&args, 0, sizeof(MethodArgs));
                //args.SetArgAsNativeObject(0, &queryReq);
                //this->mcallback_(CEF_MSG_OnQuery, &args);
                ////auto result = args.ReadOutputAsString(0);
                //CefString cefstr = args.ReadOutputAsString(0);
                //callback->Success(cefstr);
            }
            break;

            //------------------------------
            case MyCefMsg.CEF_MSG_ClientHandler_NotifyTitle:
            {
                //INIT_MY_MET_ARGS(metArgs, 1)
                //SetCefStringToJsValue2(&vargs[1], string);

                //title changed
                var    args     = new NativeCallArgs(argsPtr);
                string newtitle = args.GetArgAsString(1);
                // Console.WriteLine("title changed:" + newtitle);
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_NotifyAddress:
            {
                //INIT_MY_MET_ARGS(metArgs, 1)
                //SetCefStringToJsValue2(&vargs[1], string);
                //address changed
                var    args     = new NativeCallArgs(argsPtr);
                string newtitle = args.GetArgAsString(1);
                // Console.WriteLine("address changed:" + newtitle);
            }
            break;

            //------------------------------
            case MyCefMsg.CEF_MSG_OSR_Render:
            {
                //receive rendere msg
                var args = new NativeCallArgs(argsPtr);
                //copy bits buffer and store to files
                if (cefOsrListener != null)
                {
                    cefOsrListener.OnRender(args);
                }
            }
            break;
            }
        }
예제 #4
0
        void MxCallBack(int id, IntPtr argsPtr)
        {
            switch ((MyCefMsg)id)
            {
            case MyCefMsg.CEF_MSG_ClientHandler_NotifyBrowserCreated:
            {
                IsBrowserCreated = true;
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_NotifyBrowserClosing:
            {
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_NotifyBrowserClosed:
            {
                if (this.devForm != null)
                {
                    this.devForm.Close();
                    ((IDisposable)this.devForm).Dispose();
                    this.devForm = null;
                }
                if (this.BrowserDisposed != null)
                {
                    this.BrowserDisposed(this, EventArgs.Empty);
                }
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_OnBeforeContextMenu:
            {
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_BeforeDownload:
            {
                //handle download path here
                NativeCallArgs metArgs  = new NativeCallArgs(argsPtr);
                string         pathName = metArgs.GetArgAsString(2);
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_DownloadUpdated:
            {
                //this version we notify back
                //when
                NativeCallArgs metArgs = new NativeCallArgs(argsPtr);
                if (browserProcessListener != null)
                {
                    browserProcessListener.OnDownloadCompleted(metArgs);
                }
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_OnBeforePopup:
            {
                NativeCallArgs args = new NativeCallArgs(argsPtr);
                //open new form with specific url
                string url = args.GetArgAsString(0);
                Cef3Binder.SafeUIInvoke(() =>
                    {
                        IWindowForm form = Cef3Binder.CreateNewBrowserWindow(800, 600);
                        form.Show();
                        //and navigate to a specific url
                    });
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_OnConsoleMessage:
            {
                //console.log ...

                if (browserProcessListener != null)
                {
                    NativeCallArgs args = new NativeCallArgs(argsPtr);
                    browserProcessListener.OnConsoleLog(args);
                }
            }
            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_ClientHandler_OnLoadError:
            {
                //load page error
                //ui process
                var    args       = new NativeCallArgs(argsPtr);
                IntPtr cefBrowser = args.GetArgAsNativePtr(0);
                IntPtr cefFrame   = args.GetArgAsNativePtr(1);
                int    errorCode  = args.GetArgAsInt32(2);    //error code
                string errorText  = args.GetArgAsString(3);   //errorText
                string failedUrl  = args.GetArgAsString(4);   //failedUrl
                //---------------------------
                //load error page
                LoadErrorPage(cefBrowser, cefFrame, errorCode, errorText, failedUrl);
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_OnCertError:
            {
                var    args       = new NativeCallArgs(argsPtr);
                string certErrMsg = args.GetArgAsString(0);
                args.SetOutput(0, 1);        //true
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_ExecCustomProtocol:
            {
                //disable all protocol
                var args = new NativeCallArgs(argsPtr);
                if (browserProcessListener != null)
                {
                    browserProcessListener.OnExecProtocol(args);
                }
                else
                {
                    args.SetOutput(0, 0);        //disable all protocol
                }
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_SetResourceManager:
            {
                //setup resource mx
                if (browserProcessListener != null)
                {
                    var args       = new NativeCallArgs(argsPtr);
                    var resourceMx = new NativeResourceMx(args.GetArgAsNativePtr(0));
                    browserProcessListener.OnAddResourceMx(resourceMx);
                }
            }
            break;

            case MyCefMsg.CEF_MSG_RequestUrlFilter2:
            {
                //filter url name
                if (browserProcessListener != null)
                {
                    var args = new NativeCallArgs(argsPtr);
                    browserProcessListener.OnFilterUrl(args);
                }
            }
            break;

            case MyCefMsg.CEF_MSG_BinaryResouceProvider_OnRequest:
            {
                //request for binary resource
                if (browserProcessListener != null)
                {
                    var args = new NativeCallArgs(argsPtr);
                    browserProcessListener.OnRequestForBinaryResource(args);
                }
            }
            break;

            //------------------------------
            //eg. from cefQuery -->
            case MyCefMsg.CEF_MSG_OnQuery:
            {
                if (browserProcessListener != null)
                {
                    var args = new NativeCallArgs(argsPtr);
                    QueryRequestArgs reqArgs = QueryRequestArgs.CreateRequest(args.GetArgAsNativePtr(0));
                    browserProcessListener.OnCefQuery(args, reqArgs);
                }
            }
            break;

            //------------------------------
            case MyCefMsg.CEF_MSG_ClientHandler_OnPreKeyEvent:     //on PreKey
            {
                // Console.WriteLine("on pre key");
                NavigateTo("https://html5test.com");
            }
            break;

            //------------------------------
            case MyCefMsg.CEF_MSG_ClientHandler_NotifyTitle:
            {
                //title changed
                var    args     = new NativeCallArgs(argsPtr);
                string newtitle = args.GetArgAsString(0);
                // Console.WriteLine("title changed:" + newtitle);
            }
            break;

            case MyCefMsg.CEF_MSG_ClientHandler_NotifyAddress:
            {
                //address changed
                var    args     = new NativeCallArgs(argsPtr);
                string newtitle = args.GetArgAsString(0);
                // Console.WriteLine("address changed:" + newtitle);
            }
            break;

            //------------------------------
            case MyCefMsg.CEF_MSG_OSR_Render:
            {
                //receive rendere msg
                var args = new NativeCallArgs(argsPtr);
                //copy bits buffer and store to files
                if (cefOsrListener != null)
                {
                    cefOsrListener.OnRender(args);
                }
            } break;
            }
        }