예제 #1
0
            public override void OnRender(NativeCallArgs args)
            {
                //if not set to 0
                //images not render to native cef win

                return;

                if (n > 100)
                {
                    return;
                }
                //----------------------

                IntPtr rawBitBuffer = args.GetArgAsNativePtr(0);
                int    width        = args.GetArgAsInt32(1);
                int    height       = args.GetArgAsInt32(2);

                unsafe
                {
                    using (Bitmap bmp = new Bitmap(width, height))
                    {
                        var bmpdata = bmp.LockBits(
                            new Rectangle(0, 0, width, height),
                            System.Drawing.Imaging.ImageLockMode.ReadWrite,
                            System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                        CopyMemory(bmpdata.Scan0, rawBitBuffer, width * height * 4);
                        bmp.UnlockBits(bmpdata);
                        bmp.Save("d:\\WImageTest\\snap02" + (n++) + ".jpg");
                    }
                }
            }
예제 #2
0
            public override void OnRender(NativeCallArgs args)
            {
                //if not set to 0
                //images not render to native cef win

                return; //just return

                if (n > 100)
                {
                    return;
                }
                //----------------------

                //INIT_MY_MET_ARGS(metArgs, 3)
                //MyCefSetVoidPtr2(&vargs[1], buffer);
                //MyCefSetInt32(&vargs[2], width);
                //MyCefSetInt32(&vargs[3], height);

                IntPtr rawBitBuffer = args.GetArgAsNativePtr(1);
                int    width        = args.GetArgAsInt32(2);
                int    height       = args.GetArgAsInt32(3);

                unsafe
                {
                    using (Bitmap bmp = new Bitmap(width, height))
                    {
                        var bmpdata = bmp.LockBits(
                            new Rectangle(0, 0, width, height),
                            System.Drawing.Imaging.ImageLockMode.ReadWrite,
                            System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                        CopyMemory(bmpdata.Scan0, rawBitBuffer, width * height * 4);
                        bmp.UnlockBits(bmpdata);
                        bmp.Save(ReferencePaths.SAVE_IMAGE_PATH + (n++) + ".jpg");
                    }
                }
            }
예제 #3
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;
            }
        }