移动端浏览器

This commit is contained in:
Caiyanpeng committed 2021-12-23 09:54:14 +08:00
1 parent 5c2c22b675
commit 4260cf05d3
82 files changed
+7477 -1083

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 598e18fb001004a81960f552978ecf4e
timeCreated: 1491898971
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,42 @@
//
// UniWebViewContentInsetAdjustmentBehavior.cs
// Created by Wang Wei(@onevcat) on 2019-09-20.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
/// <summary>
/// Constants indicating how safe area insets are added to the adjusted content inset.
/// This is only for iOS.
/// </summary>
public enum UniWebViewContentInsetAdjustmentBehavior
{
/// <summary>
/// Automatically adjust the scroll view insets.
/// </summary>
Automatic = 0,
/// <summary>
/// Adjust the insets only in the scrollable directions.
/// </summary>
ScrollableAxes = 1,
/// <summary>
/// Do not adjust the scroll view insets.
/// </summary>
Never = 2,
/// <summary>
/// Always include the safe area insets in the content adjustment.
/// </summary>
Always = 3
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dc6b999829de442f2aa381a8ff78a917
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
//
// UniWebViewDownloadMatchingType.cs
// Created by Wang Wei(@onevcat) on 2021-09-02.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
//
/// <summary>
/// The matching type used when UniWebView determines whether to download from a URL or MIME type.
/// </summary>
public enum UniWebViewDownloadMatchingType
{
/// <summary>
/// Matches exact the whole value.
/// </summary>
ExactValue = 1,
/// <summary>
/// Uses the value as a regular expression.
/// </summary>
RegularExpression = 2
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ba73f1cc351846878c5731b4e22b132
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,67 @@
//
// UniWebViewHelper.cs
// Created by Wang Wei(@onevcat) on 2017-04-11.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
//
using UnityEngine;
using System.IO;
/// <summary>
/// Provides some helper utility methods for UniWebView.
/// </summary>
public class UniWebViewHelper {
/// <summary>
/// Get the local streaming asset path for a given file path related to the StreamingAssets folder.
///
/// This method will help you to create a URL string for a file under your StreamingAssets folder for different platforms.
/// <param name="path">The relative path to the Assets/StreamingAssets of your file.
/// For example, if you placed a html file under Assets/StreamingAssets/www/index.html, you should pass `www/index.html` as parameter.
/// </param>
/// <returns>The path you could use as the url for the web view.</returns>
public static string StreamingAssetURLForPath(string path)
{
#if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
return Path.Combine("file://" + Application.streamingAssetsPath, path);
#elif UNITY_ANDROID && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
return Path.Combine("file:///android_asset/", path);
#else
UniWebViewLogger.Instance.Critical("The current build target is not supported.");
return string.Empty;
#endif
}
/// <summary>
/// Get the local persistent data path for a given file path related to the data folder of your host app.
///
/// This method will help you to create a URL string for a file under you stored in the `persistentDataPath`.
/// </summary>
/// <param name="path">
/// The relative path to the persistent data path of your file.
/// </param>
/// <returns>The path you could use as the url for the web view.</returns>
public static string PersistentDataURLForPath(string path)
{
return Path.Combine("file://" + Application.persistentDataPath, path);
}
internal static bool IsEditor {
get {
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
return true;
#else
return false;
#endif
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 824ddd9d1592945268d857265662a174
timeCreated: 1495373327
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,120 @@
//
// UniWebViewLogger.cs
// Created by Wang Wei(@onevcat) on 2017-04-11.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
//
/// <summary>
/// A leveled logger which could log UniWebView related messages in
/// both development environment and final product.
/// </summary>
public class UniWebViewLogger {
/// <summary>
/// Logger level.
/// </summary>
public enum Level {
/// <summary>
/// Lowest level. When set to `Verbose`, the logger will log out all messages.
/// </summary>
Verbose = 0,
/// <summary>
/// Debug level. When set to `Debug`, the logger will log out most of messages up to this level.
/// </summary>
Debug = 10,
/// <summary>
/// Info level. When set to `Info`, the logger will log out up to info messages.
/// </summary>
Info = 20,
/// <summary>
/// Critical level. When set to `Critical`, the logger will only log out errors or exceptions.
/// </summary>
Critical = 80,
/// <summary>
/// Off level. When set to `Off`, the logger will log out nothing.
/// </summary>
Off = 99
}
private static UniWebViewLogger instance;
private Level level;
/// <summary>
/// Current level of this logger. All messages above current level will be logged out.
/// Default is `Critical`, which means the logger only prints errors and exceptions.
/// </summary>
public Level LogLevel {
get { return level; }
set {
Log(Level.Off, "Setting UniWebView logger level to: " + value);
level = value;
UniWebViewInterface.SetLogLevel((int)value);
}
}
private UniWebViewLogger(Level level) {
this.level = level;
}
/// <summary>
/// Instance of the UniWebView logger across the process. Normally you should use this for logging purpose
/// in UniWebView, instead of creating a new logger yourself.
/// </summary>
public static UniWebViewLogger Instance {
get {
if (instance == null) {
instance = new UniWebViewLogger(Level.Critical);
}
return instance;
}
}
/// <summary>
/// Log a verbose message.
/// </summary>
/// <param name="message">The message to log.</param>
public void Verbose(string message) { Log(Level.Verbose, message); }
/// <summary>
/// Log a debug message.
/// </summary>
/// <param name="message">The message to log.</param>
public void Debug(string message) { Log(Level.Debug, message); }
/// <summary>
/// Log an info message.
/// </summary>
/// <param name="message">The message to log.</param>
public void Info(string message) { Log(Level.Info, message); }
/// <summary>
/// Log a critical message.
/// </summary>
/// <param name="message">The message to log.</param>
public void Critical(string message) { Log(Level.Critical, message); }
private void Log(Level level, string message) {
if (level >= this.LogLevel) {
var logMessage = "<UniWebView> " + message;
if (level == Level.Critical) {
UnityEngine.Debug.LogError(logMessage);
} else {
UnityEngine.Debug.Log(logMessage);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 06ca7a8564d9842ba99c77d43e9ce4f5
timeCreated: 1491898971
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,111 @@
//
// UniWebViewMessage.cs
// Created by Wang Wei(@onevcat) on 2017-05-12.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
//
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
#if UNITY_2017_3_OR_NEWER
using Net = UnityEngine.Networking.UnityWebRequest;
#else
using Net = UnityEngine.WWW;
#endif
/// <summary>
/// A structure represents a message from webview.
/// </summary>
public struct UniWebViewMessage {
/// <summary>
/// Gets the raw message. It is the original url which initialized this message.
/// </summary>
public string RawMessage {get; private set;}
/// <summary>
/// The url scheme of this UniWebViewMessage. "uniwebview" was added to message scheme list
/// by default. You can add your own scheme by using `UniWebView.AddUrlScheme`.
/// </summary>
public string Scheme {get; private set;}
/// <summary>
/// The path of this UniWebViewMessage.
/// This will be the decoded value for the path of original url.
/// </summary>
public string Path {get; private set;}
/// <summary>
/// The arguments of this UniWebViewMessage.
///
/// When received url "uniwebview://yourPath?param1=value1&param2=value2",
/// the args is a Dictionary with: Args["param1"] = value1, Args["param2"] = value2
///
/// Both the key and valud will be url decoded from the original url.
/// </summary>
public Dictionary<string, string> Args{get; private set;}
/// <summary>
/// Initializes a new instance of the `UniWebViewMessage` struct.
/// </summary>
/// <param name="rawMessage">Raw message which will be parsed to a UniWebViewMessage.</param>
public UniWebViewMessage(string rawMessage): this() {
UniWebViewLogger.Instance.Debug("Try to parse raw message: " + rawMessage);
this.RawMessage = rawMessage;
string[] schemeSplit = rawMessage.Split(new string[] {"://"}, System.StringSplitOptions.None);
if (schemeSplit.Length == 1) {
// `://` not existing. Try `:/` instead.
schemeSplit = rawMessage.Split(new string[] {":/"}, System.StringSplitOptions.None);
}
if (schemeSplit.Length == 1) {
// `:/` not existing. Try `:` instead.
schemeSplit = rawMessage.Split(new string[] {":"}, System.StringSplitOptions.None);
}
if (schemeSplit.Length >= 2) {
this.Scheme = schemeSplit[0];
UniWebViewLogger.Instance.Debug("Get scheme: " + this.Scheme);
string pathAndArgsString = "";
int index = 1;
while (index < schemeSplit.Length) {
pathAndArgsString = string.Concat(pathAndArgsString, schemeSplit[index]);
index++;
}
UniWebViewLogger.Instance.Verbose("Build path and args string: " + pathAndArgsString);
string[] split = pathAndArgsString.Split("?"[0]);
this.Path = Net.UnEscapeURL(split[0].TrimEnd('/'));
this.Args = new Dictionary<string, string>();
if (split.Length > 1) {
foreach (string pair in split[1].Split("&"[0])) {
string[] elems = pair.Split("="[0]);
if (elems.Length > 1) {
var key = Net.UnEscapeURL(elems[0]);
if (Args.ContainsKey(key)) {
var existingValue = Args[key];
Args[key] = existingValue + "," + Net.UnEscapeURL(elems[1]);
} else {
Args[key] = Net.UnEscapeURL(elems[1]);
}
UniWebViewLogger.Instance.Debug("Get arg, key: " + key + " value: " + Args[key]);
}
}
}
} else {
UniWebViewLogger.Instance.Critical("Bad url scheme. Can not be parsed to UniWebViewMessage: " + rawMessage);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0dbdb1ed01b9747a1ad6eb7bcc7b4014
timeCreated: 1491898971
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,196 @@
//
// UniWebViewNativeListener.cs
// Created by Wang Wei(@onevcat) on 2017-04-11.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
//
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
/// <summary>
/// A listener script for message sent from native side of UniWebView.
/// Normally this component will be attached to a sub `GameObject` under the `UniWebView` one.
/// It will be added automatically and destroyed as needed. So there is rarely a need for you
/// to manipulate on this class.
/// </summary>
public class UniWebViewNativeListener: MonoBehaviour {
private static Dictionary<String, UniWebViewNativeListener> listeners = new Dictionary<String, UniWebViewNativeListener>();
public static void AddListener(UniWebViewNativeListener target) {
listeners.Add(target.Name, target);
}
public static void RemoveListener(String name) {
listeners.Remove(name);
}
public static UniWebViewNativeListener GetListener(String name) {
UniWebViewNativeListener result = null;
if (listeners.TryGetValue(name, out result)) {
return result;
} else {
return null;
}
}
/// <summary>
/// The web view holder of this listener.
/// It will be linked to original web view in web view context, so you should never set it yourself.
/// Either `webView` or `safeBrowsing` will be valid in this listener.
/// </summary>
[HideInInspector]
public UniWebView webView;
// The safe browsing of this listener.
/// It will be linked to original safe browsing in browsing context, so you should never set it yourself.
/// Either `webView` or `safeBrowsing` will be valid in this listener.
[HideInInspector]
public UniWebViewSafeBrowsing safeBrowsing;
/// <summary>
/// Name of current listener. This is a UUID string by which native side could use to find
/// the message destination.
/// </summary>
public string Name {
get {
return gameObject.name;
}
}
public void PageStarted(string url) {
UniWebViewLogger.Instance.Info("Page Started Event. Url: " + url);
webView.InternalOnPageStarted(url);
}
public void PageFinished(string result) {
UniWebViewLogger.Instance.Info("Page Finished Event. Url: " + result);
var payload = JsonUtility.FromJson<UniWebViewNativeResultPayload>(result);
webView.InternalOnPageFinished(payload);
}
public void PageErrorReceived(string result) {
UniWebViewLogger.Instance.Info("Page Error Received Event. Result: " + result);
var payload = JsonUtility.FromJson<UniWebViewNativeResultPayload>(result);
webView.InternalOnPageErrorReceived(payload);
}
public void PageProgressChanged(string result) {
float progress;
if (float.TryParse(result, out progress)) {
webView.InternalOnPageProgressChanged(progress);
}
}
public void ShowTransitionFinished(string identifer) {
UniWebViewLogger.Instance.Info("Show Transition Finished Event. Identifier: " + identifer);
webView.InternalOnShowTransitionFinished(identifer);
}
public void HideTransitionFinished(string identifer) {
UniWebViewLogger.Instance.Info("Hide Transition Finished Event. Identifier: " + identifer);
webView.InternalOnHideTransitionFinished(identifer);
}
public void AnimateToFinished(string identifer) {
UniWebViewLogger.Instance.Info("Animate To Finished Event. Identifier: " + identifer);
webView.InternalOnAnimateToFinished(identifer);
}
public void AddJavaScriptFinished(string result) {
UniWebViewLogger.Instance.Info("Add JavaScript Finished Event. Result: " + result);
var payload = JsonUtility.FromJson<UniWebViewNativeResultPayload>(result);
webView.InternalOnAddJavaScriptFinished(payload);
}
public void EvalJavaScriptFinished(string result) {
UniWebViewLogger.Instance.Info("Eval JavaScript Finished Event. Result: " + result);
var payload = JsonUtility.FromJson<UniWebViewNativeResultPayload>(result);
webView.InternalOnEvalJavaScriptFinished(payload);
}
public void MessageReceived(string result) {
UniWebViewLogger.Instance.Info("Message Received Event. Result: " + result);
webView.InternalOnMessageReceived(result);
}
public void WebViewDone(string param) {
UniWebViewLogger.Instance.Info("Web View Done Event.");
webView.InternalOnShouldClose();
}
public void WebContentProcessDidTerminate(string param) {
UniWebViewLogger.Instance.Info("Web Content Process Terminate Event.");
webView.InternalOnWebContentProcessDidTerminate();
}
public void SafeBrowsingFinished(string param) {
UniWebViewLogger.Instance.Info("Safe Browsing Finished.");
safeBrowsing.InternalSafeBrowsingFinished();
}
public void MultipleWindowOpened(string param) {
UniWebViewLogger.Instance.Info("MultipleWindowOpened Event. Multi Window: " + param);
webView.InternalOnMultipleWindowOpened(param);
}
public void MultipleWindowClosed(string param) {
UniWebViewLogger.Instance.Info("MultipleWindowClose Event. Multi Window: " + param);
webView.InternalOnMultipleWindowClosed(param);
}
public void FileDownloadStarted(string result) {
UniWebViewLogger.Instance.Info("FileDownloadStarted Event. Result: " + result);
var payload = JsonUtility.FromJson<UniWebViewNativeResultPayload>(result);
webView.InternalOnFileDownloadStarted(payload);
}
public void FileDownloadFinished(string result) {
UniWebViewLogger.Instance.Info("FileDownloadFinished Event. Result: " + result);
var payload = JsonUtility.FromJson<UniWebViewNativeResultPayload>(result);
webView.InternalOnFileDownloadFinished(payload);
}
public void CaptureSnapshotFinished(string result) {
UniWebViewLogger.Instance.Info("CaptureSnapshotFinished Event. Result: " + result);
var payload = JsonUtility.FromJson<UniWebViewNativeResultPayload>(result);
webView.InternalOnCaptureSnapshotFinished(payload);
}
}
/// <summary>
/// A payload received from native side. It contains information to identify the message sender,
/// as well as some necessary field to bring data from native side to Unity.
/// </summary>
[System.Serializable]
public class UniWebViewNativeResultPayload {
/// <summary>
/// The identifier bound to this payload. It would be used internally to identify the callback.
/// </summary>
public string identifier;
/// <summary>
/// The result code contained in this payload. Generally, "0" means the operation finished without
/// problem, while a non-zero value means somethings goes wrong.
/// </summary>
public string resultCode;
/// <summary>
/// Return value or data from native. You should look at
/// corresponding APIs to know what exactly contained in this.
/// </summary>
public string data;
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5538b25d1713f4de994dacdc6eaacb95
timeCreated: 1491961733
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UniWebViewSafeBrowingComponent : MonoBehaviour
{
[SerializeField]
#pragma warning disable 0649
private string url;
void Start()
{
if (string.IsNullOrEmpty(url)) {
Debug.LogError("The `url` is empty or null. Set a valid url in the prefab before you initialize it.");
return;
}
var safeBrowsing = UniWebViewSafeBrowsing.Create(url);
safeBrowsing.Show();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5843488507315421aa0a7d92c0604d10
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,194 @@
//
// UniWebViewSafeBrowsing.cs
// Created by Wang Wei(@onevcat) on 2020-07-18.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
//
using UnityEngine;
using System;
/// <summary>
/// UniWebView Safe Browsing provides a way for browsing the web content in a more browser-like way, such as Safari on
/// iOS and Chrome on Android.
///
/// This class wraps `SFSafariViewController` on iOS and "Custom Tabs" on Android. It shares cookies, auto-fill
/// completion and other more data with the browser on device. Most of permissions are also built-in supported. You can
/// use this class for some tasks that are limited for a normal web view, such as using Apple Pay or Progressive Web
/// Apps (PWA).
///
/// You create a `UniWebViewSafeBrowsing` instance by calling the static `UniWebViewSafeBrowsing.Create` method with a
/// destination URL. You cannot change this URL once the instance is created. To show the safe browsing, call `Show` on
/// the instance. The web content will be displayed in full screen with a toolbar containing the loaded URL, as well
/// as some basic controls like Go Back, Go Forward and Done.
///
/// Browsing web content in `UniWebViewSafeBrowsing` is only supported on iOS and Android. There is no such component in
/// Unity Editor. Creating and showing a `UniWebViewSafeBrowsing` on Unity Editor will fall back to open the URL in
/// external browser by using Unity's `Application.OpenURL`.
///
/// </summary>
public class UniWebViewSafeBrowsing: UnityEngine.Object {
/// <summary>
/// Delegate for safe browsing finish event.
/// </summary>
/// <param name="browsing">The `UniWebViewSafeBrowsing` object raised this event.</param>
public delegate void OnSafeBrowsingFinishedDelegate(UniWebViewSafeBrowsing browsing);
/// <summary>
/// Raised when user dismisses safe browsing by tapping the Done button or Back button.
///
/// The dismissed safe browsing instance will be invalid after this event being raised, and you should not use
/// it for another browsing purpose. Instead, create a new one for a new browsing session.
///
/// This event will not happen in Unity Editor, because the whole `UniWebViewSafeBrowsing` will fall back to an
/// external browser.
/// </summary>
public event OnSafeBrowsingFinishedDelegate OnSafeBrowsingFinished;
private string id = Guid.NewGuid().ToString();
private UniWebViewNativeListener listener;
// This is only for editor, to open the url in system browser.
private string url;
/// <summary>
/// Whether the safe browsing mode is supported in current runtime or not.
///
/// If supported, the safe browsing mode will be used when `Show` is called on a `UniWebViewSafeBrowsing` instance.
/// Otherwise, the system default browser will be used to open the page when `Show` is called.
///
/// This property always returns `true` on iOS runtime platform. On Android, it depends on whether there is an Intent
/// can handle the safe browsing request. Usually it is provided by Chrome. If there is no Intent can open the URL
/// in safe browsing mode, this property will return `false`.
///
/// To use this API on Android when you set your Target SDK to Android 11 or later, you need to declare the correct
/// intent query explicitly in your AndroidManifest.xml, to follow the Package Visibility
/// (https://developer.android.com/about/versions/11/privacy/package-visibility):
///
/// ```xml
/// <queries>
/// <intent>
/// <action android:name="android.support.customtabs.action.CustomTabsService" />
/// </intent>
/// </queries>
/// ```
/// </summary>
/// <value>
/// Returns `true` if the safe browsing mode is supported and the page will be opened in safe browsing
/// mode. Otherwise, `false`.
/// </value>
public static bool IsSafeBrowsingSupported {
get {
#if UNITY_EDITOR
return false;
#elif UNITY_IOS
return true;
#elif UNITY_ANDROID
return UniWebViewInterface.IsSafeBrowsingSupported();
#else
return false;
#endif
}
}
/// <summary>
/// Creates a new `UniWebViewSafeBrowsing` instance with a given URL.
/// </summary>
/// <param name="url">The URL to navigate to. The URL must use the `http` or `https` scheme.</param>
/// <returns>A newly created `UniWebViewSafeBrowsing` instance.</returns>
public static UniWebViewSafeBrowsing Create(string url) {
var safeBrowsing = new UniWebViewSafeBrowsing();
if (!UniWebViewHelper.IsEditor) {
safeBrowsing.listener.safeBrowsing = safeBrowsing;
safeBrowsing.Init(url);
}
safeBrowsing.url = url;
return safeBrowsing;
}
/// <summary>
/// Shows the safe browsing content above current screen.
/// </summary>
public void Show() {
if (UniWebViewSafeBrowsing.IsSafeBrowsingSupported) {
UniWebViewInterface.SafeBrowsingShow(listener.Name);
} else {
if (!UniWebViewHelper.IsEditor) {
UniWebViewLogger.Instance.Critical(@"UniWebViewSafeBrowsing.Show is called but the current device does
not support Safe Browsing.
This might be due to Chrome or any other processing app is not installed, or the manifest file not
configured correctly. Check SafeBrowsing Mode guide for more: https://docs.uniwebview.com/guide/safe-browsing.html");
}
Application.OpenURL(url);
}
}
/// <summary>
/// Dismisses the safe browsing component.
///
/// This method only works on iOS. On Android, there is no way to dismiss the safe browsing component
/// programatically as the result of the limitation from the native (Android) side.
/// </summary>
public void Dismiss() {
#if UNITY_IOS && !UNITY_EDITOR
UniWebViewInterface.SafeBrowsingDismiss(listener.Name);
#endif
}
/// <summary>
/// Sets the color for toolbar background in the safe browsing component. The changes are ignored after `Show`
/// method is called.
/// </summary>
/// <param name="color">The color to tint the toolbar.</param>
public void SetToolbarColor(Color color) {
if (!UniWebViewHelper.IsEditor) {
UniWebViewInterface.SafeBrowsingSetToolbarColor(listener.Name, color.r, color.g, color.b);
}
}
/// <summary>
/// Sets the color for toolbar controls in the safe browsing component. The changes are ignored after `Show` method
/// is called.
///
/// This method only works on iOS. On Android, the controls color is determined by system to keep a reasonable
/// contrast, based on the toolbar background color you provided in `SetToolbarColor`.
/// </summary>
/// <param name="color">The color to tint the controls on toolbar.</param>
public void SetToolbarItemColor(Color color) {
#if UNITY_IOS && !UNITY_EDITOR
UniWebViewInterface.SafeBrowsingSetToolbarItemColor(listener.Name, color.r, color.g, color.b);
#endif
}
private UniWebViewSafeBrowsing() {
if (!UniWebViewHelper.IsEditor) {
var listenerObject = new GameObject(id);
listener = listenerObject.AddComponent<UniWebViewNativeListener>();
UniWebViewNativeListener.AddListener(listener);
}
}
private void Init(string url) {
UniWebViewInterface.SafeBrowsingInit(listener.Name, url);
}
internal void InternalSafeBrowsingFinished() {
if (OnSafeBrowsingFinished != null) {
OnSafeBrowsingFinished(this);
}
UniWebViewNativeListener.RemoveListener(listener.Name);
Destroy(listener.gameObject);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dca3ba926a98540d3a2bff6312899a75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
//
// UniWebViewToolbarPosition.cs
// Created by Wang Wei(@onevcat) on 2017-05-31.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
//
/// <summary>
/// Toolbar position of webview. You can set the snapping edge for the built-in toolbar in iOS.
/// </summary>
public enum UniWebViewToolbarPosition
{
/// <summary>
/// Top screen edge.
/// </summary>
Top = 0,
/// <summary>
/// Bottom screen edge.
/// </summary>
Bottom
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9e4c706c92e5e4dc381385bf4edbd3dd
timeCreated: 1496199547
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
//
// UniWebViewTransitionEdge.cs
// Created by Wang Wei(@onevcat) on 2017-05-04.
//
// This file is a part of UniWebView Project (https://uniwebview.com)
// By purchasing the asset, you are allowed to use this code in as many as projects
// you want, only if you publish the final products under the name of the same account
// used for the purchase.
//
// This asset and all corresponding files (such as source code) are provided on an
// “as is” basis, without warranty of any kind, express of implied, including but not
// limited to the warranties of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the authors or copyright holders be liable for any
// claim, damages or other liability, whether in action of contract, tort or otherwise,
// arising from, out of or in connection with the software or the use of other dealing in the software.
/// <summary>
/// An enum to identify transition edge from or to when the UniWebView
/// transition happens. You can specify an edge in Show() or Hide() methods of web view.
/// </summary>
public enum UniWebViewTransitionEdge
{
/// <summary>
/// No transition when showing or hiding.
/// </summary>
None = 0,
/// <summary>
/// Transit the web view from/to top.
/// </summary>
Top,
/// <summary>
/// Transit the web view from/to left.
/// </summary>
Left,
/// <summary>
/// Transit the web view from/to bottom.
/// </summary>
Bottom,
/// <summary>
/// Transit the web view from/to right.
/// </summary>
Right
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1256e7eea8f184fae9b700f8f78e014c
timeCreated: 1493888384
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: