|
| 1 | +using System; |
| 2 | + |
| 3 | +namespace Immutable.Passport |
| 4 | +{ |
| 5 | + /// <summary> |
| 6 | + /// Platform abstraction interface for PassportUI WebView implementations. |
| 7 | + /// Provides a unified API for different WebView technologies across platforms: |
| 8 | + /// - Windows: Volt Unity Web Browser (UWB) with Chromium CEF |
| 9 | + /// - iOS/macOS: Gree WebView with WKWebView |
| 10 | + /// - Android: Gree WebView with Android WebView |
| 11 | + /// </summary> |
| 12 | + public interface IPassportWebView |
| 13 | + { |
| 14 | + /// <summary> |
| 15 | + /// Load a URL in the WebView |
| 16 | + /// </summary> |
| 17 | + /// <param name="url">The URL to load</param> |
| 18 | + void LoadUrl(string url); |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Show the WebView (make it visible to the user) |
| 22 | + /// </summary> |
| 23 | + void Show(); |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Hide the WebView (make it invisible) |
| 27 | + /// </summary> |
| 28 | + void Hide(); |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Execute JavaScript code in the WebView |
| 32 | + /// </summary> |
| 33 | + /// <param name="js">JavaScript code to execute</param> |
| 34 | + void ExecuteJavaScript(string js); |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Event triggered when JavaScript sends a message to Unity |
| 38 | + /// The string parameter contains the message data from JavaScript |
| 39 | + /// </summary> |
| 40 | + event Action<string> OnJavaScriptMessage; |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Event triggered when a page finishes loading in the WebView |
| 44 | + /// </summary> |
| 45 | + event Action OnLoadFinished; |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Event triggered when a page starts loading in the WebView |
| 49 | + /// </summary> |
| 50 | + event Action OnLoadStarted; |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Get or set whether the WebView is currently visible |
| 54 | + /// </summary> |
| 55 | + bool IsVisible { get; } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Get the current URL loaded in the WebView |
| 59 | + /// </summary> |
| 60 | + string CurrentUrl { get; } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Initialize the WebView with the specified configuration |
| 64 | + /// </summary> |
| 65 | + /// <param name="config">WebView configuration options</param> |
| 66 | + void Initialize(PassportWebViewConfig config); |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// Register a JavaScript method that can be called from web pages |
| 70 | + /// </summary> |
| 71 | + /// <param name="methodName">Name of the method to register</param> |
| 72 | + /// <param name="handler">Handler function to call when JavaScript invokes this method</param> |
| 73 | + void RegisterJavaScriptMethod(string methodName, Action<string> handler); |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Clean up resources and dispose of the WebView |
| 77 | + /// </summary> |
| 78 | + void Dispose(); |
| 79 | + } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Configuration options for PassportUI WebView |
| 83 | + /// </summary> |
| 84 | + public class PassportWebViewConfig |
| 85 | + { |
| 86 | + /// <summary> |
| 87 | + /// Enable remote debugging (Chrome DevTools, Safari Web Inspector, etc.) |
| 88 | + /// </summary> |
| 89 | + public bool EnableRemoteDebugging { get; set; } = false; |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Port for remote debugging (Windows UWB only) |
| 93 | + /// </summary> |
| 94 | + public uint RemoteDebuggingPort { get; set; } = 9222; |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Clear cache on initialization |
| 98 | + /// </summary> |
| 99 | + public bool ClearCacheOnInit { get; set; } = false; |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Initial URL to load (use "about:blank" for blank page) |
| 103 | + /// </summary> |
| 104 | + public string InitialUrl { get; set; } = "about:blank"; |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Custom User-Agent string (optional) |
| 108 | + /// </summary> |
| 109 | + public string UserAgent { get; set; } = ""; |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Platform-specific configuration data |
| 113 | + /// </summary> |
| 114 | + public object PlatformSpecificConfig { get; set; } |
| 115 | + } |
| 116 | +} |
0 commit comments