/// <summary> /// Clean web view cache. This removes cached local data of web view. /// /// If you need to clear all cookies, use `ClearCookies` instead. /// </summary> public void CleanCache() { UniWebViewInterface.CleanCache(listener.Name); }
/// <summary> /// Stops loading all resources on the current page. /// </summary> public void Stop() { UniWebViewInterface.Stop(listener.Name); }
/// <summary> /// Navigates to the forward item in the back-forward list. /// </summary> public void GoForward() { UniWebViewInterface.GoForward(listener.Name); }
/// <summary> /// Update and set current frame of web view to match the setting. /// /// This is useful if the `referenceRectTransform` is changed and you need to sync the frame change /// to the web view. This method follows the frame determining rules. /// </summary> public void UpdateFrame() { Rect rect = NextFrameRect(); UniWebViewInterface.SetFrame(listener.Name, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); }
/// <summary> /// Load an HTML string in current web view. /// </summary> /// <param name="htmlString">The HTML string to use as the contents of the webpage.</param> /// <param name="baseUrl">The url to use as the page's base url.</param> /// <param name="skipEncoding"> /// Whether UniWebView should skip encoding the baseUrl or not. If set to `false`, UniWebView will try to encode the baseUrl parameter before /// using it. Otherwise, your original url string will be used as the baseUrl if it is valid. Default is `false`. /// </param> public void LoadHTMLString(string htmlString, string baseUrl, bool skipEncoding = false) { UniWebViewInterface.LoadHTMLString(listener.Name, htmlString, baseUrl, skipEncoding); }
/// <summary> /// Enables user resizing for web view window. By default, you can only set the window size /// by setting its frame on mac Editor. By enabling user resizing, you would be able to resize /// the window by dragging its border as a normal macOS window. /// /// This method only works for macOS for debugging purpose. It does nothing on iOS and Android. /// </summary> /// <param name="enabled">Whether the window could be able to be resized by cursor.</param> public void SetWindowUserResizeEnabled(bool enabled) { #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN UniWebViewInterface.SetWindowUserResizeEnabled(listener.name, enabled); #endif }
void OnDestroy() { UniWebViewNativeListener.RemoveListener(listener.Name); UniWebViewInterface.Destroy(listener.Name); Destroy(listener.gameObject); }
/// <summary> /// Sets the text displayed in the loading indicator, if `SetShowSpinnerWhileLoading` is set to `true`. /// </summary> /// <param name="text">The text to display while loading indicator visible. Default is "Loading..."</param> public void SetSpinnerText(string text) { UniWebViewInterface.SetSpinnerText(listener.Name, text); }
/// <summary> /// Sets whether the vertical scroll bar should show when the web content beyonds web view bounds. /// /// This only works on mobile platforms. It will do nothing on macOS Editor. /// </summary> /// <param name="enabled">Whether enable the scroll bar or not.</param> public void SetVerticalScrollBarEnabled(bool enabled) { UniWebViewInterface.SetVerticalScrollBarEnabled(listener.Name, enabled); }
/// <summary> /// Clears any saved credentials for HTTP authentication for both Basic and Digest. /// /// On both iOS and Android, the user input credentials will be stored permanently across session. /// It could prevent your users to input username and password again until they changed. If you need the /// credentials only living in a shorter lifetime, call this method at proper timing. /// /// On iOS, it will clear the credentials immediately and completely from both disk and network cache. /// On Android, it only clears from disk database, the authentication might be still cached in the network stack /// and will not be removed until next session (app restarting). /// /// The client logout mechanism should be implemented by the Web site designer (such as server sending a HTTP /// 401 for invalidating credentials). /// /// </summary> /// <param name="host">The host to which the credentials apply. It should not contain any thing like scheme or path part.</param> /// <param name="realm">The realm to which the credentials apply.</param> public static void ClearHttpAuthUsernamePassword(string host, string realm) { UniWebViewInterface.ClearHttpAuthUsernamePassword(host, realm); }
/// <summary> /// Sets whether to show a loading indicator while the loading is in progress. /// </summary> /// <param name="flag">Whether an indicator should show.</param> public void SetShowSpinnerWhileLoading(bool flag) { UniWebViewInterface.SetShowSpinnerWhileLoading(listener.Name, flag); }
/// <summary> /// Gets the cookie value under a url and key. /// </summary> /// <param name="url">The url (domain) where the target cookie is.</param> /// <param name="key">The key for target cookie value.</param> /// <param name="skipEncoding"> /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before /// using it. Otherwise, your original url string will be used to get the cookie if it is valid. Default is `false`. /// </param> /// <returns>Value of the target cookie under url.</returns> public static string GetCookie(string url, string key, bool skipEncoding = false) { return(UniWebViewInterface.GetCookie(url, key, skipEncoding)); }
/// <summary> /// Sets a cookie for a certain url. /// </summary> /// <param name="url">The url to which cookie will be set.</param> /// <param name="cookie">The cookie string to set.</param> /// <param name="skipEncoding"> /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before /// using it. Otherwise, your original url string will be used to set the cookie if it is valid. Default is `false`. /// </param> public static void SetCookie(string url, string cookie, bool skipEncoding = false) { UniWebViewInterface.SetCookie(url, cookie, skipEncoding); }
/// <summary> /// Clears all cookies from web view. /// /// This will clear cookies from all domains in the web view and previous. /// If you only need to remove cookies from a certain domain, use `SetCookie` instead. /// </summary> public static void ClearCookies() { UniWebViewInterface.ClearCookies(); }
/// <summary> /// Sets the done button text in toolbar. /// /// By default, UniWebView will show a "Done" button at bottom-right corner in the /// toolbar. You could change its title by passing a text. /// /// This method is only for iOS, since there is no toolbar on Android. /// </summary> /// <param name="text">The text needed to be set as done button title.</param> public void SetToolbarDoneButtonText(string text) { #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN UniWebViewInterface.SetToolbarDoneButtonText(listener.Name, text); #endif }
/// <summary> /// Sets whether the web view supports zoom guesture to change content size. /// Default is `false`, which means the zoom guesture is not supported. /// </summary> /// <param name="enabled">Whether the zoom guesture is allowed or not.</param> public void SetZoomEnabled(bool enabled) { UniWebViewInterface.SetZoomEnabled(listener.Name, enabled); }
/// <summary> /// Enables debugging of web contents. You could inspect of the content of a /// web view by using a browser development tool of Chrome for Android or Safari for macOS. /// /// This method is only for Android and macOS Editor. On iOS, you do not need additional step. /// You could open Safari's developer tools to debug a web view on iOS. /// </summary> /// <param name="enabled">Whether the content debugging should be enabled.</param> public static void SetWebContentsDebuggingEnabled(bool enabled) { UniWebViewInterface.SetWebContentsDebuggingEnabled(enabled); }
/// <summary> /// Removes a trusted domain from white list. /// </summary> /// <param name="domain">The domain to remove from white list.</param> public void RemovePermissionTrustDomain(string domain) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.RemovePermissionTrustDomain(listener.Name, domain); #endif }
/// <summary> /// Prints current page. /// /// By calling this method, a native print preview panel will be brought up on iOS and Android. /// This method does nothing on macOS editor. /// On iOS and Android, the web view does not support JavaScript (window.print()), /// you can only initialize a print job from Unity by this method. /// </summary> public void Print() { UniWebViewInterface.Print(listener.name); }
/// <summary> /// Sets whether the device back button should be enabled to execute "go back" or "closing" operation. /// /// On Android, the device back button in navigation bar will navigate users to a back page. If there is /// no any back page avaliable, the back button clicking will try to raise a `OnShouldClose` event and try /// to close the web view if `true` is return from the event. If the `OnShouldClose` is not listened, /// the web view will be closed and the UniWebView component will be destroyed to release using resource. /// /// Listen to `OnKeyCodeReceived` if you need to disable the back button, but still want to get the back /// button key pressing event. /// /// Default is enabled. /// </summary> /// <param name="enabled">Whether the back button should perform go back or closing operation to web view.</param> public void SetBackButtonEnabled(bool enabled) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.SetBackButtonEnabled(listener.Name, enabled); #endif }
void OnApplicationPause(bool pause) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.ShowWebViewDialog(listener.Name, !pause); #endif }
/// <summary> /// Sets whether the web view should enable support for the "viewport" HTML meta tag or should use a wide viewport. /// </summary> /// <param name="flag">Whether to enable support for the viewport meta tag.</param> public void SetUseWideViewPort(bool flag) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.SetUseWideViewPort(listener.Name, flag); #endif }
/// <summary> /// Load a url in current web view. /// </summary> /// <param name="url">The url to be loaded. This url should start with `http://` or `https://` scheme. You could even load a non-ascii url text if it is valid.</param> /// <param name="skipEncoding"> /// Whether UniWebView should skip encoding the url or not. If set to `false`, UniWebView will try to encode the url parameter before /// loading it. Otherwise, your original url string will be used as the url if it is valid. Default is `false`. /// </param> public void Load(string url, bool skipEncoding = false) { UniWebViewInterface.Load(listener.Name, url, skipEncoding); }
/// <summary> /// Sets whether the web view loads pages in overview mode, that is, zooms out the content to fit on screen by width. /// /// This method is only for Android. Default is disabled. /// </summary> /// <param name="flag"></param> public void SetLoadWithOverviewMode(bool flag) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.SetLoadWithOverviewMode(listener.Name, flag); #endif }
/// <summary> /// Reloads the current page. /// </summary> public void Reload() { UniWebViewInterface.Reload(listener.Name); }
/// <summary> /// Sets whether the web view should behave in immersive mode, that is, /// hides the status bar and navigation bar with a sticky style. /// /// This method is only for Android. Default is enabled. /// </summary> /// <param name="enabled"></param> public void SetImmersiveModeEnabled(bool enabled) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.SetImmersiveModeEnabled(listener.Name, enabled); #endif }
/// <summary> /// Navigates to the back item in the back-forward list. /// </summary> public void GoBack() { UniWebViewInterface.GoBack(listener.Name); }
/// <summary> /// Sets whether to show a toolbar which contains navigation buttons and Done button. /// /// You could choose to show or hide the tool bar. By configuring the `animated` and `onTop` /// parameters, you can control the animating and position of the toolbar. If the toolbar is /// overlapping with some part of your web view, pass `adjustInset` with `true` to have the /// web view reloacating itself to avoid the overlap. /// /// This method is only for iOS. The toolbar is hidden by default. /// </summary> /// <param name="show">Whether the toolbar should show or hide.</param> /// <param name="animated">Whether the toolbar state changing should be with animation. Default is `false`.</param> /// <param name="onTop">Whether the toolbar should snap to top of screen or to bottom of screen. Default is `true`</param> /// <param name="adjustInset">Whether the toolbar transition should also afjust web view position and size if overlapped. Default is `false`</param> public void SetShowToolbar(bool show, bool animated = false, bool onTop = true, bool adjustInset = false) { #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN UniWebViewInterface.SetShowToolbar(listener.Name, show, animated, onTop, adjustInset); #endif }
/// <summary> /// Sets whether the link clicking in the web view should open the page in an external browser. /// </summary> /// <param name="flag">The flag indicates whether a link should be opened externally.</param> public void SetOpenLinksInExternalBrowser(bool flag) { UniWebViewInterface.SetOpenLinksInExternalBrowser(listener.Name, flag); }
/// <summary> /// Sets whether JavaScript can open windows without user interaction. /// /// By setting this to `true`, an automatically JavaScript navigation will be allowed in the web view. /// </summary> /// <param name="flag">Whether JavaScript could open window automatically.</param> public static void SetAllowJavaScriptOpenWindow(bool flag) { UniWebViewInterface.SetAllowJavaScriptOpenWindow(flag); }