UniWebView.Obsolete.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //
  2. // UniWebView.Obsolete.cs
  3. // Created by Wang Wei (@onevcat) on 2025-04-19.
  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. using System;
  18. using UnityEngine;
  19. // UniWebView Obsolete related part
  20. public partial class UniWebView {
  21. [Obsolete("Use Toolbar is deprecated. Use the embedded toolbar instead.", false)]
  22. [SerializeField][HideInInspector]
  23. private bool useToolbar;
  24. [Obsolete("Use Toolbar is deprecated. Use the embedded toolbar instead.", false)]
  25. [SerializeField][HideInInspector]
  26. private UniWebViewToolbarPosition toolbarPosition;
  27. /// <summary>
  28. /// Delegate for page error received event.
  29. ///
  30. /// Deprecated. Use `LoadingErrorReceivedDelegate` instead.
  31. /// </summary>
  32. /// <param name="webView">The web view component which raises this event.</param>
  33. /// <param name="errorCode">
  34. /// The error code which indicates the error type.
  35. /// It can be different from systems and platforms.
  36. /// </param>
  37. /// <param name="errorMessage">The error message which indicates the error.</param>
  38. [Obsolete("PageErrorReceivedDelegate is deprecated. Use `LoadingErrorReceivedDelegate` instead.", false)]
  39. public delegate void PageErrorReceivedDelegate(UniWebView webView, int errorCode, string errorMessage);
  40. /// <summary>
  41. /// Raised when an error encountered during the loading process.
  42. /// Such as the "host not found" error or "no Internet connection" error will raise this event.
  43. ///
  44. /// Deprecated. Use `OnLoadingErrorReceived` instead. If both `OnPageErrorReceived` and `OnLoadingErrorReceived` are
  45. /// listened, only the new `OnLoadingErrorReceived` will be raised, `OnPageErrorReceived` will not be called.
  46. /// </summary>
  47. [Obsolete("OnPageErrorReceived is deprecated. Use `OnLoadingErrorReceived` instead.", false)]
  48. public event PageErrorReceivedDelegate OnPageErrorReceived;
  49. /// <summary>
  50. /// Sets whether the web view should behave in immersive mode, that is,
  51. /// hides the status bar and navigation bar with a sticky style.
  52. ///
  53. /// This method is only for Android. Default is enabled.
  54. /// </summary>
  55. /// <param name="enabled"></param>
  56. [Obsolete("SetImmersiveModeEnabled is deprecated. Now UniWebView always respect navigation bar/status bar settings from Unity.", false)]
  57. public void SetImmersiveModeEnabled(bool enabled) {
  58. Debug.LogError(
  59. "SetImmersiveModeEnabled is removed in UniWebView 4." +
  60. "Now UniWebView always respect navigation bar/status bar settings from Unity."
  61. );
  62. }
  63. /// <summary>
  64. /// Delegate for code keycode received event.
  65. /// </summary>
  66. /// <param name="webView">The web view component which raises this event.</param>
  67. /// <param name="keyCode">The key code of pressed key. See [Android API for keycode](https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_0) to know the possible values.</param>
  68. [Obsolete("KeyCodeReceivedDelegate is deprecated. Now UniWebView never intercepts device key code events. Check `Input.GetKeyUp` instead.", false)]
  69. public delegate void KeyCodeReceivedDelegate(UniWebView webView, int keyCode);
  70. /// <summary>
  71. /// Raised when a key (like back button or volume up) on the device is pressed.
  72. ///
  73. /// This event only raised on Android. It is useful when you disabled the back button but still need to
  74. /// get the back button event. On iOS, user's key action is not available and this event will never be
  75. /// raised.
  76. /// </summary>
  77. [Obsolete("OnKeyCodeReceived is deprecated and never called. Now UniWebView never intercepts device key code events. Check `Input.GetKeyUp` instead.", false)]
  78. #pragma warning disable CS0067
  79. public event KeyCodeReceivedDelegate OnKeyCodeReceived;
  80. /// <summary>
  81. /// Adds a trusted domain to white list and allow permission requests from the domain.
  82. ///
  83. /// You need this on Android devices when a site needs the location or camera permission. It will allow the
  84. /// permission gets approved so you could access the corresponding devices.
  85. ///
  86. /// Deprecated. Use `RegisterOnRequestMediaCapturePermission` instead, which works for both Android and iOS and
  87. /// provides a more flexible way to handle the permission requests. By default, if neither this method and
  88. /// `RegisterOnRequestMediaCapturePermission` is called, the permission request will trigger a grant alert to ask
  89. /// the user to decide whether to allow or deny the permission.
  90. ///
  91. /// </summary>
  92. /// <param name="domain">The domain to add to the white list.</param>
  93. [Obsolete("Deprecated. Use `RegisterOnRequestMediaCapturePermission` instead. Check " +
  94. "https://docs.uniwebview.com/api/#registeronrequestmediacapturepermission", false)]
  95. public void AddPermissionTrustDomain(string domain) {
  96. #if UNITY_ANDROID && !UNITY_EDITOR
  97. UniWebViewInterface.AddPermissionTrustDomain(listener.Name, domain);
  98. #endif
  99. }
  100. /// <summary>
  101. /// Removes a trusted domain from white list.
  102. /// </summary>
  103. /// <param name="domain">The domain to remove from white list.</param>
  104. [Obsolete("Deprecated. Use `UnregisterOnRequestMediaCapturePermission` instead.", false)]
  105. public void RemovePermissionTrustDomain(string domain) {
  106. #if UNITY_ANDROID && !UNITY_EDITOR
  107. UniWebViewInterface.RemovePermissionTrustDomain(listener.Name, domain);
  108. #endif
  109. }
  110. /// <summary>
  111. /// Sets whether to show a toolbar which contains navigation buttons and Done button.
  112. ///
  113. /// You could choose to show or hide the tool bar. By configuring the `animated` and `onTop`
  114. /// parameters, you can control the animating and position of the toolbar. If the toolbar is
  115. /// overlapping with some part of your web view, pass `adjustInset` with `true` to have the
  116. /// web view relocating itself to avoid the overlap.
  117. ///
  118. /// This method is only for iOS. The toolbar is hidden by default.
  119. /// </summary>
  120. /// <param name="show">Whether the toolbar should show or hide.</param>
  121. /// <param name="animated">Whether the toolbar state changing should be with animation. Default is `false`.</param>
  122. /// <param name="onTop">Whether the toolbar should snap to top of screen or to bottom of screen.
  123. /// Default is `true`</param>
  124. /// <param name="adjustInset">Whether the toolbar transition should also adjust web view position and size
  125. /// if overlapped. Default is `false`</param>
  126. [Obsolete("`SetShowToolbar` is deprecated. Use `EmbeddedToolbar.Show()` or `EmbeddedToolbar.Hide()`" +
  127. "instead.", false)]
  128. public void SetShowToolbar(bool show, bool animated = false, bool onTop = true, bool adjustInset = false) {
  129. #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
  130. UniWebViewInterface.SetShowToolbar(listener.Name, show, animated, onTop, adjustInset);
  131. #endif
  132. }
  133. /// <summary>
  134. /// Sets the done button text in toolbar.
  135. ///
  136. /// By default, UniWebView will show a "Done" button at right size in the
  137. /// toolbar. You could change its title by passing a text.
  138. ///
  139. /// This method is only for iOS, since there is no toolbar on Android.
  140. /// </summary>
  141. /// <param name="text">The text needed to be set as done button title.</param>
  142. [Obsolete("`SetToolbarDoneButtonText` is deprecated. Use `EmbeddedToolbar.SetDoneButtonText` " +
  143. "instead.", false)]
  144. public void SetToolbarDoneButtonText(string text) {
  145. #if UNITY_IOS && !UNITY_EDITOR
  146. UniWebViewInterface.SetToolbarDoneButtonText(listener.Name, text);
  147. #endif
  148. }
  149. /// <summary>
  150. /// Sets the go back button text in toolbar.
  151. ///
  152. /// By default, UniWebView will show a back arrow at the left side in the
  153. /// toolbar. You could change its text.
  154. ///
  155. /// This method is only for iOS and macOS Editor, since there is no toolbar on Android.
  156. /// </summary>
  157. /// <param name="text">The text needed to be set as go back button.</param>
  158. [Obsolete("`SetToolbarGoBackButtonText` is deprecated. Use `EmbeddedToolbar.SetGoBackButtonText` " +
  159. "instead.", false)]
  160. public void SetToolbarGoBackButtonText(string text) {
  161. #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
  162. UniWebViewInterface.SetToolbarGoBackButtonText(listener.Name, text);
  163. #endif
  164. }
  165. /// <summary>
  166. /// Sets the go forward button text in toolbar.
  167. ///
  168. /// By default, UniWebView will show a forward arrow at the left side in the
  169. /// toolbar. You could change its text.
  170. ///
  171. /// This method is only for iOS and macOS Editor, since there is no toolbar on Android.
  172. /// </summary>
  173. /// <param name="text">The text needed to be set as go forward button.</param>
  174. [Obsolete("`SetToolbarGoForwardButtonText` is deprecated. Use `EmbeddedToolbar.SetGoForwardButtonText` " +
  175. "instead.", false)]
  176. public void SetToolbarGoForwardButtonText(string text) {
  177. #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
  178. UniWebViewInterface.SetToolbarGoForwardButtonText(listener.Name, text);
  179. #endif
  180. }
  181. /// <summary>
  182. /// Sets the background tint color for the toolbar.
  183. ///
  184. /// By default, UniWebView uses a default half-transparent iOS standard background for toolbar.
  185. /// You can change it by setting a new opaque color.
  186. ///
  187. /// This method is only for iOS, since there is no toolbar on Android.
  188. /// </summary>
  189. /// <param name="color">The color should be used for the background tint of the toolbar.</param>
  190. [Obsolete("`SetToolbarTintColor` is deprecated. Use `EmbeddedToolbar.SetBackgroundColor` " +
  191. "instead.", false)]
  192. public void SetToolbarTintColor(Color color) {
  193. #if UNITY_IOS && !UNITY_EDITOR
  194. UniWebViewInterface.SetToolbarTintColor(listener.Name, color.r, color.g, color.b);
  195. #endif
  196. }
  197. /// <summary>
  198. /// Sets the button text color for the toolbar.
  199. ///
  200. /// By default, UniWebView uses the default text color on iOS, which is blue for most cases.
  201. /// You can change it by setting a new opaque color.
  202. ///
  203. /// This method is only for iOS, since there is no toolbar on Android.
  204. /// </summary>
  205. /// <param name="color">The color should be used for the button text of the toolbar.</param>
  206. [Obsolete("`SetToolbarTextColor` is deprecated. Use `EmbeddedToolbar.SetButtonTextColor` or " +
  207. "`EmbeddedToolbar.SetTitleTextColor` instead.", false)]
  208. public void SetToolbarTextColor(Color color) {
  209. #if UNITY_IOS && !UNITY_EDITOR
  210. UniWebViewInterface.SetToolbarTextColor(listener.Name, color.r, color.g, color.b);
  211. #endif
  212. }
  213. /// <summary>
  214. /// Sets the visibility of navigation buttons, such as "Go Back" and "Go Forward", on toolbar.
  215. ///
  216. /// By default, UniWebView will show the "Go Back" and "Go Forward" navigation buttons on the toolbar.
  217. /// Users can use these buttons to perform go back or go forward action just like in a browser. If the navigation
  218. /// model is not for your case, call this method with `false` as `show` parameter to hide them.
  219. ///
  220. /// This method is only for iOS, since there is no toolbar on Android.
  221. /// </summary>
  222. /// <param name="show">Whether the navigation buttons on the toolbar should show or hide.</param>
  223. [Obsolete("`SetShowToolbarNavigationButtons` is deprecated. Use `EmbeddedToolbar.ShowNavigationButtons` or " +
  224. "`EmbeddedToolbar.HideNavigationButtons` instead.", false)]
  225. public void SetShowToolbarNavigationButtons(bool show) {
  226. #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
  227. UniWebViewInterface.SetShowToolbarNavigationButtons(listener.Name, show);
  228. #endif
  229. }
  230. [ObsoleteAttribute("Deprecated. Use `SetSupportMultipleWindows(bool enabled, bool allowJavaScriptOpen)` to set `allowJavaScriptOpen` explicitly.")]
  231. public void SetSupportMultipleWindows(bool enabled) {
  232. SetSupportMultipleWindows(enabled, true);
  233. }
  234. /// <summary>
  235. /// Clears all cookies from web view.
  236. ///
  237. /// This will clear cookies from all domains in the web view and previous.
  238. /// If you only need to remove cookies from a certain domain, use `RemoveCookies` instead.
  239. ///
  240. /// Deprecated. Use the async version `ClearCookies(Action)` with action instead.
  241. /// </summary>
  242. [Obsolete("Use the async version `ClearCookies(Action)` instead.")]
  243. public static void ClearCookies() {
  244. UniWebViewInterface.ClearCookies();
  245. }
  246. /// <summary>
  247. /// Sets a cookie for a certain url.
  248. ///
  249. /// Deprecated. Use the async version `SetCookie(String,String,Action)` with action instead.
  250. /// </summary>
  251. /// <param name="url">The url to which cookie will be set.</param>
  252. /// <param name="cookie">The cookie string to set.</param>
  253. /// <param name="skipEncoding">
  254. /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before
  255. /// using it. Otherwise, your original url string will be used to set the cookie if it is valid. Default is `false`.
  256. /// </param>
  257. [Obsolete("Use the async version `SetCookie(String,String,Action)` instead.")]
  258. public static void SetCookie(string url, string cookie, bool skipEncoding = false) {
  259. UniWebViewInterface.SetCookie(url, cookie, skipEncoding);
  260. }
  261. /// <summary>
  262. /// Gets the cookie value under a given url and key.
  263. ///
  264. /// Deprecated. Use the async version `GetCookie(String,String,Action)` with action instead.
  265. /// </summary>
  266. /// <param name="url">The url (domain) where the target cookie is.</param>
  267. /// <param name="key">The key for target cookie value.</param>
  268. /// <param name="skipEncoding">
  269. /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before
  270. /// using it. Otherwise, your original url string will be used to get the cookie if it is valid. Default is `false`.
  271. /// </param>
  272. /// <returns>Value of the target cookie under url.</returns>
  273. [Obsolete("Use the async version `GetCookie(String,String,Action)` instead.")]
  274. public static string GetCookie(string url, string key, bool skipEncoding = false) {
  275. return UniWebViewInterface.GetCookie(url, key, skipEncoding);
  276. }
  277. /// <summary>
  278. /// Gets the cookie value under a url and key. When it finishes, the `handler` will be called with the cookie value
  279. /// if exists.
  280. /// </summary>
  281. /// <param name="url">The url (domain) where the target cookie is.</param>
  282. /// <param name="key">The key for target cookie value.</param>
  283. /// <param name="handler">An action that is called after the operation finishes.</param>
  284. public static void GetCookie(string url, string key, Action<string> handler) {
  285. GetCookie(url, key, false, handler);
  286. }
  287. /// <summary>
  288. /// Removes all the cookies under a given url.
  289. /// </summary>
  290. /// <param name="url">The url (domain) where the cookies are under.</param>
  291. /// <param name="skipEncoding">
  292. /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before
  293. /// using it. Otherwise, your original url string will be used to get the cookie if it is valid. Default is `false`.
  294. /// </param>
  295. [Obsolete("Use the async version `RemoveCookies(String,Action)` instead.")]
  296. public static void RemoveCookies(string url, bool skipEncoding = false) {
  297. UniWebViewInterface.RemoveCookies(url, skipEncoding);
  298. }
  299. /// <summary>
  300. /// Removes a certain cookie under the given url for the specified key.
  301. ///
  302. /// Deprecated. Use the async version `RemoveCookie(String,String,Action)` with action instead.
  303. /// </summary>
  304. /// <param name="url">The url (domain) where the cookies are under.</param>
  305. /// <param name="key">The key for target cookie.</param>
  306. /// <param name="skipEncoding">
  307. /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before
  308. /// using it. Otherwise, your original url string will be used to get the cookie if it is valid. Default is `false`.
  309. /// </param>
  310. [Obsolete("Use the async version `RemoveCookie(String,String,Action)` instead.")]
  311. public static void RemoveCooke(string url, string key, bool skipEncoding = false) {
  312. RemoveCookie(url, key, skipEncoding);
  313. }
  314. /// <summary>
  315. /// Removes a certain cookie under the given url for the specified key.
  316. ///
  317. /// Deprecated. Use the async version `RemoveCookie(String,String,Action)` with action instead.
  318. /// </summary>
  319. /// <param name="url">The url (domain) where the cookies is under.</param>
  320. /// <param name="key">The key for target cookie.</param>
  321. /// <param name="skipEncoding">
  322. /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before
  323. /// using it. Otherwise, your original url string will be used to get the cookie if it is valid. Default is `false`.
  324. /// </param>
  325. [Obsolete("Use the async version `RemoveCookie(String,String,Action)` instead.")]
  326. public static void RemoveCookie(string url, string key, bool skipEncoding = false) {
  327. UniWebViewInterface.RemoveCookie(url, key, skipEncoding);
  328. }
  329. }