Beispiel #1
0
 public static extern void wkeOnNavigation(IntPtr webView, wkeNavigationCallback callback, IntPtr param);
        /// <summary>
        /// 初始化 MB
        /// </summary>
        public void CreateCore()
        {
            BlinkBrowserPInvoke.wkeInitialize();


            //BlinkBrowserPInvoke.wkeInitializeExWrap(new wkeSettings()
            //{
            //    proxy = new wkeProxy
            //    {
            //        hostname = "127.0.0.1",
            //        port = 8888,
            //        type = wkeProxyType.WKE_PROXY_HTTP,
            //        password = "",
            //        username = ""
            //    },
            //    mask = wkeSettingMask.WKE_SETTING_PROXY
            //});
            //BlinkBrowserPInvoke.wkeInitialize();
            //BlinkBrowserPInvoke.wkeInitializeExWrap(new wkeSettings()
            //{
            //    proxy = new wkeProxy
            //    {
            //        hostname = "127.0.0.1",
            //        port = 8888,
            //        type = wkeProxyType.WKE_PROXY_HTTP,
            //        password = "",
            //        username = ""
            //    },
            //    mask = 1
            //});

            handle = BlinkBrowserPInvoke.wkeCreateWebView();

            //只有开启才会触发 wkeOnCreateView
            //wkeSetNavigationToNewWindowEnable(handle, true);

            BlinkBrowserPInvoke.wkeSetHandle(this.handle, this.Handle);
            BlinkBrowserPInvoke.wkeSetHandleOffset(handle, Location.X - 2, 0);



            //BlinkBrowserPInvoke.wkeSetTransparent(handle, true);
            BlinkBrowserPInvoke.wkeSetCookieEnabled(handle, true);
            CookiePath = Application.StartupPath + "\\cookie\\";
            if (!Directory.Exists(CookiePath))
            {
                Directory.CreateDirectory(CookiePath);
            }
            BlinkBrowserPInvoke.wkeSetCookieJarPath(handle, CookiePath);

            BlinkBrowserPInvoke.wkeResize(handle, Width, Height);
            BlinkBrowserPInvoke.wkeSetUserAgentW(this.handle, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36");

            BindJsFunc();
            AlertBoxCallback = new AlertBoxCallback((a, b, c) =>
            {
                MessageBox.Show(Marshal.PtrToStringUni(wkeToStringW(c)), Url + "提示");
            });
            BlinkBrowserPInvoke.wkeOnAlertBox(handle, AlertBoxCallback, IntPtr.Zero);

            //设置声音
            //BlinkBrowserPInvoke.wkeSetMediaVolume(handle, 20);

            _wkeNavigationCallback = OnwkeNavigationCallback;
            BlinkBrowserPInvoke.wkeOnNavigation(handle, _wkeNavigationCallback, IntPtr.Zero);
            listObj.Add(_wkeNavigationCallback);

            //BlinkBrowserPInvoke.wkeSetCookieEnabled(handle, false);

            titleChangeCallback = OnTitleChangedCallback;
            BlinkBrowserPInvoke.wkeOnTitleChanged(this.handle, titleChangeCallback, IntPtr.Zero);
            listObj.Add(titleChangeCallback);

            titleChangeCallback2 = OnTitleChangedCallback2;
            BlinkBrowserPInvoke.wkeOnMouseOverUrlChanged(this.handle, titleChangeCallback2, IntPtr.Zero);
            listObj.Add(titleChangeCallback2);

            _wkeDocumentReadyCallback = OnwkeDocumentReadyCallback;
            BlinkBrowserPInvoke.wkeOnDocumentReady(this.handle, _wkeDocumentReadyCallback, IntPtr.Zero);
            listObj.Add(_wkeDocumentReadyCallback);

            urlChangedCallback = OnUrlChangedCallback;
            BlinkBrowserPInvoke.wkeOnURLChanged(this.handle, urlChangedCallback, IntPtr.Zero);
            listObj.Add(urlChangedCallback);

            urlChangedCallback2 = OnUrlChangedCallback2;
            BlinkBrowserPInvoke.wkeOnURLChanged2(this.handle, urlChangedCallback2, IntPtr.Zero);
            listObj.Add(urlChangedCallback2);

            _wkeConsoleMessageCallback = OnwkeConsoleMessageCallback;
            BlinkBrowserPInvoke.wkeOnConsole(this.handle, _wkeConsoleMessageCallback, IntPtr.Zero);
            listObj.Add(_wkeConsoleMessageCallback);

            _wkePaintUpdatedCallback = OnWkePaintUpdatedCallback;
            BlinkBrowserPInvoke.wkeOnPaintUpdated(this.handle, _wkePaintUpdatedCallback, IntPtr.Zero);
            listObj.Add(_wkePaintUpdatedCallback);

            _wkeDocumentReadyCallback = OnwkeDocumentReadyCallback;
            //var pa = Marshal.StringToCoTaskMemUni("我传的值:::::");
            //BlinkBrowserPInvoke.wkeOnDocumentReady(this.handle, _wkeDocumentReadyCallback, pa);

            BlinkBrowserPInvoke.wkeOnDocumentReady(this.handle, _wkeDocumentReadyCallback, IntPtr.Zero);
            listObj.Add(_wkeDocumentReadyCallback);


            _wkeLoadingFinishCallback = OnwkeLoadingFinishCallback;
            BlinkBrowserPInvoke.wkeOnLoadingFinish(this.handle, _wkeLoadingFinishCallback, IntPtr.Zero);
            listObj.Add(_wkeLoadingFinishCallback);

            //会导致 taobao 加载图片异常
            _wkeDownloadFileCallback = OnwkeDownloadFileCallback;
            BlinkBrowserPInvoke.wkeOnDownload(this.handle, _wkeDownloadFileCallback, IntPtr.Zero);
            listObj.Add(_wkeDownloadFileCallback);

            //_wkeCreateViewCallback = OnwkeCreateViewCallback;
            //BlinkBrowserPInvoke.wkeOnCreateView(this.handle, _wkeCreateViewCallback, handle);
            //listObj.Add(_wkeCreateViewCallback);

            _wkeLoadUrlBeginCallback = OnwkeLoadUrlBeginCallback;
            BlinkBrowserPInvoke.wkeOnLoadUrlBegin(this.handle, _wkeLoadUrlBeginCallback, handle);
            listObj.Add(_wkeLoadUrlBeginCallback);

            #region JS 动态绑定,并返回值
            wkeJsNativeFunction jsnav = new wkeJsNativeFunction((es, param) =>
            {
                string s      = jsToString(es, jsArg(es, 0)).Utf8IntptrToString();
                IntPtr strPtr = Marshal.StringToCoTaskMemUni("这是C#后台返回值:" + s);
                Int64 result  = jsStringW(es, strPtr);
                Marshal.FreeCoTaskMem(strPtr);
                return(result);
            });
            BlinkBrowserPInvoke.wkeJsBindFunction("jsReturnValueTest", jsnav, IntPtr.Zero, 1);
            listObj.Add(jsnav);
            #endregion

            // get
            wkeJsNativeFunction jsnavGet = new wkeJsNativeFunction((es, param) =>
            {
                Console.WriteLine("call jsBindGetter");
                return(jsStringW(es, Marshal.StringToCoTaskMemUni("{ \"name\": \"he\" }")));
            });
            BlinkBrowserPInvoke.wkeJsBindGetter("testJson", jsnavGet, IntPtr.Zero);
            listObj.Add(jsnavGet);

            // set
            wkeJsNativeFunction jsnavSet = new wkeJsNativeFunction((es, _param) =>
            {
                Console.WriteLine("call jsBindSetter");

                Int64 testJson   = jsArg(es, 0);
                IntPtr argStr    = jsToStringW(es, testJson);
                string argString = Marshal.PtrToStringUni(argStr);
                //MessageBox.Show(argString, "alert setter");

                return(jsUndefined(es));
            });
            BlinkBrowserPInvoke.wkeJsBindSetter("testJson", jsnavSet, IntPtr.Zero);
            listObj.Add(jsnavSet);

            _wkeLoadUrlEndCallback = OnwkeLoadUrlEndCallback;
            BlinkBrowserPInvoke.wkeOnLoadUrlEnd(this.handle, _wkeLoadUrlEndCallback, handle);
            listObj.Add(_wkeLoadUrlEndCallback);

            //readFileCallback = new ReadFileCallback(LoadMemoryData);
            //wkeOnReadFile(readFileCallback);
            //listObj.Add(readFileCallback);

            //文件拖放
            //AllowDrop = true;
            //DragEnter += BlinkBrowser_DragEnter;
            //DragDrop += BlinkBrowser_DragDrop;
        }
Beispiel #3
0
        /// <summary>
        /// 初始化 MB
        /// </summary>
        public void CreateCore()
        {
            BlinkBrowserPInvoke.wkeInitialize();
            handle = BlinkBrowserPInvoke.wkeCreateWebView();

            //只有开启才会触发 wkeOnCreateView
            BlinkBrowserPInvoke.wkeSetNavigationToNewWindowEnable(handle, true);

            BlinkBrowserPInvoke.wkeSetHandle(this.handle, this.Handle);
            BlinkBrowserPInvoke.wkeSetHandleOffset(handle, Location.X - 2, 0);

            //BlinkBrowserPInvoke.wkeSetTransparent(handle, true);
            BlinkBrowserPInvoke.wkeSetCookieEnabled(handle, true);
            if (string.IsNullOrEmpty(CookiePath))
            {
                CookiePath = Path.Combine(Path.GetTempPath(), "MyBrowser\\cookie");
                if (!Directory.Exists(CookiePath))
                {
                    Directory.CreateDirectory(CookiePath);
                }
                BlinkBrowserPInvoke.wkeSetCookieJarPath(handle, CookiePath);


                LocalStoragePath = Path.Combine(Path.GetTempPath(), "MyBrowser\\LocalStorage");
                if (!Directory.Exists(LocalStoragePath))
                {
                    Directory.CreateDirectory(LocalStoragePath);
                }
                BlinkBrowserPInvoke.wkeSetLocalStorageFullPath(handle, LocalStoragePath);
            }

            BlinkBrowserPInvoke.wkeResize(handle, Width, Height);
            BlinkBrowserPInvoke.wkeSetUserAgentW(this.handle, Config.GetUserAgent());

            BindJsFunc();
            AlertBoxCallback = new AlertBoxCallback((a, b, c) => {
                MessageBox.Show(Marshal.PtrToStringUni(BlinkBrowserPInvoke.wkeToStringW(c)), Url + "提示");
            });
            BlinkBrowserPInvoke.wkeOnAlertBox(handle, AlertBoxCallback, IntPtr.Zero);

            //设置声音
            //BlinkBrowserPInvoke.wkeSetMediaVolume(handle, 20);

            _wkeNavigationCallback = OnwkeNavigationCallback;
            BlinkBrowserPInvoke.wkeOnNavigation(handle, _wkeNavigationCallback, IntPtr.Zero);


            titleChangeCallback = OnTitleChangedCallback;
            BlinkBrowserPInvoke.wkeOnTitleChanged(this.handle, titleChangeCallback, IntPtr.Zero);

            titleChangeCallback2 = OnTitleChangedCallback2;
            BlinkBrowserPInvoke.wkeOnMouseOverUrlChanged(this.handle, titleChangeCallback2, IntPtr.Zero);

            _wkeDocumentReadyCallback = OnwkeDocumentReadyCallback;
            BlinkBrowserPInvoke.wkeOnDocumentReady(this.handle, _wkeDocumentReadyCallback, IntPtr.Zero);

            urlChangedCallback = OnUrlChangedCallback;
            BlinkBrowserPInvoke.wkeOnURLChanged(this.handle, urlChangedCallback, IntPtr.Zero);

            _wkeConsoleMessageCallback = OnwkeConsoleMessageCallback;
            BlinkBrowserPInvoke.wkeOnConsole(this.handle, _wkeConsoleMessageCallback, IntPtr.Zero);

            _wkePaintUpdatedCallback = OnWkePaintUpdatedCallback;
            BlinkBrowserPInvoke.wkeOnPaintUpdated(this.handle, _wkePaintUpdatedCallback, IntPtr.Zero);

            _wkeLoadingFinishCallback = OnwkeLoadingFinishCallback;
            BlinkBrowserPInvoke.wkeOnLoadingFinish(this.handle, _wkeLoadingFinishCallback, IntPtr.Zero);

            //会导致 taobao 加载图片异常
            _wkeDownloadFileCallback = OnwkeDownloadFileCallback;
            BlinkBrowserPInvoke.wkeOnDownload(this.handle, _wkeDownloadFileCallback, IntPtr.Zero);

            _wkeCreateViewCallback = OnwkeCreateViewCallback;
            BlinkBrowserPInvoke.wkeOnCreateView(this.handle, _wkeCreateViewCallback, handle);

            _wkeLoadUrlEndCallback = OnwkeLoadUrlEndCallback;
            BlinkBrowserPInvoke.wkeOnLoadUrlEnd(this.handle, _wkeLoadUrlEndCallback, handle);

            //如果在设计器里赋值了,初始化后加载URL
            if (!string.IsNullOrEmpty(url))
            {
                BlinkBrowserPInvoke.wkeLoadURLW(handle, url);
            }
        }