2019-10-28 03:58:25 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
import 'types.dart';
|
2019-10-26 20:11:23 +00:00
|
|
|
import 'package:flutter_inappbrowser/src/content_blocker.dart';
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class AndroidOptions {}
|
|
|
|
class iOSOptions {}
|
|
|
|
|
2019-10-26 20:11:23 +00:00
|
|
|
class WebViewOptions {
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 03:35:05 +00:00
|
|
|
class BrowserOptions {
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class InAppWebViewOptions implements WebViewOptions, BrowserOptions, AndroidOptions, iOSOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool useShouldOverrideUrlLoading;
|
|
|
|
bool useOnLoadResource;
|
|
|
|
bool useOnDownloadStart;
|
|
|
|
bool useOnTargetBlank;
|
|
|
|
bool clearCache;
|
|
|
|
String userAgent;
|
|
|
|
bool javaScriptEnabled;
|
2019-10-29 16:51:55 +00:00
|
|
|
bool debuggingEnabled;
|
2019-10-26 20:11:23 +00:00
|
|
|
bool javaScriptCanOpenWindowsAutomatically;
|
|
|
|
bool mediaPlaybackRequiresUserGesture;
|
|
|
|
int textZoom;
|
2019-10-28 03:58:25 +00:00
|
|
|
int minimumFontSize;
|
2019-10-26 20:11:23 +00:00
|
|
|
bool verticalScrollBarEnabled;
|
|
|
|
bool horizontalScrollBarEnabled;
|
|
|
|
List<String> resourceCustomSchemes;
|
|
|
|
List<ContentBlocker> contentBlockers;
|
2019-10-31 22:09:54 +00:00
|
|
|
InAppWebViewUserPreferredContentMode preferredContentMode;
|
2019-10-26 20:11:23 +00:00
|
|
|
|
|
|
|
InAppWebViewOptions({this.useShouldOverrideUrlLoading = false, this.useOnLoadResource = false, this.useOnDownloadStart = false, this.useOnTargetBlank = false,
|
2019-10-29 16:51:55 +00:00
|
|
|
this.clearCache = false, this.userAgent = "", this.javaScriptEnabled = true, this.debuggingEnabled = false, this.javaScriptCanOpenWindowsAutomatically = false,
|
2019-10-28 03:58:25 +00:00
|
|
|
this.mediaPlaybackRequiresUserGesture = true, this.textZoom = 100, this.minimumFontSize, this.verticalScrollBarEnabled = true, this.horizontalScrollBarEnabled = true,
|
2019-10-31 22:09:54 +00:00
|
|
|
this.resourceCustomSchemes = const [], this.contentBlockers = const [], this.preferredContentMode = InAppWebViewUserPreferredContentMode.RECOMMENDED}) {
|
2019-10-28 03:58:25 +00:00
|
|
|
if (this.minimumFontSize == null)
|
|
|
|
this.minimumFontSize = Platform.isAndroid ? 8 : 0;
|
|
|
|
}
|
2019-10-26 20:11:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
List<Map<String, Map<String, dynamic>>> contentBlockersMapList = [];
|
|
|
|
contentBlockers.forEach((contentBlocker) {
|
|
|
|
contentBlockersMapList.add(contentBlocker.toMap());
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
"useShouldOverrideUrlLoading": useShouldOverrideUrlLoading,
|
|
|
|
"useOnLoadResource": useOnLoadResource,
|
|
|
|
"useOnDownloadStart": useOnDownloadStart,
|
|
|
|
"useOnTargetBlank": useOnTargetBlank,
|
|
|
|
"clearCache": clearCache,
|
|
|
|
"userAgent": userAgent,
|
|
|
|
"javaScriptEnabled": javaScriptEnabled,
|
|
|
|
"javaScriptCanOpenWindowsAutomatically": javaScriptCanOpenWindowsAutomatically,
|
|
|
|
"mediaPlaybackRequiresUserGesture": mediaPlaybackRequiresUserGesture,
|
|
|
|
"textZoom": textZoom,
|
|
|
|
"verticalScrollBarEnabled": verticalScrollBarEnabled,
|
|
|
|
"horizontalScrollBarEnabled": horizontalScrollBarEnabled,
|
|
|
|
"resourceCustomSchemes": resourceCustomSchemes,
|
|
|
|
"contentBlockers": contentBlockersMapList,
|
2019-10-31 22:09:54 +00:00
|
|
|
"preferredContentMode": preferredContentMode?.toValue()
|
2019-10-26 20:11:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class AndroidInAppWebViewOptions implements WebViewOptions, BrowserOptions, AndroidOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool clearSessionCache;
|
|
|
|
bool builtInZoomControls;
|
|
|
|
bool displayZoomControls;
|
|
|
|
bool supportZoom;
|
|
|
|
bool databaseEnabled;
|
|
|
|
bool domStorageEnabled;
|
|
|
|
bool useWideViewPort;
|
|
|
|
bool safeBrowsingEnabled;
|
|
|
|
bool transparentBackground;
|
2019-10-28 03:58:25 +00:00
|
|
|
AndroidInAppWebViewMixedContentMode mixedContentMode;
|
|
|
|
bool allowContentAccess;
|
|
|
|
bool allowFileAccess;
|
|
|
|
bool allowFileAccessFromFileURLs;
|
|
|
|
bool allowUniversalAccessFromFileURLs;
|
|
|
|
bool appCacheEnabled;
|
|
|
|
String appCachePath;
|
|
|
|
bool blockNetworkImage;
|
|
|
|
bool blockNetworkLoads;
|
|
|
|
AndroidInAppWebViewCacheMode cacheMode;
|
|
|
|
String cursiveFontFamily;
|
|
|
|
int defaultFixedFontSize;
|
|
|
|
int defaultFontSize;
|
|
|
|
String defaultTextEncodingName;
|
|
|
|
AndroidInAppWebViewModeMenuItem disabledActionModeMenuItems;
|
|
|
|
String fantasyFontFamily;
|
|
|
|
String fixedFontFamily;
|
|
|
|
AndroidInAppWebViewForceDark forceDark;
|
|
|
|
bool geolocationEnabled;
|
|
|
|
AndroidInAppWebViewLayoutAlgorithm layoutAlgorithm;
|
|
|
|
bool loadWithOverviewMode;
|
|
|
|
bool loadsImagesAutomatically;
|
|
|
|
int minimumLogicalFontSize;
|
|
|
|
bool needInitialFocus;
|
|
|
|
bool offscreenPreRaster;
|
|
|
|
String sansSerifFontFamily;
|
|
|
|
String serifFontFamily;
|
|
|
|
String standardFontFamily;
|
2019-10-26 20:11:23 +00:00
|
|
|
|
|
|
|
AndroidInAppWebViewOptions({this.clearSessionCache = false, this.builtInZoomControls = false, this.displayZoomControls = false, this.supportZoom = true, this.databaseEnabled = false,
|
2019-10-28 03:58:25 +00:00
|
|
|
this.domStorageEnabled = false, this.useWideViewPort = true, this.safeBrowsingEnabled = true, this.transparentBackground = false, this.mixedContentMode,
|
|
|
|
this.allowContentAccess = true, this.allowFileAccess = true, this.allowFileAccessFromFileURLs = true, this.allowUniversalAccessFromFileURLs = true,
|
|
|
|
this.appCacheEnabled = true, this.appCachePath, this.blockNetworkImage = false, this.blockNetworkLoads = false, this.cacheMode = AndroidInAppWebViewCacheMode.LOAD_DEFAULT,
|
|
|
|
this.cursiveFontFamily = "cursive", this.defaultFixedFontSize = 16, this.defaultFontSize = 16, this.defaultTextEncodingName = "UTF-8",
|
|
|
|
this.disabledActionModeMenuItems, this.fantasyFontFamily = "fantasy", this.fixedFontFamily = "monospace", this.forceDark = AndroidInAppWebViewForceDark.FORCE_DARK_OFF,
|
|
|
|
this.geolocationEnabled = true, this.layoutAlgorithm, this.loadWithOverviewMode = true, this.loadsImagesAutomatically = true,
|
|
|
|
this.minimumLogicalFontSize = 8, this.needInitialFocus = true, this.offscreenPreRaster = false, this.sansSerifFontFamily = "sans-serif", this.serifFontFamily = "sans-serif",
|
|
|
|
this.standardFontFamily = "sans-serif"
|
|
|
|
});
|
2019-10-26 20:11:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"clearSessionCache": clearSessionCache,
|
|
|
|
"builtInZoomControls": builtInZoomControls,
|
|
|
|
"displayZoomControls": displayZoomControls,
|
|
|
|
"supportZoom": supportZoom,
|
|
|
|
"databaseEnabled": databaseEnabled,
|
|
|
|
"domStorageEnabled": domStorageEnabled,
|
|
|
|
"useWideViewPort": useWideViewPort,
|
|
|
|
"safeBrowsingEnabled": safeBrowsingEnabled,
|
|
|
|
"transparentBackground": transparentBackground,
|
2019-10-28 03:58:25 +00:00
|
|
|
"mixedContentMode": mixedContentMode?.toValue(),
|
|
|
|
"allowContentAccess": allowContentAccess,
|
|
|
|
"allowFileAccess": allowFileAccess,
|
|
|
|
"allowFileAccessFromFileURLs": allowFileAccessFromFileURLs,
|
|
|
|
"allowUniversalAccessFromFileURLs": allowUniversalAccessFromFileURLs,
|
|
|
|
"appCacheEnabled": appCacheEnabled,
|
|
|
|
"appCachePath": appCachePath,
|
|
|
|
"blockNetworkImage": blockNetworkImage,
|
|
|
|
"blockNetworkLoads": blockNetworkLoads,
|
|
|
|
"cacheMode": cacheMode?.toValue(),
|
|
|
|
"cursiveFontFamily": cursiveFontFamily,
|
|
|
|
"defaultFixedFontSize": defaultFixedFontSize,
|
|
|
|
"defaultFontSize": defaultFontSize,
|
|
|
|
"defaultTextEncodingName": defaultTextEncodingName,
|
|
|
|
"disabledActionModeMenuItems": disabledActionModeMenuItems?.toValue(),
|
|
|
|
"fantasyFontFamily": fantasyFontFamily,
|
|
|
|
"fixedFontFamily": fixedFontFamily,
|
|
|
|
"forceDark": forceDark?.toValue(),
|
|
|
|
"geolocationEnabled": geolocationEnabled,
|
|
|
|
"layoutAlgorithm": layoutAlgorithm?.toValue(),
|
|
|
|
"loadWithOverviewMode": loadWithOverviewMode,
|
|
|
|
"loadsImagesAutomatically": loadsImagesAutomatically,
|
|
|
|
"minimumLogicalFontSize": minimumLogicalFontSize,
|
|
|
|
"needInitialFocus": needInitialFocus,
|
|
|
|
"offscreenPreRaster": offscreenPreRaster,
|
|
|
|
"sansSerifFontFamily": sansSerifFontFamily,
|
|
|
|
"serifFontFamily": serifFontFamily,
|
|
|
|
"standardFontFamily": standardFontFamily
|
2019-10-26 20:11:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class iOSInAppWebViewOptions implements WebViewOptions, BrowserOptions, iOSOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool disallowOverScroll;
|
|
|
|
bool enableViewportScale;
|
|
|
|
bool suppressesIncrementalRendering;
|
|
|
|
bool allowsAirPlayForMediaPlayback;
|
|
|
|
bool allowsBackForwardNavigationGestures;
|
|
|
|
bool allowsLinkPreview;
|
|
|
|
bool ignoresViewportScaleLimits;
|
|
|
|
bool allowsInlineMediaPlayback;
|
|
|
|
bool allowsPictureInPictureMediaPlayback;
|
|
|
|
bool transparentBackground;
|
2019-10-28 03:58:25 +00:00
|
|
|
String applicationNameForUserAgent;
|
|
|
|
bool isFraudulentWebsiteWarningEnabled;
|
|
|
|
iOSInAppWebViewSelectionGranularity selectionGranularity;
|
|
|
|
List<iOSInAppWebViewDataDetectorTypes> dataDetectorTypes;
|
|
|
|
|
2019-10-26 20:11:23 +00:00
|
|
|
iOSInAppWebViewOptions({this.disallowOverScroll = false, this.enableViewportScale = false, this.suppressesIncrementalRendering = false, this.allowsAirPlayForMediaPlayback = true,
|
|
|
|
this.allowsBackForwardNavigationGestures = true, this.allowsLinkPreview = true, this.ignoresViewportScaleLimits = false, this.allowsInlineMediaPlayback = false,
|
2019-10-28 03:58:25 +00:00
|
|
|
this.allowsPictureInPictureMediaPlayback = true, this.transparentBackground = false, this.applicationNameForUserAgent = "", this.isFraudulentWebsiteWarningEnabled = true,
|
2019-10-31 22:09:54 +00:00
|
|
|
this.selectionGranularity = iOSInAppWebViewSelectionGranularity.DYNAMIC, this.dataDetectorTypes = const [iOSInAppWebViewDataDetectorTypes.NONE]
|
2019-10-28 03:58:25 +00:00
|
|
|
});
|
2019-10-26 20:11:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
2019-10-28 03:58:25 +00:00
|
|
|
List<String> dataDetectorTypesList = [];
|
|
|
|
dataDetectorTypes.forEach((dataDetectorType) {
|
|
|
|
dataDetectorTypesList.add(dataDetectorType.toValue());
|
|
|
|
});
|
|
|
|
|
2019-10-26 20:11:23 +00:00
|
|
|
return {
|
|
|
|
"disallowOverScroll": disallowOverScroll,
|
|
|
|
"enableViewportScale": enableViewportScale,
|
|
|
|
"suppressesIncrementalRendering": suppressesIncrementalRendering,
|
|
|
|
"allowsAirPlayForMediaPlayback": allowsAirPlayForMediaPlayback,
|
|
|
|
"allowsBackForwardNavigationGestures": allowsBackForwardNavigationGestures,
|
|
|
|
"allowsLinkPreview": allowsLinkPreview,
|
|
|
|
"ignoresViewportScaleLimits": ignoresViewportScaleLimits,
|
|
|
|
"allowsInlineMediaPlayback": allowsInlineMediaPlayback,
|
|
|
|
"allowsPictureInPictureMediaPlayback": allowsPictureInPictureMediaPlayback,
|
|
|
|
"transparentBackground": transparentBackground,
|
2019-10-28 03:58:25 +00:00
|
|
|
"applicationNameForUserAgent": applicationNameForUserAgent,
|
|
|
|
"isFraudulentWebsiteWarningEnabled": isFraudulentWebsiteWarningEnabled,
|
|
|
|
"selectionGranularity": selectionGranularity.toValue(),
|
2019-10-31 22:09:54 +00:00
|
|
|
"dataDetectorTypes": dataDetectorTypesList
|
2019-10-26 20:11:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class InAppBrowserOptions implements BrowserOptions, AndroidOptions, iOSOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool hidden;
|
|
|
|
bool toolbarTop;
|
|
|
|
String toolbarTopBackgroundColor;
|
|
|
|
String toolbarTopFixedTitle;
|
|
|
|
bool hideUrlBar;
|
|
|
|
|
|
|
|
InAppBrowserOptions({this.hidden = false, this.toolbarTop = true, this.toolbarTopBackgroundColor = "", this.toolbarTopFixedTitle = "", this.hideUrlBar = false});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"hidden": hidden,
|
|
|
|
"toolbarTop": toolbarTop,
|
|
|
|
"toolbarTopBackgroundColor": toolbarTopBackgroundColor,
|
|
|
|
"toolbarTopFixedTitle": toolbarTopFixedTitle,
|
|
|
|
"hideUrlBar": hideUrlBar,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class AndroidInAppBrowserOptions implements BrowserOptions, AndroidOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool hideTitleBar;
|
|
|
|
bool closeOnCannotGoBack;
|
|
|
|
bool progressBar;
|
|
|
|
|
|
|
|
AndroidInAppBrowserOptions({this.hideTitleBar = true, this.closeOnCannotGoBack = true, this.progressBar = true});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"hideTitleBar": hideTitleBar,
|
|
|
|
"closeOnCannotGoBack": closeOnCannotGoBack,
|
|
|
|
"progressBar": progressBar,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class iOSInAppBrowserOptions implements BrowserOptions, iOSOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool toolbarBottom;
|
|
|
|
String toolbarBottomBackgroundColor;
|
|
|
|
bool toolbarBottomTranslucent;
|
|
|
|
String closeButtonCaption;
|
|
|
|
String closeButtonColor;
|
2019-10-31 02:20:07 +00:00
|
|
|
iOSWebViewOptionsPresentationStyle presentationStyle;
|
|
|
|
iOSWebViewOptionsTransitionStyle transitionStyle;
|
2019-10-26 20:11:23 +00:00
|
|
|
bool spinner;
|
|
|
|
|
|
|
|
iOSInAppBrowserOptions({this.toolbarBottom = true, this.toolbarBottomBackgroundColor = "", this.toolbarBottomTranslucent = true, this.closeButtonCaption = "",
|
2019-10-31 02:20:07 +00:00
|
|
|
this.closeButtonColor = "", this.presentationStyle = iOSWebViewOptionsPresentationStyle.FULL_SCREEN,
|
|
|
|
this.transitionStyle = iOSWebViewOptionsTransitionStyle.COVER_VERTICAL, this.spinner = true});
|
2019-10-26 20:11:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"toolbarBottom": toolbarBottom,
|
|
|
|
"toolbarBottomBackgroundColor": toolbarBottomBackgroundColor,
|
|
|
|
"toolbarBottomTranslucent": toolbarBottomTranslucent,
|
|
|
|
"closeButtonCaption": closeButtonCaption,
|
|
|
|
"closeButtonColor": closeButtonColor,
|
2019-10-29 14:27:50 +00:00
|
|
|
"presentationStyle": presentationStyle.toValue(),
|
|
|
|
"transitionStyle": transitionStyle.toValue(),
|
2019-10-26 20:11:23 +00:00
|
|
|
"spinner": spinner,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class ChromeSafariBrowserOptions {
|
2019-10-27 03:35:05 +00:00
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class AndroidChromeCustomTabsOptions implements ChromeSafariBrowserOptions, AndroidOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool addShareButton;
|
|
|
|
bool showTitle;
|
|
|
|
String toolbarBackgroundColor;
|
|
|
|
bool enableUrlBarHiding;
|
|
|
|
bool instantAppsEnabled;
|
|
|
|
|
|
|
|
AndroidChromeCustomTabsOptions({this.addShareButton = true, this.showTitle = true, this.toolbarBackgroundColor = "", this.enableUrlBarHiding = false, this.instantAppsEnabled = false});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"addShareButton": addShareButton,
|
|
|
|
"showTitle": showTitle,
|
|
|
|
"toolbarBackgroundColor": toolbarBackgroundColor,
|
|
|
|
"enableUrlBarHiding": enableUrlBarHiding,
|
|
|
|
"instantAppsEnabled": instantAppsEnabled,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
class iOSSafariOptions implements ChromeSafariBrowserOptions, iOSOptions {
|
2019-10-26 20:11:23 +00:00
|
|
|
bool entersReaderIfAvailable;
|
|
|
|
bool barCollapsingEnabled;
|
2019-10-31 02:20:07 +00:00
|
|
|
iOSSafariOptionsDismissButtonStyle dismissButtonStyle;
|
2019-10-26 20:11:23 +00:00
|
|
|
String preferredBarTintColor;
|
|
|
|
String preferredControlTintColor;
|
2019-10-31 02:20:07 +00:00
|
|
|
iOSWebViewOptionsPresentationStyle presentationStyle;
|
|
|
|
iOSWebViewOptionsTransitionStyle transitionStyle;
|
2019-10-26 20:11:23 +00:00
|
|
|
|
2019-10-31 02:20:07 +00:00
|
|
|
iOSSafariOptions({this.entersReaderIfAvailable = false, this.barCollapsingEnabled = false, this.dismissButtonStyle = iOSSafariOptionsDismissButtonStyle.DONE,
|
|
|
|
this.preferredBarTintColor = "", this.preferredControlTintColor = "", this.presentationStyle = iOSWebViewOptionsPresentationStyle.FULL_SCREEN,
|
|
|
|
this.transitionStyle = iOSWebViewOptionsTransitionStyle.COVER_VERTICAL});
|
2019-10-26 20:11:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"entersReaderIfAvailable": entersReaderIfAvailable,
|
|
|
|
"barCollapsingEnabled": barCollapsingEnabled,
|
2019-10-29 14:27:50 +00:00
|
|
|
"dismissButtonStyle": dismissButtonStyle.toValue(),
|
2019-10-26 20:11:23 +00:00
|
|
|
"preferredBarTintColor": preferredBarTintColor,
|
|
|
|
"preferredControlTintColor": preferredControlTintColor,
|
2019-10-29 14:27:50 +00:00
|
|
|
"presentationStyle": presentationStyle.toValue(),
|
|
|
|
"transitionStyle": transitionStyle.toValue(),
|
2019-10-26 20:11:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|