Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. #if UNITY_ANDROID && !UNITY_EDITOR
  2. using UnityEngine;
  3. class UniWebViewMethodChannel: AndroidJavaProxy
  4. {
  5. public UniWebViewMethodChannel() : base("com.onevcat.uniwebview.UniWebViewNativeChannel") { }
  6. string invokeChannelMethod(string name, string method, string parameters) {
  7. UniWebViewLogger.Instance.Verbose("invokeChannelMethod invoked by native side. Name: " + name + " Method: "
  8. + method + " Params: " + parameters);
  9. return UniWebViewChannelMethodManager.Instance.InvokeMethod(name, method, parameters);
  10. }
  11. }
  12. public class UniWebViewInterface {
  13. private static readonly AndroidJavaClass plugin;
  14. private static bool correctPlatform = Application.platform == RuntimePlatform.Android;
  15. static UniWebViewInterface() {
  16. var go = new GameObject("UniWebViewAndroidStaticListener");
  17. go.AddComponent<UniWebViewAndroidStaticListener>();
  18. plugin = new AndroidJavaClass("com.onevcat.uniwebview.UniWebViewInterface");
  19. CheckPlatform();
  20. plugin.CallStatic("prepare");
  21. UniWebViewLogger.Instance.Info("Connecting to native side method channel.");
  22. plugin.CallStatic("registerChannel", new UniWebViewMethodChannel());
  23. }
  24. public static void SetLogLevel(int level) {
  25. CheckPlatform();
  26. plugin.CallStatic("setLogLevel", level);
  27. }
  28. public static bool IsWebViewSupported() {
  29. CheckPlatform();
  30. return plugin.CallStatic<bool>("isWebViewSupported");
  31. }
  32. public static void Init(string name, int x, int y, int width, int height) {
  33. CheckPlatform();
  34. plugin.CallStatic("init", name, x, y, width, height);
  35. }
  36. public static void Destroy(string name) {
  37. CheckPlatform();
  38. plugin.CallStatic("destroy", name);
  39. }
  40. public static void Load(string name, string url, bool skipEncoding, string readAccessURL) {
  41. CheckPlatform();
  42. plugin.CallStatic("load", name, url);
  43. }
  44. public static void LoadHTMLString(string name, string html, string baseUrl, bool skipEncoding) {
  45. CheckPlatform();
  46. plugin.CallStatic("loadHTMLString", name, html, baseUrl);
  47. }
  48. public static void Reload(string name) {
  49. CheckPlatform();
  50. plugin.CallStatic("reload", name);
  51. }
  52. public static void Stop(string name) {
  53. CheckPlatform();
  54. plugin.CallStatic("stop", name);
  55. }
  56. public static string GetUrl(string name) {
  57. CheckPlatform();
  58. return plugin.CallStatic<string>("getUrl", name);
  59. }
  60. public static void SetFrame(string name, int x, int y, int width, int height) {
  61. CheckPlatform();
  62. plugin.CallStatic("setFrame", name, x, y, width, height);
  63. }
  64. public static void SetPosition(string name, int x, int y) {
  65. CheckPlatform();
  66. plugin.CallStatic("setPosition", name, x, y);
  67. }
  68. public static void SetSize(string name, int width, int height) {
  69. CheckPlatform();
  70. plugin.CallStatic("setSize", name, width, height);
  71. }
  72. public static bool Show(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
  73. CheckPlatform();
  74. if (useAsync) {
  75. plugin.CallStatic("showAsync", name, fade, edge, duration, identifier);
  76. return true;
  77. } else {
  78. return plugin.CallStatic<bool>("show", name, fade, edge, duration, identifier);
  79. }
  80. }
  81. public static bool Hide(string name, bool fade, int edge, float duration, bool useAsync, string identifier) {
  82. CheckPlatform();
  83. if (useAsync) {
  84. plugin.CallStatic("hideAsync", name, fade, edge, duration, identifier);
  85. return true;
  86. } else {
  87. return plugin.CallStatic<bool>("hide", name, fade, edge, duration, identifier);
  88. }
  89. }
  90. public static bool AnimateTo(string name, int x, int y, int width, int height, float duration, float delay, string identifier) {
  91. CheckPlatform();
  92. return plugin.CallStatic<bool>("animateTo", name, x, y, width, height, duration, delay, identifier);
  93. }
  94. public static void AddJavaScript(string name, string jsString, string identifier) {
  95. CheckPlatform();
  96. plugin.CallStatic("addJavaScript", name, jsString, identifier);
  97. }
  98. public static void EvaluateJavaScript(string name, string jsString, string identifier) {
  99. CheckPlatform();
  100. plugin.CallStatic("evaluateJavaScript", name, jsString, identifier);
  101. }
  102. public static void AddUrlScheme(string name, string scheme) {
  103. CheckPlatform();
  104. plugin.CallStatic("addUrlScheme", name, scheme);
  105. }
  106. public static void RemoveUrlScheme(string name, string scheme) {
  107. CheckPlatform();
  108. plugin.CallStatic("removeUrlScheme", name, scheme);
  109. }
  110. public static void AddSslExceptionDomain(string name, string domain) {
  111. CheckPlatform();
  112. plugin.CallStatic("addSslExceptionDomain", name, domain);
  113. }
  114. public static void RemoveSslExceptionDomain(string name, string domain) {
  115. CheckPlatform();
  116. plugin.CallStatic("removeSslExceptionDomain", name, domain);
  117. }
  118. public static void AddPermissionTrustDomain(string name, string domain) {
  119. CheckPlatform();
  120. plugin.CallStatic("addPermissionTrustDomain", name, domain);
  121. }
  122. public static void RemovePermissionTrustDomain(string name, string domain) {
  123. CheckPlatform();
  124. plugin.CallStatic("removePermissionTrustDomain", name, domain);
  125. }
  126. public static void SetHeaderField(string name, string key, string value) {
  127. CheckPlatform();
  128. plugin.CallStatic("setHeaderField", name, key, value);
  129. }
  130. public static void SetUserAgent(string name, string userAgent) {
  131. CheckPlatform();
  132. plugin.CallStatic("setUserAgent", name, userAgent);
  133. }
  134. public static string GetUserAgent(string name) {
  135. CheckPlatform();
  136. return plugin.CallStatic<string>("getUserAgent", name);
  137. }
  138. public static void SetAllowAutoPlay(bool flag) {
  139. CheckPlatform();
  140. plugin.CallStatic("setAllowAutoPlay", flag);
  141. }
  142. public static void SetAllowJavaScriptOpenWindow(bool flag) {
  143. CheckPlatform();
  144. plugin.CallStatic("setAllowJavaScriptOpenWindow", flag);
  145. }
  146. public static void SetAllowFileAccess(string name, bool flag) {
  147. CheckPlatform();
  148. plugin.CallStatic("setAllowFileAccess", name, flag);
  149. }
  150. public static void SetAcceptThirdPartyCookies(string name, bool flag) {
  151. CheckPlatform();
  152. plugin.CallStatic("setAcceptThirdPartyCookies", name, flag);
  153. }
  154. public static void SetAllowFileAccessFromFileURLs(string name, bool flag) {
  155. CheckPlatform();
  156. plugin.CallStatic("setAllowFileAccessFromFileURLs", name, flag);
  157. }
  158. public static void SetAllowUniversalAccessFromFileURLs(bool flag) {
  159. CheckPlatform();
  160. plugin.CallStatic("setAllowUniversalAccessFromFileURLs", flag);
  161. }
  162. public static void SetEnableKeyboardAvoidance(bool flag) {
  163. CheckPlatform();
  164. plugin.CallStatic("setEnableKeyboardAvoidance", flag);
  165. }
  166. public static void SetJavaScriptEnabled(bool enabled) {
  167. CheckPlatform();
  168. plugin.CallStatic("setJavaScriptEnabled", enabled);
  169. }
  170. public static void CleanCache(string name) {
  171. CheckPlatform();
  172. plugin.CallStatic("cleanCache", name);
  173. }
  174. public static void ClearCookies() {
  175. CheckPlatform();
  176. plugin.CallStatic("clearCookies");
  177. }
  178. public static void SetCookie(string url, string cookie, bool skipEncoding) {
  179. CheckPlatform();
  180. plugin.CallStatic("setCookie", url, cookie);
  181. }
  182. public static string GetCookie(string url, string key, bool skipEncoding) {
  183. CheckPlatform();
  184. return plugin.CallStatic<string>("getCookie", url, key);
  185. }
  186. public static void RemoveCookies(string url, bool skipEncoding) {
  187. CheckPlatform();
  188. plugin.CallStatic("removeCookies", url);
  189. }
  190. public static void RemoveCookie(string url, string key, bool skipEncoding) {
  191. CheckPlatform();
  192. plugin.CallStatic("removeCookie", url, key);
  193. }
  194. public static void ClearHttpAuthUsernamePassword(string host, string realm) {
  195. CheckPlatform();
  196. plugin.CallStatic("clearHttpAuthUsernamePassword", host, realm);
  197. }
  198. public static void SetBackgroundColor(string name, float r, float g, float b, float a) {
  199. CheckPlatform();
  200. plugin.CallStatic("setBackgroundColor", name, r, g, b, a);
  201. }
  202. public static void SetWebViewAlpha(string name, float alpha) {
  203. CheckPlatform();
  204. plugin.CallStatic("setWebViewAlpha", name, alpha);
  205. }
  206. public static float GetWebViewAlpha(string name) {
  207. CheckPlatform();
  208. return plugin.CallStatic<float>("getWebViewAlpha", name);
  209. }
  210. public static void SetShowSpinnerWhileLoading(string name, bool show) {
  211. CheckPlatform();
  212. plugin.CallStatic("setShowSpinnerWhileLoading", name, show);
  213. }
  214. public static void SetSpinnerText(string name, string text) {
  215. CheckPlatform();
  216. plugin.CallStatic("setSpinnerText", name, text);
  217. }
  218. public static void SetAllowUserDismissSpinnerByGesture(string name, bool flag) {
  219. CheckPlatform();
  220. plugin.CallStatic("setAllowUserDismissSpinnerByGesture", name, flag);
  221. }
  222. public static void ShowSpinner(string name) {
  223. CheckPlatform();
  224. plugin.CallStatic("showSpinner", name);
  225. }
  226. public static void HideSpinner(string name) {
  227. CheckPlatform();
  228. plugin.CallStatic("hideSpinner", name);
  229. }
  230. public static bool CanGoBack(string name) {
  231. CheckPlatform();
  232. return plugin.CallStatic<bool>("canGoBack", name);
  233. }
  234. public static bool CanGoForward(string name) {
  235. CheckPlatform();
  236. return plugin.CallStatic<bool>("canGoForward", name);
  237. }
  238. public static void GoBack(string name) {
  239. CheckPlatform();
  240. plugin.CallStatic("goBack", name);
  241. }
  242. public static void GoForward(string name) {
  243. CheckPlatform();
  244. plugin.CallStatic("goForward", name);
  245. }
  246. public static void SetOpenLinksInExternalBrowser(string name, bool flag) {
  247. CheckPlatform();
  248. plugin.CallStatic("setOpenLinksInExternalBrowser", name, flag);
  249. }
  250. public static void SetHorizontalScrollBarEnabled(string name, bool enabled) {
  251. CheckPlatform();
  252. plugin.CallStatic("setHorizontalScrollBarEnabled", name, enabled);
  253. }
  254. public static void SetVerticalScrollBarEnabled(string name, bool enabled) {
  255. CheckPlatform();
  256. plugin.CallStatic("setVerticalScrollBarEnabled", name, enabled);
  257. }
  258. public static void SetBouncesEnabled(string name, bool enabled) {
  259. CheckPlatform();
  260. plugin.CallStatic("setBouncesEnabled", name, enabled);
  261. }
  262. public static void SetZoomEnabled(string name, bool enabled) {
  263. CheckPlatform();
  264. plugin.CallStatic("setZoomEnabled", name, enabled);
  265. }
  266. public static void SetUseWideViewPort(string name, bool use) {
  267. CheckPlatform();
  268. plugin.CallStatic("setUseWideViewPort", name, use);
  269. }
  270. public static void SetLoadWithOverviewMode(string name, bool overview) {
  271. CheckPlatform();
  272. plugin.CallStatic("setLoadWithOverviewMode", name, overview);
  273. }
  274. public static void SetImmersiveModeEnabled(string name, bool enabled) {
  275. CheckPlatform();
  276. plugin.CallStatic("setImmersiveModeEnabled", name, enabled);
  277. }
  278. public static void SetUserInteractionEnabled(string name, bool enabled) {
  279. CheckPlatform();
  280. plugin.CallStatic("setUserInteractionEnabled", name, enabled);
  281. }
  282. public static void SetTransparencyClickingThroughEnabled(string name, bool enabled) {
  283. CheckPlatform();
  284. plugin.CallStatic("setTransparencyClickingThroughEnabled", name, enabled);
  285. }
  286. public static void SetWebContentsDebuggingEnabled(bool enabled) {
  287. CheckPlatform();
  288. plugin.CallStatic("setWebContentsDebuggingEnabled", enabled);
  289. }
  290. public static void SetAllowHTTPAuthPopUpWindow(string name, bool flag) {
  291. CheckPlatform();
  292. plugin.CallStatic("setAllowHTTPAuthPopUpWindow", name, flag);
  293. }
  294. public static void Print(string name) {
  295. CheckPlatform();
  296. plugin.CallStatic("print", name);
  297. }
  298. public static void CaptureSnapshot(string name, string filename) {
  299. CheckPlatform();
  300. plugin.CallStatic("captureSnapshot", name, filename);
  301. }
  302. public static void ScrollTo(string name, int x, int y, bool animated) {
  303. CheckPlatform();
  304. plugin.CallStatic("scrollTo", name, x, y, animated);
  305. }
  306. public static void SetCalloutEnabled(string name, bool flag) {
  307. CheckPlatform();
  308. plugin.CallStatic("setCalloutEnabled", name, flag);
  309. }
  310. public static void SetSupportMultipleWindows(string name, bool enabled, bool allowJavaScriptOpening) {
  311. CheckPlatform();
  312. plugin.CallStatic("setSupportMultipleWindows", name, enabled, allowJavaScriptOpening);
  313. }
  314. public static void SetDefaultFontSize(string name, int size) {
  315. CheckPlatform();
  316. plugin.CallStatic("setDefaultFontSize", name, size);
  317. }
  318. public static void SetTextZoom(string name, int textZoom) {
  319. CheckPlatform();
  320. plugin.CallStatic("setTextZoom", name, textZoom);
  321. }
  322. public static float NativeScreenWidth() {
  323. CheckPlatform();
  324. return plugin.CallStatic<float>("screenWidth");
  325. }
  326. public static float NativeScreenHeight() {
  327. CheckPlatform();
  328. return plugin.CallStatic<float>("screenHeight");
  329. }
  330. public static void SetDownloadEventForContextMenuEnabled(string name, bool enabled) {
  331. CheckPlatform();
  332. plugin.CallStatic("setDownloadEventForContextMenuEnabled", name, enabled);
  333. }
  334. // Safe Browsing
  335. public static bool IsSafeBrowsingSupported() {
  336. CheckPlatform();
  337. return plugin.CallStatic<bool>("isSafeBrowsingSupported");
  338. }
  339. public static void SafeBrowsingInit(string name, string url) {
  340. CheckPlatform();
  341. plugin.CallStatic("safeBrowsingInit", name, url);
  342. }
  343. public static void SafeBrowsingSetToolbarColor(string name, float r, float g, float b) {
  344. CheckPlatform();
  345. plugin.CallStatic("safeBrowsingSetToolbarColor", name, r, g, b);
  346. }
  347. public static void SafeBrowsingShow(string name) {
  348. CheckPlatform();
  349. plugin.CallStatic("safeBrowsingShow", name);
  350. }
  351. // Authentication
  352. public static bool IsAuthenticationIsSupported() {
  353. CheckPlatform();
  354. return plugin.CallStatic<bool>("isAuthenticationIsSupported");
  355. }
  356. public static void AuthenticationInit(string name, string url, string scheme) {
  357. CheckPlatform();
  358. plugin.CallStatic("authenticationInit", name, url, scheme);
  359. }
  360. public static void AuthenticationStart(string name) {
  361. CheckPlatform();
  362. plugin.CallStatic("authenticationStart", name);
  363. }
  364. public static void AuthenticationSetPrivateMode(string name, bool enabled) {
  365. CheckPlatform();
  366. plugin.CallStatic("authenticationSetPrivateMode", name, enabled);
  367. }
  368. public static void SetShowEmbeddedToolbar(string name, bool show) {
  369. CheckPlatform();
  370. plugin.CallStatic("setShowEmbeddedToolbar", name, show);
  371. }
  372. public static void SetEmbeddedToolbarOnTop(string name, bool top) {
  373. CheckPlatform();
  374. plugin.CallStatic("setEmbeddedToolbarOnTop", name, top);
  375. }
  376. public static void SetEmbeddedToolbarDoneButtonText(string name, string text) {
  377. CheckPlatform();
  378. plugin.CallStatic("setEmbeddedToolbarDoneButtonText", name, text);
  379. }
  380. public static void SetEmbeddedToolbarGoBackButtonText(string name, string text) {
  381. CheckPlatform();
  382. plugin.CallStatic("setEmbeddedToolbarGoBackButtonText", name, text);
  383. }
  384. public static void SetEmbeddedToolbarGoForwardButtonText(string name, string text) {
  385. CheckPlatform();
  386. plugin.CallStatic("setEmbeddedToolbarGoForwardButtonText", name, text);
  387. }
  388. public static void SetEmbeddedToolbarTitleText(string name, string text) {
  389. CheckPlatform();
  390. plugin.CallStatic("setEmbeddedToolbarTitleText", name, text);
  391. }
  392. public static void SetEmbeddedToolbarBackgroundColor(string name, Color color) {
  393. CheckPlatform();
  394. plugin.CallStatic("setEmbeddedToolbarBackgroundColor", name, color.r, color.g, color.b, color.a);
  395. }
  396. public static void SetEmbeddedToolbarButtonTextColor(string name, Color color) {
  397. CheckPlatform();
  398. plugin.CallStatic("setEmbeddedToolbarButtonTextColor", name, color.r, color.g, color.b, color.a);
  399. }
  400. public static void SetEmbeddedToolbarTitleTextColor(string name, Color color) {
  401. CheckPlatform();
  402. plugin.CallStatic("setEmbeddedToolbarTitleTextColor", name, color.r, color.g, color.b, color.a);
  403. }
  404. public static void SetEmeddedToolbarNavigationButtonsShow(string name, bool show) {
  405. CheckPlatform();
  406. plugin.CallStatic("setEmbeddedToolbarNavigationButtonsShow", name, show);
  407. }
  408. // Platform
  409. public static void CheckPlatform() {
  410. if (!correctPlatform) {
  411. throw new System.InvalidOperationException("Method can only be performed on Android.");
  412. }
  413. }
  414. }
  415. #endif