Domain Controller Facades: Navigation, JavaScript, Cookies, Settings
The domain-controller layer is the coordination seam between the public WebView controller and platform-specific behavior. Instead of concentrating navigation, JavaScript, cookies, and settings in one implementation, ZikZak composes four focused delegates behind a stable facade. This page explains that boundary, how calls move through it, and why it matters when extending or debugging the plugin.
Architectural Position of the Facade
Section titled “Architectural Position of the Facade”The facade sits above platform controllers and below application-facing WebView APIs. Its role is intentionally narrow: retain a coherent controller surface while delegating domain behavior to injected collaborators. That keeps the public contract stable while allowing each platform to implement browser semantics independently.
flowchart LR App[Application Code] --> Facade[Domain Controller Facade] Facade --> Nav[Navigation Delegate] Facade --> JS[JavaScript Delegate] Facade --> Cookies[Cookie Delegate] Facade --> Settings[Settings Delegate] Nav --> Platform[Platform Controller] JS --> Platform Cookies --> Platform Settings --> PlatformThe important design property is composition over inheritance. The facade does not subclass behavior; it aggregates it. This makes the controller easier to test, easier to evolve, and less coupled to any single native backend.
Sources: in_app_webview_controller_delegates_test.dart, in_app_webview_controller.dart
Construction and Dependency Injection
Section titled “Construction and Dependency Injection”The facade constructor accepts four required delegates and stores them as late-final fields. This is a deliberate contract: construction fails fast if any domain is omitted, and call sites can substitute test doubles without touching native code. The constructor is synchronous and side-effect free, which keeps initialization predictable.
| Dependency | Type | Responsibility |
|---|---|---|
InAppWebViewNavigationDelegate |
Navigation | URL loading, history, reload/stop, scroll and zoom |
InAppWebViewJavaScriptDelegate |
JavaScript | Evaluation, async calls, injection, user scripts |
InAppWebViewCookieDelegate |
Cookies | Cookie read/write and deletion |
InAppWebViewSettingsDelegate |
Settings | Settings retrieval and application |
Because dependencies are constructor-injected, the facade remains a thin orchestration object. The platform layer decides how to instantiate concrete delegates, while tests can verify forwarding without platform channels.
Sources: in_app_webview_controller.dart, in_app_webview_controller_delegates_test.dart
Navigation Facade: URL and History Control
Section titled “Navigation Facade: URL and History Control”Navigation is the most state-sensitive domain because it changes page context and user-visible history. The facade exposes a compact set of operations and forwards each directly to the navigation delegate. There is no hidden policy in the facade; policy lives in the delegate or platform controller.
| Facade Method | Delegate Target | Operational Meaning |
|---|---|---|
loadUrl |
loadUrl |
Start a new navigation |
loadData |
loadData |
Render in-memory content |
loadFile |
loadFile |
Load a local asset |
postUrl |
postUrl |
Submit form-like data |
goBack / goForward |
same | Traverse history |
reload / stopLoading |
same | Control active load |
goToHistory |
same | Jump to history entry |
This separation is useful when diagnosing navigation bugs: if history or URL transitions misbehave, inspect the navigation delegate and native handler rather than the facade. The facade is intentionally transparent.
Sources: in_app_webview_controller.dart, in_app_webview_controller_delegates_test.dart
JavaScript Facade: Execution and Injection
Section titled “JavaScript Facade: Execution and Injection”The JavaScript domain covers both immediate evaluation and longer-lived script management. The facade groups these methods so callers can reason about script behavior as one capability, while the delegate handles runtime details and platform bridging.
| Facade Method | Delegate Target | Use Case |
|---|---|---|
evaluateJavascript |
evaluateJavascript |
One-shot script result |
callAsyncJavaScript |
callAsyncJavaScript |
Promise-like callback flow |
injectDeferredJavascript |
injectDeferredJavascript |
Deferred injection |
add/removeUserScript |
same | Manage persistent scripts |
hasUserScript |
same | Inspect script registration |
The behavioral tests show the facade forwards arguments unchanged and returns delegate results directly. That means JavaScript semantics, error propagation, and user-script lifecycle remain in the delegate and platform layer, not in the facade.
Sources: in_app_webview_controller.dart, domain_controllers_js_behavioral_test.dart
Cookies and Settings Facades: State and Preferences
Section titled “Cookies and Settings Facades: State and Preferences”Cookies and settings are smaller facades but follow the same rule: delegate calls only. Cookie operations are grouped to keep session and persistence behavior cohesive. Settings operations are grouped to keep runtime preference changes explicit and observable.
| Domain | Representative Facade Methods | Delegate Responsibility |
|---|---|---|
| Cookies | getCookies, setCookie, deleteCookie, deleteCookies |
Cookie store interaction |
| Settings | getSettings, setSettings, getOptions, setOptions |
Preference access and mutation |
This grouping improves traceability. A cookie defect can be isolated to the cookie delegate and platform cookie manager; a settings defect can be isolated to the settings delegate and native settings bridge. The facade remains a stable lookup point.
Sources: in_app_webview_controller.dart, domain_controllers_cookie_behavioral_test.dart
Platform Consumption Pattern
Section titled “Platform Consumption Pattern”Native-facing controllers receive the same domain interfaces and route work to the appropriate internal manager. On Android, for example, navigation and settings are split across dedicated managers, while JavaScript and cookie concerns are handled through controller-level helpers and cookie manager calls. This demonstrates that the facade boundary is not only a Dart convenience; it is an architectural contract used across the stack.
sequenceDiagram participant Caller participant Facade participant Delegate participant Platform Caller->>Facade: loadUrl(request) Facade->>Delegate: loadUrl(request) Delegate->>Platform: navigate(...) Platform-->>Caller: result / eventsThe sequence is consistent across domains: caller intent enters the facade, the facade selects the domain delegate, and the delegate performs platform work. This predictability is what makes the split valuable for maintenance and extension.
Sources: in_app_webview_controller.dart, in_app_webview_controller.dart
Design Takeaways
Section titled “Design Takeaways”The domain-controller facade is best understood as a contract-preserving router. It keeps the public controller surface coherent, enforces explicit dependencies, and isolates domain behavior into testable units. When extending ZikZak, preserve this pattern: add behavior to the relevant delegate and platform manager, not to the facade.
Sources: in_app_webview_controller.dart, in_app_webview_controller_delegates_test.dart
Next Steps
Section titled “Next Steps”Continue with Zorphy Entity Model Layer and Code Generation to see how model types support these controller contracts, then move to InAppWebView Widget and InAppWebViewController for the public API surface. For lifecycle concerns, read Disposal Lifecycle and KeepAlive Patterns.