ArmorWebViewPolicy class

Keeps an in-app WebView on your own sites.

The page may only move to allowedHosts (and their subdomains) over HTTPS. Other https, mailto and tel links should open outside the app, so a link in a chat or ad can't load a look-alike login page inside it. Anything else is blocked.

With webview_flutter:

final policy = ArmorWebViewPolicy(allowedHosts: ['support.example.com']);
NavigationDelegate(onNavigationRequest: (r) {
  switch (policy.decide(r.url, isMainFrame: r.isMainFrame)) {
    case ArmorNavigation.allow: return NavigationDecision.navigate;
    case ArmorNavigation.openExternally: launchUrl(Uri.parse(r.url));
    case ArmorNavigation.block: break;
  }
  return NavigationDecision.prevent;
});

Constructors

ArmorWebViewPolicy({required Iterable<String> allowedHosts, bool allowSubdomains = true, Set<String> externalSchemes = const {'https', 'mailto', 'tel'}})
ArmorWebViewPolicy.forSite(String url)
Allows url's registrable domain, e.g. https://help.example.com allows example.com and its subdomains.
factory

Properties

allowedHosts → Set<String>
final
allowSubdomains → bool
final
externalSchemes → Set<String>
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

decide(String url, {bool isMainFrame = true}) → ArmorNavigation
Frames inside the page (chat widgets, embeds) are allowed; only moving the whole page is checked.
isAllowed(Uri uri) → bool
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited