From a866cd6b24f5c2a69035c1cebb2a49bbb2c8931a Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Wed, 20 Apr 2022 01:30:45 +0200 Subject: [PATCH] initial refactor --- .../{Options.java => IWebViewSettings.java} | 0 ...Options.java => InAppBrowserSettings.java} | 4 +- ...Options.java => InAppWebViewSettings.java} | 0 .../pull_to_refresh/PullToRefreshOptions.java | 6 +- .../{Options.swift => IWebViewSettings.swift} | 4 +- ...tions.swift => InAppBrowserSettings.swift} | 2 +- .../InAppWebView/InAppWebViewOptions.swift | 139 --- .../InAppWebView/InAppWebViewSettings.swift | 139 +++ ...ions.swift => PullToRefreshSettings.swift} | 6 +- .../android/in_app_browser_options.dart | 18 +- ...ions.dart => in_app_browser_settings.dart} | 163 +++- .../ios/in_app_browser_options.dart | 28 +- .../android/in_app_webview_options.dart | 126 ++- .../in_app_webview_options.dart | 340 ------- .../in_app_webview_settings.dart | 867 ++++++++++++++++++ .../ios/in_app_webview_options.dart | 75 +- 16 files changed, 1299 insertions(+), 618 deletions(-) rename android/src/main/java/com/pichillilorenzo/flutter_inappwebview/{Options.java => IWebViewSettings.java} (100%) rename android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/{InAppBrowserOptions.java => InAppBrowserSettings.java} (95%) rename android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/{InAppWebViewOptions.java => InAppWebViewSettings.java} (100%) rename ios/Classes/{Options.swift => IWebViewSettings.swift} (90%) rename ios/Classes/InAppBrowser/{InAppBrowserOptions.swift => InAppBrowserSettings.swift} (97%) delete mode 100755 ios/Classes/InAppWebView/InAppWebViewOptions.swift create mode 100755 ios/Classes/InAppWebView/InAppWebViewSettings.swift rename ios/Classes/PullToRefresh/{PullToRefreshOptions.swift => PullToRefreshSettings.swift} (79%) rename lib/src/in_app_browser/{in_app_browser_options.dart => in_app_browser_settings.dart} (55%) delete mode 100755 lib/src/in_app_webview/in_app_webview_options.dart create mode 100755 lib/src/in_app_webview/in_app_webview_settings.dart diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Options.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/IWebViewSettings.java similarity index 100% rename from android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Options.java rename to android/src/main/java/com/pichillilorenzo/flutter_inappwebview/IWebViewSettings.java diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserSettings.java similarity index 95% rename from android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserOptions.java rename to android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserSettings.java index 99cf5216..bc75a513 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserSettings.java @@ -2,13 +2,13 @@ package com.pichillilorenzo.flutter_inappwebview.in_app_browser; import androidx.annotation.Nullable; -import com.pichillilorenzo.flutter_inappwebview.Options; +import com.pichillilorenzo.flutter_inappwebview.IWebViewSettings; import com.pichillilorenzo.flutter_inappwebview.R; import java.util.HashMap; import java.util.Map; -public class InAppBrowserOptions implements Options { +public class InAppBrowserOptions implements IWebViewSettings { public static final String LOG_TAG = "InAppBrowserOptions"; diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java similarity index 100% rename from android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewOptions.java rename to android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshOptions.java index 81d3af99..20d47e5b 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshOptions.java @@ -2,12 +2,12 @@ package com.pichillilorenzo.flutter_inappwebview.pull_to_refresh; import androidx.annotation.Nullable; -import com.pichillilorenzo.flutter_inappwebview.Options; +import com.pichillilorenzo.flutter_inappwebview.IWebViewSettings; import java.util.HashMap; import java.util.Map; -public class PullToRefreshOptions implements Options { +public class PullToRefreshOptions implements IWebViewSettings { public static final String LOG_TAG = "PullToRefreshOptions"; public Boolean enabled = true; @@ -67,7 +67,7 @@ public class PullToRefreshOptions implements Options { } @Override - public Map getRealOptions(PullToRefreshLayout pullToRefreshLayout) { + public Map getRealSettings(PullToRefreshLayout pullToRefreshLayout) { Map realOptions = toMap(); return realOptions; } diff --git a/ios/Classes/Options.swift b/ios/Classes/IWebViewSettings.swift similarity index 90% rename from ios/Classes/Options.swift rename to ios/Classes/IWebViewSettings.swift index 46ecf21c..85fbf1c5 100755 --- a/ios/Classes/Options.swift +++ b/ios/Classes/IWebViewSettings.swift @@ -8,13 +8,13 @@ import Foundation @objcMembers -public class Options: NSObject { +public class IWebViewSettings: NSObject { override init(){ super.init() } - func parse(options: [String: Any?]) -> Options { + func parse(options: [String: Any?]) -> IWebViewSettings { for (key, value) in options { if !(value is NSNull), value != nil, self.responds(to: Selector(key)) { self.setValue(value, forKey: key) diff --git a/ios/Classes/InAppBrowser/InAppBrowserOptions.swift b/ios/Classes/InAppBrowser/InAppBrowserSettings.swift similarity index 97% rename from ios/Classes/InAppBrowser/InAppBrowserOptions.swift rename to ios/Classes/InAppBrowser/InAppBrowserSettings.swift index 4f475430..19d76c3e 100755 --- a/ios/Classes/InAppBrowser/InAppBrowserOptions.swift +++ b/ios/Classes/InAppBrowser/InAppBrowserSettings.swift @@ -8,7 +8,7 @@ import Foundation @objcMembers -public class InAppBrowserOptions: Options { +public class InAppBrowserSettings: Options { var hidden = false var hideToolbarTop = true diff --git a/ios/Classes/InAppWebView/InAppWebViewOptions.swift b/ios/Classes/InAppWebView/InAppWebViewOptions.swift deleted file mode 100755 index fcb3f009..00000000 --- a/ios/Classes/InAppWebView/InAppWebViewOptions.swift +++ /dev/null @@ -1,139 +0,0 @@ -// -// InAppWebViewOptions.swift -// flutter_inappwebview -// -// Created by Lorenzo on 21/10/18. -// - -import Foundation -import WebKit - -@objcMembers -public class InAppWebViewOptions: Options { - - var useShouldOverrideUrlLoading = false - var useOnLoadResource = false - var useOnDownloadStart = false - var clearCache = false - var userAgent = "" - var applicationNameForUserAgent = "" - var javaScriptEnabled = true - var javaScriptCanOpenWindowsAutomatically = false - var mediaPlaybackRequiresUserGesture = true - var verticalScrollBarEnabled = true - var horizontalScrollBarEnabled = true - var resourceCustomSchemes: [String] = [] - var contentBlockers: [[String: [String : Any]]] = [] - var minimumFontSize = 0 - var useShouldInterceptAjaxRequest = false - var useShouldInterceptFetchRequest = false - var incognito = false - var cacheEnabled = true - var transparentBackground = false - var disableVerticalScroll = false - var disableHorizontalScroll = false - var disableContextMenu = false - var supportZoom = true - var allowUniversalAccessFromFileURLs = false - var allowFileAccessFromFileURLs = false - - var disallowOverScroll = false - var enableViewportScale = false - var suppressesIncrementalRendering = false - var allowsAirPlayForMediaPlayback = true - var allowsBackForwardNavigationGestures = true - var allowsLinkPreview = true - var ignoresViewportScaleLimits = false - var allowsInlineMediaPlayback = false - var allowsPictureInPictureMediaPlayback = true - var isFraudulentWebsiteWarningEnabled = true; - var selectionGranularity = 0; - var dataDetectorTypes: [String] = ["NONE"] // WKDataDetectorTypeNone - var preferredContentMode = 0 - var sharedCookiesEnabled = false - var automaticallyAdjustsScrollIndicatorInsets = false - var accessibilityIgnoresInvertColors = false - var decelerationRate = "NORMAL" // UIScrollView.DecelerationRate.normal - var alwaysBounceVertical = false - var alwaysBounceHorizontal = false - var scrollsToTop = true - var isPagingEnabled = false - var maximumZoomScale = 1.0 - var minimumZoomScale = 1.0 - var contentInsetAdjustmentBehavior = 2 // UIScrollView.ContentInsetAdjustmentBehavior.never - var isDirectionalLockEnabled = false - var mediaType: String? = nil - var pageZoom = 1.0 - var limitsNavigationsToAppBoundDomains = false - var useOnNavigationResponse = false - var applePayAPIEnabled = false - var allowingReadAccessTo: String? = nil - var disableLongPressContextMenuOnLinks = false - var disableInputAccessoryView = false - - override init(){ - super.init() - } - - override func parse(options: [String: Any?]) -> InAppWebViewOptions { - let _ = super.parse(options: options) - if #available(iOS 13.0, *) {} else { - applePayAPIEnabled = false - } - return self - } - - override func getRealOptions(obj: InAppWebView?) -> [String: Any?] { - var realOptions: [String: Any?] = toMap() - if let webView = obj { - let configuration = webView.configuration - if #available(iOS 9.0, *) { - realOptions["userAgent"] = webView.customUserAgent - realOptions["applicationNameForUserAgent"] = configuration.applicationNameForUserAgent - realOptions["allowsAirPlayForMediaPlayback"] = configuration.allowsAirPlayForMediaPlayback - realOptions["allowsLinkPreview"] = webView.allowsLinkPreview - realOptions["allowsPictureInPictureMediaPlayback"] = configuration.allowsPictureInPictureMediaPlayback - } - realOptions["javaScriptCanOpenWindowsAutomatically"] = configuration.preferences.javaScriptCanOpenWindowsAutomatically - if #available(iOS 10.0, *) { - realOptions["mediaPlaybackRequiresUserGesture"] = configuration.mediaTypesRequiringUserActionForPlayback == .all - realOptions["ignoresViewportScaleLimits"] = configuration.ignoresViewportScaleLimits - realOptions["dataDetectorTypes"] = Util.getDataDetectorTypeString(type: configuration.dataDetectorTypes) - } else { - realOptions["mediaPlaybackRequiresUserGesture"] = configuration.mediaPlaybackRequiresUserAction - } - realOptions["minimumFontSize"] = configuration.preferences.minimumFontSize - realOptions["suppressesIncrementalRendering"] = configuration.suppressesIncrementalRendering - realOptions["allowsBackForwardNavigationGestures"] = webView.allowsBackForwardNavigationGestures - realOptions["allowsInlineMediaPlayback"] = configuration.allowsInlineMediaPlayback - if #available(iOS 13.0, *) { - realOptions["isFraudulentWebsiteWarningEnabled"] = configuration.preferences.isFraudulentWebsiteWarningEnabled - realOptions["preferredContentMode"] = configuration.defaultWebpagePreferences.preferredContentMode.rawValue - realOptions["automaticallyAdjustsScrollIndicatorInsets"] = webView.scrollView.automaticallyAdjustsScrollIndicatorInsets - } - realOptions["selectionGranularity"] = configuration.selectionGranularity.rawValue - if #available(iOS 11.0, *) { - realOptions["accessibilityIgnoresInvertColors"] = webView.accessibilityIgnoresInvertColors - realOptions["contentInsetAdjustmentBehavior"] = webView.scrollView.contentInsetAdjustmentBehavior.rawValue - } - realOptions["decelerationRate"] = Util.getDecelerationRateString(type: webView.scrollView.decelerationRate) - realOptions["alwaysBounceVertical"] = webView.scrollView.alwaysBounceVertical - realOptions["alwaysBounceHorizontal"] = webView.scrollView.alwaysBounceHorizontal - realOptions["scrollsToTop"] = webView.scrollView.scrollsToTop - realOptions["isPagingEnabled"] = webView.scrollView.isPagingEnabled - realOptions["maximumZoomScale"] = webView.scrollView.maximumZoomScale - realOptions["minimumZoomScale"] = webView.scrollView.minimumZoomScale - realOptions["allowUniversalAccessFromFileURLs"] = configuration.value(forKey: "allowUniversalAccessFromFileURLs") - realOptions["allowFileAccessFromFileURLs"] = configuration.preferences.value(forKey: "allowFileAccessFromFileURLs") - realOptions["isDirectionalLockEnabled"] = webView.scrollView.isDirectionalLockEnabled - realOptions["javaScriptEnabled"] = configuration.preferences.javaScriptEnabled - if #available(iOS 14.0, *) { - realOptions["mediaType"] = webView.mediaType - realOptions["pageZoom"] = Float(webView.pageZoom) - realOptions["limitsNavigationsToAppBoundDomains"] = configuration.limitsNavigationsToAppBoundDomains - realOptions["javaScriptEnabled"] = configuration.defaultWebpagePreferences.allowsContentJavaScript - } - } - return realOptions - } -} diff --git a/ios/Classes/InAppWebView/InAppWebViewSettings.swift b/ios/Classes/InAppWebView/InAppWebViewSettings.swift new file mode 100755 index 00000000..85c8b2de --- /dev/null +++ b/ios/Classes/InAppWebView/InAppWebViewSettings.swift @@ -0,0 +1,139 @@ +// +// InAppWebViewOptions.swift +// flutter_inappwebview +// +// Created by Lorenzo on 21/10/18. +// + +import Foundation +import WebKit + +@objcMembers +public class InAppWebViewSettings: IWebViewSettings { + + var useShouldOverrideUrlLoading = false + var useOnLoadResource = false + var useOnDownloadStart = false + var clearCache = false + var userAgent = "" + var applicationNameForUserAgent = "" + var javaScriptEnabled = true + var javaScriptCanOpenWindowsAutomatically = false + var mediaPlaybackRequiresUserGesture = true + var verticalScrollBarEnabled = true + var horizontalScrollBarEnabled = true + var resourceCustomSchemes: [String] = [] + var contentBlockers: [[String: [String : Any]]] = [] + var minimumFontSize = 0 + var useShouldInterceptAjaxRequest = false + var useShouldInterceptFetchRequest = false + var incognito = false + var cacheEnabled = true + var transparentBackground = false + var disableVerticalScroll = false + var disableHorizontalScroll = false + var disableContextMenu = false + var supportZoom = true + var allowUniversalAccessFromFileURLs = false + var allowFileAccessFromFileURLs = false + + var disallowOverScroll = false + var enableViewportScale = false + var suppressesIncrementalRendering = false + var allowsAirPlayForMediaPlayback = true + var allowsBackForwardNavigationGestures = true + var allowsLinkPreview = true + var ignoresViewportScaleLimits = false + var allowsInlineMediaPlayback = false + var allowsPictureInPictureMediaPlayback = true + var isFraudulentWebsiteWarningEnabled = true; + var selectionGranularity = 0; + var dataDetectorTypes: [String] = ["NONE"] // WKDataDetectorTypeNone + var preferredContentMode = 0 + var sharedCookiesEnabled = false + var automaticallyAdjustsScrollIndicatorInsets = false + var accessibilityIgnoresInvertColors = false + var decelerationRate = "NORMAL" // UIScrollView.DecelerationRate.normal + var alwaysBounceVertical = false + var alwaysBounceHorizontal = false + var scrollsToTop = true + var isPagingEnabled = false + var maximumZoomScale = 1.0 + var minimumZoomScale = 1.0 + var contentInsetAdjustmentBehavior = 2 // UIScrollView.ContentInsetAdjustmentBehavior.never + var isDirectionalLockEnabled = false + var mediaType: String? = nil + var pageZoom = 1.0 + var limitsNavigationsToAppBoundDomains = false + var useOnNavigationResponse = false + var applePayAPIEnabled = false + var allowingReadAccessTo: String? = nil + var disableLongPressContextMenuOnLinks = false + var disableInputAccessoryView = false + + override init(){ + super.init() + } + + override func parse(settings: [String: Any?]) -> InAppWebViewSettings { + let _ = super.parse(settings: settings) + if #available(iOS 13.0, *) {} else { + applePayAPIEnabled = false + } + return self + } + + override func getRealSettings(obj: InAppWebView?) -> [String: Any?] { + var realSettings: [String: Any?] = toMap() + if let webView = obj { + let configuration = webView.configuration + if #available(iOS 9.0, *) { + realSettings["userAgent"] = webView.customUserAgent + realSettings["applicationNameForUserAgent"] = configuration.applicationNameForUserAgent + realSettings["allowsAirPlayForMediaPlayback"] = configuration.allowsAirPlayForMediaPlayback + realSettings["allowsLinkPreview"] = webView.allowsLinkPreview + realSettings["allowsPictureInPictureMediaPlayback"] = configuration.allowsPictureInPictureMediaPlayback + } + realSettings["javaScriptCanOpenWindowsAutomatically"] = configuration.preferences.javaScriptCanOpenWindowsAutomatically + if #available(iOS 10.0, *) { + realSettings["mediaPlaybackRequiresUserGesture"] = configuration.mediaTypesRequiringUserActionForPlayback == .all + realSettings["ignoresViewportScaleLimits"] = configuration.ignoresViewportScaleLimits + realSettings["dataDetectorTypes"] = Util.getDataDetectorTypeString(type: configuration.dataDetectorTypes) + } else { + realSettings["mediaPlaybackRequiresUserGesture"] = configuration.mediaPlaybackRequiresUserAction + } + realSettings["minimumFontSize"] = configuration.preferences.minimumFontSize + realSettings["suppressesIncrementalRendering"] = configuration.suppressesIncrementalRendering + realSettings["allowsBackForwardNavigationGestures"] = webView.allowsBackForwardNavigationGestures + realSettings["allowsInlineMediaPlayback"] = configuration.allowsInlineMediaPlayback + if #available(iOS 13.0, *) { + realSettings["isFraudulentWebsiteWarningEnabled"] = configuration.preferences.isFraudulentWebsiteWarningEnabled + realSettings["preferredContentMode"] = configuration.defaultWebpagePreferences.preferredContentMode.rawValue + realSettings["automaticallyAdjustsScrollIndicatorInsets"] = webView.scrollView.automaticallyAdjustsScrollIndicatorInsets + } + realSettings["selectionGranularity"] = configuration.selectionGranularity.rawValue + if #available(iOS 11.0, *) { + realSettings["accessibilityIgnoresInvertColors"] = webView.accessibilityIgnoresInvertColors + realSettings["contentInsetAdjustmentBehavior"] = webView.scrollView.contentInsetAdjustmentBehavior.rawValue + } + realSettings["decelerationRate"] = Util.getDecelerationRateString(type: webView.scrollView.decelerationRate) + realSettings["alwaysBounceVertical"] = webView.scrollView.alwaysBounceVertical + realSettings["alwaysBounceHorizontal"] = webView.scrollView.alwaysBounceHorizontal + realSettings["scrollsToTop"] = webView.scrollView.scrollsToTop + realSettings["isPagingEnabled"] = webView.scrollView.isPagingEnabled + realSettings["maximumZoomScale"] = webView.scrollView.maximumZoomScale + realSettings["minimumZoomScale"] = webView.scrollView.minimumZoomScale + realSettings["allowUniversalAccessFromFileURLs"] = configuration.value(forKey: "allowUniversalAccessFromFileURLs") + realSettings["allowFileAccessFromFileURLs"] = configuration.preferences.value(forKey: "allowFileAccessFromFileURLs") + realSettings["isDirectionalLockEnabled"] = webView.scrollView.isDirectionalLockEnabled + realSettings["javaScriptEnabled"] = configuration.preferences.javaScriptEnabled + if #available(iOS 14.0, *) { + realSettings["mediaType"] = webView.mediaType + realSettings["pageZoom"] = Float(webView.pageZoom) + realSettings["limitsNavigationsToAppBoundDomains"] = configuration.limitsNavigationsToAppBoundDomains + realSettings["javaScriptEnabled"] = configuration.defaultWebpagePreferences.allowsContentJavaScript + } + } + return realSettings + } +} diff --git a/ios/Classes/PullToRefresh/PullToRefreshOptions.swift b/ios/Classes/PullToRefresh/PullToRefreshSettings.swift similarity index 79% rename from ios/Classes/PullToRefresh/PullToRefreshOptions.swift rename to ios/Classes/PullToRefresh/PullToRefreshSettings.swift index 58c3399a..9ea5687d 100644 --- a/ios/Classes/PullToRefresh/PullToRefreshOptions.swift +++ b/ios/Classes/PullToRefresh/PullToRefreshSettings.swift @@ -7,7 +7,7 @@ import Foundation -public class PullToRefreshOptions : Options { +public class PullToRefreshSettings : IWebViewSettings { var enabled = true var color: String? @@ -18,7 +18,7 @@ public class PullToRefreshOptions : Options { super.init() } - override func parse(options: [String: Any?]) -> PullToRefreshOptions { + override func parse(options: [String: Any?]) -> PullToRefreshSettings { let _ = super.parse(options: options) if let attributedTitle = options["attributedTitle"] as? [String: Any?] { self.attributedTitle = attributedTitle @@ -26,7 +26,7 @@ public class PullToRefreshOptions : Options { return self } - override func getRealOptions(obj: PullToRefreshControl?) -> [String: Any?] { + override func getRealSettings(obj: PullToRefreshControl?) -> [String: Any?] { let realOptions: [String: Any?] = toMap() return realOptions } diff --git a/lib/src/in_app_browser/android/in_app_browser_options.dart b/lib/src/in_app_browser/android/in_app_browser_options.dart index 4a99acc0..1ab5ba24 100755 --- a/lib/src/in_app_browser/android/in_app_browser_options.dart +++ b/lib/src/in_app_browser/android/in_app_browser_options.dart @@ -1,9 +1,11 @@ import '../../in_app_webview/android/in_app_webview_options.dart'; -import '../in_app_browser_options.dart'; +import '../in_app_browser_settings.dart'; import '../in_app_browser.dart'; ///This class represents all the Android-only [InAppBrowser] options available. +///Use [InAppBrowserSettings] instead. +@Deprecated('Use InAppBrowserSettings instead') class AndroidInAppBrowserOptions implements BrowserOptions, AndroidOptions { ///Set to `true` if you want the title should be displayed. The default value is `false`. bool hideTitleBar; @@ -39,14 +41,14 @@ class AndroidInAppBrowserOptions implements BrowserOptions, AndroidOptions { } static AndroidInAppBrowserOptions fromMap(Map map) { - AndroidInAppBrowserOptions options = AndroidInAppBrowserOptions(); - options.hideTitleBar = map["hideTitleBar"]; - options.toolbarTopFixedTitle = map["toolbarTopFixedTitle"]; - options.closeOnCannotGoBack = map["closeOnCannotGoBack"]; - options.allowGoBackWithBackButton = map["allowGoBackWithBackButton"]; - options.shouldCloseOnBackButtonPressed = + var instance = AndroidInAppBrowserOptions(); + instance.hideTitleBar = map["hideTitleBar"]; + instance.toolbarTopFixedTitle = map["toolbarTopFixedTitle"]; + instance.closeOnCannotGoBack = map["closeOnCannotGoBack"]; + instance.allowGoBackWithBackButton = map["allowGoBackWithBackButton"]; + instance.shouldCloseOnBackButtonPressed = map["shouldCloseOnBackButtonPressed"]; - return options; + return instance; } @override diff --git a/lib/src/in_app_browser/in_app_browser_options.dart b/lib/src/in_app_browser/in_app_browser_settings.dart similarity index 55% rename from lib/src/in_app_browser/in_app_browser_options.dart rename to lib/src/in_app_browser/in_app_browser_settings.dart index 5a9f8790..a559e303 100755 --- a/lib/src/in_app_browser/in_app_browser_options.dart +++ b/lib/src/in_app_browser/in_app_browser_settings.dart @@ -1,24 +1,29 @@ import 'dart:ui'; import 'package:flutter/foundation.dart'; +import 'package:flutter_inappwebview/src/types.dart'; import '../util.dart'; -import '../in_app_webview/in_app_webview_options.dart'; +import '../in_app_webview/in_app_webview_settings.dart'; import 'android/in_app_browser_options.dart'; -import '../in_app_webview/android/in_app_webview_options.dart'; +import '../in_app_webview/android/in_app_webview_settings.dart'; -import 'ios/in_app_browser_options.dart'; -import '../in_app_webview/ios/in_app_webview_options.dart'; +import 'ios/in_app_browser_settings.dart'; +import '../in_app_webview/ios/in_app_webview_settings.dart'; class BrowserOptions { Map toMap() { return {}; } - static BrowserOptions fromMap(Map map) { - return new BrowserOptions(); + static BrowserOptions fromMap(Map map, {BrowserOptions? instance}) { + return BrowserOptions(); + } + + static Map instanceToMap(BrowserOptions options) { + return options.toMap(); } BrowserOptions copy() { @@ -35,7 +40,153 @@ class BrowserOptions { } } +///Class that represents the settings that can be used for an [InAppBrowser] WebView. +class InAppBrowserClassSettings { + ///Browser settings. + late InAppBrowserSettings settings; + + ///WebView settings. + late InAppWebViewSettings webViewSettings; + + InAppBrowserClassSettings( + {InAppBrowserSettings? settings, + InAppWebViewSettings? webViewSettings}) { + this.settings = settings ?? InAppBrowserSettings(); + this.webViewSettings = webViewSettings ?? InAppWebViewSettings(); + } + + Map toMap() { + Map options = {}; + + options.addAll(this.settings.toMap()); + options.addAll(this.webViewSettings.toMap()); + + return options; + } + + static Map instanceToMap(InAppBrowserClassSettings settings) { + return settings.toMap(); + } + + Map toJson() { + return this.toMap(); + } + + @override + String toString() { + return toMap().toString(); + } + + static InAppBrowserClassSettings fromMap(Map options, {InAppBrowserClassSettings? instance}) { + if (instance == null) { + instance = InAppBrowserClassSettings(); + } + instance.settings = InAppBrowserSettings.fromMap(options); + instance.webViewSettings = InAppWebViewSettings.fromMap(options); + return instance; + } + + InAppBrowserClassSettings copy() { + return InAppBrowserClassSettings.fromMap(this.toMap()); + } +} + +class InAppBrowserSettings extends InAppBrowserOptions implements AndroidInAppBrowserOptions, IOSInAppBrowserOptions { + @override + bool allowGoBackWithBackButton; + + @override + String? closeButtonCaption; + + @override + Color? closeButtonColor; + + @override + bool closeOnCannotGoBack; + + @override + bool hideTitleBar; + + @override + bool hideToolbarBottom; + + @override + IOSUIModalPresentationStyle presentationStyle; + + @override + bool shouldCloseOnBackButtonPressed; + + @override + Color? toolbarBottomBackgroundColor; + + @override + Color? toolbarBottomTintColor; + + @override + bool toolbarBottomTranslucent; + + @override + Color? toolbarTopBarTintColor; + + @override + String? toolbarTopFixedTitle; + + @override + Color? toolbarTopTintColor; + + @override + bool toolbarTopTranslucent; + + @override + IOSUIModalTransitionStyle transitionStyle; + + Map toMap() { + Map options = {}; + // ignore: deprecated_member_use_from_same_package + options.addAll(InAppBrowserOptions.instanceToMap(this)); + options.addAll(AndroidInAppBrowserSettings.instanceToMap(this)); + options.addAll(IOSInAppBrowserSettings.instanceToMap(this)); + return options; + } + + static Map instanceToMap(InAppBrowserSettings settings) { + return settings.toMap(); + } + + static InAppBrowserSettings fromMap(Map options, {InAppBrowserSettings? instance}) { + if (instance == null) { + instance = InAppBrowserSettings(); + } + // ignore: deprecated_member_use_from_same_package + InAppBrowserOptions.fromMap(options, instance: instance); + if (defaultTargetPlatform == TargetPlatform.android) { + AndroidInAppBrowserSettings.fromMap(options, instance: instance); + } + else if (defaultTargetPlatform == TargetPlatform.iOS) { + IOSInAppBrowserSettings.fromMap(options, instance: instance); + } + return instance; + } + + @override + Map toJson() { + return this.toMap(); + } + + @override + String toString() { + return toMap().toString(); + } + + @override + InAppBrowserSettings copy() { + return InAppBrowserSettings.fromMap(this.toMap()); + } +} + ///Class that represents the options that can be used for an [InAppBrowser] WebView. +///Use [InAppBrowserClassSettings] instead. +@Deprecated('Use InAppBrowserClassSettings instead') class InAppBrowserClassOptions { ///Cross-platform options. late InAppBrowserOptions crossPlatform; diff --git a/lib/src/in_app_browser/ios/in_app_browser_options.dart b/lib/src/in_app_browser/ios/in_app_browser_options.dart index e3b377a8..ef99cc6e 100755 --- a/lib/src/in_app_browser/ios/in_app_browser_options.dart +++ b/lib/src/in_app_browser/ios/in_app_browser_options.dart @@ -2,13 +2,15 @@ import 'dart:ui'; import '../../in_app_webview/ios/in_app_webview_options.dart'; -import '../in_app_browser_options.dart'; +import '../in_app_browser_settings.dart'; import '../in_app_browser.dart'; import '../../types.dart'; import '../../util.dart'; ///This class represents all the iOS-only [InAppBrowser] options available. +///Use [InAppBrowserSettings] instead. +@Deprecated('Use InAppBrowserSettings instead') class IOSInAppBrowserOptions implements BrowserOptions, IosOptions { ///Set to `true` to set the toolbar at the top translucent. The default value is `true`. bool toolbarTopTranslucent; @@ -72,22 +74,22 @@ class IOSInAppBrowserOptions implements BrowserOptions, IosOptions { } static IOSInAppBrowserOptions fromMap(Map map) { - IOSInAppBrowserOptions options = IOSInAppBrowserOptions(); - options.toolbarTopTranslucent = map["toolbarTopTranslucent"]; - options.toolbarTopTintColor = UtilColor.fromHex(map["toolbarTopTintColor"]); - options.hideToolbarBottom = map["hideToolbarBottom"]; - options.toolbarBottomBackgroundColor = + var instance = IOSInAppBrowserOptions(); + instance.toolbarTopTranslucent = map["toolbarTopTranslucent"]; + instance.toolbarTopTintColor = UtilColor.fromHex(map["toolbarTopTintColor"]); + instance.hideToolbarBottom = map["hideToolbarBottom"]; + instance.toolbarBottomBackgroundColor = UtilColor.fromHex(map["toolbarBottomBackgroundColor"]); - options.toolbarBottomTintColor = + instance.toolbarBottomTintColor = UtilColor.fromHex(map["toolbarBottomTintColor"]); - options.toolbarBottomTranslucent = map["toolbarBottomTranslucent"]; - options.closeButtonCaption = map["closeButtonCaption"]; - options.closeButtonColor = UtilColor.fromHex(map["closeButtonColor"]); - options.presentationStyle = + instance.toolbarBottomTranslucent = map["toolbarBottomTranslucent"]; + instance.closeButtonCaption = map["closeButtonCaption"]; + instance.closeButtonColor = UtilColor.fromHex(map["closeButtonColor"]); + instance.presentationStyle = IOSUIModalPresentationStyle.fromValue(map["presentationStyle"])!; - options.transitionStyle = + instance.transitionStyle = IOSUIModalTransitionStyle.fromValue(map["transitionStyle"])!; - return options; + return instance; } @override diff --git a/lib/src/in_app_webview/android/in_app_webview_options.dart b/lib/src/in_app_webview/android/in_app_webview_options.dart index cb5b5212..41c4cbd8 100755 --- a/lib/src/in_app_webview/android/in_app_webview_options.dart +++ b/lib/src/in_app_webview/android/in_app_webview_options.dart @@ -1,17 +1,15 @@ import 'dart:ui'; -import 'package:flutter_inappwebview/src/util.dart'; - +import '../../util.dart'; import '../../types.dart'; - -import '../../in_app_browser/in_app_browser_options.dart'; - -import '../in_app_webview_options.dart'; +import '../../in_app_browser/in_app_browser_settings.dart'; +import '../in_app_webview_settings.dart'; import '../webview.dart'; class AndroidOptions {} -///This class represents all the Android-only WebView options available. +///Use [InAppWebViewSettings] instead. +@Deprecated('Use InAppWebViewSettings instead') class AndroidInAppWebViewOptions implements WebViewOptions, BrowserOptions, AndroidOptions { ///Sets the text zoom of the page in percent. The default value is `100`. @@ -360,77 +358,77 @@ class AndroidInAppWebViewOptions } static AndroidInAppWebViewOptions fromMap(Map map) { - AndroidInAppWebViewOptions options = AndroidInAppWebViewOptions(); - options.textZoom = map["textZoom"]; - options.clearSessionCache = map["clearSessionCache"]; - options.builtInZoomControls = map["builtInZoomControls"]; - options.displayZoomControls = map["displayZoomControls"]; - options.databaseEnabled = map["databaseEnabled"]; - options.domStorageEnabled = map["domStorageEnabled"]; - options.useWideViewPort = map["useWideViewPort"]; - options.safeBrowsingEnabled = map["safeBrowsingEnabled"]; - options.mixedContentMode = + var instance = AndroidInAppWebViewOptions(); + instance.textZoom = map["textZoom"]; + instance.clearSessionCache = map["clearSessionCache"]; + instance.builtInZoomControls = map["builtInZoomControls"]; + instance.displayZoomControls = map["displayZoomControls"]; + instance.databaseEnabled = map["databaseEnabled"]; + instance.domStorageEnabled = map["domStorageEnabled"]; + instance.useWideViewPort = map["useWideViewPort"]; + instance.safeBrowsingEnabled = map["safeBrowsingEnabled"]; + instance.mixedContentMode = AndroidMixedContentMode.fromValue(map["mixedContentMode"]); - options.allowContentAccess = map["allowContentAccess"]; - options.allowFileAccess = map["allowFileAccess"]; - options.appCachePath = map["appCachePath"]; - options.blockNetworkImage = map["blockNetworkImage"]; - options.blockNetworkLoads = map["blockNetworkLoads"]; - options.cacheMode = AndroidCacheMode.fromValue(map["cacheMode"]); - options.cursiveFontFamily = map["cursiveFontFamily"]; - options.defaultFixedFontSize = map["defaultFixedFontSize"]; - options.defaultFontSize = map["defaultFontSize"]; - options.defaultTextEncodingName = map["defaultTextEncodingName"]; - options.disabledActionModeMenuItems = + instance.allowContentAccess = map["allowContentAccess"]; + instance.allowFileAccess = map["allowFileAccess"]; + instance.appCachePath = map["appCachePath"]; + instance.blockNetworkImage = map["blockNetworkImage"]; + instance.blockNetworkLoads = map["blockNetworkLoads"]; + instance.cacheMode = AndroidCacheMode.fromValue(map["cacheMode"]); + instance.cursiveFontFamily = map["cursiveFontFamily"]; + instance.defaultFixedFontSize = map["defaultFixedFontSize"]; + instance.defaultFontSize = map["defaultFontSize"]; + instance.defaultTextEncodingName = map["defaultTextEncodingName"]; + instance.disabledActionModeMenuItems = AndroidActionModeMenuItem.fromValue(map["disabledActionModeMenuItems"]); - options.fantasyFontFamily = map["fantasyFontFamily"]; - options.fixedFontFamily = map["fixedFontFamily"]; - options.forceDark = AndroidForceDark.fromValue(map["forceDark"]); - options.geolocationEnabled = map["geolocationEnabled"]; - options.layoutAlgorithm = + instance.fantasyFontFamily = map["fantasyFontFamily"]; + instance.fixedFontFamily = map["fixedFontFamily"]; + instance.forceDark = AndroidForceDark.fromValue(map["forceDark"]); + instance.geolocationEnabled = map["geolocationEnabled"]; + instance.layoutAlgorithm = AndroidLayoutAlgorithm.fromValue(map["layoutAlgorithm"]); - options.loadWithOverviewMode = map["loadWithOverviewMode"]; - options.loadsImagesAutomatically = map["loadsImagesAutomatically"]; - options.minimumLogicalFontSize = map["minimumLogicalFontSize"]; - options.initialScale = map["initialScale"]; - options.needInitialFocus = map["needInitialFocus"]; - options.offscreenPreRaster = map["offscreenPreRaster"]; - options.sansSerifFontFamily = map["sansSerifFontFamily"]; - options.serifFontFamily = map["serifFontFamily"]; - options.standardFontFamily = map["standardFontFamily"]; - options.saveFormData = map["saveFormData"]; - options.thirdPartyCookiesEnabled = map["thirdPartyCookiesEnabled"]; - options.hardwareAcceleration = map["hardwareAcceleration"]; - options.supportMultipleWindows = map["supportMultipleWindows"]; - options.regexToCancelSubFramesLoading = + instance.loadWithOverviewMode = map["loadWithOverviewMode"]; + instance.loadsImagesAutomatically = map["loadsImagesAutomatically"]; + instance.minimumLogicalFontSize = map["minimumLogicalFontSize"]; + instance.initialScale = map["initialScale"]; + instance.needInitialFocus = map["needInitialFocus"]; + instance.offscreenPreRaster = map["offscreenPreRaster"]; + instance.sansSerifFontFamily = map["sansSerifFontFamily"]; + instance.serifFontFamily = map["serifFontFamily"]; + instance.standardFontFamily = map["standardFontFamily"]; + instance.saveFormData = map["saveFormData"]; + instance.thirdPartyCookiesEnabled = map["thirdPartyCookiesEnabled"]; + instance.hardwareAcceleration = map["hardwareAcceleration"]; + instance.supportMultipleWindows = map["supportMultipleWindows"]; + instance.regexToCancelSubFramesLoading = map["regexToCancelSubFramesLoading"]; - options.useHybridComposition = map["useHybridComposition"]; - options.useShouldInterceptRequest = map["useShouldInterceptRequest"]; - options.useOnRenderProcessGone = map["useOnRenderProcessGone"]; - options.overScrollMode = + instance.useHybridComposition = map["useHybridComposition"]; + instance.useShouldInterceptRequest = map["useShouldInterceptRequest"]; + instance.useOnRenderProcessGone = map["useOnRenderProcessGone"]; + instance.overScrollMode = AndroidOverScrollMode.fromValue(map["overScrollMode"]); - options.networkAvailable = map["networkAvailable"]; - options.scrollBarStyle = + instance.networkAvailable = map["networkAvailable"]; + instance.scrollBarStyle = AndroidScrollBarStyle.fromValue(map["scrollBarStyle"]); - options.verticalScrollbarPosition = + instance.verticalScrollbarPosition = AndroidVerticalScrollbarPosition.fromValue( map["verticalScrollbarPosition"]); - options.scrollBarDefaultDelayBeforeFade = + instance.scrollBarDefaultDelayBeforeFade = map["scrollBarDefaultDelayBeforeFade"]; - options.scrollbarFadingEnabled = map["scrollbarFadingEnabled"]; - options.scrollBarFadeDuration = map["scrollBarFadeDuration"]; - options.rendererPriorityPolicy = RendererPriorityPolicy.fromMap( + instance.scrollbarFadingEnabled = map["scrollbarFadingEnabled"]; + instance.scrollBarFadeDuration = map["scrollBarFadeDuration"]; + instance.rendererPriorityPolicy = RendererPriorityPolicy.fromMap( map["rendererPriorityPolicy"]?.cast()); - options.disableDefaultErrorPage = map["disableDefaultErrorPage"]; - options.verticalScrollbarThumbColor = + instance.disableDefaultErrorPage = map["disableDefaultErrorPage"]; + instance.verticalScrollbarThumbColor = UtilColor.fromHex(map["verticalScrollbarThumbColor"]); - options.verticalScrollbarTrackColor = + instance.verticalScrollbarTrackColor = UtilColor.fromHex(map["verticalScrollbarTrackColor"]); - options.horizontalScrollbarThumbColor = + instance.horizontalScrollbarThumbColor = UtilColor.fromHex(map["horizontalScrollbarThumbColor"]); - options.horizontalScrollbarTrackColor = + instance.horizontalScrollbarTrackColor = UtilColor.fromHex(map["horizontalScrollbarTrackColor"]); - return options; + return instance; } @override diff --git a/lib/src/in_app_webview/in_app_webview_options.dart b/lib/src/in_app_webview/in_app_webview_options.dart deleted file mode 100755 index cad4d874..00000000 --- a/lib/src/in_app_webview/in_app_webview_options.dart +++ /dev/null @@ -1,340 +0,0 @@ -import 'package:flutter/foundation.dart'; - -import 'android/in_app_webview_options.dart'; -import 'ios/in_app_webview_options.dart'; -import '../content_blocker.dart'; -import '../types.dart'; -import '../in_app_browser/in_app_browser_options.dart'; -import 'webview.dart'; - -class WebViewOptions { - Map toMap() { - return {}; - } - - static WebViewOptions fromMap(Map map) { - return new WebViewOptions(); - } - - WebViewOptions copy() { - return WebViewOptions.fromMap(this.toMap()); - } - - Map toJson() { - return this.toMap(); - } - - @override - String toString() { - return toMap().toString(); - } -} - -///Class that represents the options that can be used for a [WebView]. -class InAppWebViewGroupOptions { - ///Cross-platform options. - late InAppWebViewOptions crossPlatform; - - ///Android-specific options. - late AndroidInAppWebViewOptions android; - - ///iOS-specific options. - late IOSInAppWebViewOptions ios; - - InAppWebViewGroupOptions( - {InAppWebViewOptions? crossPlatform, - AndroidInAppWebViewOptions? android, - IOSInAppWebViewOptions? ios}) { - this.crossPlatform = crossPlatform ?? InAppWebViewOptions(); - this.android = android ?? AndroidInAppWebViewOptions(); - this.ios = ios ?? IOSInAppWebViewOptions(); - } - - Map toMap() { - Map options = {}; - options.addAll(this.crossPlatform.toMap()); - if (defaultTargetPlatform == TargetPlatform.android) - options.addAll(this.android.toMap()); - else if (defaultTargetPlatform == TargetPlatform.iOS) - options.addAll(this.ios.toMap()); - - return options; - } - - static InAppWebViewGroupOptions fromMap(Map options) { - InAppWebViewGroupOptions inAppWebViewGroupOptions = - InAppWebViewGroupOptions(); - - inAppWebViewGroupOptions.crossPlatform = - InAppWebViewOptions.fromMap(options); - if (defaultTargetPlatform == TargetPlatform.android) - inAppWebViewGroupOptions.android = - AndroidInAppWebViewOptions.fromMap(options); - else if (defaultTargetPlatform == TargetPlatform.iOS) - inAppWebViewGroupOptions.ios = IOSInAppWebViewOptions.fromMap(options); - - return inAppWebViewGroupOptions; - } - - Map toJson() { - return this.toMap(); - } - - @override - String toString() { - return toMap().toString(); - } - - InAppWebViewGroupOptions copy() { - return InAppWebViewGroupOptions.fromMap(this.toMap()); - } -} - -///This class represents all the cross-platform WebView options available. -class InAppWebViewOptions - implements WebViewOptions, BrowserOptions, AndroidOptions, IosOptions { - ///Set to `true` to be able to listen at the [WebView.shouldOverrideUrlLoading] event. The default value is `false`. - bool useShouldOverrideUrlLoading; - - ///Set to `true` to be able to listen at the [WebView.onLoadResource] event. The default value is `false`. - bool useOnLoadResource; - - ///Set to `true` to be able to listen at the [WebView.onDownloadStart] event. The default value is `false`. - bool useOnDownloadStart; - - ///Set to `true` to have all the browser's cache cleared before the new WebView is opened. The default value is `false`. - bool clearCache; - - ///Sets the user-agent for the WebView. - /// - ///**NOTE**: available on iOS 9.0+. - String userAgent; - - ///Append to the existing user-agent. Setting userAgent will override this. - /// - ///**NOTE**: available on Android 17+ and on iOS 9.0+. - String applicationNameForUserAgent; - - ///Set to `true` to enable JavaScript. The default value is `true`. - bool javaScriptEnabled; - - ///Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`. - bool javaScriptCanOpenWindowsAutomatically; - - ///Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`. - /// - ///**NOTE**: available on iOS 10.0+. - bool mediaPlaybackRequiresUserGesture; - - ///Sets the minimum font size. The default value is `8` for Android, `0` for iOS. - int? minimumFontSize; - - ///Define whether the vertical scrollbar should be drawn or not. The default value is `true`. - bool verticalScrollBarEnabled; - - ///Define whether the horizontal scrollbar should be drawn or not. The default value is `true`. - bool horizontalScrollBarEnabled; - - ///List of custom schemes that the WebView must handle. Use the [WebView.onLoadResourceCustomScheme] event to intercept resource requests with custom scheme. - /// - ///**NOTE**: available on iOS 11.0+. - List resourceCustomSchemes; - - ///List of [ContentBlocker] that are a set of rules used to block content in the browser window. - /// - ///**NOTE**: available on iOS 11.0+. - List contentBlockers; - - ///Sets the content mode that the WebView needs to use when loading and rendering a webpage. The default value is [UserPreferredContentMode.RECOMMENDED]. - /// - ///**NOTE**: available on iOS 13.0+. - UserPreferredContentMode? preferredContentMode; - - ///Set to `true` to be able to listen at the [WebView.shouldInterceptAjaxRequest] event. The default value is `false`. - bool useShouldInterceptAjaxRequest; - - ///Set to `true` to be able to listen at the [WebView.shouldInterceptFetchRequest] event. The default value is `false`. - bool useShouldInterceptFetchRequest; - - ///Set to `true` to open a browser window with incognito mode. The default value is `false`. - /// - ///**NOTE**: available on iOS 9.0+. - ///On Android, by setting this option to `true`, it will clear all the cookies of all WebView instances, - ///because there isn't any way to make the website data store non-persistent for the specific WebView instance such as on iOS. - bool incognito; - - ///Sets whether WebView should use browser caching. The default value is `true`. - /// - ///**NOTE**: available on iOS 9.0+. - bool cacheEnabled; - - ///Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`. - bool transparentBackground; - - ///Set to `true` to disable vertical scroll. The default value is `false`. - bool disableVerticalScroll; - - ///Set to `true` to disable horizontal scroll. The default value is `false`. - bool disableHorizontalScroll; - - ///Set to `true` to disable context menu. The default value is `false`. - bool disableContextMenu; - - ///Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`. - bool supportZoom; - - ///Sets whether cross-origin requests in the context of a file scheme URL should be allowed to access content from other file scheme URLs. - ///Note that some accesses such as image HTML elements don't follow same-origin rules and aren't affected by this setting. - /// - ///Don't enable this setting if you open files that may be created or altered by external sources. - ///Enabling this setting allows malicious scripts loaded in a `file://` context to access arbitrary local files including WebView cookies and app private data. - /// - ///Note that the value of this setting is ignored if the value of [allowUniversalAccessFromFileURLs] is `true`. - /// - ///The default value is `false`. - bool allowFileAccessFromFileURLs; - - ///Sets whether cross-origin requests in the context of a file scheme URL should be allowed to access content from any origin. - ///This includes access to content from other file scheme URLs or web contexts. - ///Note that some access such as image HTML elements doesn't follow same-origin rules and isn't affected by this setting. - /// - ///Don't enable this setting if you open files that may be created or altered by external sources. - ///Enabling this setting allows malicious scripts loaded in a `file://` context to launch cross-site scripting attacks, - ///either accessing arbitrary local files including WebView cookies, app private data or even credentials used on arbitrary web sites. - /// - ///The default value is `false`. - bool allowUniversalAccessFromFileURLs; - - InAppWebViewOptions( - {this.useShouldOverrideUrlLoading = false, - this.useOnLoadResource = false, - this.useOnDownloadStart = false, - this.clearCache = false, - this.userAgent = "", - this.applicationNameForUserAgent = "", - this.javaScriptEnabled = true, - this.javaScriptCanOpenWindowsAutomatically = false, - this.mediaPlaybackRequiresUserGesture = true, - this.minimumFontSize, - this.verticalScrollBarEnabled = true, - this.horizontalScrollBarEnabled = true, - this.resourceCustomSchemes = const [], - this.contentBlockers = const [], - this.preferredContentMode = UserPreferredContentMode.RECOMMENDED, - this.useShouldInterceptAjaxRequest = false, - this.useShouldInterceptFetchRequest = false, - this.incognito = false, - this.cacheEnabled = true, - this.transparentBackground = false, - this.disableVerticalScroll = false, - this.disableHorizontalScroll = false, - this.disableContextMenu = false, - this.supportZoom = true, - this.allowFileAccessFromFileURLs = false, - this.allowUniversalAccessFromFileURLs = false}) { - if (this.minimumFontSize == null) - this.minimumFontSize = - defaultTargetPlatform == TargetPlatform.android ? 8 : 0; - assert(!this.resourceCustomSchemes.contains("http") && - !this.resourceCustomSchemes.contains("https")); - } - - @override - Map toMap() { - List>> contentBlockersMapList = []; - contentBlockers.forEach((contentBlocker) { - contentBlockersMapList.add(contentBlocker.toMap()); - }); - - return { - "useShouldOverrideUrlLoading": useShouldOverrideUrlLoading, - "useOnLoadResource": useOnLoadResource, - "useOnDownloadStart": useOnDownloadStart, - "clearCache": clearCache, - "userAgent": userAgent, - "applicationNameForUserAgent": applicationNameForUserAgent, - "javaScriptEnabled": javaScriptEnabled, - "javaScriptCanOpenWindowsAutomatically": - javaScriptCanOpenWindowsAutomatically, - "mediaPlaybackRequiresUserGesture": mediaPlaybackRequiresUserGesture, - "verticalScrollBarEnabled": verticalScrollBarEnabled, - "horizontalScrollBarEnabled": horizontalScrollBarEnabled, - "resourceCustomSchemes": resourceCustomSchemes, - "contentBlockers": contentBlockersMapList, - "preferredContentMode": preferredContentMode?.toValue(), - "useShouldInterceptAjaxRequest": useShouldInterceptAjaxRequest, - "useShouldInterceptFetchRequest": useShouldInterceptFetchRequest, - "incognito": incognito, - "cacheEnabled": cacheEnabled, - "transparentBackground": transparentBackground, - "disableVerticalScroll": disableVerticalScroll, - "disableHorizontalScroll": disableHorizontalScroll, - "disableContextMenu": disableContextMenu, - "supportZoom": supportZoom, - "allowFileAccessFromFileURLs": allowFileAccessFromFileURLs, - "allowUniversalAccessFromFileURLs": allowUniversalAccessFromFileURLs - }; - } - - static InAppWebViewOptions fromMap(Map map) { - List contentBlockers = []; - List? contentBlockersMapList = map["contentBlockers"]; - if (contentBlockersMapList != null) { - contentBlockersMapList.forEach((contentBlocker) { - contentBlockers.add(ContentBlocker.fromMap( - Map>.from( - Map.from(contentBlocker)))); - }); - } - - InAppWebViewOptions options = InAppWebViewOptions(); - options.useShouldOverrideUrlLoading = map["useShouldOverrideUrlLoading"]; - options.useOnLoadResource = map["useOnLoadResource"]; - options.useOnDownloadStart = map["useOnDownloadStart"]; - options.clearCache = map["clearCache"]; - options.userAgent = map["userAgent"]; - options.applicationNameForUserAgent = map["applicationNameForUserAgent"]; - options.javaScriptEnabled = map["javaScriptEnabled"]; - options.javaScriptCanOpenWindowsAutomatically = - map["javaScriptCanOpenWindowsAutomatically"]; - options.mediaPlaybackRequiresUserGesture = - map["mediaPlaybackRequiresUserGesture"]; - options.verticalScrollBarEnabled = map["verticalScrollBarEnabled"]; - options.horizontalScrollBarEnabled = map["horizontalScrollBarEnabled"]; - options.resourceCustomSchemes = - List.from(map["resourceCustomSchemes"] ?? []); - options.contentBlockers = contentBlockers; - options.preferredContentMode = - UserPreferredContentMode.fromValue(map["preferredContentMode"]); - options.useShouldInterceptAjaxRequest = - map["useShouldInterceptAjaxRequest"]; - options.useShouldInterceptFetchRequest = - map["useShouldInterceptFetchRequest"]; - options.incognito = map["incognito"]; - options.cacheEnabled = map["cacheEnabled"]; - options.transparentBackground = map["transparentBackground"]; - options.disableVerticalScroll = map["disableVerticalScroll"]; - options.disableHorizontalScroll = map["disableHorizontalScroll"]; - options.disableContextMenu = map["disableContextMenu"]; - options.supportZoom = map["supportZoom"]; - options.allowFileAccessFromFileURLs = map["allowFileAccessFromFileURLs"]; - options.allowUniversalAccessFromFileURLs = - map["allowUniversalAccessFromFileURLs"]; - return options; - } - - @override - Map toJson() { - return this.toMap(); - } - - @override - String toString() { - return toMap().toString(); - } - - @override - InAppWebViewOptions copy() { - return InAppWebViewOptions.fromMap(this.toMap()); - } -} diff --git a/lib/src/in_app_webview/in_app_webview_settings.dart b/lib/src/in_app_webview/in_app_webview_settings.dart new file mode 100755 index 00000000..c7ee5c3d --- /dev/null +++ b/lib/src/in_app_webview/in_app_webview_settings.dart @@ -0,0 +1,867 @@ +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; + +import 'android/in_app_webview_settings.dart'; +import 'ios/in_app_webview_settings.dart'; +import '../content_blocker.dart'; +import '../types.dart'; +import '../in_app_browser/in_app_browser_options.dart'; +import 'webview.dart'; + +class WebViewOptions { + Map toMap() { + return {}; + } + + static WebViewOptions fromMap(Map map, {WebViewOptions? instance}) { + return WebViewOptions(); + } + + static Map instanceToMap(WebViewOptions webViewOptions) { + return webViewOptions.toMap(); + } + + WebViewOptions copy() { + return WebViewOptions.fromMap(this.toMap()); + } + + Map toJson() { + return this.toMap(); + } + + @override + String toString() { + return toMap().toString(); + } +} + + +///This class represents all the WebView settings available. +// ignore: deprecated_member_use_from_same_package +class InAppWebViewSettings extends InAppWebViewOptions implements AndroidInAppWebViewSettings, IOSInAppWebViewSettings { + @override + bool accessibilityIgnoresInvertColors; + + @override + bool allowContentAccess; + + @override + bool allowFileAccess; + + @override + bool allowFileAccessFromFileURLs; + + @override + bool allowUniversalAccessFromFileURLs; + + @override + Uri? allowingReadAccessTo; + + @override + bool allowsAirPlayForMediaPlayback; + + @override + bool allowsBackForwardNavigationGestures; + + @override + bool allowsInlineMediaPlayback; + + @override + bool allowsLinkPreview; + + @override + bool allowsPictureInPictureMediaPlayback; + + @override + bool alwaysBounceHorizontal; + + @override + bool alwaysBounceVertical; + + @override + String? appCachePath; + + @override + bool applePayAPIEnabled; + + @override + String applicationNameForUserAgent; + + @override + bool automaticallyAdjustsScrollIndicatorInsets; + + @override + bool blockNetworkImage; + + @override + bool blockNetworkLoads; + + @override + bool builtInZoomControls; + + @override + bool cacheEnabled; + + @override + AndroidCacheMode? cacheMode; + + @override + bool clearCache; + + @override + bool clearSessionCache; + + @override + List contentBlockers; + + @override + IOSUIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior; + + @override + String cursiveFontFamily; + + @override + List dataDetectorTypes; + + @override + bool databaseEnabled; + + @override + IOSUIScrollViewDecelerationRate decelerationRate; + + @override + int defaultFixedFontSize; + + @override + int defaultFontSize; + + @override + String defaultTextEncodingName; + + @override + bool disableContextMenu; + + @override + bool disableDefaultErrorPage; + + @override + bool disableHorizontalScroll; + + @override + bool disableInputAccessoryView; + + @override + bool disableLongPressContextMenuOnLinks; + + @override + bool disableVerticalScroll; + + @override + AndroidActionModeMenuItem? disabledActionModeMenuItems; + + @override + bool disallowOverScroll; + + @override + bool displayZoomControls; + + @override + bool domStorageEnabled; + + @override + bool enableViewportScale; + + @override + String fantasyFontFamily; + + @override + String fixedFontFamily; + + @override + AndroidForceDark? forceDark; + + @override + bool geolocationEnabled; + + @override + bool hardwareAcceleration; + + @override + bool horizontalScrollBarEnabled; + + @override + Color? horizontalScrollbarThumbColor; + + @override + Color? horizontalScrollbarTrackColor; + + @override + bool ignoresViewportScaleLimits; + + @override + bool incognito; + + @override + int initialScale; + + @override + bool isDirectionalLockEnabled; + + @override + bool isFraudulentWebsiteWarningEnabled; + + @override + bool isPagingEnabled; + + @override + bool javaScriptCanOpenWindowsAutomatically; + + @override + bool javaScriptEnabled; + + @override + AndroidLayoutAlgorithm? layoutAlgorithm; + + @override + bool limitsNavigationsToAppBoundDomains; + + @override + bool loadWithOverviewMode; + + @override + bool loadsImagesAutomatically; + + @override + double maximumZoomScale; + + @override + bool mediaPlaybackRequiresUserGesture; + + @override + String? mediaType; + + @override + int? minimumFontSize; + + @override + int minimumLogicalFontSize; + + @override + double minimumZoomScale; + + @override + AndroidMixedContentMode? mixedContentMode; + + @override + bool needInitialFocus; + + @override + bool? networkAvailable; + + @override + bool offscreenPreRaster; + + @override + AndroidOverScrollMode? overScrollMode; + + @override + double pageZoom; + + @override + UserPreferredContentMode? preferredContentMode; + + @override + String? regexToCancelSubFramesLoading; + + @override + RendererPriorityPolicy? rendererPriorityPolicy; + + @override + List resourceCustomSchemes; + + @override + bool safeBrowsingEnabled; + + @override + String sansSerifFontFamily; + + @override + bool saveFormData; + + @override + int? scrollBarDefaultDelayBeforeFade; + + @override + int? scrollBarFadeDuration; + + @override + AndroidScrollBarStyle? scrollBarStyle; + + @override + bool scrollbarFadingEnabled; + + @override + bool scrollsToTop; + + @override + IOSWKSelectionGranularity selectionGranularity; + + @override + String serifFontFamily; + + @override + bool sharedCookiesEnabled; + + @override + String standardFontFamily; + + @override + bool supportMultipleWindows; + + @override + bool supportZoom; + + @override + bool suppressesIncrementalRendering; + + @override + int textZoom; + + @override + bool thirdPartyCookiesEnabled; + + @override + bool transparentBackground; + + @override + bool useHybridComposition; + + @override + bool useOnDownloadStart; + + @override + bool useOnLoadResource; + + @override + bool useOnNavigationResponse; + + @override + bool useOnRenderProcessGone; + + @override + bool useShouldInterceptAjaxRequest; + + @override + bool useShouldInterceptFetchRequest; + + @override + bool useShouldInterceptRequest; + + @override + bool useShouldOverrideUrlLoading; + + @override + bool useWideViewPort; + + @override + String userAgent; + + @override + bool verticalScrollBarEnabled; + + @override + AndroidVerticalScrollbarPosition? verticalScrollbarPosition; + + @override + Color? verticalScrollbarThumbColor; + + @override + Color? verticalScrollbarTrackColor; + + InAppWebViewSettings( + {this.useShouldOverrideUrlLoading = false, + this.useOnLoadResource = false, + this.useOnDownloadStart = false, + this.clearCache = false, + this.userAgent = "", + this.applicationNameForUserAgent = "", + this.javaScriptEnabled = true, + this.javaScriptCanOpenWindowsAutomatically = false, + this.mediaPlaybackRequiresUserGesture = true, + this.minimumFontSize, + this.verticalScrollBarEnabled = true, + this.horizontalScrollBarEnabled = true, + this.resourceCustomSchemes = const [], + this.contentBlockers = const [], + this.preferredContentMode = UserPreferredContentMode.RECOMMENDED, + this.useShouldInterceptAjaxRequest = false, + this.useShouldInterceptFetchRequest = false, + this.incognito = false, + this.cacheEnabled = true, + this.transparentBackground = false, + this.disableVerticalScroll = false, + this.disableHorizontalScroll = false, + this.disableContextMenu = false, + this.supportZoom = true, + this.allowFileAccessFromFileURLs = false, + this.allowUniversalAccessFromFileURLs = false, + this.textZoom = 100, + this.clearSessionCache = false, + this.builtInZoomControls = true, + this.displayZoomControls = false, + this.databaseEnabled = true, + this.domStorageEnabled = true, + this.useWideViewPort = true, + this.safeBrowsingEnabled = true, + this.mixedContentMode, + this.allowContentAccess = true, + this.allowFileAccess = true, + this.appCachePath, + this.blockNetworkImage = false, + this.blockNetworkLoads = false, + this.cacheMode = AndroidCacheMode.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 = AndroidForceDark.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", + this.saveFormData = true, + this.thirdPartyCookiesEnabled = true, + this.hardwareAcceleration = true, + this.initialScale = 0, + this.supportMultipleWindows = false, + this.regexToCancelSubFramesLoading, + this.useHybridComposition = false, + this.useShouldInterceptRequest = false, + this.useOnRenderProcessGone = false, + this.overScrollMode = AndroidOverScrollMode.OVER_SCROLL_IF_CONTENT_SCROLLS, + this.networkAvailable, + this.scrollBarStyle = AndroidScrollBarStyle.SCROLLBARS_INSIDE_OVERLAY, + this.verticalScrollbarPosition = + AndroidVerticalScrollbarPosition.SCROLLBAR_POSITION_DEFAULT, + this.scrollBarDefaultDelayBeforeFade, + this.scrollbarFadingEnabled = true, + this.scrollBarFadeDuration, + this.rendererPriorityPolicy, + this.disableDefaultErrorPage = false, + this.verticalScrollbarThumbColor, + this.verticalScrollbarTrackColor, + this.horizontalScrollbarThumbColor, + this.horizontalScrollbarTrackColor, + this.disallowOverScroll = false, + this.enableViewportScale = false, + this.suppressesIncrementalRendering = false, + this.allowsAirPlayForMediaPlayback = true, + this.allowsBackForwardNavigationGestures = true, + this.allowsLinkPreview = true, + this.ignoresViewportScaleLimits = false, + this.allowsInlineMediaPlayback = false, + this.allowsPictureInPictureMediaPlayback = true, + this.isFraudulentWebsiteWarningEnabled = true, + this.selectionGranularity = IOSWKSelectionGranularity.DYNAMIC, + this.dataDetectorTypes = const [IOSWKDataDetectorTypes.NONE], + this.sharedCookiesEnabled = false, + this.automaticallyAdjustsScrollIndicatorInsets = false, + this.accessibilityIgnoresInvertColors = false, + this.decelerationRate = IOSUIScrollViewDecelerationRate.NORMAL, + this.alwaysBounceVertical = false, + this.alwaysBounceHorizontal = false, + this.scrollsToTop = true, + this.isPagingEnabled = false, + this.maximumZoomScale = 1.0, + this.minimumZoomScale = 1.0, + this.contentInsetAdjustmentBehavior = + IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER, + this.isDirectionalLockEnabled = false, + this.mediaType, + this.pageZoom = 1.0, + this.limitsNavigationsToAppBoundDomains = false, + this.useOnNavigationResponse = false, + this.applePayAPIEnabled = false, + this.allowingReadAccessTo, + this.disableLongPressContextMenuOnLinks = false, + this.disableInputAccessoryView = false}) { + if (this.minimumFontSize == null) + this.minimumFontSize = + defaultTargetPlatform == TargetPlatform.android ? 8 : 0; + assert(!this.resourceCustomSchemes.contains("http") && + !this.resourceCustomSchemes.contains("https")); + assert(allowingReadAccessTo == null || allowingReadAccessTo!.isScheme("file")); + } + + Map toMap() { + Map options = {}; + // ignore: deprecated_member_use_from_same_package + options.addAll(InAppWebViewOptions.instanceToMap(this)); + options.addAll(AndroidInAppWebViewSettings.instanceToMap(this)); + options.addAll(IOSInAppWebViewSettings.instanceToMap(this)); + return options; + } + + static Map instanceToMap(InAppWebViewSettings settings) { + return settings.toMap(); + } + + static InAppWebViewSettings fromMap(Map options, {InAppWebViewSettings? instance}) { + if (instance == null) { + instance = InAppWebViewSettings(); + } + // ignore: deprecated_member_use_from_same_package + InAppWebViewOptions.fromMap(options, instance: instance); + if (defaultTargetPlatform == TargetPlatform.android) { + AndroidInAppWebViewSettings.fromMap(options, instance: instance); + } + else if (defaultTargetPlatform == TargetPlatform.iOS) { + IOSInAppWebViewSettings.fromMap(options, instance: instance); + } + return instance; + } + + @override + Map toJson() { + return this.toMap(); + } + + @override + String toString() { + return toMap().toString(); + } + + @override + InAppWebViewSettings copy() { + return InAppWebViewSettings.fromMap(this.toMap()); + } +} + +///Class that represents the options that can be used for a [WebView]. +///Use [InAppWebViewSettings] instead. +@Deprecated('Use InAppWebViewSettings instead') +class InAppWebViewGroupOptions { + ///Cross-platform options. + late InAppWebViewOptions crossPlatform; + + ///Android-specific options. + late AndroidInAppWebViewOptions android; + + ///iOS-specific options. + late IOSInAppWebViewOptions ios; + + InAppWebViewGroupOptions( + {InAppWebViewOptions? crossPlatform, + AndroidInAppWebViewOptions? android, + IOSInAppWebViewOptions? ios}) { + this.crossPlatform = crossPlatform ?? InAppWebViewOptions(); + this.android = android ?? AndroidInAppWebViewOptions(); + this.ios = ios ?? IOSInAppWebViewOptions(); + } + + Map toMap() { + Map options = {}; + options.addAll(this.crossPlatform.toMap()); + if (defaultTargetPlatform == TargetPlatform.android) + options.addAll(this.android.toMap()); + else if (defaultTargetPlatform == TargetPlatform.iOS) + options.addAll(this.ios.toMap()); + + return options; + } + + static InAppWebViewGroupOptions fromMap(Map options) { + InAppWebViewGroupOptions inAppWebViewGroupOptions = + InAppWebViewGroupOptions(); + + inAppWebViewGroupOptions.crossPlatform = + InAppWebViewOptions.fromMap(options); + if (defaultTargetPlatform == TargetPlatform.android) + inAppWebViewGroupOptions.android = + AndroidInAppWebViewOptions.fromMap(options); + else if (defaultTargetPlatform == TargetPlatform.iOS) + inAppWebViewGroupOptions.ios = IOSInAppWebViewOptions.fromMap(options); + + return inAppWebViewGroupOptions; + } + + Map toJson() { + return this.toMap(); + } + + @override + String toString() { + return toMap().toString(); + } + + InAppWebViewGroupOptions copy() { + return InAppWebViewGroupOptions.fromMap(this.toMap()); + } +} + +///Use [InAppWebViewSettings] instead. +@Deprecated('Use InAppWebViewSettings instead') +class InAppWebViewOptions + implements WebViewOptions, BrowserOptions, AndroidOptions, IosOptions { + ///Set to `true` to be able to listen at the [WebView.shouldOverrideUrlLoading] event. The default value is `false`. + bool useShouldOverrideUrlLoading; + + ///Set to `true` to be able to listen at the [WebView.onLoadResource] event. The default value is `false`. + bool useOnLoadResource; + + ///Set to `true` to be able to listen at the [WebView.onDownloadStart] event. The default value is `false`. + bool useOnDownloadStart; + + ///Set to `true` to have all the browser's cache cleared before the new WebView is opened. The default value is `false`. + bool clearCache; + + ///Sets the user-agent for the WebView. + /// + ///**NOTE**: available on iOS 9.0+. + String userAgent; + + ///Append to the existing user-agent. Setting userAgent will override this. + /// + ///**NOTE**: available on Android 17+ and on iOS 9.0+. + String applicationNameForUserAgent; + + ///Set to `true` to enable JavaScript. The default value is `true`. + bool javaScriptEnabled; + + ///Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`. + bool javaScriptCanOpenWindowsAutomatically; + + ///Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`. + /// + ///**NOTE**: available on iOS 10.0+. + bool mediaPlaybackRequiresUserGesture; + + ///Sets the minimum font size. The default value is `8` for Android, `0` for iOS. + int? minimumFontSize; + + ///Define whether the vertical scrollbar should be drawn or not. The default value is `true`. + bool verticalScrollBarEnabled; + + ///Define whether the horizontal scrollbar should be drawn or not. The default value is `true`. + bool horizontalScrollBarEnabled; + + ///List of custom schemes that the WebView must handle. Use the [WebView.onLoadResourceCustomScheme] event to intercept resource requests with custom scheme. + /// + ///**NOTE**: available on iOS 11.0+. + List resourceCustomSchemes; + + ///List of [ContentBlocker] that are a set of rules used to block content in the browser window. + /// + ///**NOTE**: available on iOS 11.0+. + List contentBlockers; + + ///Sets the content mode that the WebView needs to use when loading and rendering a webpage. The default value is [UserPreferredContentMode.RECOMMENDED]. + /// + ///**NOTE**: available on iOS 13.0+. + UserPreferredContentMode? preferredContentMode; + + ///Set to `true` to be able to listen at the [WebView.shouldInterceptAjaxRequest] event. The default value is `false`. + bool useShouldInterceptAjaxRequest; + + ///Set to `true` to be able to listen at the [WebView.shouldInterceptFetchRequest] event. The default value is `false`. + bool useShouldInterceptFetchRequest; + + ///Set to `true` to open a browser window with incognito mode. The default value is `false`. + /// + ///**NOTE**: available on iOS 9.0+. + ///On Android, by setting this option to `true`, it will clear all the cookies of all WebView instances, + ///because there isn't any way to make the website data store non-persistent for the specific WebView instance such as on iOS. + bool incognito; + + ///Sets whether WebView should use browser caching. The default value is `true`. + /// + ///**NOTE**: available on iOS 9.0+. + bool cacheEnabled; + + ///Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`. + bool transparentBackground; + + ///Set to `true` to disable vertical scroll. The default value is `false`. + bool disableVerticalScroll; + + ///Set to `true` to disable horizontal scroll. The default value is `false`. + bool disableHorizontalScroll; + + ///Set to `true` to disable context menu. The default value is `false`. + bool disableContextMenu; + + ///Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`. + bool supportZoom; + + ///Sets whether cross-origin requests in the context of a file scheme URL should be allowed to access content from other file scheme URLs. + ///Note that some accesses such as image HTML elements don't follow same-origin rules and aren't affected by this setting. + /// + ///Don't enable this setting if you open files that may be created or altered by external sources. + ///Enabling this setting allows malicious scripts loaded in a `file://` context to access arbitrary local files including WebView cookies and app private data. + /// + ///Note that the value of this setting is ignored if the value of [allowUniversalAccessFromFileURLs] is `true`. + /// + ///The default value is `false`. + bool allowFileAccessFromFileURLs; + + ///Sets whether cross-origin requests in the context of a file scheme URL should be allowed to access content from any origin. + ///This includes access to content from other file scheme URLs or web contexts. + ///Note that some access such as image HTML elements doesn't follow same-origin rules and isn't affected by this setting. + /// + ///Don't enable this setting if you open files that may be created or altered by external sources. + ///Enabling this setting allows malicious scripts loaded in a `file://` context to launch cross-site scripting attacks, + ///either accessing arbitrary local files including WebView cookies, app private data or even credentials used on arbitrary web sites. + /// + ///The default value is `false`. + bool allowUniversalAccessFromFileURLs; + + InAppWebViewOptions( + {this.useShouldOverrideUrlLoading = false, + this.useOnLoadResource = false, + this.useOnDownloadStart = false, + this.clearCache = false, + this.userAgent = "", + this.applicationNameForUserAgent = "", + this.javaScriptEnabled = true, + this.javaScriptCanOpenWindowsAutomatically = false, + this.mediaPlaybackRequiresUserGesture = true, + this.minimumFontSize, + this.verticalScrollBarEnabled = true, + this.horizontalScrollBarEnabled = true, + this.resourceCustomSchemes = const [], + this.contentBlockers = const [], + this.preferredContentMode = UserPreferredContentMode.RECOMMENDED, + this.useShouldInterceptAjaxRequest = false, + this.useShouldInterceptFetchRequest = false, + this.incognito = false, + this.cacheEnabled = true, + this.transparentBackground = false, + this.disableVerticalScroll = false, + this.disableHorizontalScroll = false, + this.disableContextMenu = false, + this.supportZoom = true, + this.allowFileAccessFromFileURLs = false, + this.allowUniversalAccessFromFileURLs = false}) { + if (this.minimumFontSize == null) + this.minimumFontSize = + defaultTargetPlatform == TargetPlatform.android ? 8 : 0; + assert(!this.resourceCustomSchemes.contains("http") && + !this.resourceCustomSchemes.contains("https")); + } + + static Map instanceToMap(InAppWebViewOptions options) { + return options.toMap(); + } + + @override + Map toMap() { + List>> contentBlockersMapList = []; + contentBlockers.forEach((contentBlocker) { + contentBlockersMapList.add(contentBlocker.toMap()); + }); + + return { + "useShouldOverrideUrlLoading": useShouldOverrideUrlLoading, + "useOnLoadResource": useOnLoadResource, + "useOnDownloadStart": useOnDownloadStart, + "clearCache": clearCache, + "userAgent": userAgent, + "applicationNameForUserAgent": applicationNameForUserAgent, + "javaScriptEnabled": javaScriptEnabled, + "javaScriptCanOpenWindowsAutomatically": + javaScriptCanOpenWindowsAutomatically, + "mediaPlaybackRequiresUserGesture": mediaPlaybackRequiresUserGesture, + "verticalScrollBarEnabled": verticalScrollBarEnabled, + "horizontalScrollBarEnabled": horizontalScrollBarEnabled, + "resourceCustomSchemes": resourceCustomSchemes, + "contentBlockers": contentBlockersMapList, + "preferredContentMode": preferredContentMode?.toValue(), + "useShouldInterceptAjaxRequest": useShouldInterceptAjaxRequest, + "useShouldInterceptFetchRequest": useShouldInterceptFetchRequest, + "incognito": incognito, + "cacheEnabled": cacheEnabled, + "transparentBackground": transparentBackground, + "disableVerticalScroll": disableVerticalScroll, + "disableHorizontalScroll": disableHorizontalScroll, + "disableContextMenu": disableContextMenu, + "supportZoom": supportZoom, + "allowFileAccessFromFileURLs": allowFileAccessFromFileURLs, + "allowUniversalAccessFromFileURLs": allowUniversalAccessFromFileURLs + }; + } + + static InAppWebViewOptions fromMap(Map map, {InAppWebViewOptions? instance}) { + List contentBlockers = []; + List? contentBlockersMapList = map["contentBlockers"]; + if (contentBlockersMapList != null) { + contentBlockersMapList.forEach((contentBlocker) { + contentBlockers.add(ContentBlocker.fromMap( + Map>.from( + Map.from(contentBlocker)))); + }); + } + + if (instance == null) { + instance = InAppWebViewOptions(); + } + + instance.useShouldOverrideUrlLoading = map["useShouldOverrideUrlLoading"]; + instance.useOnLoadResource = map["useOnLoadResource"]; + instance.useOnDownloadStart = map["useOnDownloadStart"]; + instance.clearCache = map["clearCache"]; + instance.userAgent = map["userAgent"]; + instance.applicationNameForUserAgent = map["applicationNameForUserAgent"]; + instance.javaScriptEnabled = map["javaScriptEnabled"]; + instance.javaScriptCanOpenWindowsAutomatically = + map["javaScriptCanOpenWindowsAutomatically"]; + instance.mediaPlaybackRequiresUserGesture = + map["mediaPlaybackRequiresUserGesture"]; + instance.verticalScrollBarEnabled = map["verticalScrollBarEnabled"]; + instance.horizontalScrollBarEnabled = map["horizontalScrollBarEnabled"]; + instance.resourceCustomSchemes = + List.from(map["resourceCustomSchemes"] ?? []); + instance.contentBlockers = contentBlockers; + instance.preferredContentMode = + UserPreferredContentMode.fromValue(map["preferredContentMode"]); + instance.useShouldInterceptAjaxRequest = + map["useShouldInterceptAjaxRequest"]; + instance.useShouldInterceptFetchRequest = + map["useShouldInterceptFetchRequest"]; + instance.incognito = map["incognito"]; + instance.cacheEnabled = map["cacheEnabled"]; + instance.transparentBackground = map["transparentBackground"]; + instance.disableVerticalScroll = map["disableVerticalScroll"]; + instance.disableHorizontalScroll = map["disableHorizontalScroll"]; + instance.disableContextMenu = map["disableContextMenu"]; + instance.supportZoom = map["supportZoom"]; + instance.allowFileAccessFromFileURLs = map["allowFileAccessFromFileURLs"]; + instance.allowUniversalAccessFromFileURLs = + map["allowUniversalAccessFromFileURLs"]; + return instance; + } + + @override + Map toJson() { + return this.toMap(); + } + + @override + String toString() { + return toMap().toString(); + } + + @override + InAppWebViewOptions copy() { + return InAppWebViewOptions.fromMap(this.toMap()); + } +} diff --git a/lib/src/in_app_webview/ios/in_app_webview_options.dart b/lib/src/in_app_webview/ios/in_app_webview_options.dart index a0c21e92..f6788dcc 100755 --- a/lib/src/in_app_webview/ios/in_app_webview_options.dart +++ b/lib/src/in_app_webview/ios/in_app_webview_options.dart @@ -1,14 +1,15 @@ import '../../types.dart'; -import '../../in_app_browser/in_app_browser_options.dart'; +import '../../in_app_browser/in_app_browser_settings.dart'; -import '../in_app_webview_options.dart'; +import '../in_app_webview_settings.dart'; import '../webview.dart'; import '../in_app_webview_controller.dart'; class IosOptions {} -///This class represents all the iOS-only WebView options available. +///Use [InAppWebViewSettings] instead. +@Deprecated('Use InAppWebViewSettings instead') class IOSInAppWebViewOptions implements WebViewOptions, BrowserOptions, IosOptions { ///Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`. @@ -324,55 +325,55 @@ class IOSInAppWebViewOptions } }); - IOSInAppWebViewOptions options = IOSInAppWebViewOptions(); - options.disallowOverScroll = map["disallowOverScroll"]; - options.enableViewportScale = map["enableViewportScale"]; - options.suppressesIncrementalRendering = + var instance = IOSInAppWebViewOptions(); + instance.disallowOverScroll = map["disallowOverScroll"]; + instance.enableViewportScale = map["enableViewportScale"]; + instance.suppressesIncrementalRendering = map["suppressesIncrementalRendering"]; - options.allowsAirPlayForMediaPlayback = + instance.allowsAirPlayForMediaPlayback = map["allowsAirPlayForMediaPlayback"]; - options.allowsBackForwardNavigationGestures = + instance.allowsBackForwardNavigationGestures = map["allowsBackForwardNavigationGestures"]; - options.allowsLinkPreview = map["allowsLinkPreview"]; - options.ignoresViewportScaleLimits = map["ignoresViewportScaleLimits"]; - options.allowsInlineMediaPlayback = map["allowsInlineMediaPlayback"]; - options.allowsPictureInPictureMediaPlayback = + instance.allowsLinkPreview = map["allowsLinkPreview"]; + instance.ignoresViewportScaleLimits = map["ignoresViewportScaleLimits"]; + instance.allowsInlineMediaPlayback = map["allowsInlineMediaPlayback"]; + instance.allowsPictureInPictureMediaPlayback = map["allowsPictureInPictureMediaPlayback"]; - options.isFraudulentWebsiteWarningEnabled = + instance.isFraudulentWebsiteWarningEnabled = map["isFraudulentWebsiteWarningEnabled"]; - options.selectionGranularity = + instance.selectionGranularity = IOSWKSelectionGranularity.fromValue(map["selectionGranularity"])!; - options.dataDetectorTypes = dataDetectorTypes; - options.sharedCookiesEnabled = map["sharedCookiesEnabled"]; - options.automaticallyAdjustsScrollIndicatorInsets = + instance.dataDetectorTypes = dataDetectorTypes; + instance.sharedCookiesEnabled = map["sharedCookiesEnabled"]; + instance.automaticallyAdjustsScrollIndicatorInsets = map["automaticallyAdjustsScrollIndicatorInsets"]; - options.accessibilityIgnoresInvertColors = + instance.accessibilityIgnoresInvertColors = map["accessibilityIgnoresInvertColors"]; - options.decelerationRate = + instance.decelerationRate = IOSUIScrollViewDecelerationRate.fromValue(map["decelerationRate"])!; - options.alwaysBounceVertical = map["alwaysBounceVertical"]; - options.alwaysBounceHorizontal = map["alwaysBounceHorizontal"]; - options.scrollsToTop = map["scrollsToTop"]; - options.isPagingEnabled = map["isPagingEnabled"]; - options.maximumZoomScale = map["maximumZoomScale"]; - options.minimumZoomScale = map["minimumZoomScale"]; - options.contentInsetAdjustmentBehavior = + instance.alwaysBounceVertical = map["alwaysBounceVertical"]; + instance.alwaysBounceHorizontal = map["alwaysBounceHorizontal"]; + instance.scrollsToTop = map["scrollsToTop"]; + instance.isPagingEnabled = map["isPagingEnabled"]; + instance.maximumZoomScale = map["maximumZoomScale"]; + instance.minimumZoomScale = map["minimumZoomScale"]; + instance.contentInsetAdjustmentBehavior = IOSUIScrollViewContentInsetAdjustmentBehavior.fromValue( map["contentInsetAdjustmentBehavior"])!; - options.isDirectionalLockEnabled = map["isDirectionalLockEnabled"]; - options.mediaType = map["mediaType"]; - options.pageZoom = map["pageZoom"]; - options.limitsNavigationsToAppBoundDomains = + instance.isDirectionalLockEnabled = map["isDirectionalLockEnabled"]; + instance.mediaType = map["mediaType"]; + instance.pageZoom = map["pageZoom"]; + instance.limitsNavigationsToAppBoundDomains = map["limitsNavigationsToAppBoundDomains"]; - options.useOnNavigationResponse = map["useOnNavigationResponse"]; - options.applePayAPIEnabled = map["applePayAPIEnabled"]; - options.allowingReadAccessTo = map["allowingReadAccessTo"] != null + instance.useOnNavigationResponse = map["useOnNavigationResponse"]; + instance.applePayAPIEnabled = map["applePayAPIEnabled"]; + instance.allowingReadAccessTo = map["allowingReadAccessTo"] != null ? Uri.parse(map["allowingReadAccessTo"]) : null; - options.disableLongPressContextMenuOnLinks = + instance.disableLongPressContextMenuOnLinks = map["disableLongPressContextMenuOnLinks"]; - options.disableInputAccessoryView = map["disableInputAccessoryView"]; - return options; + instance.disableInputAccessoryView = map["disableInputAccessoryView"]; + return instance; } @override