public RetValue(mbWebView mbWebView, IntPtr param, mbJsExecState mbJsExecState, mbJsValue mbJsValue) { WebView = mbWebView; ValueType = NativeMethods.mbGetJsValueType(mbJsExecState, mbJsValue); switch (ValueType) { default: case mbJsType.kMbJsTypeUndefined: case mbJsType.kMbJsTypeNull: Result = null; break; case mbJsType.kMbJsTypeNumber: Result = NativeMethods.mbJsToDouble(mbJsExecState, mbJsValue); break; case mbJsType.kMbJsTypeBool: Result = NativeMethods.mbJsToBoolean(mbJsExecState, mbJsValue); break; case mbJsType.kMbJsTypeString: Result = NativeMethods.mbJsToString(mbJsExecState, mbJsValue); break; } }
internal static void GetSourceCallback(mbWebView webview, IntPtr token, string mhtml) { if (s_getStringCallbackDict.TryRemove(token, out TaskCompletionSource <string> taskCompletionSource)) { taskCompletionSource.SetResult(mhtml); } }
public void OnPaintUpdate(mbWebView webview, IntPtr param, IntPtr hdc, int x, int y, int cx, int cy) { if (!IsDisposed) { Bitmap bitmap = _image; int cw = x + cx; int ch = y + cy; if (bitmap == default || bitmap.Width < cw || bitmap.Height < ch) { bitmap = new Bitmap(Width > cw ? Width : cw, Height > ch ? Height : ch); _image = bitmap; } using (Graphics graphics = Graphics.FromImage(bitmap)) { IntPtr ptr = graphics.GetHdc(); try { BitBlt(ptr, x, y, cx, cy, hdc, x, y, 0xcc0020); } finally { graphics.ReleaseHdc(ptr); } graphics.Save(); } } }
internal static void GetCookieCallback(mbWebView webview, IntPtr token, MbAsynRequestState state, string cookie) { if (s_getStringCallbackDict.TryRemove(token, out TaskCompletionSource <string> taskCompletionSource)) { taskCompletionSource.SetResult(state == MbAsynRequestState.kMbAsynRequestStateOk ? cookie : null); } }
public bool RegWebsocketHookCallbacks(mbWebView mbWebView, ref mbWebsocketHookCallbacks mbWebsocketHookCallbacks, IntPtr param) { if (mbWebsocketHookCallbacks.CanUse) { NativeMethods.mbNetSetWebsocketCallback(mbWebView, ref mbWebsocketHookCallbacks, param); } return(true); }
internal static void RunJsCallback(mbWebView webview, IntPtr token, mbJsExecState es, mbJsValue v) { RetValue retValue = new RetValue(webview, token, es, v); if (s_runJsCallbackDict.TryRemove(token, out TaskCompletionSource <RetValue> taskCompletionSource)) { taskCompletionSource.SetResult(retValue); } }
public static Task <string> GetSource(this IMiniblinkProxy miniblinkProxy) { mbWebView mbWebView = miniblinkProxy.WebView; IntPtr token = CreateToken(); var taskSource = new TaskCompletionSource <string>(); s_getStringCallbackDict.TryAdd(token, taskSource); mbWebView.GetSource(s_mbGetSourceCallback, token); return(taskSource.Task); }
public void mbPaintBitUpdated(mbWebView webview, IntPtr param, IntPtr buffer, ref mbRect r, int width, int height) { Bitmap image; if (_image == null || _image.Width < width || _image.Height < height) { lock (this) { _image = new Bitmap(width, height, PixelFormat.Format32bppArgb); _drawSize = new Size(width, height); image = _image; } } else { image = _image; } unsafe { //计算更新区域 var rect = new Rectangle { X = r.x >= width ? width - 1 : r.x, Y = r.y >= height ? height - 1 : r.y }; rect.Width = rect.X + r.w > width ? width - rect.X : r.w; rect.Height = rect.Y + r.h > height ? height - rect.Y : r.h; BitmapData bitmapData = image.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); IntPtr ptr = bitmapData.Scan0; int targetStride = image.Width; int sourceStride = width; int *target = (int *)ptr; int *source = (int *)buffer; int targetPix; int sourcePix; for (int h = 0; h < rect.Height; h++) { for (int w = 0; w < rect.Width; w++) { targetPix = targetStride * h + w; sourcePix = sourceStride * (rect.Y + h) + (rect.X + w); *(target + targetPix) = *(source + sourcePix); } } _image.UnlockBits(bitmapData); Invalidate(rect); } }
public void mbPaintBitUpdated(mbWebView webview, IntPtr param, IntPtr buffer, ref mbRect r, int width, int height) { int stride = width * 4; if (_image == null || _image.PixelWidth < width || _image.PixelHeight < height) { _image = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, BitmapPalettes.WebPaletteTransparent); InvalidateVisual(); } //计算更新区域 var rect = new Int32Rect(); rect.X = r.x >= width ? width - 1 : r.x; rect.Y = r.y >= height ? height - 1 : r.y; rect.Width = rect.X + r.w > width ? width - rect.X : r.w; rect.Height = rect.Y + r.h > height ? height - rect.Y : r.h; _image.WritePixels(rect, buffer, stride * (rect.Height + rect.Y), stride, r.x, r.y); _drawSize = new Size(width, height); }
public static void SetCookie(mbWebView mbWebView, string url, System.Net.Cookie cookie) { if (string.IsNullOrEmpty(cookie.Name) || string.IsNullOrEmpty(cookie.Value)) { return; } StringBuilder builder = new StringBuilder(); builder.Append(cookie.Name); builder.Append('='); builder.Append(cookie.Value); if (cookie.Expires != default) { builder.Append("; expires="); builder.Append(cookie.Expires.ToString("r")); } if (!string.IsNullOrEmpty(cookie.Path)) { builder.Append("; path="); builder.Append(cookie.Path); } if (!string.IsNullOrEmpty(cookie.Domain)) { builder.Append("; domain="); builder.Append(cookie.Domain); } if (cookie.HttpOnly) { builder.Append("; HttpOnly"); } if (cookie.Secure) { builder.Append("; Secure"); } mbWebView.SetCookie(url, builder.ToString()); }
public bool RegSocketOnWillConnect(mbWebView mbWebView, onWillConnect onWillConnect, IntPtr param) { _mbWebsocketHookCallbacks.onWillConnect = onWillConnect; return(RegWebsocketHookCallbacks(mbWebView, ref _mbWebsocketHookCallbacks, param)); }
public extern static void mbLoadHtmlWithBaseUrl(mbWebView webView, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Tnelab.MiniBlinkV.Utf8Marshaler))] utf8 html, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Tnelab.MiniBlinkV.Utf8Marshaler))] utf8 baseUrl);
public extern static HDC mbGetLockedViewDC(mbWebView webView);
public extern static void mbRunJs(mbWebView webView, mbWebFrameHandle frameId, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Tnelab.MiniBlinkV.Utf8Marshaler))] utf8 script, bool isInClosure, mbRunJsCallback callback, IntPtr param, IntPtr unuse);
public bool RegSocketOnError(mbWebView mbWebView, onError onError, IntPtr param) { _mbWebsocketHookCallbacks.onError = onError; return(RegWebsocketHookCallbacks(mbWebView, ref _mbWebsocketHookCallbacks, param)); }
public bool RegSocketOnReceive(mbWebView mbWebView, onReceive onReceive, IntPtr param) { _mbWebsocketHookCallbacks.onReceive = onReceive; return(RegWebsocketHookCallbacks(mbWebView, ref _mbWebsocketHookCallbacks, param));; }
public static Task <RetValue> RunJs(this IMiniblinkProxy miniblinkProxy, string js, bool isInClosure) { mbWebView mbWebView = miniblinkProxy.WebView; return(RunJs(miniblinkProxy, mbWebView.GetMainFrame(), js, isInClosure)); }
public extern static void mbShowWindow(mbWebView webWindow, bool show);
public extern static void mbUtilSerializeToMHTML(mbWebView webView, mbGetMHTMLCallback calback, IntPtr param);
public extern static bool mbIsMainFrame(mbWebView webView, mbWebFrameHandle frameId);
public extern static mbWebFrameHandle mbWebFrameGetMainFrame(mbWebView webView);
public extern static mbJsValue mbRunJsSync(mbWebView webView, mbWebFrameHandle frameId, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Tnelab.MiniBlinkV.Utf8Marshaler))] utf8 script, bool isInClosure);
public extern static void mbLoadURL(mbWebView webView, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Tnelab.MiniBlinkV.Utf8Marshaler))] utf8 url);
public extern static void mbOnJsQuery(mbWebView webView, mbJsQueryCallback callback, IntPtr param);
public bool RegSocketOnConnected(mbWebView mbWebView, onConnected onConnected, IntPtr param) { _mbWebsocketHookCallbacks.onConnected = onConnected; return(RegWebsocketHookCallbacks(mbWebView, ref _mbWebsocketHookCallbacks, param)); }
public extern static void mbWake(mbWebView webView);
public bool RegSocketOnSend(mbWebView mbWebView, onSend onSend, IntPtr param) { _mbWebsocketHookCallbacks.onSend = onSend; return(RegWebsocketHookCallbacks(mbWebView, ref _mbWebsocketHookCallbacks, param)); }
public extern static void mbUnlockViewDC(mbWebView webView);
public extern static void mbKillFocus(mbWebView webView);
public extern static void mbResponseQuery(mbWebView webView, int64_t queryId, int customMsg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Tnelab.MiniBlinkV.Utf8Marshaler))] utf8 response);