コード例 #1
0
        public override void OnAddResourceMx(NativeResourceMx nativeResourceMx)
        {
            var resProvider = new ResourceProvider();

            nativeResourceMx.AddResourceProvider(resProvider);
        }
コード例 #2
0
ファイル: MyCefBrowser.cs プロジェクト: jaswgq/CefBridge
        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;
            }
        }