Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UniWebViewCocoa.cs 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. public class UniWebViewInterface {
  24. static UniWebViewInterface() {
  25. ConnectMessageSender();
  26. RegisterChannel();
  27. }
  28. delegate void UnitySendMessageDelegate(IntPtr objectName, IntPtr methodName, IntPtr parameter);
  29. private const string DllLib =
  30. #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
  31. "UniWebView";
  32. #else
  33. "__Internal";
  34. #endif
  35. private static bool correctPlatform =
  36. #if UNITY_EDITOR_OSX
  37. Application.platform == RuntimePlatform.OSXEditor ||
  38. Application.platform == RuntimePlatform.IPhonePlayer || // Support for Device Simulator package
  39. Application.platform == RuntimePlatform.Android; // Support for Device Simulator package
  40. #elif UNITY_STANDALONE_OSX
  41. Application.platform == RuntimePlatform.OSXPlayer;
  42. #else
  43. Application.platform == RuntimePlatform.IPhonePlayer;
  44. #endif
  45. [DllImport(DllLib)]
  46. private static extern void uv_connectMessageSender(
  47. [MarshalAs(UnmanagedType.FunctionPtr)] UnitySendMessageDelegate sendMessageDelegate
  48. );
  49. static void ConnectMessageSender() {
  50. UniWebViewLogger.Instance.Info("Connecting to native side message sender.");
  51. CheckPlatform();
  52. uv_connectMessageSender(SendMessage);
  53. }
  54. [MonoPInvokeCallback(typeof(UnitySendMessageDelegate))]
  55. private static void SendMessage(IntPtr namePtr, IntPtr methodPtr, IntPtr parameterPtr) {
  56. string name = Marshal.PtrToStringAuto(namePtr);
  57. string method = Marshal.PtrToStringAuto(methodPtr);
  58. string parameters = Marshal.PtrToStringAuto(parameterPtr);
  59. UniWebViewLogger.Instance.Verbose(
  60. "Received message sent from native. Name: " + name + " Method: " + method + " Params: " + parameters
  61. );
  62. var listener = UniWebViewNativeListener.GetListener(name);
  63. if (listener) {
  64. MethodInfo methodInfo = typeof(UniWebViewNativeListener).GetMethod(method);
  65. if (methodInfo != null) {
  66. methodInfo.Invoke(listener, new object[] { parameters });
  67. }
  68. }
  69. }
  70. delegate string ChannelMethodDelegate(IntPtr namePtr, IntPtr methodPtr, IntPtr parameterPtr);
  71. [DllImport(DllLib)]
  72. private static extern void uv_registerChannel([MarshalAs(UnmanagedType.FunctionPtr)] ChannelMethodDelegate channel);
  73. public static void RegisterChannel() {
  74. UniWebViewLogger.Instance.Info("Connecting to native side method channel.");
  75. CheckPlatform();
  76. uv_registerChannel(ChannelFunc);
  77. }
  78. [MonoPInvokeCallback(typeof(ChannelMethodDelegate))]
  79. private static string ChannelFunc(IntPtr namePtr, IntPtr methodPtr, IntPtr parameterPtr) {
  80. string name = Marshal.PtrToStringAuto(namePtr);
  81. string method = Marshal.PtrToStringAuto(methodPtr);
  82. string parameters = Marshal.PtrToStringAuto(parameterPtr);
  83. UniWebViewLogger.Instance.Verbose("ChannelFunc invoked by native side. Name: " + name + " Method: "
  84. + method + " Params: " + parameters);
  85. return UniWebViewChannelMethodManager.Instance.InvokeMethod(name, method, parameters);
  86. }
  87. [DllImport(DllLib)]
  88. private static extern void uv_setLogLevel(int level);
  89. public static void SetLogLevel(int level) {
  90. CheckPlatform();
  91. uv_setLogLevel(level);
  92. }
  93. [DllImport(DllLib)]
  94. private static extern void uv_init(string name, int x, int y, int width, int height);
  95. public static void Init(string name, int x, int y, int width, int height) {
  96. CheckPlatform();
  97. if (String.IsNullOrEmpty(name)) {
  98. return;
  99. }
  100. uv_init(name, x, y, width, height);
  101. }
  102. [DllImport(DllLib)]
  103. private static extern void uv_destroy(string name);
  104. public static void Destroy(string name) {
  105. CheckPlatform();
  106. uv_destroy(name);
  107. }
  108. [DllImport(DllLib)]
  109. private static extern void uv_load(string name, string url, bool skipEncoding, string readAccessURL);
  110. public static void Load(string name, string url, bool skipEncoding, string readAccessURL) {
  111. CheckPlatform();
  112. uv_load(name, url, skipEncoding, readAccessURL);
  113. }
  114. [DllImport(DllLib)]
  115. private static extern void uv_loadHTMLString(string name, string html, string baseUrl, bool skipEncoding);
  116. public static void LoadHTMLString(string name, string html, string baseUrl, bool skipEncoding) {
  117. CheckPlatform();
  118. uv_loadHTMLString(name, html, baseUrl, skipEncoding);
  119. }
  120. [DllImport(DllLib)]
  121. private static extern void uv_reload(string name);
  122. public static void Reload(string name) {
  123. CheckPlatform();
  124. uv_reload(name);
  125. }
  126. [DllImport(DllLib)]
  127. private static extern void uv_stop(string name);
  128. public static void Stop(string name) {
  129. CheckPlatform();
  130. uv_stop(name);
  131. }
  132. [DllImport(DllLib)]
  133. private static extern string uv_getUrl(string name);
  134. public static string GetUrl(string name) {
  135. CheckPlatform();
  136. return uv_getUrl(name);
  137. }
  138. [DllImport(DllLib)]
  139. private static extern void uv_setFrame(string name, int x, int y, int width, int height);
  140. public static void SetFrame(string name, int x, int y, int width, int height) {
  141. CheckPlatform();
  142. uv_setFrame(name, x, y, width, height);
  143. }
  144. [DllImport(DllLib)]
  145. private static extern void uv_setPosition(string name, int x, int y);
  146. public static void SetPosition(string name, int x, int y) {
  147. CheckPlatform();
  148. uv_setPosition(name, x, y);
  149. }
  150. [DllImport(DllLib)]
  151. private static extern void uv_setSize(string name, int width, int height);
  152. public static void SetSize(string name, int width, int height) {
  153. CheckPlatform();
  154. uv_setSize(name, width, height);
  155. }
  156. [DllImport(DllLib)]
  157. private static extern bool uv_show(string name, bool fade, int edge, float duration, string identifier);
  158. public static bool Show(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
  159. CheckPlatform();
  160. return uv_show(name, fade, edge, duration, identifier);
  161. }
  162. [DllImport(DllLib)]
  163. private static extern bool uv_hide(string name, bool fade, int edge, float duration, string identifier);
  164. public static bool Hide(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
  165. CheckPlatform();
  166. return uv_hide(name, fade, edge, duration, identifier);
  167. }
  168. [DllImport(DllLib)]
  169. private static extern bool uv_animateTo(
  170. string name, int x, int y, int width, int height, float duration, float delay, string identifier
  171. );
  172. public static bool AnimateTo(
  173. string name, int x, int y, int width, int height, float duration, float delay, string identifier)
  174. {
  175. CheckPlatform();
  176. return uv_animateTo(name, x, y, width, height, duration, delay, identifier);
  177. }
  178. [DllImport(DllLib)]
  179. private static extern void uv_addJavaScript(string name, string jsString, string identifier);
  180. public static void AddJavaScript(string name, string jsString, string identifier) {
  181. CheckPlatform();
  182. uv_addJavaScript(name, jsString, identifier);
  183. }
  184. [DllImport(DllLib)]
  185. private static extern void uv_evaluateJavaScript(string name, string jsString, string identifier);
  186. public static void EvaluateJavaScript(string name, string jsString, string identifier) {
  187. CheckPlatform();
  188. uv_evaluateJavaScript(name, jsString, identifier);
  189. }
  190. [DllImport(DllLib)]
  191. private static extern void uv_addUrlScheme(string name, string scheme);
  192. public static void AddUrlScheme(string name, string scheme) {
  193. CheckPlatform();
  194. uv_addUrlScheme(name, scheme);
  195. }
  196. [DllImport(DllLib)]
  197. private static extern void uv_removeUrlScheme(string name, string scheme);
  198. public static void RemoveUrlScheme(string name, string scheme) {
  199. CheckPlatform();
  200. uv_removeUrlScheme(name, scheme);
  201. }
  202. [DllImport(DllLib)]
  203. private static extern void uv_addSslExceptionDomain(string name, string domain);
  204. public static void AddSslExceptionDomain(string name, string domain) {
  205. CheckPlatform();
  206. uv_addSslExceptionDomain(name, domain);
  207. }
  208. [DllImport(DllLib)]
  209. private static extern void uv_removeSslExceptionDomain(string name, string domain);
  210. public static void RemoveSslExceptionDomain(string name, string domain) {
  211. CheckPlatform();
  212. uv_removeSslExceptionDomain(name, domain);
  213. }
  214. [DllImport(DllLib)]
  215. private static extern void uv_setHeaderField(string name, string key, string value);
  216. public static void SetHeaderField(string name, string key, string value) {
  217. CheckPlatform();
  218. uv_setHeaderField(name, key, value);
  219. }
  220. [DllImport(DllLib)]
  221. private static extern void uv_setUserAgent(string name, string userAgent);
  222. public static void SetUserAgent(string name, string userAgent) {
  223. CheckPlatform();
  224. uv_setUserAgent(name, userAgent);
  225. }
  226. [DllImport(DllLib)]
  227. private static extern string uv_getUserAgent(string name);
  228. public static string GetUserAgent(string name) {
  229. CheckPlatform();
  230. return uv_getUserAgent(name);
  231. }
  232. [DllImport(DllLib)]
  233. private static extern void uv_setContentInsetAdjustmentBehavior(string name, int behavior);
  234. public static void SetContentInsetAdjustmentBehavior(
  235. string name, UniWebViewContentInsetAdjustmentBehavior behavior
  236. )
  237. {
  238. CheckPlatform();
  239. uv_setContentInsetAdjustmentBehavior(name, (int)behavior);
  240. }
  241. [DllImport(DllLib)]
  242. private static extern void uv_setAllowAutoPlay(bool flag);
  243. public static void SetAllowAutoPlay(bool flag) {
  244. CheckPlatform();
  245. uv_setAllowAutoPlay(flag);
  246. }
  247. [DllImport(DllLib)]
  248. private static extern void uv_setAllowInlinePlay(bool flag);
  249. public static void SetAllowInlinePlay(bool flag) {
  250. CheckPlatform();
  251. uv_setAllowInlinePlay(flag);
  252. }
  253. [DllImport(DllLib)]
  254. private static extern void uv_setAllowFileAccess(string name, bool flag);
  255. public static void SetAllowFileAccess(string name, bool flag) {
  256. CheckPlatform();
  257. uv_setAllowFileAccess(name, flag);
  258. }
  259. [DllImport(DllLib)]
  260. private static extern void uv_setAllowFileAccessFromFileURLs(string name, bool flag);
  261. public static void SetAllowFileAccessFromFileURLs(string name, bool flag) {
  262. CheckPlatform();
  263. uv_setAllowFileAccessFromFileURLs(name, flag);
  264. }
  265. [DllImport(DllLib)]
  266. private static extern void uv_setAllowUniversalAccessFromFileURLs(bool flag);
  267. public static void SetAllowUniversalAccessFromFileURLs(bool flag) {
  268. CheckPlatform();
  269. uv_setAllowUniversalAccessFromFileURLs(flag);
  270. }
  271. [DllImport(DllLib)]
  272. private static extern void uv_setAllowJavaScriptOpenWindow(bool flag);
  273. public static void SetAllowJavaScriptOpenWindow(bool flag) {
  274. CheckPlatform();
  275. uv_setAllowJavaScriptOpenWindow(flag);
  276. }
  277. [DllImport(DllLib)]
  278. private static extern void uv_setJavaScriptEnabled(bool flag);
  279. public static void SetJavaScriptEnabled(bool flag) {
  280. CheckPlatform();
  281. uv_setJavaScriptEnabled(flag);
  282. }
  283. [DllImport(DllLib)]
  284. private static extern void uv_setLimitsNavigationsToAppBoundDomains(bool flag);
  285. public static void SetLimitsNavigationsToAppBoundDomains(bool flag) {
  286. CheckPlatform();
  287. uv_setLimitsNavigationsToAppBoundDomains(flag);
  288. }
  289. [DllImport(DllLib)]
  290. private static extern void uv_cleanCache(string name);
  291. public static void CleanCache(string name) {
  292. CheckPlatform();
  293. uv_cleanCache(name);
  294. }
  295. [DllImport(DllLib)]
  296. private static extern void uv_clearCookies();
  297. public static void ClearCookies() {
  298. CheckPlatform();
  299. uv_clearCookies();
  300. }
  301. [DllImport(DllLib)]
  302. private static extern void uv_setCookie(string url, string cookie, bool skipEncoding);
  303. public static void SetCookie(string url, string cookie, bool skipEncoding) {
  304. CheckPlatform();
  305. uv_setCookie(url, cookie, skipEncoding);
  306. }
  307. [DllImport(DllLib)]
  308. private static extern void uv_removeCookies(string url, bool skipEncoding);
  309. public static void RemoveCookies(string url, bool skipEncoding) {
  310. CheckPlatform();
  311. uv_removeCookies(url, skipEncoding);
  312. }
  313. [DllImport(DllLib)]
  314. private static extern void uv_removeCookie(string url, string key, bool skipEncoding);
  315. public static void RemoveCookie(string url, string key, bool skipEncoding) {
  316. CheckPlatform();
  317. uv_removeCookie(url, key, skipEncoding);
  318. }
  319. [DllImport(DllLib)]
  320. private static extern string uv_getCookie(string url, string key, bool skipEncoding);
  321. public static string GetCookie(string url, string key, bool skipEncoding) {
  322. CheckPlatform();
  323. return uv_getCookie(url, key, skipEncoding);
  324. }
  325. [DllImport(DllLib)]
  326. private static extern void uv_clearHttpAuthUsernamePasswordHost(string host, string realm);
  327. public static void ClearHttpAuthUsernamePassword(string host, string realm) {
  328. CheckPlatform();
  329. uv_clearHttpAuthUsernamePasswordHost(host, realm);
  330. }
  331. [DllImport(DllLib)]
  332. private static extern void uv_setBackgroundColor(string name, float r, float g, float b, float a);
  333. public static void SetBackgroundColor(string name, float r, float g, float b, float a) {
  334. CheckPlatform();
  335. uv_setBackgroundColor(name, r, g, b, a);
  336. }
  337. [DllImport(DllLib)]
  338. private static extern void uv_setWebViewAlpha(string name, float alpha);
  339. public static void SetWebViewAlpha(string name, float alpha) {
  340. CheckPlatform();
  341. uv_setWebViewAlpha(name, alpha);
  342. }
  343. [DllImport(DllLib)]
  344. private static extern float uv_getWebViewAlpha(string name);
  345. public static float GetWebViewAlpha(string name) {
  346. CheckPlatform();
  347. return uv_getWebViewAlpha(name);
  348. }
  349. [DllImport(DllLib)]
  350. private static extern void uv_setShowSpinnerWhileLoading(string name, bool show);
  351. public static void SetShowSpinnerWhileLoading(string name, bool show) {
  352. CheckPlatform();
  353. uv_setShowSpinnerWhileLoading(name, show);
  354. }
  355. [DllImport(DllLib)]
  356. private static extern void uv_setSpinnerText(string name, string text);
  357. public static void SetSpinnerText(string name, string text) {
  358. CheckPlatform();
  359. uv_setSpinnerText(name, text);
  360. }
  361. [DllImport(DllLib)]
  362. private static extern void uv_setAllowUserDismissSpinnerByGesture(string name, bool flag);
  363. public static void SetAllowUserDismissSpinnerByGesture(string name, bool flag) {
  364. CheckPlatform();
  365. uv_setAllowUserDismissSpinnerByGesture(name, flag);
  366. }
  367. [DllImport(DllLib)]
  368. private static extern void uv_showSpinner(string name);
  369. public static void ShowSpinner(string name) {
  370. CheckPlatform();
  371. uv_showSpinner(name);
  372. }
  373. [DllImport(DllLib)]
  374. private static extern void uv_hideSpinner(string name);
  375. public static void HideSpinner(string name) {
  376. CheckPlatform();
  377. uv_hideSpinner(name);
  378. }
  379. [DllImport(DllLib)]
  380. private static extern bool uv_canGoBack(string name);
  381. public static bool CanGoBack(string name) {
  382. CheckPlatform();
  383. return uv_canGoBack(name);
  384. }
  385. [DllImport(DllLib)]
  386. private static extern bool uv_canGoForward(string name);
  387. public static bool CanGoForward(string name) {
  388. CheckPlatform();
  389. return uv_canGoForward(name);
  390. }
  391. [DllImport(DllLib)]
  392. private static extern void uv_goBack(string name);
  393. public static void GoBack(string name) {
  394. CheckPlatform();
  395. uv_goBack(name);
  396. }
  397. [DllImport(DllLib)]
  398. private static extern void uv_goForward(string name);
  399. public static void GoForward(string name) {
  400. CheckPlatform();
  401. uv_goForward(name);
  402. }
  403. [DllImport(DllLib)]
  404. private static extern void uv_setOpenLinksInExternalBrowser(string name, bool flag);
  405. public static void SetOpenLinksInExternalBrowser(string name, bool flag) {
  406. CheckPlatform();
  407. uv_setOpenLinksInExternalBrowser(name, flag);
  408. }
  409. [DllImport(DllLib)]
  410. private static extern void uv_setHorizontalScrollBarEnabled(string name, bool enabled);
  411. public static void SetHorizontalScrollBarEnabled(string name, bool enabled) {
  412. CheckPlatform();
  413. uv_setHorizontalScrollBarEnabled(name, enabled);
  414. }
  415. [DllImport(DllLib)]
  416. private static extern void uv_setVerticalScrollBarEnabled(string name, bool enabled);
  417. public static void SetVerticalScrollBarEnabled(string name, bool enabled) {
  418. CheckPlatform();
  419. uv_setVerticalScrollBarEnabled(name, enabled);
  420. }
  421. [DllImport(DllLib)]
  422. private static extern void uv_setBouncesEnabled(string name, bool enabled);
  423. public static void SetBouncesEnabled(string name, bool enabled) {
  424. CheckPlatform();
  425. uv_setBouncesEnabled(name, enabled);
  426. }
  427. [DllImport(DllLib)]
  428. private static extern void uv_setZoomEnabled(string name, bool enabled);
  429. public static void SetZoomEnabled(string name, bool enabled) {
  430. CheckPlatform();
  431. uv_setZoomEnabled(name, enabled);
  432. }
  433. [DllImport(DllLib)]
  434. private static extern void uv_setWindowUserResizeEnabled(string name, bool enabled);
  435. public static void SetWindowUserResizeEnabled(string name, bool enabled) {
  436. CheckPlatform();
  437. uv_setWindowUserResizeEnabled(name, enabled);
  438. }
  439. [DllImport(DllLib)]
  440. private static extern void uv_setUserInteractionEnabled(string name, bool enabled);
  441. public static void SetUserInteractionEnabled(string name, bool enabled) {
  442. CheckPlatform();
  443. uv_setUserInteractionEnabled(name, enabled);
  444. }
  445. [DllImport(DllLib)]
  446. private static extern void uv_setTransparencyClickingThroughEnabled(string name, bool enabled);
  447. public static void SetTransparencyClickingThroughEnabled(string name, bool enabled) {
  448. CheckPlatform();
  449. uv_setTransparencyClickingThroughEnabled(name, enabled);
  450. }
  451. [DllImport(DllLib)]
  452. private static extern void uv_setWebContentsDebuggingEnabled(bool enabled);
  453. public static void SetWebContentsDebuggingEnabled(bool enabled) {
  454. CheckPlatform();
  455. uv_setWebContentsDebuggingEnabled(enabled);
  456. }
  457. [DllImport(DllLib)]
  458. private static extern void uv_setAllowBackForwardNavigationGestures(string name, bool flag);
  459. public static void SetAllowBackForwardNavigationGestures(string name, bool flag) {
  460. CheckPlatform();
  461. uv_setAllowBackForwardNavigationGestures(name, flag);
  462. }
  463. [DllImport(DllLib)]
  464. private static extern void uv_setAllowHTTPAuthPopUpWindow(string name, bool flag);
  465. public static void SetAllowHTTPAuthPopUpWindow(string name, bool flag) {
  466. CheckPlatform();
  467. uv_setAllowHTTPAuthPopUpWindow(name, flag);
  468. }
  469. [DllImport(DllLib)]
  470. private static extern void uv_print(string name);
  471. public static void Print(string name) {
  472. CheckPlatform();
  473. uv_print(name);
  474. }
  475. [DllImport(DllLib)]
  476. private static extern void uv_captureSnapshot(string name, string fileName);
  477. public static void CaptureSnapshot(string name, string fileName) {
  478. CheckPlatform();
  479. uv_captureSnapshot(name, fileName);
  480. }
  481. [DllImport(DllLib)]
  482. private static extern void uv_scrollTo(string name, int x, int y, bool animated);
  483. public static void ScrollTo(string name, int x, int y, bool animated) {
  484. CheckPlatform();
  485. uv_scrollTo(name, x, y, animated);
  486. }
  487. [DllImport(DllLib)]
  488. private static extern void uv_setCalloutEnabled(string name, bool flag);
  489. public static void SetCalloutEnabled(string name, bool flag) {
  490. CheckPlatform();
  491. uv_setCalloutEnabled(name, flag);
  492. }
  493. [DllImport(DllLib)]
  494. private static extern void uv_setSupportMultipleWindows(string name, bool enabled, bool allowJavaScriptOpening);
  495. public static void SetSupportMultipleWindows(string name, bool enabled, bool allowJavaScriptOpening) {
  496. CheckPlatform();
  497. uv_setSupportMultipleWindows(name, enabled, allowJavaScriptOpening);
  498. }
  499. [DllImport(DllLib)]
  500. private static extern void uv_setDragInteractionEnabled(string name, bool flag);
  501. public static void SetDragInteractionEnabled(string name, bool flag) {
  502. CheckPlatform();
  503. uv_setDragInteractionEnabled(name, flag);
  504. }
  505. [DllImport(DllLib)]
  506. private static extern float uv_nativeScreenWidth();
  507. public static float NativeScreenWidth() {
  508. #if UNITY_EDITOR_OSX
  509. return Screen.width;
  510. #else
  511. return uv_nativeScreenWidth();
  512. #endif
  513. }
  514. [DllImport(DllLib)]
  515. private static extern float uv_nativeScreenHeight();
  516. public static float NativeScreenHeight() {
  517. #if UNITY_EDITOR_OSX
  518. return Screen.height;
  519. #else
  520. return uv_nativeScreenHeight();
  521. #endif
  522. }
  523. [DllImport(DllLib)]
  524. private static extern void uv_addDownloadURL(string name, string urlString, int type);
  525. public static void AddDownloadURL(string name, string urlString, int type) {
  526. CheckPlatform();
  527. uv_addDownloadURL(name, urlString, type);
  528. }
  529. [DllImport(DllLib)]
  530. private static extern void uv_removeDownloadURL(string name, string urlString, int type);
  531. public static void RemoveDownloadURL(string name, string urlString, int type) {
  532. CheckPlatform();
  533. uv_removeDownloadURL(name, urlString, type);
  534. }
  535. [DllImport(DllLib)]
  536. private static extern void uv_addDownloadMIMEType(string name, string MIMEType, int type);
  537. public static void AddDownloadMIMEType(string name, string MIMEType, int type) {
  538. CheckPlatform();
  539. uv_addDownloadMIMEType(name, MIMEType, type);
  540. }
  541. [DllImport(DllLib)]
  542. private static extern void uv_removeDownloadMIMETypes(string name, string MIMEType, int type);
  543. public static void RemoveDownloadMIMETypes(string name, string MIMEType, int type) {
  544. CheckPlatform();
  545. uv_removeDownloadMIMETypes(name, MIMEType, type);
  546. }
  547. [DllImport(DllLib)]
  548. private static extern void uv_setAllowUserChooseActionAfterDownloading(string name, bool allowed);
  549. public static void SetAllowUserChooseActionAfterDownloading(string name, bool allowed) {
  550. CheckPlatform();
  551. uv_setAllowUserChooseActionAfterDownloading(name, allowed);
  552. }
  553. [DllImport(DllLib)]
  554. private static extern void uv_safeBrowsingInit(string name, string url);
  555. public static void SafeBrowsingInit(string name, string url) {
  556. CheckPlatform();
  557. if (String.IsNullOrEmpty(name)) {
  558. return;
  559. }
  560. uv_safeBrowsingInit(name, url);
  561. }
  562. [DllImport(DllLib)]
  563. private static extern void uv_safeBrowsingShow(string name);
  564. public static void SafeBrowsingShow(string name) {
  565. CheckPlatform();
  566. uv_safeBrowsingShow(name);
  567. }
  568. [DllImport(DllLib)]
  569. private static extern void uv_safeBrowsingSetToolbarColor(string name, float r, float g, float b);
  570. public static void SafeBrowsingSetToolbarColor(string name, float r, float g, float b) {
  571. CheckPlatform();
  572. uv_safeBrowsingSetToolbarColor(name, r, g, b);
  573. }
  574. [DllImport(DllLib)]
  575. private static extern void uv_safeBrowsingSetToolbarItemColor(string name, float r, float g, float b);
  576. public static void SafeBrowsingSetToolbarItemColor(string name, float r, float g, float b) {
  577. CheckPlatform();
  578. uv_safeBrowsingSetToolbarItemColor(name, r, g, b);
  579. }
  580. [DllImport(DllLib)]
  581. private static extern void uv_safeBrowsingDismiss(string name);
  582. public static void SafeBrowsingDismiss(string name) {
  583. CheckPlatform();
  584. uv_safeBrowsingDismiss(name);
  585. }
  586. [DllImport(DllLib)]
  587. private static extern bool uv_authenticationIsSupported();
  588. public static bool IsAuthenticationIsSupported() {
  589. CheckPlatform();
  590. return uv_authenticationIsSupported();
  591. }
  592. [DllImport(DllLib)]
  593. private static extern void uv_authenticationInit(string name, string url, string scheme);
  594. public static void AuthenticationInit(string name, string url, string scheme) {
  595. CheckPlatform();
  596. uv_authenticationInit(name, url, scheme);
  597. }
  598. [DllImport(DllLib)]
  599. private static extern void uv_authenticationStart(string name);
  600. public static void AuthenticationStart(string name) {
  601. CheckPlatform();
  602. uv_authenticationStart(name);
  603. }
  604. [DllImport(DllLib)]
  605. private static extern void uv_authenticationSetPrivateMode(string name, bool flag);
  606. public static void AuthenticationSetPrivateMode(string name, bool flag) {
  607. CheckPlatform();
  608. uv_authenticationSetPrivateMode(name, flag);
  609. }
  610. [DllImport(DllLib)]
  611. private static extern void uv_setShowEmbeddedToolbar(string name, bool show);
  612. public static void SetShowEmbeddedToolbar(string name, bool show) {
  613. CheckPlatform();
  614. uv_setShowEmbeddedToolbar(name, show);
  615. }
  616. [DllImport(DllLib)]
  617. private static extern void uv_setEmbeddedToolbarOnTop(string name, bool top);
  618. public static void SetEmbeddedToolbarOnTop(string name, bool top) {
  619. CheckPlatform();
  620. uv_setEmbeddedToolbarOnTop(name, top);
  621. }
  622. [DllImport(DllLib)]
  623. private static extern void uv_setEmbeddedToolbarDoneButtonText(string name, string text);
  624. public static void SetEmbeddedToolbarDoneButtonText(string name, string text) {
  625. CheckPlatform();
  626. uv_setEmbeddedToolbarDoneButtonText(name, text);
  627. }
  628. [DllImport(DllLib)]
  629. private static extern void uv_setEmbeddedToolbarGoBackButtonText(string name, string text);
  630. public static void SetEmbeddedToolbarGoBackButtonText(string name, string text) {
  631. CheckPlatform();
  632. uv_setEmbeddedToolbarGoBackButtonText(name, text);
  633. }
  634. [DllImport(DllLib)]
  635. private static extern void uv_setEmbeddedToolbarGoForwardButtonText(string name, string text);
  636. public static void SetEmbeddedToolbarGoForwardButtonText(string name, string text) {
  637. CheckPlatform();
  638. uv_setEmbeddedToolbarGoForwardButtonText(name, text);
  639. }
  640. [DllImport(DllLib)]
  641. private static extern void uv_setEmbeddedToolbarTitleText(string name, string text);
  642. public static void SetEmbeddedToolbarTitleText(string name, string text) {
  643. CheckPlatform();
  644. uv_setEmbeddedToolbarTitleText(name, text);
  645. }
  646. [DllImport(DllLib)]
  647. private static extern void uv_setEmbeddedToolbarBackgroundColor(string name, float r, float g, float b, float a);
  648. public static void SetEmbeddedToolbarBackgroundColor(string name, Color color) {
  649. CheckPlatform();
  650. uv_setEmbeddedToolbarBackgroundColor(name, color.r, color.g, color.b, color.a);
  651. }
  652. [DllImport(DllLib)]
  653. private static extern void uv_setEmbeddedToolbarButtonTextColor(string name, float r, float g, float b, float a);
  654. public static void SetEmbeddedToolbarButtonTextColor(string name, Color color) {
  655. CheckPlatform();
  656. uv_setEmbeddedToolbarButtonTextColor(name, color.r, color.g, color.b, color.a);
  657. }
  658. [DllImport(DllLib)]
  659. private static extern void uv_setEmbeddedToolbarTitleTextColor(string name, float r, float g, float b, float a);
  660. public static void SetEmbeddedToolbarTitleTextColor(string name, Color color) {
  661. CheckPlatform();
  662. uv_setEmbeddedToolbarTitleTextColor(name, color.r, color.g, color.b, color.a);
  663. }
  664. [DllImport(DllLib)]
  665. private static extern void uv_setEmbeddedToolbarNavigationButtonsShow(string name, bool show);
  666. public static void SetEmeddedToolbarNavigationButtonsShow(string name, bool show) {
  667. CheckPlatform();
  668. uv_setEmbeddedToolbarNavigationButtonsShow(name, show);
  669. }
  670. #region Deprecated
  671. [DllImport(DllLib)]
  672. private static extern void uv_setShowToolbar(string name, bool show, bool animated, bool onTop, bool adjustInset);
  673. public static void SetShowToolbar(string name, bool show, bool animated, bool onTop, bool adjustInset) {
  674. CheckPlatform();
  675. uv_setShowToolbar(name, show, animated, onTop, adjustInset);
  676. }
  677. [DllImport(DllLib)]
  678. private static extern void uv_setShowToolbarNavigationButtons(string name, bool show);
  679. public static void SetShowToolbarNavigationButtons(string name, bool show) {
  680. CheckPlatform();
  681. uv_setShowToolbarNavigationButtons(name, show);
  682. }
  683. [DllImport(DllLib)]
  684. private static extern void uv_setToolbarDoneButtonText(string name, string text);
  685. public static void SetToolbarDoneButtonText(string name, string text) {
  686. CheckPlatform();
  687. uv_setToolbarDoneButtonText(name, text);
  688. }
  689. [DllImport(DllLib)]
  690. private static extern void uv_setGoBackButtonText(string name, string text);
  691. public static void SetToolbarGoBackButtonText(string name, string text) {
  692. CheckPlatform();
  693. uv_setGoBackButtonText(name, text);
  694. }
  695. [DllImport(DllLib)]
  696. private static extern void uv_setGoForwardButtonText(string name, string text);
  697. public static void SetToolbarGoForwardButtonText(string name, string text) {
  698. CheckPlatform();
  699. uv_setGoForwardButtonText(name, text);
  700. }
  701. [DllImport(DllLib)]
  702. private static extern void uv_setToolbarTintColor(string name, float r, float g, float b);
  703. public static void SetToolbarTintColor(string name, float r, float g, float b) {
  704. CheckPlatform();
  705. uv_setToolbarTintColor(name, r, g, b);
  706. }
  707. [DllImport(DllLib)]
  708. private static extern void uv_setToolbarTextColor(string name, float r, float g, float b);
  709. public static void SetToolbarTextColor(string name, float r, float g, float b) {
  710. CheckPlatform();
  711. uv_setToolbarTextColor(name, r, g, b);
  712. }
  713. #endregion
  714. public static void CheckPlatform() {
  715. if (!correctPlatform) {
  716. throw new System.InvalidOperationException(
  717. "Method can only be performed on correct platform. Current: " + Application.platform
  718. );
  719. }
  720. }
  721. }
  722. #endif