diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/IWebViewSettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ISettings.java similarity index 62% rename from android/src/main/java/com/pichillilorenzo/flutter_inappwebview/IWebViewSettings.java rename to android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ISettings.java index 3a2dc606..e6d326ab 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/IWebViewSettings.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ISettings.java @@ -2,8 +2,8 @@ package com.pichillilorenzo.flutter_inappwebview; import java.util.Map; -public interface IWebViewSettings { - public IWebViewSettings parse(Map settings); +public interface ISettings { + public ISettings parse(Map settings); public Map toMap(); public Map getRealSettings(T obj); } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsSettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsSettings.java index 0d4c0845..f8af7c91 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsSettings.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsSettings.java @@ -7,14 +7,14 @@ import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.trusted.ScreenOrientation; import androidx.browser.trusted.TrustedWebActivityDisplayMode; -import com.pichillilorenzo.flutter_inappwebview.IWebViewSettings; +import com.pichillilorenzo.flutter_inappwebview.ISettings; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class ChromeCustomTabsSettings implements IWebViewSettings { +public class ChromeCustomTabsSettings implements ISettings { final static String LOG_TAG = "ChromeCustomTabsSettings"; diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserSettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserSettings.java index 12c188f8..682f1820 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserSettings.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.IWebViewSettings; +import com.pichillilorenzo.flutter_inappwebview.ISettings; import com.pichillilorenzo.flutter_inappwebview.R; import java.util.HashMap; import java.util.Map; -public class InAppBrowserSettings implements IWebViewSettings { +public class InAppBrowserSettings implements ISettings { public static final String LOG_TAG = "InAppBrowserSettings"; diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/ContextMenuOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/ContextMenuSettings.java similarity index 82% rename from android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/ContextMenuOptions.java rename to android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/ContextMenuSettings.java index 6e937450..cbbafe5d 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/ContextMenuOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/ContextMenuSettings.java @@ -1,16 +1,16 @@ package com.pichillilorenzo.flutter_inappwebview.in_app_webview; -import com.pichillilorenzo.flutter_inappwebview.IWebViewSettings; +import com.pichillilorenzo.flutter_inappwebview.ISettings; import java.util.HashMap; import java.util.Map; -public class ContextMenuOptions implements IWebViewSettings { +public class ContextMenuSettings implements ISettings { public static final String LOG_TAG = "ContextMenuOptions"; public Boolean hideDefaultSystemContextMenuItems = false; - public ContextMenuOptions parse(Map options) { + public ContextMenuSettings parse(Map options) { for (Map.Entry pair : options.entrySet()) { String key = pair.getKey(); Object value = pair.getValue(); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java index 3d7a987f..f4eac58e 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java @@ -55,6 +55,7 @@ import androidx.webkit.WebViewFeature; import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin; import com.pichillilorenzo.flutter_inappwebview.types.DownloadStartRequest; +import com.pichillilorenzo.flutter_inappwebview.types.HitTestResult; import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface; import com.pichillilorenzo.flutter_inappwebview.JavaScriptBridgeInterface; import com.pichillilorenzo.flutter_inappwebview.R; @@ -1367,17 +1368,17 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie LinearLayout menuItemListLayout = (LinearLayout) horizontalScrollView.getChildAt(0); List> customMenuItems = new ArrayList<>(); - ContextMenuOptions contextMenuOptions = new ContextMenuOptions(); + ContextMenuSettings contextMenuSettings = new ContextMenuSettings(); if (contextMenu != null) { customMenuItems = (List>) contextMenu.get("menuItems"); - Map contextMenuOptionsMap = (Map) contextMenu.get("options"); + Map contextMenuOptionsMap = (Map) contextMenu.get("settings"); if (contextMenuOptionsMap != null) { - contextMenuOptions.parse(contextMenuOptionsMap); + contextMenuSettings.parse(contextMenuOptionsMap); } } customMenuItems = customMenuItems == null ? new ArrayList>() : customMenuItems; - if (contextMenuOptions.hideDefaultSystemContextMenuItems == null || !contextMenuOptions.hideDefaultSystemContextMenuItems) { + if (contextMenuSettings.hideDefaultSystemContextMenuItems == null || !contextMenuSettings.hideDefaultSystemContextMenuItems) { for (int i = 0; i < actionMenu.size(); i++) { final MenuItem menuItem = actionMenu.getItem(i); final int itemId = menuItem.getItemId(); @@ -1393,6 +1394,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie callback.onActionItemClicked(actionMode, menuItem); Map obj = new HashMap<>(); + obj.put("id", itemId); obj.put("androidId", itemId); obj.put("iosId", null); obj.put("title", itemTitle); @@ -1406,7 +1408,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie } for (final Map menuItem : customMenuItems) { - final int itemId = (int) menuItem.get("androidId"); + final int itemId = (int) menuItem.get("id"); final String itemTitle = (String) menuItem.get("title"); TextView text = (TextView) LayoutInflater.from(this.getContext()) .inflate(R.layout.floating_action_mode_item, this, false); @@ -1417,6 +1419,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie hideContextMenu(); Map obj = new HashMap<>(); + obj.put("id", itemId); obj.put("androidId", itemId); obj.put("iosId", null); obj.put("title", itemTitle); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java index 2fb040be..3b3e0c07 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java @@ -6,7 +6,7 @@ import android.webkit.WebSettings; import androidx.annotation.Nullable; -import com.pichillilorenzo.flutter_inappwebview.IWebViewSettings; +import com.pichillilorenzo.flutter_inappwebview.ISettings; import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface; import com.pichillilorenzo.flutter_inappwebview.types.PreferredContentModeOptionType; @@ -18,7 +18,7 @@ import java.util.Map; import static android.webkit.WebSettings.LayoutAlgorithm.NARROW_COLUMNS; import static android.webkit.WebSettings.LayoutAlgorithm.NORMAL; -public class InAppWebViewSettings implements IWebViewSettings { +public class InAppWebViewSettings implements ISettings { public static final String LOG_TAG = "InAppWebViewSettings"; diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshSettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshSettings.java index 4a13c943..479a9697 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshSettings.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshSettings.java @@ -2,12 +2,12 @@ package com.pichillilorenzo.flutter_inappwebview.pull_to_refresh; import androidx.annotation.Nullable; -import com.pichillilorenzo.flutter_inappwebview.IWebViewSettings; +import com.pichillilorenzo.flutter_inappwebview.ISettings; import java.util.HashMap; import java.util.Map; -public class PullToRefreshSettings implements IWebViewSettings { +public class PullToRefreshSettings implements ISettings { public static final String LOG_TAG = "PullToRefreshSettings"; public Boolean enabled = true; diff --git a/example/lib/chrome_safari_browser_example.screen.dart b/example/lib/chrome_safari_browser_example.screen.dart index f1ab1ea5..b21f569a 100755 --- a/example/lib/chrome_safari_browser_example.screen.dart +++ b/example/lib/chrome_safari_browser_example.screen.dart @@ -71,8 +71,7 @@ class _ChromeSafariBrowserExampleScreenState keepAliveEnabled: true, dismissButtonStyle: DismissButtonStyle.CLOSE, presentationStyle: - ModalPresentationStyle.OVER_FULL_SCREEN - )); + ModalPresentationStyle.OVER_FULL_SCREEN)); }, child: Text("Open Chrome Safari Browser")), )); diff --git a/example/lib/in_app_browser_example.screen.dart b/example/lib/in_app_browser_example.screen.dart index c7a5e22b..2a28996b 100755 --- a/example/lib/in_app_browser_example.screen.dart +++ b/example/lib/in_app_browser_example.screen.dart @@ -121,14 +121,14 @@ class _InAppBrowserExampleScreenState extends State { ElevatedButton( onPressed: () async { await widget.browser.openUrlRequest( - urlRequest: - URLRequest(url: Uri.parse("https://flutter.dev")), - settings: InAppBrowserClassSettings( - webViewSettings: InAppWebViewSettings( - useShouldOverrideUrlLoading: true, - useOnLoadResource: true, - ), + urlRequest: + URLRequest(url: Uri.parse("https://flutter.dev")), + settings: InAppBrowserClassSettings( + webViewSettings: InAppWebViewSettings( + useShouldOverrideUrlLoading: true, + useOnLoadResource: true, ), + ), ); }, child: Text("Open In-App Browser")), diff --git a/example/lib/in_app_webiew_example.screen.dart b/example/lib/in_app_webiew_example.screen.dart index f6b6a4d6..c43c5caa 100755 --- a/example/lib/in_app_webiew_example.screen.dart +++ b/example/lib/in_app_webiew_example.screen.dart @@ -1,11 +1,7 @@ import 'dart:collection'; -// import 'dart:convert'; -import 'dart:io'; -// import 'dart:typed_data'; - +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; -// import 'package:path_provider/path_provider.dart'; import 'package:url_launcher/url_launcher.dart'; import 'main.dart'; @@ -17,7 +13,6 @@ class InAppWebViewExampleScreen extends StatefulWidget { } class _InAppWebViewExampleScreenState extends State { - final GlobalKey webViewKey = GlobalKey(); InAppWebViewController? webViewController; @@ -25,8 +20,7 @@ class _InAppWebViewExampleScreenState extends State { useShouldOverrideUrlLoading: true, mediaPlaybackRequiresUserGesture: false, useHybridComposition: true, - allowsInlineMediaPlayback: true - ); + allowsInlineMediaPlayback: true); late PullToRefreshController pullToRefreshController; late ContextMenu contextMenu; @@ -41,8 +35,7 @@ class _InAppWebViewExampleScreenState extends State { contextMenu = ContextMenu( menuItems: [ ContextMenuItem( - androidId: 1, - iosId: "1", + id: 1, title: "Special", action: () async { print("Menu item Special clicked!"); @@ -50,7 +43,7 @@ class _InAppWebViewExampleScreenState extends State { await webViewController?.clearFocus(); }) ], - options: ContextMenuOptions(hideDefaultSystemContextMenuItems: false), + settings: ContextMenuSettings(hideDefaultSystemContextMenuItems: false), onCreateContextMenu: (hitTestResult) async { print("onCreateContextMenu"); print(hitTestResult.extra); @@ -60,9 +53,7 @@ class _InAppWebViewExampleScreenState extends State { print("onHideContextMenu"); }, onContextMenuActionItemClicked: (contextMenuItemClicked) async { - var id = (Platform.isAndroid) - ? contextMenuItemClicked.androidId - : contextMenuItemClicked.iosId; + var id = contextMenuItemClicked.id; print("onContextMenuActionItemClicked: " + id.toString() + " " + @@ -74,9 +65,9 @@ class _InAppWebViewExampleScreenState extends State { color: Colors.blue, ), onRefresh: () async { - if (Platform.isAndroid) { + if (defaultTargetPlatform == TargetPlatform.android) { webViewController?.reload(); - } else if (Platform.isIOS) { + } else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) { webViewController?.loadUrl( urlRequest: URLRequest(url: await webViewController?.getUrl())); } @@ -97,9 +88,7 @@ class _InAppWebViewExampleScreenState extends State { body: SafeArea( child: Column(children: [ TextField( - decoration: InputDecoration( - prefixIcon: Icon(Icons.search) - ), + decoration: InputDecoration(prefixIcon: Icon(Icons.search)), controller: urlController, keyboardType: TextInputType.url, onSubmitted: (value) { @@ -107,94 +96,95 @@ class _InAppWebViewExampleScreenState extends State { if (url.scheme.isEmpty) { url = Uri.parse("https://www.google.com/search?q=" + value); } - webViewController?.loadUrl( - urlRequest: URLRequest(url: url)); + webViewController?.loadUrl(urlRequest: URLRequest(url: url)); }, ), Expanded( - child: Stack( - children: [ - InAppWebView( - key: webViewKey, - // contextMenu: contextMenu, - initialUrlRequest: - URLRequest(url: Uri.parse("http://github.com/flutter/")), - // initialFile: "assets/index.html", - initialUserScripts: UnmodifiableListView([]), - initialSettings: settings, - pullToRefreshController: pullToRefreshController, - onWebViewCreated: (controller) { - webViewController = controller; - }, - onLoadStart: (controller, url) async { - setState(() { - this.url = url.toString(); - urlController.text = this.url; - }); - }, - onPermissionRequest: (controller, request) async { - return PermissionResponse( - resources: request.resources, - action: PermissionResponseAction.GRANT); - }, - shouldOverrideUrlLoading: (controller, navigationAction) async { - var uri = navigationAction.request.url!; + child: Stack( + children: [ + InAppWebView( + key: webViewKey, + // contextMenu: contextMenu, + initialUrlRequest: + URLRequest(url: Uri.parse("http://github.com/flutter/")), + // initialFile: "assets/index.html", + initialUserScripts: UnmodifiableListView([]), + initialSettings: settings, + // contextMenu: contextMenu, + pullToRefreshController: pullToRefreshController, + onWebViewCreated: (controller) { + webViewController = controller; + }, + onLoadStart: (controller, url) async { + setState(() { + this.url = url.toString(); + urlController.text = this.url; + }); + }, + onPermissionRequest: (controller, request) async { + return PermissionResponse( + resources: request.resources, + action: PermissionResponseAction.GRANT); + }, + shouldOverrideUrlLoading: + (controller, navigationAction) async { + var uri = navigationAction.request.url!; - if (![ - "http", - "https", - "file", - "chrome", - "data", - "javascript", - "about" - ].contains(uri.scheme)) { - if (await canLaunch(url)) { - // Launch the App - await launch( - url, - ); - // and cancel the request - return NavigationActionPolicy.CANCEL; - } + if (![ + "http", + "https", + "file", + "chrome", + "data", + "javascript", + "about" + ].contains(uri.scheme)) { + if (await canLaunch(url)) { + // Launch the App + await launch( + url, + ); + // and cancel the request + return NavigationActionPolicy.CANCEL; } + } - return NavigationActionPolicy.ALLOW; - }, - onLoadStop: (controller, url) async { + return NavigationActionPolicy.ALLOW; + }, + onLoadStop: (controller, url) async { + pullToRefreshController.endRefreshing(); + setState(() { + this.url = url.toString(); + urlController.text = this.url; + }); + }, + onLoadError: (controller, url, code, message) { + pullToRefreshController.endRefreshing(); + }, + onProgressChanged: (controller, progress) { + if (progress == 100) { pullToRefreshController.endRefreshing(); - setState(() { - this.url = url.toString(); - urlController.text = this.url; - }); - }, - onLoadError: (controller, url, code, message) { - pullToRefreshController.endRefreshing(); - }, - onProgressChanged: (controller, progress) { - if (progress == 100) { - pullToRefreshController.endRefreshing(); - } - setState(() { - this.progress = progress / 100; - urlController.text = this.url; - }); - }, - onUpdateVisitedHistory: (controller, url, androidIsReload) { - setState(() { - this.url = url.toString(); - urlController.text = this.url; - }); - }, - onConsoleMessage: (controller, consoleMessage) { - print(consoleMessage); - }, - ), - progress < 1.0 - ? LinearProgressIndicator(value: progress) - : Container(), - ], - ), + } + setState(() { + this.progress = progress / 100; + urlController.text = this.url; + }); + }, + onUpdateVisitedHistory: (controller, url, androidIsReload) { + setState(() { + this.url = url.toString(); + urlController.text = this.url; + }); + }, + onConsoleMessage: (controller, consoleMessage) { + print(consoleMessage); + }, + ), + progress < 1.0 + ? LinearProgressIndicator(value: progress) + : Container(), + ], + ), ), ButtonBar( alignment: MainAxisAlignment.center, diff --git a/example/lib/main.dart b/example/lib/main.dart index 2a782777..4c65d583 100755 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -31,8 +31,7 @@ Future main() async { ServiceWorkerController serviceWorkerController = ServiceWorkerController.instance(); - await serviceWorkerController - .setServiceWorkerClient(ServiceWorkerClient( + await serviceWorkerController.setServiceWorkerClient(ServiceWorkerClient( shouldInterceptRequest: (request) async { print(request); return null; diff --git a/ios/Classes/ContextMenuOptions.swift b/ios/Classes/ContextMenuSettings.swift similarity index 81% rename from ios/Classes/ContextMenuOptions.swift rename to ios/Classes/ContextMenuSettings.swift index f113670f..e0b5594d 100644 --- a/ios/Classes/ContextMenuOptions.swift +++ b/ios/Classes/ContextMenuSettings.swift @@ -7,7 +7,7 @@ import Foundation -class ContextMenuOptions: IWebViewSettings { +class ContextMenuSettings: ISettings { var hideDefaultSystemContextMenuItems = false; diff --git a/ios/Classes/IWebViewSettings.swift b/ios/Classes/ISettings.swift similarity index 90% rename from ios/Classes/IWebViewSettings.swift rename to ios/Classes/ISettings.swift index 4a3c247b..7e12fdd5 100755 --- a/ios/Classes/IWebViewSettings.swift +++ b/ios/Classes/ISettings.swift @@ -8,13 +8,13 @@ import Foundation @objcMembers -public class IWebViewSettings: NSObject { +public class ISettings: NSObject { override init(){ super.init() } - func parse(settings: [String: Any?]) -> IWebViewSettings { + func parse(settings: [String: Any?]) -> ISettings { for (key, value) in settings { if !(value is NSNull), value != nil, self.responds(to: Selector(key)) { self.setValue(value, forKey: key) diff --git a/ios/Classes/InAppBrowser/InAppBrowserSettings.swift b/ios/Classes/InAppBrowser/InAppBrowserSettings.swift index 5dd8d07c..ea265651 100755 --- a/ios/Classes/InAppBrowser/InAppBrowserSettings.swift +++ b/ios/Classes/InAppBrowser/InAppBrowserSettings.swift @@ -8,7 +8,7 @@ import Foundation @objcMembers -public class InAppBrowserSettings: IWebViewSettings { +public class InAppBrowserSettings: ISettings { var hidden = false var hideToolbarTop = true diff --git a/ios/Classes/InAppWebView/InAppWebView.swift b/ios/Classes/InAppWebView/InAppWebView.swift index 856270c3..c0cbc1cf 100755 --- a/ios/Classes/InAppWebView/InAppWebView.swift +++ b/ios/Classes/InAppWebView/InAppWebView.swift @@ -203,13 +203,15 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi if let menu = self.contextMenu { if let menuItems = menu["menuItems"] as? [[String : Any]] { for menuItem in menuItems { - let id = menuItem["iosId"] as! String + let id = menuItem["id"]! let title = menuItem["title"] as! String - let targetMethodName = "onContextMenuActionItemClicked-" + String(self.hash) + "-" + id + let targetMethodName = "onContextMenuActionItemClicked-" + String(self.hash) + "-" + + (id is Int64 ? String(id as! Int64) : id as! String) if !self.responds(to: Selector(targetMethodName)) { let customAction: () -> Void = { let arguments: [String: Any?] = [ - "iosId": id, + "id": id, + "iosId": id is Int64 ? String(id as! Int64) : id as! String, "androidId": nil, "title": title ] @@ -244,10 +246,10 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi } if let menu = contextMenu { - let contextMenuOptions = ContextMenuOptions() - if let contextMenuOptionsMap = menu["options"] as? [String: Any?] { - let _ = contextMenuOptions.parse(settings: contextMenuOptionsMap) - if !action.description.starts(with: "onContextMenuActionItemClicked-") && contextMenuOptions.hideDefaultSystemContextMenuItems { + let contextMenuSettings = ContextMenuSettings() + if let contextMenuSettingsMap = menu["settings"] as? [String: Any?] { + let _ = contextMenuSettings.parse(settings: contextMenuSettingsMap) + if !action.description.starts(with: "onContextMenuActionItemClicked-") && contextMenuSettings.hideDefaultSystemContextMenuItems { return false } } @@ -256,6 +258,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi if contextMenuIsShowing, !action.description.starts(with: "onContextMenuActionItemClicked-") { let id = action.description.compactMap({ $0.asciiValue?.description }).joined() let arguments: [String: Any?] = [ + "id": id, "iosId": id, "androidId": nil, "title": action.description diff --git a/ios/Classes/InAppWebView/InAppWebViewSettings.swift b/ios/Classes/InAppWebView/InAppWebViewSettings.swift index c51b1c99..d3597bb5 100755 --- a/ios/Classes/InAppWebView/InAppWebViewSettings.swift +++ b/ios/Classes/InAppWebView/InAppWebViewSettings.swift @@ -9,7 +9,7 @@ import Foundation import WebKit @objcMembers -public class InAppWebViewSettings: IWebViewSettings { +public class InAppWebViewSettings: ISettings { var useShouldOverrideUrlLoading = false var useOnLoadResource = false diff --git a/ios/Classes/PullToRefresh/PullToRefreshSettings.swift b/ios/Classes/PullToRefresh/PullToRefreshSettings.swift index 01125db7..f241c59d 100644 --- a/ios/Classes/PullToRefresh/PullToRefreshSettings.swift +++ b/ios/Classes/PullToRefresh/PullToRefreshSettings.swift @@ -7,7 +7,7 @@ import Foundation -public class PullToRefreshSettings : IWebViewSettings { +public class PullToRefreshSettings : ISettings { var enabled = true var color: String? diff --git a/ios/Classes/SafariViewController/SafariBrowserSettings.swift b/ios/Classes/SafariViewController/SafariBrowserSettings.swift index af67ee76..dd9d1f8a 100755 --- a/ios/Classes/SafariViewController/SafariBrowserSettings.swift +++ b/ios/Classes/SafariViewController/SafariBrowserSettings.swift @@ -9,7 +9,7 @@ import Foundation @available(iOS 9.0, *) @objcMembers -public class SafariBrowserSettings: IWebViewSettings { +public class SafariBrowserSettings: ISettings { var entersReaderIfAvailable = false var barCollapsingEnabled = false diff --git a/lib/src/chrome_safari_browser/chrome_safari_browser_settings.dart b/lib/src/chrome_safari_browser/chrome_safari_browser_settings.dart index a9ccc7ff..7187c56b 100755 --- a/lib/src/chrome_safari_browser/chrome_safari_browser_settings.dart +++ b/lib/src/chrome_safari_browser/chrome_safari_browser_settings.dart @@ -242,8 +242,8 @@ class ChromeSafariBrowserSettings implements ChromeSafariBrowserOptions { settings.additionalTrustedOrigins = map["additionalTrustedOrigins"]; switch (map["displayMode"]["type"]) { case "IMMERSIVE_MODE": - settings.displayMode = - TrustedWebActivityImmersiveDisplayMode.fromMap(map["displayMode"]); + settings.displayMode = TrustedWebActivityImmersiveDisplayMode.fromMap( + map["displayMode"]); break; case "DEFAULT_MODE": default: @@ -256,15 +256,15 @@ class ChromeSafariBrowserSettings implements ChromeSafariBrowserOptions { settings.entersReaderIfAvailable = map["entersReaderIfAvailable"]; settings.barCollapsingEnabled = map["barCollapsingEnabled"]; settings.dismissButtonStyle = - DismissButtonStyle.fromValue(map["dismissButtonStyle"])!; + DismissButtonStyle.fromValue(map["dismissButtonStyle"])!; settings.preferredBarTintColor = UtilColor.fromHex(map["preferredBarTintColor"]); settings.preferredControlTintColor = UtilColor.fromHex(map["preferredControlTintColor"]); settings.presentationStyle = - ModalPresentationStyle.fromValue(map["presentationStyle"])!; + ModalPresentationStyle.fromValue(map["presentationStyle"])!; settings.transitionStyle = - ModalTransitionStyle.fromValue(map["transitionStyle"])!; + ModalTransitionStyle.fromValue(map["transitionStyle"])!; } return settings; } diff --git a/lib/src/context_menu.dart b/lib/src/context_menu.dart index 1ff12542..038ddcfe 100644 --- a/lib/src/context_menu.dart +++ b/lib/src/context_menu.dart @@ -1,3 +1,5 @@ +import 'package:flutter/foundation.dart'; + import 'in_app_webview/webview.dart'; import 'types.dart'; @@ -20,9 +22,13 @@ class ContextMenu { final void Function(ContextMenuItem contextMenuItemClicked)? onContextMenuActionItemClicked; - ///Context menu options. + ///Use [settings] instead + @Deprecated("Use settings instead") final ContextMenuOptions? options; + ///Context menu settings. + final ContextMenuSettings? settings; + ///List of the custom [ContextMenuItem]. final List menuItems; @@ -31,12 +37,14 @@ class ContextMenu { this.onCreateContextMenu, this.onHideContextMenu, this.options, + this.settings, this.onContextMenuActionItemClicked}); Map toMap() { return { "menuItems": menuItems.map((menuItem) => menuItem.toMap()).toList(), - "options": options?.toMap() + // ignore: deprecated_member_use_from_same_package + "settings": settings?.toMap() ?? options?.toMap() }; } @@ -52,12 +60,19 @@ class ContextMenu { ///Class that represent an item of the [ContextMenu]. class ContextMenuItem { - ///Android menu item ID. + ///Use [id] instead. + @Deprecated("Use id instead") int? androidId; - ///iOS menu item ID. + ///Use [id] instead. + @Deprecated("Use id instead") String? iosId; + ///Menu item ID. It cannot be `null` and it can be a [String] or an [int]. + /// + ///**NOTE for Android**: it must be an [int] value. + dynamic id; + ///Menu item title. String title; @@ -65,10 +80,31 @@ class ContextMenuItem { Function()? action; ContextMenuItem( - {this.androidId, this.iosId, required this.title, this.action}); + {this.id, + this.androidId, + this.iosId, + required this.title, + this.action}) { + if (defaultTargetPlatform == TargetPlatform.android) { + // ignore: deprecated_member_use_from_same_package + this.id = this.id ?? this.androidId; + assert(this.id is int); + } else if (defaultTargetPlatform == TargetPlatform.iOS) { + // ignore: deprecated_member_use_from_same_package + this.id = this.id ?? this.iosId; + } + assert(this.id != null && (this.id is int || this.id is String)); + } Map toMap() { - return {"androidId": androidId, "iosId": iosId, "title": title}; + return { + "id": id, + // ignore: deprecated_member_use_from_same_package + "androidId": androidId, + // ignore: deprecated_member_use_from_same_package + "iosId": iosId, + "title": title + }; } Map toJson() { @@ -81,7 +117,31 @@ class ContextMenuItem { } } -///Class that represents available options used by [ContextMenu]. +///Class that represents available settings used by [ContextMenu]. +class ContextMenuSettings { + ///Whether all the default system context menu items should be hidden or not. The default value is `false`. + bool hideDefaultSystemContextMenuItems; + + ContextMenuSettings({this.hideDefaultSystemContextMenuItems = false}); + + Map toMap() { + return { + "hideDefaultSystemContextMenuItems": hideDefaultSystemContextMenuItems + }; + } + + Map toJson() { + return this.toMap(); + } + + @override + String toString() { + return toMap().toString(); + } +} + +///Use [ContextMenuSettings] instead. +@Deprecated("Use ContextMenuSettings instead") class ContextMenuOptions { ///Whether all the default system context menu items should be hidden or not. The default value is `false`. bool hideDefaultSystemContextMenuItems; diff --git a/lib/src/in_app_browser/in_app_browser_settings.dart b/lib/src/in_app_browser/in_app_browser_settings.dart index 023829bd..05aaab6f 100755 --- a/lib/src/in_app_browser/in_app_browser_settings.dart +++ b/lib/src/in_app_browser/in_app_browser_settings.dart @@ -287,7 +287,7 @@ class InAppBrowserSettings settings.closeOnCannotGoBack = map["closeOnCannotGoBack"]; settings.allowGoBackWithBackButton = map["allowGoBackWithBackButton"]; settings.shouldCloseOnBackButtonPressed = - map["shouldCloseOnBackButtonPressed"]; + map["shouldCloseOnBackButtonPressed"]; } if (Platform.isIOS || Platform.isMacOS) { settings.toolbarTopTranslucent = map["toolbarTopTranslucent"]; @@ -302,9 +302,9 @@ class InAppBrowserSettings settings.closeButtonCaption = map["closeButtonCaption"]; settings.closeButtonColor = UtilColor.fromHex(map["closeButtonColor"]); settings.presentationStyle = - ModalPresentationStyle.fromValue(map["presentationStyle"])!; + ModalPresentationStyle.fromValue(map["presentationStyle"])!; settings.transitionStyle = - ModalTransitionStyle.fromValue(map["transitionStyle"])!; + ModalTransitionStyle.fromValue(map["transitionStyle"])!; } return settings; } diff --git a/lib/src/in_app_webview/apple/in_app_webview_controller.dart b/lib/src/in_app_webview/apple/in_app_webview_controller.dart index ad43faa1..9c3de23d 100644 --- a/lib/src/in_app_webview/apple/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/apple/in_app_webview_controller.dart @@ -107,7 +107,8 @@ abstract class AppleInAppWebViewControllerMixin { ///- iOS ([Official API - WKWebView.requestMediaPlaybackState](https://developer.apple.com/documentation/webkit/wkwebview/3752241-requestmediaplaybackstate)). Future requestMediaPlaybackState() async { Map args = {}; - return MediaPlaybackState.fromValue(await _channel.invokeMethod('requestMediaPlaybackState', args)); + return MediaPlaybackState.fromValue( + await _channel.invokeMethod('requestMediaPlaybackState', args)); } } diff --git a/lib/src/in_app_webview/in_app_webview.dart b/lib/src/in_app_webview/in_app_webview.dart index 5a48f574..89dc27cc 100755 --- a/lib/src/in_app_webview/in_app_webview.dart +++ b/lib/src/in_app_webview/in_app_webview.dart @@ -469,8 +469,7 @@ class InAppWebView extends StatefulWidget implements WebView { NavigationResponse navigationResponse)? onNavigationResponse; @override - final Future Function( - InAppWebViewController controller, + final Future Function(InAppWebViewController controller, PermissionRequest permissionRequest)? onPermissionRequest; @override diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index b68b9445..191a98f0 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -732,9 +732,9 @@ class InAppWebViewController List resources = call.arguments["resources"].cast(); Map arguments = - call.arguments.cast(); + call.arguments.cast(); PermissionRequest permissionRequest = - PermissionRequest.fromMap(arguments)!; + PermissionRequest.fromMap(arguments)!; if (_webview != null) { if (_webview!.onPermissionRequest != null) @@ -748,11 +748,12 @@ class InAppWebViewController ?.toMap(); } } else { - return (await _inAppBrowser! - .onPermissionRequest(permissionRequest))?.toMap() ?? - (await _inAppBrowser! + return (await _inAppBrowser!.onPermissionRequest(permissionRequest)) + ?.toMap() ?? + (await _inAppBrowser! // ignore: deprecated_member_use_from_same_package - .androidOnPermissionRequest(origin, resources))?.toMap(); + .androidOnPermissionRequest(origin, resources)) + ?.toMap(); } } break; @@ -945,16 +946,18 @@ class InAppWebViewController if (contextMenu != null) { int? androidId = call.arguments["androidId"]; String? iosId = call.arguments["iosId"]; + dynamic id = call.arguments["id"]; String title = call.arguments["title"]; ContextMenuItem menuItemClicked = ContextMenuItem( - androidId: androidId, iosId: iosId, title: title, action: null); + id: id, + androidId: androidId, + iosId: iosId, + title: title, + action: null); for (var menuItem in contextMenu.menuItems) { - if ((defaultTargetPlatform == TargetPlatform.android && - menuItem.androidId == androidId) || - (defaultTargetPlatform == TargetPlatform.iOS && - menuItem.iosId == iosId)) { + if (menuItem.id == id) { menuItemClicked = menuItem; if (menuItem.action != null) { menuItem.action!(); @@ -1847,7 +1850,8 @@ class InAppWebViewController ///Use [setSettings] instead. @Deprecated('Use setSettings instead') Future setOptions({required InAppWebViewGroupOptions options}) async { - InAppWebViewSettings settings = InAppWebViewSettings.fromMap(options.toMap()); + InAppWebViewSettings settings = + InAppWebViewSettings.fromMap(options.toMap()); await setSettings(settings: settings); } @@ -2306,7 +2310,8 @@ class InAppWebViewController try { Map args = {}; - themeColor = UtilColor.fromStringRepresentation(await _channel.invokeMethod('getMetaThemeColor', args)); + themeColor = UtilColor.fromStringRepresentation( + await _channel.invokeMethod('getMetaThemeColor', args)); } catch (e) { // not implemented } diff --git a/lib/src/in_app_webview/in_app_webview_settings.dart b/lib/src/in_app_webview/in_app_webview_settings.dart index d5becaca..7b23b00d 100755 --- a/lib/src/in_app_webview/in_app_webview_settings.dart +++ b/lib/src/in_app_webview/in_app_webview_settings.dart @@ -1357,7 +1357,7 @@ class InAppWebViewSettings settings.hardwareAcceleration = map["hardwareAcceleration"]; settings.supportMultipleWindows = map["supportMultipleWindows"]; settings.regexToCancelSubFramesLoading = - map["regexToCancelSubFramesLoading"]; + map["regexToCancelSubFramesLoading"]; settings.useHybridComposition = map["useHybridComposition"]; settings.useShouldInterceptRequest = map["useShouldInterceptRequest"]; settings.useOnRenderProcessGone = map["useOnRenderProcessGone"]; @@ -1367,7 +1367,7 @@ class InAppWebViewSettings settings.verticalScrollbarPosition = VerticalScrollbarPosition.fromValue(map["verticalScrollbarPosition"]); settings.scrollBarDefaultDelayBeforeFade = - map["scrollBarDefaultDelayBeforeFade"]; + map["scrollBarDefaultDelayBeforeFade"]; settings.scrollbarFadingEnabled = map["scrollbarFadingEnabled"]; settings.scrollBarFadeDuration = map["scrollBarFadeDuration"]; settings.rendererPriorityPolicy = RendererPriorityPolicy.fromMap( @@ -1386,28 +1386,28 @@ class InAppWebViewSettings settings.disallowOverScroll = map["disallowOverScroll"]; settings.enableViewportScale = map["enableViewportScale"]; settings.suppressesIncrementalRendering = - map["suppressesIncrementalRendering"]; + map["suppressesIncrementalRendering"]; settings.allowsAirPlayForMediaPlayback = - map["allowsAirPlayForMediaPlayback"]; + map["allowsAirPlayForMediaPlayback"]; settings.allowsBackForwardNavigationGestures = - map["allowsBackForwardNavigationGestures"]; + map["allowsBackForwardNavigationGestures"]; settings.allowsLinkPreview = map["allowsLinkPreview"]; settings.ignoresViewportScaleLimits = map["ignoresViewportScaleLimits"]; settings.allowsInlineMediaPlayback = map["allowsInlineMediaPlayback"]; settings.allowsPictureInPictureMediaPlayback = - map["allowsPictureInPictureMediaPlayback"]; + map["allowsPictureInPictureMediaPlayback"]; settings.isFraudulentWebsiteWarningEnabled = - map["isFraudulentWebsiteWarningEnabled"]; + map["isFraudulentWebsiteWarningEnabled"]; settings.selectionGranularity = - SelectionGranularity.fromValue(map["selectionGranularity"])!; + SelectionGranularity.fromValue(map["selectionGranularity"])!; settings.dataDetectorTypes = dataDetectorTypes; settings.sharedCookiesEnabled = map["sharedCookiesEnabled"]; settings.automaticallyAdjustsScrollIndicatorInsets = - map["automaticallyAdjustsScrollIndicatorInsets"]; + map["automaticallyAdjustsScrollIndicatorInsets"]; settings.accessibilityIgnoresInvertColors = - map["accessibilityIgnoresInvertColors"]; + map["accessibilityIgnoresInvertColors"]; settings.decelerationRate = - ScrollViewDecelerationRate.fromValue(map["decelerationRate"])!; + ScrollViewDecelerationRate.fromValue(map["decelerationRate"])!; settings.alwaysBounceVertical = map["alwaysBounceVertical"]; settings.alwaysBounceHorizontal = map["alwaysBounceHorizontal"]; settings.scrollsToTop = map["scrollsToTop"]; @@ -1415,24 +1415,26 @@ class InAppWebViewSettings settings.maximumZoomScale = map["maximumZoomScale"]; settings.minimumZoomScale = map["minimumZoomScale"]; settings.contentInsetAdjustmentBehavior = - ScrollViewContentInsetAdjustmentBehavior.fromValue( - map["contentInsetAdjustmentBehavior"])!; + ScrollViewContentInsetAdjustmentBehavior.fromValue( + map["contentInsetAdjustmentBehavior"])!; settings.isDirectionalLockEnabled = map["isDirectionalLockEnabled"]; settings.mediaType = map["mediaType"]; settings.pageZoom = map["pageZoom"]; settings.limitsNavigationsToAppBoundDomains = - map["limitsNavigationsToAppBoundDomains"]; + map["limitsNavigationsToAppBoundDomains"]; settings.useOnNavigationResponse = map["useOnNavigationResponse"]; settings.applePayAPIEnabled = map["applePayAPIEnabled"]; settings.allowingReadAccessTo = map["allowingReadAccessTo"] != null ? Uri.parse(map["allowingReadAccessTo"]) : null; settings.disableLongPressContextMenuOnLinks = - map["disableLongPressContextMenuOnLinks"]; + map["disableLongPressContextMenuOnLinks"]; settings.disableInputAccessoryView = map["disableInputAccessoryView"]; - settings.underPageBackgroundColor = UtilColor.fromHex(map["underPageBackgroundColor"]); + settings.underPageBackgroundColor = + UtilColor.fromHex(map["underPageBackgroundColor"]); settings.isTextInteractionEnabled = map["isTextInteractionEnabled"]; - settings.isSiteSpecificQuirksModeEnabled = map["isSiteSpecificQuirksModeEnabled"]; + settings.isSiteSpecificQuirksModeEnabled = + map["isSiteSpecificQuirksModeEnabled"]; settings.upgradeKnownHostsToHTTPS = map["upgradeKnownHostsToHTTPS"]; } return settings; diff --git a/lib/src/in_app_webview/webview.dart b/lib/src/in_app_webview/webview.dart index af7036fa..326144c0 100644 --- a/lib/src/in_app_webview/webview.dart +++ b/lib/src/in_app_webview/webview.dart @@ -510,8 +510,7 @@ abstract class WebView { /// ///**Supported Platforms/Implementations**: ///- Android native WebView ([Official API - WebChromeClient.onPermissionRequest](https://developer.android.com/reference/android/webkit/WebChromeClient#onPermissionRequest(android.webkit.PermissionRequest))) - final Future Function( - InAppWebViewController controller, + final Future Function(InAppWebViewController controller, PermissionRequest permissionRequest)? onPermissionRequest; ///Use [onGeolocationPermissionsShowPrompt] instead. diff --git a/lib/src/types.dart b/lib/src/types.dart index e9fa0c63..6d323c96 100755 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -4769,7 +4769,8 @@ class PermissionResourceType { PermissionResourceType.RESOURCE_VIDEO_CAPTURE, ].toSet(); - static final Set _appleValues = [ + static final Set _appleValues = + [ PermissionResourceType.CAMERA, PermissionResourceType.MICROPHONE, PermissionResourceType.CAMERA_AND_MICROPHONE, @@ -4779,7 +4780,8 @@ class PermissionResourceType { static PermissionResourceType? fromValue(dynamic? value) { if (value != null) { try { - Set valueList = [].toSet(); + Set valueList = + [].toSet(); if (Platform.isAndroid) { valueList = PermissionResourceType._androidValues; } else if (Platform.isIOS || Platform.isMacOS) { @@ -4815,52 +4817,51 @@ class PermissionResourceType { ///Resource belongs to audio capture device, like microphone. /// ///**NOTE**: available only on Android. - static const RESOURCE_AUDIO_CAPTURE = const PermissionResourceType._internal('android.webkit.resource.AUDIO_CAPTURE'); + static const RESOURCE_AUDIO_CAPTURE = const PermissionResourceType._internal( + 'android.webkit.resource.AUDIO_CAPTURE'); - ///Resource will allow sysex messages to be sent to or received from MIDI devices. - ///These messages are privileged operations, e.g. modifying sound libraries and sampling data, or even updating the MIDI device's firmware. + ///Resource will allow sysex messages to be sent to or received from MIDI devices. + ///These messages are privileged operations, e.g. modifying sound libraries and sampling data, or even updating the MIDI device's firmware. ///Permission may be requested for this resource in API levels 21 and above, if the Android device has been updated to WebView 45 or above. /// ///**NOTE**: available only on Android. - static const RESOURCE_MIDI_SYSEX = - const PermissionResourceType._internal('android.webkit.resource.MIDI_SYSEX'); + static const RESOURCE_MIDI_SYSEX = const PermissionResourceType._internal( + 'android.webkit.resource.MIDI_SYSEX'); ///Resource belongs to protected media identifier. After the user grants this resource, the origin can use EME APIs to generate the license requests. /// ///**NOTE**: available only on Android. static const RESOURCE_PROTECTED_MEDIA_ID = - const PermissionResourceType._internal('android.webkit.resource.PROTECTED_MEDIA_ID'); - + const PermissionResourceType._internal( + 'android.webkit.resource.PROTECTED_MEDIA_ID'); ///Resource belongs to video capture device, like camera. /// ///**NOTE**: available only on Android. - static const RESOURCE_VIDEO_CAPTURE = - const PermissionResourceType._internal('android.webkit.resource.VIDEO_CAPTURE'); + static const RESOURCE_VIDEO_CAPTURE = const PermissionResourceType._internal( + 'android.webkit.resource.VIDEO_CAPTURE'); ///A media device that can capture video. /// ///**NOTE**: available only on iOS. - static const CAMERA = - const PermissionResourceType._internal(0); + static const CAMERA = const PermissionResourceType._internal(0); ///A media device that can capture audio. /// ///**NOTE**: available only on iOS. - static const MICROPHONE = - const PermissionResourceType._internal(1); + static const MICROPHONE = const PermissionResourceType._internal(1); ///A media device or devices that can capture audio and video. /// ///**NOTE**: available only on iOS. static const CAMERA_AND_MICROPHONE = - const PermissionResourceType._internal(2); + const PermissionResourceType._internal(2); ///Resource belongs to the device’s orientation and motion. /// ///**NOTE**: available only on iOS. static const DEVICE_ORIENTATION_AND_MOTION = - const PermissionResourceType._internal('deviceOrientationAndMotion'); + const PermissionResourceType._internal('deviceOrientationAndMotion'); bool operator ==(value) => value == _value; @@ -4880,9 +4881,7 @@ class PermissionRequest { FrameInfo? frame; PermissionRequest( - {required this.origin, - this.resources = const [], - this.frame}); + {required this.origin, this.resources = const [], this.frame}); static PermissionRequest? fromMap(Map? map) { if (map == null) { @@ -4891,8 +4890,7 @@ class PermissionRequest { List resources = []; if (map["resources"] != null) { - (map["resources"].cast() as List) - .forEach((element) { + (map["resources"].cast() as List).forEach((element) { var resource = PermissionResourceType.fromValue(element); if (resource != null) { resources.add(resource); @@ -4908,7 +4906,7 @@ class PermissionRequest { Map toMap() { return { - "origin": origin.toString(), + "origin": origin.toString(), "resources": resources.map((e) => e.toValue()).toList(), "frame": frame?.toMap() }; @@ -4933,8 +4931,7 @@ class PermissionResponse { PermissionResponseAction? action; PermissionResponse( - {this.resources = const [], - this.action = PermissionResponseAction.DENY}); + {this.resources = const [], this.action = PermissionResponseAction.DENY}); Map toMap() { return { @@ -10688,19 +10685,16 @@ class MediaPlaybackState { static const NONE = const MediaPlaybackState._internal(0); ///The media is playing. - static const PLAYING = - const MediaPlaybackState._internal(1); + static const PLAYING = const MediaPlaybackState._internal(1); ///The media playback is paused. - static const PAUSED = - const MediaPlaybackState._internal(2); + static const PAUSED = const MediaPlaybackState._internal(2); ///The media is not playing, and cannot be resumed until the user revokes the suspension. - static const SUSPENDED = - const MediaPlaybackState._internal(3); + static const SUSPENDED = const MediaPlaybackState._internal(3); bool operator ==(value) => value == _value; @override int get hashCode => _value.hashCode; -} \ No newline at end of file +}