UniWebViewCocoa.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. //
  2. // UniWebViewInterface.cs
  3. // Created by Wang Wei(@onevcat) on 2017-04-11.
  4. //
  5. // This file is a part of UniWebView Project (https://uniwebview.com)
  6. // By purchasing the asset, you are allowed to use this code in as many as projects
  7. // you want, only if you publish the final products under the name of the same account
  8. // used for the purchase.
  9. //
  10. // This asset and all corresponding files (such as source code) are provided on an
  11. // “as is” basis, without warranty of any kind, express of implied, including but not
  12. // limited to the warranties of merchantability, fitness for a particular purpose, and
  13. // noninfringement. In no event shall the authors or copyright holders be liable for any
  14. // claim, damages or other liability, whether in action of contract, tort or otherwise,
  15. // arising from, out of or in connection with the software or the use of other dealing in the software.
  16. //
  17. #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
  18. using UnityEngine;
  19. using System;
  20. using System.Runtime.InteropServices;
  21. using AOT;
  22. using System.Reflection;
  23. using System.Text;
  24. using UnityEngine.Rendering;
  25. public class UniWebViewInterface {
  26. private const string StaticListenerName = "__UniWebViewGlobalListener";
  27. private const string GlobalChannelIdentifier = "__UniWebViewGlobalChannelIdentifier";
  28. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  29. delegate void UnitySendMessageDelegate(IntPtr objectName, IntPtr methodName, IntPtr parameter);
  30. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  31. delegate IntPtr ChannelMethodDelegate(IntPtr namePtr, IntPtr methodPtr, IntPtr parameterPtr);
  32. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  33. delegate void ChannelMethodResultReleaseDelegate(IntPtr resultPtr);
  34. private const string DllLib =
  35. #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
  36. "UniWebView";
  37. #else
  38. "__Internal";
  39. #endif
  40. static UniWebViewInterface() {
  41. ConnectMessageSender();
  42. RegisterChannel();
  43. // Prepare dispatcher instance. Some callbacks may come from non-UI threads. Use this dispatcher to
  44. // send any action to the Unity main thread.
  45. _ = UniWebViewMainThreadDispatcher.Instance;
  46. }
  47. // Keep strong managed references to the callbacks handed to native. Native holds these function
  48. // pointers for the whole app lifetime; without a rooted reference the marshalled thunk can be
  49. // garbage collected (notably under Mono in the macOS Editor), leaving native with a dangling
  50. // pointer that crashes on the next callback.
  51. private static readonly UnitySendMessageDelegate sendMessageDelegate = SendMessage;
  52. private static readonly ChannelMethodDelegate channelMethodDelegate = ChannelFunc;
  53. private static readonly ChannelMethodResultReleaseDelegate channelMethodResultReleaseDelegate = ReleaseChannelResult;
  54. private static bool correctPlatform =
  55. #if UNITY_EDITOR_OSX
  56. Application.platform == RuntimePlatform.OSXEditor ||
  57. Application.platform == RuntimePlatform.IPhonePlayer || // Support for Device Simulator package
  58. Application.platform == RuntimePlatform.Android; // Support for Device Simulator package
  59. #elif UNITY_STANDALONE_OSX
  60. Application.platform == RuntimePlatform.OSXPlayer;
  61. #else
  62. Application.platform == RuntimePlatform.IPhonePlayer;
  63. #endif
  64. [DllImport(DllLib)]
  65. private static extern void uv_connectMessageSender(
  66. [MarshalAs(UnmanagedType.FunctionPtr)] UnitySendMessageDelegate sendMessageDelegate
  67. );
  68. static void ConnectMessageSender() {
  69. UniWebViewLogger.Instance.Info("Connecting to native side message sender.");
  70. CheckPlatform();
  71. uv_connectMessageSender(sendMessageDelegate);
  72. }
  73. [MonoPInvokeCallback(typeof(UnitySendMessageDelegate))]
  74. private static void SendMessage(IntPtr namePtr, IntPtr methodPtr, IntPtr parameterPtr) {
  75. try {
  76. string name = Marshal.PtrToStringAuto(namePtr);
  77. string method = Marshal.PtrToStringAuto(methodPtr);
  78. string parameters = Marshal.PtrToStringAuto(parameterPtr);
  79. UniWebViewLogger.Instance.Verbose(
  80. "Received message sent from native. Name: " + name + " Method: " + method + " Params: " + parameters
  81. );
  82. if (name == StaticListenerName) {
  83. UniWebViewStaticListener.InvokeStaticMethod(method, parameters);
  84. } else {
  85. var listener = UniWebViewNativeListener.GetListener(name);
  86. if (listener != null) {
  87. // Check if the listener's host reference is still valid
  88. // This prevents crash when webView is destroyed but callbacks are still pending
  89. if (listener.webView == null && listener.safeBrowsing == null && listener.session == null) {
  90. UniWebViewLogger.Instance.Debug(
  91. "Ignored message for destroyed webView. Listener: " + name + " Method: " + method
  92. );
  93. return;
  94. }
  95. MethodInfo methodInfo = typeof(UniWebViewNativeListener).GetMethod(method);
  96. if (methodInfo != null) {
  97. try {
  98. methodInfo.Invoke(listener, new object[] { parameters });
  99. } catch (System.Exception e) {
  100. // Additional safety: Log and ignore exceptions from destroyed objects
  101. UniWebViewLogger.Instance.Critical(
  102. "Exception in SendMessage callback - Listener: " + name +
  103. " Method: " + method + " Error: " + e.Message
  104. );
  105. }
  106. }
  107. }
  108. }
  109. } catch (System.Exception e) {
  110. // Top-level safety net for any marshalling or other issues
  111. UniWebViewLogger.Instance.Critical(
  112. "Critical error in SendMessage: " + e.Message + "\nStackTrace: " + e.StackTrace
  113. );
  114. }
  115. }
  116. [DllImport(DllLib)]
  117. private static extern void uv_registerChannel(
  118. [MarshalAs(UnmanagedType.FunctionPtr)] ChannelMethodDelegate channel,
  119. [MarshalAs(UnmanagedType.FunctionPtr)] ChannelMethodResultReleaseDelegate release
  120. );
  121. public static void RegisterChannel() {
  122. UniWebViewLogger.Instance.Info("Connecting to native side method channel.");
  123. CheckPlatform();
  124. uv_registerChannel(channelMethodDelegate, channelMethodResultReleaseDelegate);
  125. }
  126. [MonoPInvokeCallback(typeof(ChannelMethodDelegate))]
  127. private static IntPtr ChannelFunc(IntPtr namePtr, IntPtr methodPtr, IntPtr parameterPtr) {
  128. // This runs as a native->managed callback. An exception must never escape here: crossing the
  129. // reverse-P/Invoke boundary aborts the process under IL2CPP. Catch everything and return null.
  130. try {
  131. string name = Marshal.PtrToStringAuto(namePtr);
  132. string method = Marshal.PtrToStringAuto(methodPtr);
  133. string parameters = Marshal.PtrToStringAuto(parameterPtr);
  134. string result;
  135. if (name == GlobalChannelIdentifier) {
  136. UniWebViewLogger.Instance.Verbose( () =>
  137. "Global channel method invoked. Method: " + method + " Params: " + parameters
  138. );
  139. result = UniWebViewStaticListener.InvokeStaticMethod(method, parameters);
  140. } else {
  141. UniWebViewLogger.Instance.Verbose(() => $"ChannelFunc invoked by native side. Name: {name} Method: {method} Params: {parameters}");
  142. result = UniWebViewChannelMethodManager.Instance.InvokeMethod(name, method, parameters);
  143. }
  144. return AllocateChannelResult(result);
  145. } catch (System.Exception e) {
  146. UniWebViewLogger.Instance.Critical(
  147. "Critical error in ChannelFunc: " + e.Message + "\nStackTrace: " + e.StackTrace
  148. );
  149. return IntPtr.Zero;
  150. }
  151. }
  152. private static IntPtr AllocateChannelResult(string value) {
  153. if (value == null) {
  154. return IntPtr.Zero;
  155. }
  156. byte[] bytes = Encoding.UTF8.GetBytes(value);
  157. IntPtr resultPtr = Marshal.AllocHGlobal(bytes.Length + 1);
  158. try {
  159. Marshal.Copy(bytes, 0, resultPtr, bytes.Length);
  160. Marshal.WriteByte(resultPtr, bytes.Length, 0);
  161. return resultPtr;
  162. } catch {
  163. Marshal.FreeHGlobal(resultPtr);
  164. throw;
  165. }
  166. }
  167. [MonoPInvokeCallback(typeof(ChannelMethodResultReleaseDelegate))]
  168. private static void ReleaseChannelResult(IntPtr resultPtr) {
  169. if (resultPtr != IntPtr.Zero) {
  170. Marshal.FreeHGlobal(resultPtr);
  171. }
  172. }
  173. [DllImport(DllLib)]
  174. private static extern void uv_setLogLevel(int level);
  175. public static void SetLogLevel(int level) {
  176. CheckPlatform();
  177. uv_setLogLevel(level);
  178. }
  179. [DllImport(DllLib)]
  180. private static extern void uv_init(string name, int x, int y, int width, int height);
  181. public static void Init(string name, int x, int y, int width, int height) {
  182. CheckPlatform();
  183. if (String.IsNullOrEmpty(name)) {
  184. return;
  185. }
  186. uv_init(name, x, y, width, height);
  187. }
  188. [DllImport(DllLib)]
  189. private static extern void uv_destroy(string name);
  190. public static void Destroy(string name) {
  191. CheckPlatform();
  192. uv_destroy(name);
  193. }
  194. [DllImport(DllLib)]
  195. private static extern void uv_load(string name, string url, bool skipEncoding, string readAccessURL);
  196. public static void Load(string name, string url, bool skipEncoding, string readAccessURL) {
  197. CheckPlatform();
  198. uv_load(name, url, skipEncoding, readAccessURL);
  199. }
  200. [DllImport(DllLib)]
  201. private static extern void uv_loadHTMLString(string name, string html, string baseUrl, bool skipEncoding);
  202. public static void LoadHTMLString(string name, string html, string baseUrl, bool skipEncoding) {
  203. CheckPlatform();
  204. uv_loadHTMLString(name, html, baseUrl, skipEncoding);
  205. }
  206. [DllImport(DllLib)]
  207. private static extern void uv_reload(string name);
  208. public static void Reload(string name) {
  209. CheckPlatform();
  210. uv_reload(name);
  211. }
  212. [DllImport(DllLib)]
  213. private static extern void uv_stop(string name);
  214. public static void Stop(string name) {
  215. CheckPlatform();
  216. uv_stop(name);
  217. }
  218. [DllImport(DllLib)]
  219. private static extern string uv_getUrl(string name);
  220. public static string GetUrl(string name) {
  221. CheckPlatform();
  222. return uv_getUrl(name);
  223. }
  224. [DllImport(DllLib)]
  225. private static extern void uv_setFrame(string name, int x, int y, int width, int height);
  226. public static void SetFrame(string name, int x, int y, int width, int height) {
  227. CheckPlatform();
  228. uv_setFrame(name, x, y, width, height);
  229. }
  230. [DllImport(DllLib)]
  231. private static extern void uv_setPosition(string name, int x, int y);
  232. public static void SetPosition(string name, int x, int y) {
  233. CheckPlatform();
  234. uv_setPosition(name, x, y);
  235. }
  236. [DllImport(DllLib)]
  237. private static extern void uv_setSize(string name, int width, int height);
  238. public static void SetSize(string name, int width, int height) {
  239. CheckPlatform();
  240. uv_setSize(name, width, height);
  241. }
  242. [DllImport(DllLib)]
  243. private static extern void uv_setTransform(string name, float rotation, float scaleX, float scaleY);
  244. public static void SetTransform(string name, float rotation, float scaleX, float scaleY) {
  245. CheckPlatform();
  246. uv_setTransform(name, rotation, scaleX, scaleY);
  247. }
  248. [DllImport(DllLib)]
  249. private static extern void uv_setRoundCornerRadius(string name, float topLeft, float topRight, float bottomLeft, float bottomRight);
  250. public static void SetRoundCornerRadius(string name, float topLeft, float topRight, float bottomLeft, float bottomRight) {
  251. CheckPlatform();
  252. uv_setRoundCornerRadius(name, topLeft, topRight, bottomLeft, bottomRight);
  253. }
  254. [DllImport(DllLib)]
  255. private static extern void uv_setShadow(
  256. string name,
  257. float red,
  258. float green,
  259. float blue,
  260. float alpha,
  261. float opacity,
  262. float radius,
  263. float offsetX,
  264. float offsetY,
  265. float spread
  266. );
  267. public static void SetShadow(
  268. string name,
  269. float red,
  270. float green,
  271. float blue,
  272. float alpha,
  273. float opacity,
  274. float radius,
  275. float offsetX,
  276. float offsetY,
  277. float spread
  278. ) {
  279. CheckPlatform();
  280. uv_setShadow(name, red, green, blue, alpha, opacity, radius, offsetX, offsetY, spread);
  281. }
  282. [DllImport(DllLib)]
  283. [return: MarshalAs(UnmanagedType.I1)]
  284. private static extern bool uv_show(string name, bool fade, int edge, float duration, string identifier);
  285. public static bool Show(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
  286. CheckPlatform();
  287. return uv_show(name, fade, edge, duration, identifier);
  288. }
  289. [DllImport(DllLib)]
  290. [return: MarshalAs(UnmanagedType.I1)]
  291. private static extern bool uv_hide(string name, bool fade, int edge, float duration, string identifier);
  292. public static bool Hide(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
  293. CheckPlatform();
  294. return uv_hide(name, fade, edge, duration, identifier);
  295. }
  296. [DllImport(DllLib)]
  297. [return: MarshalAs(UnmanagedType.I1)]
  298. private static extern bool uv_animateTo(
  299. string name, int x, int y, int width, int height, float duration, float delay, string identifier
  300. );
  301. public static bool AnimateTo(
  302. string name, int x, int y, int width, int height, float duration, float delay, string identifier)
  303. {
  304. CheckPlatform();
  305. return uv_animateTo(name, x, y, width, height, duration, delay, identifier);
  306. }
  307. [DllImport(DllLib)]
  308. private static extern void uv_addJavaScript(string name, string jsString, string identifier);
  309. public static void AddJavaScript(string name, string jsString, string identifier) {
  310. CheckPlatform();
  311. uv_addJavaScript(name, jsString, identifier);
  312. }
  313. [DllImport(DllLib)]
  314. private static extern void uv_evaluateJavaScript(string name, string jsString, string identifier);
  315. public static void EvaluateJavaScript(string name, string jsString, string identifier) {
  316. CheckPlatform();
  317. uv_evaluateJavaScript(name, jsString, identifier);
  318. }
  319. [DllImport(DllLib)]
  320. private static extern void uv_popupClose(string name, string popupId);
  321. public static void ClosePopupWindow(string name, string popupId) {
  322. CheckPlatform();
  323. uv_popupClose(name, popupId);
  324. }
  325. [DllImport(DllLib)]
  326. private static extern void uv_popupGoBack(string name, string popupId);
  327. public static void GoBackPopupWindow(string name, string popupId) {
  328. CheckPlatform();
  329. uv_popupGoBack(name, popupId);
  330. }
  331. [DllImport(DllLib)]
  332. private static extern void uv_popupGoForward(string name, string popupId);
  333. public static void GoForwardPopupWindow(string name, string popupId) {
  334. CheckPlatform();
  335. uv_popupGoForward(name, popupId);
  336. }
  337. [DllImport(DllLib)]
  338. private static extern void uv_popupEvaluateJavaScript(
  339. string name,
  340. string popupId,
  341. string jsString,
  342. string identifier
  343. );
  344. public static void EvaluateJavaScriptInPopupWindow(
  345. string name,
  346. string popupId,
  347. string jsString,
  348. string identifier
  349. ) {
  350. CheckPlatform();
  351. uv_popupEvaluateJavaScript(name, popupId, jsString, identifier);
  352. }
  353. [DllImport(DllLib)]
  354. private static extern void uv_popupCloseAll(string name);
  355. public static void CloseAllPopupWindows(string name) {
  356. CheckPlatform();
  357. uv_popupCloseAll(name);
  358. }
  359. [DllImport(DllLib)]
  360. private static extern void uv_popupSetPageEventEnabled(string name, bool enabled);
  361. public static void SetPopupPageEventEnabled(string name, bool enabled) {
  362. CheckPlatform();
  363. uv_popupSetPageEventEnabled(name, enabled);
  364. }
  365. [DllImport(DllLib)]
  366. private static extern void uv_addUrlScheme(string name, string scheme);
  367. public static void AddUrlScheme(string name, string scheme) {
  368. CheckPlatform();
  369. uv_addUrlScheme(name, scheme);
  370. }
  371. [DllImport(DllLib)]
  372. private static extern void uv_removeUrlScheme(string name, string scheme);
  373. public static void RemoveUrlScheme(string name, string scheme) {
  374. CheckPlatform();
  375. uv_removeUrlScheme(name, scheme);
  376. }
  377. [DllImport(DllLib)]
  378. private static extern void uv_addSslExceptionDomain(string name, string domain);
  379. [Obsolete("AddSslExceptionDomain is deprecated. Use AddSslPinnedFingerprint instead.")]
  380. public static void AddSslExceptionDomain(string name, string domain) {
  381. CheckPlatform();
  382. uv_addSslExceptionDomain(name, domain);
  383. }
  384. [DllImport(DllLib)]
  385. private static extern void uv_removeSslExceptionDomain(string name, string domain);
  386. [Obsolete("RemoveSslExceptionDomain is deprecated. Use RemoveSslPinnedFingerprint instead.")]
  387. public static void RemoveSslExceptionDomain(string name, string domain) {
  388. CheckPlatform();
  389. uv_removeSslExceptionDomain(name, domain);
  390. }
  391. [DllImport(DllLib)]
  392. private static extern void uv_addSslPinnedFingerprint(string name, string domain, string fingerprint);
  393. public static void AddSslPinnedFingerprint(string name, string domain, string fingerprint) {
  394. CheckPlatform();
  395. uv_addSslPinnedFingerprint(name, domain, fingerprint);
  396. }
  397. [DllImport(DllLib)]
  398. private static extern void uv_removeSslPinnedFingerprint(string name, string domain, string fingerprint);
  399. public static void RemoveSslPinnedFingerprint(string name, string domain, string fingerprint) {
  400. CheckPlatform();
  401. uv_removeSslPinnedFingerprint(name, domain, fingerprint);
  402. }
  403. [DllImport(DllLib)]
  404. private static extern void uv_setHeaderField(string name, string key, string value);
  405. public static void SetHeaderField(string name, string key, string value) {
  406. CheckPlatform();
  407. uv_setHeaderField(name, key, value);
  408. }
  409. [DllImport(DllLib)]
  410. private static extern void uv_setUserAgent(string name, string userAgent);
  411. public static void SetUserAgent(string name, string userAgent) {
  412. CheckPlatform();
  413. uv_setUserAgent(name, userAgent);
  414. }
  415. [DllImport(DllLib)]
  416. private static extern string uv_getUserAgent(string name);
  417. public static string GetUserAgent(string name) {
  418. CheckPlatform();
  419. return uv_getUserAgent(name);
  420. }
  421. [DllImport(DllLib)]
  422. private static extern void uv_setContentInsetAdjustmentBehavior(string name, int behavior);
  423. public static void SetContentInsetAdjustmentBehavior(
  424. string name, UniWebViewContentInsetAdjustmentBehavior behavior
  425. )
  426. {
  427. CheckPlatform();
  428. uv_setContentInsetAdjustmentBehavior(name, (int)behavior);
  429. }
  430. [DllImport(DllLib)]
  431. private static extern void uv_setAllowAutoPlay(bool flag);
  432. public static void SetAllowAutoPlay(bool flag) {
  433. CheckPlatform();
  434. uv_setAllowAutoPlay(flag);
  435. }
  436. [DllImport(DllLib)]
  437. private static extern void uv_setAllowInlinePlay(bool flag);
  438. public static void SetAllowInlinePlay(bool flag) {
  439. CheckPlatform();
  440. uv_setAllowInlinePlay(flag);
  441. }
  442. [DllImport(DllLib)]
  443. private static extern void uv_setAllowFileAccess(string name, bool flag);
  444. public static void SetAllowFileAccess(string name, bool flag) {
  445. CheckPlatform();
  446. uv_setAllowFileAccess(name, flag);
  447. }
  448. [DllImport(DllLib)]
  449. private static extern void uv_setAllowFileAccessFromFileURLs(string name, bool flag);
  450. public static void SetAllowFileAccessFromFileURLs(string name, bool flag) {
  451. CheckPlatform();
  452. uv_setAllowFileAccessFromFileURLs(name, flag);
  453. }
  454. [DllImport(DllLib)]
  455. private static extern void uv_setAllowUniversalAccessFromFileURLs(bool flag);
  456. public static void SetAllowUniversalAccessFromFileURLs(bool flag) {
  457. CheckPlatform();
  458. uv_setAllowUniversalAccessFromFileURLs(flag);
  459. }
  460. [DllImport(DllLib)]
  461. private static extern void uv_setForwardWebConsoleToNativeOutput(bool flag);
  462. public static void SetForwardWebConsoleToNativeOutput(bool flag) {
  463. CheckPlatform();
  464. uv_setForwardWebConsoleToNativeOutput(flag);
  465. }
  466. [DllImport(DllLib)]
  467. private static extern void uv_setAllowJavaScriptOpenWindow(bool flag);
  468. public static void SetAllowJavaScriptOpenWindow(bool flag) {
  469. CheckPlatform();
  470. uv_setAllowJavaScriptOpenWindow(flag);
  471. }
  472. [DllImport(DllLib)]
  473. private static extern void uv_setJavaScriptEnabled(bool flag);
  474. public static void SetJavaScriptEnabled(bool flag) {
  475. CheckPlatform();
  476. uv_setJavaScriptEnabled(flag);
  477. }
  478. [DllImport(DllLib)]
  479. private static extern void uv_setLimitsNavigationsToAppBoundDomains(bool flag);
  480. public static void SetLimitsNavigationsToAppBoundDomains(bool flag) {
  481. CheckPlatform();
  482. uv_setLimitsNavigationsToAppBoundDomains(flag);
  483. }
  484. [DllImport(DllLib)]
  485. private static extern void uv_cleanCache(string name, bool includeStorage, string identifier);
  486. public static void CleanCache(string name, bool includeStorage, string identifier) {
  487. CheckPlatform();
  488. uv_cleanCache(name, includeStorage, identifier);
  489. }
  490. [DllImport(DllLib)]
  491. private static extern void uv_setCacheMode(string name, int mode);
  492. public static void SetCacheMode(string name, int mode) {
  493. CheckPlatform();
  494. uv_setCacheMode(name, mode);
  495. }
  496. [DllImport(DllLib)]
  497. private static extern void uv_clearCookies();
  498. public static void ClearCookies() {
  499. CheckPlatform();
  500. uv_clearCookies();
  501. }
  502. [DllImport(DllLib)]
  503. private static extern void uv_clearCookiesAsync(string identifier);
  504. public static void ClearCookies(string identifier) {
  505. CheckPlatform();
  506. uv_clearCookiesAsync(identifier);
  507. }
  508. [DllImport(DllLib)]
  509. private static extern void uv_setCookie(string url, string cookie, bool skipEncoding);
  510. public static void SetCookie(string url, string cookie, bool skipEncoding) {
  511. CheckPlatform();
  512. uv_setCookie(url, cookie, skipEncoding);
  513. }
  514. [DllImport(DllLib)]
  515. private static extern void uv_setCookieAsync(string url, string cookie, bool skipEncoding, string identifier);
  516. public static void SetCookie(string url, string cookie, bool skipEncoding, string identifier) {
  517. CheckPlatform();
  518. uv_setCookieAsync(url, cookie, skipEncoding, identifier);
  519. }
  520. [DllImport(DllLib)]
  521. private static extern void uv_removeCookies(string url, bool skipEncoding);
  522. public static void RemoveCookies(string url, bool skipEncoding) {
  523. CheckPlatform();
  524. uv_removeCookies(url, skipEncoding);
  525. }
  526. [DllImport(DllLib)]
  527. private static extern void uv_removeCookiesAsync(string url, bool skipEncoding, string identifier);
  528. public static void RemoveCookies(string url, bool skipEncoding, string identifier) {
  529. CheckPlatform();
  530. uv_removeCookiesAsync(url, skipEncoding, identifier);
  531. }
  532. [DllImport(DllLib)]
  533. private static extern void uv_removeCookie(string url, string key, bool skipEncoding);
  534. public static void RemoveCookie(string url, string key, bool skipEncoding) {
  535. CheckPlatform();
  536. uv_removeCookie(url, key, skipEncoding);
  537. }
  538. [DllImport(DllLib)]
  539. private static extern void uv_removeCookieAsync(string url, string key, bool skipEncoding, string identifier);
  540. public static void RemoveCookie(string url, string key, bool skipEncoding, string identifier) {
  541. CheckPlatform();
  542. uv_removeCookieAsync(url, key, skipEncoding, identifier);
  543. }
  544. [DllImport(DllLib)]
  545. private static extern string uv_getCookie(string url, string key, bool skipEncoding);
  546. public static string GetCookie(string url, string key, bool skipEncoding) {
  547. CheckPlatform();
  548. return uv_getCookie(url, key, skipEncoding);
  549. }
  550. [DllImport(DllLib)]
  551. private static extern void uv_getCookieAsync(string url, string key, bool skipEncoding, string identifier);
  552. public static void GetCookie(string url, string key, bool skipEncoding, string identifier) {
  553. CheckPlatform();
  554. uv_getCookieAsync(url, key, skipEncoding, identifier);
  555. }
  556. [DllImport(DllLib)]
  557. private static extern void uv_clearHttpAuthUsernamePasswordHost(string host, string realm);
  558. public static void ClearHttpAuthUsernamePassword(string host, string realm) {
  559. CheckPlatform();
  560. uv_clearHttpAuthUsernamePasswordHost(host, realm);
  561. }
  562. [DllImport(DllLib)]
  563. private static extern void uv_setBackgroundColor(string name, float r, float g, float b, float a);
  564. public static void SetBackgroundColor(string name, float r, float g, float b, float a) {
  565. CheckPlatform();
  566. uv_setBackgroundColor(name, r, g, b, a);
  567. }
  568. [DllImport(DllLib)]
  569. private static extern void uv_setWebViewAlpha(string name, float alpha);
  570. public static void SetWebViewAlpha(string name, float alpha) {
  571. CheckPlatform();
  572. uv_setWebViewAlpha(name, alpha);
  573. }
  574. [DllImport(DllLib)]
  575. private static extern float uv_getWebViewAlpha(string name);
  576. public static float GetWebViewAlpha(string name) {
  577. CheckPlatform();
  578. return uv_getWebViewAlpha(name);
  579. }
  580. [DllImport(DllLib)]
  581. private static extern void uv_setShowSpinnerWhileLoading(string name, bool show);
  582. public static void SetShowSpinnerWhileLoading(string name, bool show) {
  583. CheckPlatform();
  584. uv_setShowSpinnerWhileLoading(name, show);
  585. }
  586. [DllImport(DllLib)]
  587. private static extern void uv_setSpinnerText(string name, string text);
  588. public static void SetSpinnerText(string name, string text) {
  589. CheckPlatform();
  590. uv_setSpinnerText(name, text);
  591. }
  592. [DllImport(DllLib)]
  593. private static extern void uv_setAllowUserDismissSpinnerByGesture(string name, bool flag);
  594. public static void SetAllowUserDismissSpinnerByGesture(string name, bool flag) {
  595. CheckPlatform();
  596. uv_setAllowUserDismissSpinnerByGesture(name, flag);
  597. }
  598. [DllImport(DllLib)]
  599. private static extern void uv_showSpinner(string name);
  600. public static void ShowSpinner(string name) {
  601. CheckPlatform();
  602. uv_showSpinner(name);
  603. }
  604. [DllImport(DllLib)]
  605. private static extern void uv_hideSpinner(string name);
  606. public static void HideSpinner(string name) {
  607. CheckPlatform();
  608. uv_hideSpinner(name);
  609. }
  610. [DllImport(DllLib)]
  611. [return: MarshalAs(UnmanagedType.I1)]
  612. private static extern bool uv_canGoBack(string name);
  613. public static bool CanGoBack(string name) {
  614. CheckPlatform();
  615. return uv_canGoBack(name);
  616. }
  617. [DllImport(DllLib)]
  618. [return: MarshalAs(UnmanagedType.I1)]
  619. private static extern bool uv_canGoForward(string name);
  620. public static bool CanGoForward(string name) {
  621. CheckPlatform();
  622. return uv_canGoForward(name);
  623. }
  624. [DllImport(DllLib)]
  625. private static extern void uv_goBack(string name);
  626. public static void GoBack(string name) {
  627. CheckPlatform();
  628. uv_goBack(name);
  629. }
  630. [DllImport(DllLib)]
  631. private static extern void uv_goForward(string name);
  632. public static void GoForward(string name) {
  633. CheckPlatform();
  634. uv_goForward(name);
  635. }
  636. [DllImport(DllLib)]
  637. private static extern void uv_setOpenLinksInExternalBrowser(string name, bool flag);
  638. public static void SetOpenLinksInExternalBrowser(string name, bool flag) {
  639. CheckPlatform();
  640. uv_setOpenLinksInExternalBrowser(name, flag);
  641. }
  642. [DllImport(DllLib)]
  643. private static extern void uv_setHorizontalScrollBarEnabled(string name, bool enabled);
  644. public static void SetHorizontalScrollBarEnabled(string name, bool enabled) {
  645. CheckPlatform();
  646. uv_setHorizontalScrollBarEnabled(name, enabled);
  647. }
  648. [DllImport(DllLib)]
  649. private static extern void uv_setVerticalScrollBarEnabled(string name, bool enabled);
  650. public static void SetVerticalScrollBarEnabled(string name, bool enabled) {
  651. CheckPlatform();
  652. uv_setVerticalScrollBarEnabled(name, enabled);
  653. }
  654. [DllImport(DllLib)]
  655. private static extern void uv_setBouncesEnabled(string name, bool enabled);
  656. public static void SetBouncesEnabled(string name, bool enabled) {
  657. CheckPlatform();
  658. uv_setBouncesEnabled(name, enabled);
  659. }
  660. [DllImport(DllLib)]
  661. private static extern void uv_setZoomEnabled(string name, bool enabled);
  662. public static void SetZoomEnabled(string name, bool enabled) {
  663. CheckPlatform();
  664. uv_setZoomEnabled(name, enabled);
  665. }
  666. [DllImport(DllLib)]
  667. private static extern void uv_setWindowUserResizeEnabled(string name, bool enabled);
  668. public static void SetWindowUserResizeEnabled(string name, bool enabled) {
  669. CheckPlatform();
  670. uv_setWindowUserResizeEnabled(name, enabled);
  671. }
  672. [DllImport(DllLib)]
  673. private static extern void uv_setUserInteractionEnabled(string name, bool enabled);
  674. public static void SetUserInteractionEnabled(string name, bool enabled) {
  675. CheckPlatform();
  676. uv_setUserInteractionEnabled(name, enabled);
  677. }
  678. [DllImport(DllLib)]
  679. private static extern void uv_setTransparencyClickingThroughEnabled(string name, bool enabled);
  680. public static void SetTransparencyClickingThroughEnabled(string name, bool enabled) {
  681. CheckPlatform();
  682. uv_setTransparencyClickingThroughEnabled(name, enabled);
  683. }
  684. [DllImport(DllLib)]
  685. private static extern void uv_refreshTransparencyClickingThroughLayout(string name);
  686. public static void RefreshTransparencyClickingThroughLayout(string name) {
  687. CheckPlatform();
  688. uv_refreshTransparencyClickingThroughLayout(name);
  689. }
  690. [DllImport(DllLib)]
  691. private static extern void uv_setWebContentsDebuggingEnabled(bool enabled);
  692. public static void SetWebContentsDebuggingEnabled(bool enabled) {
  693. CheckPlatform();
  694. uv_setWebContentsDebuggingEnabled(enabled);
  695. }
  696. [DllImport(DllLib)]
  697. private static extern void uv_setAllowBackForwardNavigationGestures(string name, bool flag);
  698. public static void SetAllowBackForwardNavigationGestures(string name, bool flag) {
  699. CheckPlatform();
  700. uv_setAllowBackForwardNavigationGestures(name, flag);
  701. }
  702. [DllImport(DllLib)]
  703. private static extern void uv_setAllowHTTPAuthPopUpWindow(string name, bool flag);
  704. public static void SetAllowHTTPAuthPopUpWindow(string name, bool flag) {
  705. CheckPlatform();
  706. uv_setAllowHTTPAuthPopUpWindow(name, flag);
  707. }
  708. [DllImport(DllLib)]
  709. private static extern void uv_print(string name);
  710. public static void Print(string name) {
  711. CheckPlatform();
  712. uv_print(name);
  713. }
  714. [DllImport(DllLib)]
  715. private static extern void uv_captureSnapshot(string name, string fileName);
  716. public static void CaptureSnapshot(string name, string fileName) {
  717. CheckPlatform();
  718. uv_captureSnapshot(name, fileName);
  719. }
  720. [DllImport(DllLib)]
  721. private static extern void uv_scrollTo(string name, int x, int y, bool animated);
  722. public static void ScrollTo(string name, int x, int y, bool animated) {
  723. CheckPlatform();
  724. uv_scrollTo(name, x, y, animated);
  725. }
  726. [DllImport(DllLib)]
  727. private static extern void uv_setCalloutEnabled(string name, bool flag);
  728. public static void SetCalloutEnabled(string name, bool flag) {
  729. CheckPlatform();
  730. uv_setCalloutEnabled(name, flag);
  731. }
  732. [DllImport(DllLib)]
  733. private static extern void uv_setSupportMultipleWindows(string name, bool enabled, bool allowJavaScriptOpening);
  734. public static void SetSupportMultipleWindows(string name, bool enabled, bool allowJavaScriptOpening) {
  735. CheckPlatform();
  736. uv_setSupportMultipleWindows(name, enabled, allowJavaScriptOpening);
  737. }
  738. [DllImport(DllLib)]
  739. private static extern void uv_setDragInteractionEnabled(string name, bool flag);
  740. public static void SetDragInteractionEnabled(string name, bool flag) {
  741. CheckPlatform();
  742. uv_setDragInteractionEnabled(name, flag);
  743. }
  744. [DllImport(DllLib)]
  745. private static extern float uv_nativeScreenWidth();
  746. public static float NativeScreenWidth() {
  747. #if UNITY_EDITOR_OSX
  748. return Screen.width;
  749. #else
  750. return uv_nativeScreenWidth();
  751. #endif
  752. }
  753. [DllImport(DllLib)]
  754. private static extern float uv_nativeScreenHeight();
  755. public static float NativeScreenHeight() {
  756. #if UNITY_EDITOR_OSX
  757. return Screen.height;
  758. #else
  759. return uv_nativeScreenHeight();
  760. #endif
  761. }
  762. [DllImport(DllLib)]
  763. private static extern void uv_addDownloadURL(string name, string urlString, int type);
  764. public static void AddDownloadURL(string name, string urlString, int type) {
  765. CheckPlatform();
  766. uv_addDownloadURL(name, urlString, type);
  767. }
  768. [DllImport(DllLib)]
  769. private static extern void uv_removeDownloadURL(string name, string urlString, int type);
  770. public static void RemoveDownloadURL(string name, string urlString, int type) {
  771. CheckPlatform();
  772. uv_removeDownloadURL(name, urlString, type);
  773. }
  774. [DllImport(DllLib)]
  775. private static extern void uv_addDownloadMIMEType(string name, string MIMEType, int type);
  776. public static void AddDownloadMIMEType(string name, string MIMEType, int type) {
  777. CheckPlatform();
  778. uv_addDownloadMIMEType(name, MIMEType, type);
  779. }
  780. [DllImport(DllLib)]
  781. private static extern void uv_removeDownloadMIMETypes(string name, string MIMEType, int type);
  782. public static void RemoveDownloadMIMETypes(string name, string MIMEType, int type) {
  783. CheckPlatform();
  784. uv_removeDownloadMIMETypes(name, MIMEType, type);
  785. }
  786. [DllImport(DllLib)]
  787. private static extern void uv_setAllowUserEditFileNameBeforeDownloading(string name, bool allowed);
  788. public static void SetAllowUserEditFileNameBeforeDownloading(string name, bool allowed) {
  789. CheckPlatform();
  790. uv_setAllowUserEditFileNameBeforeDownloading(name, allowed);
  791. }
  792. [DllImport(DllLib)]
  793. private static extern void uv_setAutoDownloadEnabled(string name, bool enabled);
  794. public static void SetAutoDownloadEnabled(string name, bool enabled) {
  795. CheckPlatform();
  796. uv_setAutoDownloadEnabled(name, enabled);
  797. }
  798. [DllImport(DllLib)]
  799. private static extern void uv_setAllowUserChooseActionAfterDownloading(string name, bool allowed);
  800. public static void SetAllowUserChooseActionAfterDownloading(string name, bool allowed) {
  801. CheckPlatform();
  802. uv_setAllowUserChooseActionAfterDownloading(name, allowed);
  803. }
  804. [DllImport(DllLib)]
  805. private static extern void uv_safeBrowsingInit(string name, string url);
  806. public static void SafeBrowsingInit(string name, string url) {
  807. CheckPlatform();
  808. if (String.IsNullOrEmpty(name)) {
  809. return;
  810. }
  811. uv_safeBrowsingInit(name, url);
  812. }
  813. [DllImport(DllLib)]
  814. private static extern void uv_safeBrowsingShow(string name);
  815. public static void SafeBrowsingShow(string name) {
  816. CheckPlatform();
  817. uv_safeBrowsingShow(name);
  818. }
  819. [DllImport(DllLib)]
  820. private static extern void uv_safeBrowsingSetToolbarColor(string name, float r, float g, float b);
  821. public static void SafeBrowsingSetToolbarColor(string name, float r, float g, float b) {
  822. CheckPlatform();
  823. uv_safeBrowsingSetToolbarColor(name, r, g, b);
  824. }
  825. [DllImport(DllLib)]
  826. private static extern void uv_safeBrowsingSetToolbarItemColor(string name, float r, float g, float b);
  827. public static void SafeBrowsingSetToolbarItemColor(string name, float r, float g, float b) {
  828. CheckPlatform();
  829. uv_safeBrowsingSetToolbarItemColor(name, r, g, b);
  830. }
  831. [DllImport(DllLib)]
  832. private static extern void uv_safeBrowsingDismiss(string name);
  833. public static void SafeBrowsingDismiss(string name) {
  834. CheckPlatform();
  835. uv_safeBrowsingDismiss(name);
  836. }
  837. [DllImport(DllLib)]
  838. private static extern void uv_safeBrowsingInvalidate(string name);
  839. public static void SafeBrowsingInvalidate(string name) {
  840. CheckPlatform();
  841. uv_safeBrowsingInvalidate(name);
  842. }
  843. [DllImport(DllLib)]
  844. [return: MarshalAs(UnmanagedType.I1)]
  845. private static extern bool uv_authenticationIsSupported();
  846. public static bool IsAuthenticationIsSupported() {
  847. CheckPlatform();
  848. return uv_authenticationIsSupported();
  849. }
  850. [DllImport(DllLib)]
  851. private static extern void uv_authenticationInit(string name, string url, string scheme);
  852. public static void AuthenticationInit(string name, string url, string scheme) {
  853. CheckPlatform();
  854. uv_authenticationInit(name, url, scheme);
  855. }
  856. [DllImport(DllLib)]
  857. private static extern void uv_authenticationStart(string name);
  858. public static void AuthenticationStart(string name) {
  859. CheckPlatform();
  860. uv_authenticationStart(name);
  861. }
  862. [DllImport(DllLib)]
  863. private static extern void uv_authenticationCancel(string name);
  864. public static void AuthenticationCancel(string name) {
  865. CheckPlatform();
  866. uv_authenticationCancel(name);
  867. }
  868. [DllImport(DllLib)]
  869. private static extern void uv_authenticationSetPrivateMode(string name, bool flag);
  870. public static void AuthenticationSetPrivateMode(string name, bool flag) {
  871. CheckPlatform();
  872. uv_authenticationSetPrivateMode(name, flag);
  873. }
  874. [DllImport(DllLib)]
  875. [return: MarshalAs(UnmanagedType.I1)]
  876. private static extern bool uv_setEmbeddedToolbarConfig(string name, string json);
  877. public static bool SetEmbeddedToolbarConfig(string name, string json) {
  878. CheckPlatform();
  879. return uv_setEmbeddedToolbarConfig(name, json);
  880. }
  881. [DllImport(DllLib)]
  882. private static extern void uv_setShowEmbeddedToolbar(string name, bool show);
  883. public static void SetShowEmbeddedToolbar(string name, bool show) {
  884. CheckPlatform();
  885. uv_setShowEmbeddedToolbar(name, show);
  886. }
  887. [DllImport(DllLib)]
  888. private static extern void uv_setEmbeddedToolbarOnTop(string name, bool top);
  889. public static void SetEmbeddedToolbarOnTop(string name, bool top) {
  890. CheckPlatform();
  891. uv_setEmbeddedToolbarOnTop(name, top);
  892. }
  893. [DllImport(DllLib)]
  894. private static extern void uv_setEmbeddedToolbarDoneButtonText(string name, string text);
  895. public static void SetEmbeddedToolbarDoneButtonText(string name, string text) {
  896. CheckPlatform();
  897. uv_setEmbeddedToolbarDoneButtonText(name, text);
  898. }
  899. [DllImport(DllLib)]
  900. private static extern void uv_setEmbeddedToolbarGoBackButtonText(string name, string text);
  901. public static void SetEmbeddedToolbarGoBackButtonText(string name, string text) {
  902. CheckPlatform();
  903. uv_setEmbeddedToolbarGoBackButtonText(name, text);
  904. }
  905. [DllImport(DllLib)]
  906. private static extern void uv_setEmbeddedToolbarGoForwardButtonText(string name, string text);
  907. public static void SetEmbeddedToolbarGoForwardButtonText(string name, string text) {
  908. CheckPlatform();
  909. uv_setEmbeddedToolbarGoForwardButtonText(name, text);
  910. }
  911. [DllImport(DllLib)]
  912. private static extern void uv_setEmbeddedToolbarTitleText(string name, string text);
  913. public static void SetEmbeddedToolbarTitleText(string name, string text) {
  914. CheckPlatform();
  915. uv_setEmbeddedToolbarTitleText(name, text);
  916. }
  917. [DllImport(DllLib)]
  918. private static extern void uv_setEmbeddedToolbarBackgroundColor(string name, float r, float g, float b, float a);
  919. public static void SetEmbeddedToolbarBackgroundColor(string name, Color color) {
  920. CheckPlatform();
  921. uv_setEmbeddedToolbarBackgroundColor(name, color.r, color.g, color.b, color.a);
  922. }
  923. [DllImport(DllLib)]
  924. private static extern void uv_setEmbeddedToolbarButtonTextColor(string name, float r, float g, float b, float a);
  925. public static void SetEmbeddedToolbarButtonTextColor(string name, Color color) {
  926. CheckPlatform();
  927. uv_setEmbeddedToolbarButtonTextColor(name, color.r, color.g, color.b, color.a);
  928. }
  929. [DllImport(DllLib)]
  930. private static extern void uv_setEmbeddedToolbarTitleTextColor(string name, float r, float g, float b, float a);
  931. public static void SetEmbeddedToolbarTitleTextColor(string name, Color color) {
  932. CheckPlatform();
  933. uv_setEmbeddedToolbarTitleTextColor(name, color.r, color.g, color.b, color.a);
  934. }
  935. [DllImport(DllLib)]
  936. private static extern void uv_setEmbeddedToolbarNavigationButtonsShow(string name, bool show);
  937. public static void SetEmeddedToolbarNavigationButtonsShow(string name, bool show) {
  938. CheckPlatform();
  939. uv_setEmbeddedToolbarNavigationButtonsShow(name, show);
  940. }
  941. [DllImport(DllLib)]
  942. private static extern void uv_setEmbeddedToolbarMaxHeight(string name, float height);
  943. public static void SetEmbeddedToolbarMaxHeight(string name, float height) {
  944. CheckPlatform();
  945. uv_setEmbeddedToolbarMaxHeight(name, height);
  946. }
  947. [DllImport(DllLib)]
  948. private static extern void uv_startSnapshotForRendering(string name, string identifier);
  949. public static void StartSnapshotForRendering(string name, string identifier) {
  950. CheckPlatform();
  951. uv_startSnapshotForRendering(name, identifier);
  952. }
  953. [DllImport(DllLib)]
  954. private static extern void uv_stopSnapshotForRendering(string name);
  955. public static void StopSnapshotForRendering(string name) {
  956. CheckPlatform();
  957. uv_stopSnapshotForRendering(name);
  958. }
  959. [DllImport(DllLib)]
  960. private static extern IntPtr uv_getRenderedData(string name, int x, int y, int width, int height, out int length);
  961. public static byte[] GetRenderedData(string name, int x, int y, int width, int height) {
  962. CheckPlatform();
  963. IntPtr dataPtr = uv_getRenderedData(name, x, y, width, height, out var length);
  964. if (dataPtr == IntPtr.Zero || length <= 0) {
  965. return null;
  966. }
  967. byte[] managedData = new byte[length];
  968. Marshal.Copy(dataPtr, managedData, 0, length);
  969. return managedData;
  970. }
  971. [DllImport(DllLib)]
  972. [return: MarshalAs(UnmanagedType.I1)]
  973. private static extern bool uv_startSnapshotTextureStream(string name, long streamId, int x, int y, int width, int height, float resolutionScale);
  974. public static bool StartSnapshotTextureStream(string name, long streamId, int x, int y, int width, int height, float resolutionScale) {
  975. CheckPlatform();
  976. if (!IsSnapshotTextureStreamGraphicsBackendSupported()) {
  977. UniWebViewLogger.Instance.Critical("Snapshot texture stream is unavailable. Cocoa currently supports Metal only.");
  978. return false;
  979. }
  980. return uv_startSnapshotTextureStream(name, streamId, x, y, width, height, resolutionScale);
  981. }
  982. [DllImport(DllLib)]
  983. [return: MarshalAs(UnmanagedType.I1)]
  984. private static extern bool uv_startSnapshotTextureStreamSynthetic(string name, long streamId, int width, int height, int framePattern);
  985. public static bool StartSnapshotTextureStreamWithSyntheticFrames(
  986. string name, long streamId, int width, int height, int framePattern
  987. ) {
  988. CheckPlatform();
  989. if (!IsSnapshotTextureStreamGraphicsBackendSupported()) {
  990. UniWebViewLogger.Instance.Critical("Snapshot texture stream is unavailable. Cocoa currently supports Metal only.");
  991. return false;
  992. }
  993. return uv_startSnapshotTextureStreamSynthetic(name, streamId, width, height, framePattern);
  994. }
  995. [DllImport(DllLib)]
  996. private static extern void uv_stopSnapshotTextureStream(string name, long streamId);
  997. public static void StopSnapshotTextureStream(string name, long streamId) {
  998. CheckPlatform();
  999. uv_stopSnapshotTextureStream(name, streamId);
  1000. }
  1001. [DllImport(DllLib)]
  1002. private static extern void uv_tickSnapshotTextureStream(string name, long streamId);
  1003. public static void TickSnapshotTextureStream(string name, long streamId) {
  1004. CheckPlatform();
  1005. uv_tickSnapshotTextureStream(name, streamId);
  1006. }
  1007. public static void PumpSnapshotTextureStream(string name, long streamId) {
  1008. CheckPlatform();
  1009. }
  1010. [DllImport(DllLib)]
  1011. [return: MarshalAs(UnmanagedType.I1)]
  1012. private static extern bool uv_isSnapshotTextureStreamReady(string name, long streamId);
  1013. public static bool IsSnapshotTextureStreamReady(string name, long streamId) {
  1014. CheckPlatform();
  1015. return uv_isSnapshotTextureStreamReady(name, streamId);
  1016. }
  1017. [DllImport(DllLib)]
  1018. private static extern int uv_getSnapshotTextureStreamWidth(string name, long streamId);
  1019. public static int GetSnapshotTextureStreamWidth(string name, long streamId) {
  1020. CheckPlatform();
  1021. return uv_getSnapshotTextureStreamWidth(name, streamId);
  1022. }
  1023. [DllImport(DllLib)]
  1024. private static extern int uv_getSnapshotTextureStreamHeight(string name, long streamId);
  1025. public static int GetSnapshotTextureStreamHeight(string name, long streamId) {
  1026. CheckPlatform();
  1027. return uv_getSnapshotTextureStreamHeight(name, streamId);
  1028. }
  1029. [DllImport(DllLib)]
  1030. private static extern long uv_getSnapshotTextureStreamFrameIndex(string name, long streamId);
  1031. public static long GetSnapshotTextureStreamFrameIndex(string name, long streamId) {
  1032. CheckPlatform();
  1033. return uv_getSnapshotTextureStreamFrameIndex(name, streamId);
  1034. }
  1035. [DllImport(DllLib)]
  1036. private static extern IntPtr uv_getSnapshotTextureStreamTexturePointer(string name, long streamId);
  1037. public static IntPtr GetSnapshotTextureStreamTexturePointer(string name, long streamId) {
  1038. CheckPlatform();
  1039. return uv_getSnapshotTextureStreamTexturePointer(name, streamId);
  1040. }
  1041. public static TextureFormat GetSnapshotTextureStreamTextureFormat() {
  1042. CheckPlatform();
  1043. return TextureFormat.BGRA32;
  1044. }
  1045. public static long ConsumeSnapshotTextureStreamCpuFrame(string name, long streamId, IntPtr destination, int capacity) {
  1046. CheckPlatform();
  1047. return -1;
  1048. }
  1049. public static bool SnapshotTextureStreamUsesCpuFallback() {
  1050. CheckPlatform();
  1051. return false;
  1052. }
  1053. private static bool IsSnapshotTextureStreamGraphicsBackendSupported() {
  1054. return SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal;
  1055. }
  1056. [DllImport(DllLib)]
  1057. private static extern string uv_copyBackForwardList(string name);
  1058. public static string CopyBackForwardList(string name) {
  1059. CheckPlatform();
  1060. return uv_copyBackForwardList(name);
  1061. }
  1062. [DllImport(DllLib)]
  1063. private static extern void uv_goToIndexInBackForwardList(string name, int index);
  1064. public static void GoToIndexInBackForwardList(string listenerName, int index) {
  1065. CheckPlatform();
  1066. uv_goToIndexInBackForwardList(listenerName, index);
  1067. }
  1068. #region Deprecated
  1069. [DllImport(DllLib)]
  1070. private static extern void uv_setShowToolbar(string name, bool show, bool animated, bool onTop, bool adjustInset);
  1071. public static void SetShowToolbar(string name, bool show, bool animated, bool onTop, bool adjustInset) {
  1072. CheckPlatform();
  1073. uv_setShowToolbar(name, show, animated, onTop, adjustInset);
  1074. }
  1075. [DllImport(DllLib)]
  1076. private static extern void uv_setShowToolbarNavigationButtons(string name, bool show);
  1077. public static void SetShowToolbarNavigationButtons(string name, bool show) {
  1078. CheckPlatform();
  1079. uv_setShowToolbarNavigationButtons(name, show);
  1080. }
  1081. [DllImport(DllLib)]
  1082. private static extern void uv_setToolbarDoneButtonText(string name, string text);
  1083. public static void SetToolbarDoneButtonText(string name, string text) {
  1084. CheckPlatform();
  1085. uv_setToolbarDoneButtonText(name, text);
  1086. }
  1087. [DllImport(DllLib)]
  1088. private static extern void uv_setGoBackButtonText(string name, string text);
  1089. public static void SetToolbarGoBackButtonText(string name, string text) {
  1090. CheckPlatform();
  1091. uv_setGoBackButtonText(name, text);
  1092. }
  1093. [DllImport(DllLib)]
  1094. private static extern void uv_setGoForwardButtonText(string name, string text);
  1095. public static void SetToolbarGoForwardButtonText(string name, string text) {
  1096. CheckPlatform();
  1097. uv_setGoForwardButtonText(name, text);
  1098. }
  1099. [DllImport(DllLib)]
  1100. private static extern void uv_setToolbarTintColor(string name, float r, float g, float b);
  1101. public static void SetToolbarTintColor(string name, float r, float g, float b) {
  1102. CheckPlatform();
  1103. uv_setToolbarTintColor(name, r, g, b);
  1104. }
  1105. [DllImport(DllLib)]
  1106. private static extern void uv_setToolbarTextColor(string name, float r, float g, float b);
  1107. public static void SetToolbarTextColor(string name, float r, float g, float b) {
  1108. CheckPlatform();
  1109. uv_setToolbarTextColor(name, r, g, b);
  1110. }
  1111. #endregion
  1112. public static void CheckPlatform() {
  1113. if (!correctPlatform) {
  1114. throw new System.InvalidOperationException(
  1115. "Method can only be performed on correct platform. Current: " + Application.platform
  1116. );
  1117. }
  1118. }
  1119. }
  1120. #endif