| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969 |
- #if UNITY_ANDROID && !UNITY_EDITOR
- using System;
- using System.Runtime.InteropServices;
- using UnityEngine;
- using UnityEngine.Rendering;
- class UniWebViewMethodChannel: AndroidJavaProxy {
- private const string GlobalChannelIdentifier = "__UniWebViewGlobalChannelIdentifier";
- public UniWebViewMethodChannel() : base("com.onevcat.uniwebview.UniWebViewNativeChannel") { }
- string invokeChannelMethod(string name, string method, string parameters) {
- if (name == GlobalChannelIdentifier) {
- UniWebViewLogger.Instance.Verbose(
- "Global channel method invoked. Method: " + method + " Params: " + parameters
- );
- return UniWebViewStaticListener.InvokeStaticMethod(method, parameters);
- } else {
- UniWebViewLogger.Instance.Verbose("invokeChannelMethod invoked by native side. Name: " + name + " Method: "
- + method + " Params: " + parameters);
- return UniWebViewChannelMethodManager.Instance.InvokeMethod(name, method, parameters);
- }
- }
- }
- public class UniWebViewInterface {
- private const int SnapshotTextureStreamStopRenderEventCount = 3;
- private static readonly AndroidJavaClass plugin;
- private static bool correctPlatform = Application.platform == RuntimePlatform.Android;
-
- static UniWebViewInterface() {
- var go = new GameObject("UniWebViewAndroidStaticListener");
- go.AddComponent<UniWebViewAndroidStaticListener>();
- plugin = new AndroidJavaClass("com.onevcat.uniwebview.UniWebViewInterface");
-
- // Prepare dispatcher instance. Some callbacks may come from non-UI threads. Use this dispatcher to
- // send any action to the Unity main thread.
- _ = UniWebViewMainThreadDispatcher.Instance;
- CheckPlatform();
- plugin.CallStatic("prepare");
- UniWebViewLogger.Instance.Info("Connecting to native side method channel.");
- plugin.CallStatic("registerChannel", new UniWebViewMethodChannel());
- }
- public static void SetLogLevel(int level) {
- CheckPlatform();
- plugin.CallStatic("setLogLevel", level);
- }
- public static bool IsWebViewSupported() {
- CheckPlatform();
- return plugin.CallStatic<bool>("isWebViewSupported");
- }
- public static void Init(string name, int x, int y, int width, int height) {
- CheckPlatform();
- plugin.CallStatic("init", name, x, y, width, height);
- }
- public static void Destroy(string name) {
- CheckPlatform();
- plugin.CallStatic("destroy", name);
- }
- public static void Load(string name, string url, bool skipEncoding, string readAccessURL) {
- CheckPlatform();
- plugin.CallStatic("load", name, url);
- }
- public static void LoadHTMLString(string name, string html, string baseUrl, bool skipEncoding) {
- CheckPlatform();
- plugin.CallStatic("loadHTMLString", name, html, baseUrl);
- }
- public static void Reload(string name) {
- CheckPlatform();
- plugin.CallStatic("reload", name);
- }
- public static void Stop(string name) {
- CheckPlatform();
- plugin.CallStatic("stop", name);
- }
- public static string GetUrl(string name) {
- CheckPlatform();
- return plugin.CallStatic<string>("getUrl", name);
- }
- public static void SetFrame(string name, int x, int y, int width, int height) {
- CheckPlatform();
- plugin.CallStatic("setFrame", name, x, y, width, height);
- }
- public static void SetPosition(string name, int x, int y) {
- CheckPlatform();
- plugin.CallStatic("setPosition", name, x, y);
- }
- public static void SetSize(string name, int width, int height) {
- CheckPlatform();
- plugin.CallStatic("setSize", name, width, height);
- }
- public static void SetTransform(string name, float rotation, float scaleX, float scaleY) {
- CheckPlatform();
- plugin.CallStatic("setTransform", name, rotation, scaleX, scaleY);
- }
- public static void SetRoundCornerRadius(string name, float topLeft, float topRight, float bottomLeft, float bottomRight) {
- CheckPlatform();
- plugin.CallStatic("setCornerRadius", name, topLeft, topRight, bottomLeft, bottomRight);
- }
- public static void SetShadow(
- string name,
- float red,
- float green,
- float blue,
- float alpha,
- float opacity,
- float radius,
- float offsetX,
- float offsetY,
- float spread
- ) {
- CheckPlatform();
- plugin.CallStatic("setShadow", name, red, green, blue, alpha, opacity, radius, offsetX, offsetY, spread);
- }
- public static bool Show(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
- CheckPlatform();
- if (useAsync) {
- plugin.CallStatic("showAsync", name, fade, edge, duration, identifier);
- return true;
- } else {
- return plugin.CallStatic<bool>("show", name, fade, edge, duration, identifier);
- }
- }
- public static bool Hide(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
- CheckPlatform();
- if (useAsync) {
- plugin.CallStatic("hideAsync", name, fade, edge, duration, identifier);
- return true;
- } else {
- return plugin.CallStatic<bool>("hide", name, fade, edge, duration, identifier);
- }
- }
- public static bool AnimateTo(string name, int x, int y, int width, int height, float duration, float delay, string identifier) {
- CheckPlatform();
- return plugin.CallStatic<bool>("animateTo", name, x, y, width, height, duration, delay, identifier);
- }
- public static void AddJavaScript(string name, string jsString, string identifier) {
- CheckPlatform();
- plugin.CallStatic("addJavaScript", name, jsString, identifier);
- }
- public static void EvaluateJavaScript(string name, string jsString, string identifier) {
- CheckPlatform();
- plugin.CallStatic("evaluateJavaScript", name, jsString, identifier);
- }
- public static void ClosePopupWindow(string name, string popupId) {
- CheckPlatform();
- plugin.CallStatic("closePopupWindow", name, popupId);
- }
- public static void GoBackPopupWindow(string name, string popupId) {
- CheckPlatform();
- plugin.CallStatic("goBackPopupWindow", name, popupId);
- }
- public static void GoForwardPopupWindow(string name, string popupId) {
- CheckPlatform();
- plugin.CallStatic("goForwardPopupWindow", name, popupId);
- }
- public static void EvaluateJavaScriptInPopupWindow(
- string name,
- string popupId,
- string jsString,
- string identifier
- ) {
- CheckPlatform();
- plugin.CallStatic("evaluateJavaScriptInPopupWindow", name, popupId, jsString, identifier);
- }
- public static void CloseAllPopupWindows(string name) {
- CheckPlatform();
- plugin.CallStatic("closeAllPopupWindows", name);
- }
- public static void SetPopupPageEventEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setPopupPageEventEnabled", name, enabled);
- }
- public static void AddUrlScheme(string name, string scheme) {
- CheckPlatform();
- plugin.CallStatic("addUrlScheme", name, scheme);
- }
- public static void RemoveUrlScheme(string name, string scheme) {
- CheckPlatform();
- plugin.CallStatic("removeUrlScheme", name, scheme);
- }
- [Obsolete("AddSslExceptionDomain is deprecated. Use AddSslPinnedFingerprint instead.")]
- public static void AddSslExceptionDomain(string name, string domain) {
- CheckPlatform();
- plugin.CallStatic("addSslExceptionDomain", name, domain);
- }
- [Obsolete("RemoveSslExceptionDomain is deprecated. Use RemoveSslPinnedFingerprint instead.")]
- public static void RemoveSslExceptionDomain(string name, string domain) {
- CheckPlatform();
- plugin.CallStatic("removeSslExceptionDomain", name, domain);
- }
- public static void AddSslPinnedFingerprint(string name, string domain, string fingerprint) {
- CheckPlatform();
- plugin.CallStatic("addSslPinnedFingerprint", name, domain, fingerprint);
- }
- public static void RemoveSslPinnedFingerprint(string name, string domain, string fingerprint) {
- CheckPlatform();
- plugin.CallStatic("removeSslPinnedFingerprint", name, domain, fingerprint);
- }
- public static void AddPermissionTrustDomain(string name, string domain) {
- CheckPlatform();
- plugin.CallStatic("addPermissionTrustDomain", name, domain);
- }
- public static void RemovePermissionTrustDomain(string name, string domain) {
- CheckPlatform();
- plugin.CallStatic("removePermissionTrustDomain", name, domain);
- }
- public static void SetHeaderField(string name, string key, string value) {
- CheckPlatform();
- plugin.CallStatic("setHeaderField", name, key, value);
- }
- public static void SetUserAgent(string name, string userAgent) {
- CheckPlatform();
- plugin.CallStatic("setUserAgent", name, userAgent);
- }
- public static string GetUserAgent(string name) {
- CheckPlatform();
- return plugin.CallStatic<string>("getUserAgent", name);
- }
- public static void SetAllowAutoPlay(bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAllowAutoPlay", flag);
- }
- public static void SetAllowJavaScriptOpenWindow(bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAllowJavaScriptOpenWindow", flag);
- }
- public static void SetAllowFileAccess(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAllowFileAccess", name, flag);
- }
- public static void SetAcceptThirdPartyCookies(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAcceptThirdPartyCookies", name, flag);
- }
- public static void SetAllowFileAccessFromFileURLs(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAllowFileAccessFromFileURLs", name, flag);
- }
- public static void SetAllowUniversalAccessFromFileURLs(bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAllowUniversalAccessFromFileURLs", flag);
- }
- public static void BringContentToFront(string name) {
- CheckPlatform();
- plugin.CallStatic("bringContentToFront", name);
- }
- public static void SetForwardWebConsoleToNativeOutput(bool flag) {
- CheckPlatform();
- plugin.CallStatic("setForwardWebConsoleToNativeOutput", flag);
- }
- public static void SetEnableKeyboardAvoidance(bool flag) {
- CheckPlatform();
- plugin.CallStatic("setEnableKeyboardAvoidance", flag);
- }
- public static void SetJavaScriptEnabled(bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setJavaScriptEnabled", enabled);
- }
- public static void CleanCache(string name, bool includeStorage, string identifier) {
- CheckPlatform();
- plugin.CallStatic("cleanCache", name, includeStorage, identifier);
- }
- public static void SetCacheMode(string name, int mode) {
- CheckPlatform();
- plugin.CallStatic("setCacheMode", name, mode);
- }
- public static void ClearCookies() {
- CheckPlatform();
- plugin.CallStatic("clearCookies");
- }
- public static void ClearCookies(string identifier) {
- CheckPlatform();
- plugin.CallStatic("clearCookiesAsync", identifier);
- }
- public static void SetCookie(string url, string cookie, bool skipEncoding) {
- CheckPlatform();
- plugin.CallStatic("setCookie", url, cookie);
- }
- public static void SetCookie(string url, string cookie, bool skipEncoding, string identifier) {
- CheckPlatform();
- plugin.CallStatic("setCookieAsync", url, cookie, identifier);
- }
- public static string GetCookie(string url, string key, bool skipEncoding) {
- CheckPlatform();
- return plugin.CallStatic<string>("getCookie", url, key);
- }
- public static void GetCookie(string url, string key, bool skipEncoding, string identifier) {
- CheckPlatform();
- plugin.CallStatic("getCookieAsync", url, key, identifier);
- }
- public static void RemoveCookies(string url, bool skipEncoding) {
- CheckPlatform();
- plugin.CallStatic("removeCookies", url);
- }
- public static void RemoveCookies(string url, bool skipEncoding, string identifier) {
- CheckPlatform();
- plugin.CallStatic("removeCookiesAsync", url, identifier);
- }
- public static void RemoveCookie(string url, string key, bool skipEncoding) {
- CheckPlatform();
- plugin.CallStatic("removeCookie", url, key);
- }
- public static void RemoveCookie(string url, string key, bool skipEncoding, string identifier) {
- CheckPlatform();
- plugin.CallStatic("removeCookieAsync", url, key, identifier);
- }
- public static void ClearHttpAuthUsernamePassword(string host, string realm) {
- CheckPlatform();
- plugin.CallStatic("clearHttpAuthUsernamePassword", host, realm);
- }
- public static void SetBackgroundColor(string name, float r, float g, float b, float a) {
- CheckPlatform();
- plugin.CallStatic("setBackgroundColor", name, r, g, b, a);
- }
- public static void SetWebViewAlpha(string name, float alpha) {
- CheckPlatform();
- plugin.CallStatic("setWebViewAlpha", name, alpha);
- }
- public static float GetWebViewAlpha(string name) {
- CheckPlatform();
- return plugin.CallStatic<float>("getWebViewAlpha", name);
- }
- public static void SetShowSpinnerWhileLoading(string name, bool show) {
- CheckPlatform();
- plugin.CallStatic("setShowSpinnerWhileLoading", name, show);
- }
- public static void SetSpinnerText(string name, string text) {
- CheckPlatform();
- plugin.CallStatic("setSpinnerText", name, text);
- }
- public static void SetAllowUserDismissSpinnerByGesture(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAllowUserDismissSpinnerByGesture", name, flag);
- }
- public static void ShowSpinner(string name) {
- CheckPlatform();
- plugin.CallStatic("showSpinner", name);
- }
- public static void HideSpinner(string name) {
- CheckPlatform();
- plugin.CallStatic("hideSpinner", name);
- }
- public static bool CanGoBack(string name) {
- CheckPlatform();
- return plugin.CallStatic<bool>("canGoBack", name);
- }
- public static bool CanGoForward(string name) {
- CheckPlatform();
- return plugin.CallStatic<bool>("canGoForward", name);
- }
- public static void GoBack(string name) {
- CheckPlatform();
- plugin.CallStatic("goBack", name);
- }
- public static void GoForward(string name) {
- CheckPlatform();
- plugin.CallStatic("goForward", name);
- }
- public static void SetOpenLinksInExternalBrowser(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setOpenLinksInExternalBrowser", name, flag);
- }
- public static void SetHorizontalScrollBarEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setHorizontalScrollBarEnabled", name, enabled);
- }
- public static void SetVerticalScrollBarEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setVerticalScrollBarEnabled", name, enabled);
- }
- public static void SetBouncesEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setBouncesEnabled", name, enabled);
- }
- public static void SetZoomEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setZoomEnabled", name, enabled);
- }
- public static void SetUseWideViewPort(string name, bool use) {
- CheckPlatform();
- plugin.CallStatic("setUseWideViewPort", name, use);
- }
- public static void SetLoadWithOverviewMode(string name, bool overview) {
- CheckPlatform();
- plugin.CallStatic("setLoadWithOverviewMode", name, overview);
- }
- public static void SetImmersiveModeEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setImmersiveModeEnabled", name, enabled);
- }
- public static void SetUserInteractionEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setUserInteractionEnabled", name, enabled);
- }
- public static void SetTransparencyClickingThroughEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setTransparencyClickingThroughEnabled", name, enabled);
- }
- public static void RefreshTransparencyClickingThroughLayout(string name) {
- CheckPlatform();
- plugin.CallStatic("refreshTransparencyClickingThroughLayout", name);
- }
- public static void SetWebContentsDebuggingEnabled(bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setWebContentsDebuggingEnabled", enabled);
- }
- public static void SetAllowHTTPAuthPopUpWindow(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setAllowHTTPAuthPopUpWindow", name, flag);
- }
- public static void Print(string name) {
- CheckPlatform();
- plugin.CallStatic("print", name);
- }
- public static void CaptureSnapshot(string name, string filename) {
- CheckPlatform();
- plugin.CallStatic("captureSnapshot", name, filename);
- }
- public static void ScrollTo(string name, int x, int y, bool animated) {
- CheckPlatform();
- plugin.CallStatic("scrollTo", name, x, y, animated);
- }
- public static void SetCalloutEnabled(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setCalloutEnabled", name, flag);
- }
- public static void SetSupportMultipleWindows(string name, bool enabled, bool allowJavaScriptOpening) {
- CheckPlatform();
- plugin.CallStatic("setSupportMultipleWindows", name, enabled, allowJavaScriptOpening);
- }
- public static void SetDragInteractionEnabled(string name, bool flag) {
- CheckPlatform();
- plugin.CallStatic("setDragInteractionEnabled", name, flag);
- }
- public static void SetDefaultFontSize(string name, int size) {
- CheckPlatform();
- plugin.CallStatic("setDefaultFontSize", name, size);
- }
- public static void SetTextZoom(string name, int textZoom) {
- CheckPlatform();
- plugin.CallStatic("setTextZoom", name, textZoom);
- }
- public static float NativeScreenWidth() {
- CheckPlatform();
- return plugin.CallStatic<float>("screenWidth");
- }
- public static float NativeScreenHeight() {
- CheckPlatform();
- return plugin.CallStatic<float>("screenHeight");
- }
- public static int GetStatusBarHeight() {
- CheckPlatform();
- return plugin.CallStatic<int>("getStatusBarHeight");
- }
- // Returns the padding of the native content view as [left, top, right, bottom] in pixels.
- // Returns all zeros if the value cannot be retrieved, so callers fall back to the
- // status-bar-based frame mapping.
- public static float[] GetContentViewPadding() {
- CheckPlatform();
- try {
- var result = plugin.CallStatic<string>("getContentViewPadding");
- var parts = result.Split(',');
- if (parts.Length == 4) {
- return new float[] {
- int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3])
- };
- }
- UniWebViewLogger.Instance.Warning("Unexpected content view padding value: " + result);
- } catch (Exception e) {
- UniWebViewLogger.Instance.Warning("Failed to get content view padding: " + e.Message);
- }
- return new float[] { 0, 0, 0, 0 };
- }
- public static void SetDownloadEventForContextMenuEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setDownloadEventForContextMenuEnabled", name, enabled);
- }
- public static void SetAutoDownloadEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("setAutoDownloadEnabled", name, enabled);
- }
- public static void SetAllowUserEditFileNameBeforeDownloading(string name, bool allowed) {
- CheckPlatform();
- plugin.CallStatic("setAllowUserEditFileNameBeforeDownloading", name, allowed);
- }
- // Safe Browsing
- public static bool IsSafeBrowsingSupported() {
- CheckPlatform();
- return plugin.CallStatic<bool>("isSafeBrowsingSupported");
- }
- public static string GetSafeBrowsingCustomTabsProviderPackageName() {
- CheckPlatform();
- return plugin.CallStatic<string>("getSafeBrowsingCustomTabsProviderPackageName");
- }
- public static void SafeBrowsingInit(string name, string url) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingInit", name, url);
- }
- public static void SafeBrowsingChangeUrl(string name, string url) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingChangeUrl", name, url);
- }
- public static void SafeBrowsingSetToolbarColor(string name, float r, float g, float b) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetToolbarColor", name, r, g, b);
- }
- public static void SafeBrowsingSetColorScheme(string name, int colorScheme) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetColorScheme", name, colorScheme);
- }
- public static void SafeBrowsingShow(string name) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingShow", name);
- }
- public static void SafeBrowsingInvalidate(string name) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingInvalidate", name);
- }
- public static void SetPreferredCustomTabsBrowsers(string[] packages) {
- CheckPlatform();
- plugin.CallStatic("setPreferredCustomTabsBrowsers", (object)packages);
- }
- public static void SafeBrowsingSetSecondaryToolbarColor(string name, float r, float g, float b) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetSecondaryToolbarColor", name, r, g, b);
- }
- public static void SafeBrowsingSetNavigationBarColor(string name, float r, float g, float b) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetNavigationBarColor", name, r, g, b);
- }
- public static void SafeBrowsingSetNavigationBarDividerColor(string name, float r, float g, float b) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetNavigationBarDividerColor", name, r, g, b);
- }
- public static void SafeBrowsingSetToolbarCornerRadiusDp(string name, int cornerRadiusDp) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetToolbarCornerRadiusDp", name, cornerRadiusDp);
- }
- public static void SafeBrowsingSetInitialHeightPx(string name, int initialHeightPx, int resizeBehavior = (int)UniWebViewSafeBrowsing.ActivityHeightResizeBehavior.Fixed) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetInitialHeightPx", name, initialHeightPx, resizeBehavior);
- }
- public static void SafeBrowsingSetInitialWidthPx(string name, int initialWidthPx) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetInitialWidthPx", name, initialWidthPx);
- }
- public static void SafeBrowsingSetShareMenuItemEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetShareMenuItemEnabled", name, enabled);
- }
- public static void SafeBrowsingSetUrlBarHidingEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetUrlBarHidingEnabled", name, enabled);
- }
- public static void SafeBrowsingSetSendToExternalDefaultHandlerEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetSendToExternalDefaultHandlerEnabled", name, enabled);
- }
- public static void SafeBrowsingSetMaximizationEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetMaximizationEnabled", name, enabled);
- }
- public static void SafeBrowsingSetDownloadButtonEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetDownloadButtonEnabled", name, enabled);
- }
- public static void SafeBrowsingSetBookmarksButtonEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetBookmarksButtonEnabled", name, enabled);
- }
- public static void SafeBrowsingSetBackgroundInteractionEnabled(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetBackgroundInteractionEnabled", name, enabled);
- }
- public static void SafeBrowsingSetWarmup(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetWarmup", name, enabled);
- }
- public static void SafeBrowsingSetPrefetch(string name, bool enabled, string optionalAlternativeUrl = null) {
- CheckPlatform();
- plugin.CallStatic("safeBrowsingSetPrefetch", name, enabled, optionalAlternativeUrl);
- }
-
- // Authentication
- public static bool IsAuthenticationIsSupported() {
- CheckPlatform();
- return plugin.CallStatic<bool>("isAuthenticationIsSupported");
- }
- public static void AuthenticationInit(string name, string url, string scheme) {
- CheckPlatform();
- plugin.CallStatic("authenticationInit", name, url, scheme);
- }
- public static void AuthenticationStart(string name) {
- CheckPlatform();
- plugin.CallStatic("authenticationStart", name);
- }
- public static void AuthenticationSetPrivateMode(string name, bool enabled) {
- CheckPlatform();
- plugin.CallStatic("authenticationSetPrivateMode", name, enabled);
- }
- public static bool SetEmbeddedToolbarConfig(string name, string json) {
- CheckPlatform();
- return plugin.CallStatic<bool>("setEmbeddedToolbarConfig", name, json);
- }
- public static void SetShowEmbeddedToolbar(string name, bool show) {
- CheckPlatform();
- plugin.CallStatic("setShowEmbeddedToolbar", name, show);
- }
- public static void SetEmbeddedToolbarOnTop(string name, bool top) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarOnTop", name, top);
- }
- public static void SetEmbeddedToolbarDoneButtonText(string name, string text) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarDoneButtonText", name, text);
- }
- public static void SetEmbeddedToolbarGoBackButtonText(string name, string text) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarGoBackButtonText", name, text);
- }
- public static void SetEmbeddedToolbarGoForwardButtonText(string name, string text) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarGoForwardButtonText", name, text);
- }
-
- public static void SetEmbeddedToolbarTitleText(string name, string text) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarTitleText", name, text);
- }
- public static void SetEmbeddedToolbarBackgroundColor(string name, Color color) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarBackgroundColor", name, color.r, color.g, color.b, color.a);
- }
-
- public static void SetEmbeddedToolbarButtonTextColor(string name, Color color) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarButtonTextColor", name, color.r, color.g, color.b, color.a);
- }
- public static void SetEmbeddedToolbarTitleTextColor(string name, Color color) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarTitleTextColor", name, color.r, color.g, color.b, color.a);
- }
- public static void SetEmeddedToolbarNavigationButtonsShow(string name, bool show) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarNavigationButtonsShow", name, show);
- }
- public static void SetEmbeddedToolbarMaxHeight(string name, float height) {
- CheckPlatform();
- plugin.CallStatic("setEmbeddedToolbarMaxHeight", name, height);
- }
- public static void StartSnapshotForRendering(string name, string identifier) {
- CheckPlatform();
- plugin.CallStatic("startSnapshotForRendering", name, identifier);
- }
- public static void StopSnapshotForRendering(string name) {
- CheckPlatform();
- plugin.CallStatic("stopSnapshotForRendering", name);
- }
- public static byte[] GetRenderedData(string name, int x, int y, int width, int height) {
- CheckPlatform();
- var sbyteArray = plugin.CallStatic<sbyte[]>("getRenderedData", name, x, y, width, height);
- if (sbyteArray == null) {
- return null;
- }
- byte[] byteArray = new byte[sbyteArray.Length];
- // sbyte and byte share the same bit layout; a bulk copy avoids a per-element loop over a
- // multi-megabyte image buffer.
- Buffer.BlockCopy(sbyteArray, 0, byteArray, 0, sbyteArray.Length);
- return byteArray;
- }
- public static bool StartSnapshotTextureStream(string name, long streamId, int x, int y, int width, int height, float resolutionScale) {
- CheckPlatform();
- LogSnapshotTextureStreamCpuFallbackIfNeeded();
- if (!Mathf.Approximately(resolutionScale, 1.0f)) {
- UniWebViewLogger.Instance.Info("Snapshot texture stream resolutionScale is not supported on Android yet. Capturing at full resolution.");
- }
- return plugin.CallStatic<bool>("startSnapshotTextureStream", name, streamId, x, y, width, height);
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- [return: MarshalAs(UnmanagedType.I1)]
- private static extern bool uv_startSnapshotTextureStreamSynthetic(string name, long streamId, int width, int height, int framePattern);
- public static bool StartSnapshotTextureStreamWithSyntheticFrames(
- string name, long streamId, int width, int height, int framePattern
- ) {
- CheckPlatform();
- LogSnapshotTextureStreamCpuFallbackIfNeeded();
- return uv_startSnapshotTextureStreamSynthetic(name, streamId, width, height, framePattern);
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern void uv_stopSnapshotTextureStream(string name, long streamId);
- public static void StopSnapshotTextureStream(string name, long streamId) {
- CheckPlatform();
- uv_stopSnapshotTextureStream(name, streamId);
- plugin.CallStatic("stopSnapshotTextureStream", name, streamId);
- if (!SnapshotTextureStreamUsesCpuFallback()) {
- IssueSnapshotTextureStreamRenderEvents(SnapshotTextureStreamStopRenderEventCount);
- }
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern void uv_tickSnapshotTextureStream(string name, long streamId);
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern IntPtr uv_getSnapshotTextureStreamRenderEventFunc();
- public static void TickSnapshotTextureStream(string name, long streamId) {
- CheckPlatform();
- plugin.CallStatic("tickSnapshotTextureStream", name, streamId);
- uv_tickSnapshotTextureStream(name, streamId);
- }
- public static void PumpSnapshotTextureStream(string name, long streamId) {
- CheckPlatform();
- if (SnapshotTextureStreamUsesCpuFallback()) {
- return;
- }
- IssueSnapshotTextureStreamRenderEvent();
- }
- private static void IssueSnapshotTextureStreamRenderEvent() {
- GL.IssuePluginEvent(uv_getSnapshotTextureStreamRenderEventFunc(), 0);
- }
- private static void IssueSnapshotTextureStreamRenderEvents(int count) {
- for (var i = 0; i < count; i++) {
- IssueSnapshotTextureStreamRenderEvent();
- }
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- [return: MarshalAs(UnmanagedType.I1)]
- private static extern bool uv_isSnapshotTextureStreamReady(string name, long streamId);
- public static bool IsSnapshotTextureStreamReady(string name, long streamId) {
- CheckPlatform();
- return uv_isSnapshotTextureStreamReady(name, streamId);
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern int uv_getSnapshotTextureStreamWidth(string name, long streamId);
- public static int GetSnapshotTextureStreamWidth(string name, long streamId) {
- CheckPlatform();
- return uv_getSnapshotTextureStreamWidth(name, streamId);
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern int uv_getSnapshotTextureStreamHeight(string name, long streamId);
- public static int GetSnapshotTextureStreamHeight(string name, long streamId) {
- CheckPlatform();
- return uv_getSnapshotTextureStreamHeight(name, streamId);
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern long uv_getSnapshotTextureStreamFrameIndex(string name, long streamId);
- public static long GetSnapshotTextureStreamFrameIndex(string name, long streamId) {
- CheckPlatform();
- return uv_getSnapshotTextureStreamFrameIndex(name, streamId);
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern IntPtr uv_getSnapshotTextureStreamTexturePointer(string name, long streamId);
- public static IntPtr GetSnapshotTextureStreamTexturePointer(string name, long streamId) {
- CheckPlatform();
- return uv_getSnapshotTextureStreamTexturePointer(name, streamId);
- }
- public static TextureFormat GetSnapshotTextureStreamTextureFormat() {
- CheckPlatform();
- return TextureFormat.RGBA32;
- }
- [System.Runtime.InteropServices.DllImport("UniWebViewNativeTexture")]
- private static extern long uv_consumeSnapshotTextureStreamCpuFrame(string name, long streamId, IntPtr destination, int capacity);
- public static long ConsumeSnapshotTextureStreamCpuFrame(string name, long streamId, IntPtr destination, int capacity) {
- CheckPlatform();
- return uv_consumeSnapshotTextureStreamCpuFrame(name, streamId, destination, capacity);
- }
- // The optimized native texture path renders through OpenGL ES. On other graphics backends
- // (Vulkan), the stream falls back to a CPU readback that updates a stream-owned Texture2D.
- public static bool SnapshotTextureStreamUsesCpuFallback() {
- CheckPlatform();
- return !IsSnapshotTextureStreamGLBackend();
- }
- private static void LogSnapshotTextureStreamCpuFallbackIfNeeded() {
- if (SnapshotTextureStreamUsesCpuFallback()) {
- UniWebViewLogger.Instance.Info(
- "Snapshot texture stream is using the CPU readback fallback since the current " +
- "graphics backend is not OpenGL ES: " + SystemInfo.graphicsDeviceType
- );
- }
- }
- private static bool IsSnapshotTextureStreamGLBackend() {
- #if UNITY_2023_1_OR_NEWER
- // OpenGL ES 2.0 is no longer a selectable graphics API since Unity 2023.1.
- return SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3;
- #else
- return SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2 ||
- SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3;
- #endif
- }
- public static string CopyBackForwardList(string name) {
- CheckPlatform();
- return plugin.CallStatic<string>("copyBackForwardList", name);
- }
- public static void GoToIndexInBackForwardList(string listenerName, int index) {
- CheckPlatform();
- plugin.CallStatic("goToIndexInBackForwardList", listenerName, index);
- }
- // Platform
- public static void CheckPlatform() {
- if (!correctPlatform) {
- throw new System.InvalidOperationException("Method can only be performed on Android.");
- }
- }
- }
- #endif
|