Skip to content

Commit

Permalink
Updated code docs, Fixed some missing macOS asserts, fix #1447
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Nov 30, 2022
1 parent 2d32eff commit fc98712
Show file tree
Hide file tree
Showing 41 changed files with 1,226 additions and 998 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 6.0.0-beta.19

- Updated code docs
- Fixed "Cannot Grant Permission at Android 21" [#1447](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1447)
- Fixed some missing macOS asserts

## 6.0.0-beta.18

- Fixed `InAppWebViewSettings` automatic infer if `initialSettings` is `null`
Expand Down Expand Up @@ -158,6 +164,10 @@
- Removed `URLProtectionSpace.iosIsProxy` property
- `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null`

## 5.7.2+1

- Fixed "Cannot Grant Permission at Android 21" [#1447](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1447)

## 5.7.2

- Removed Android Hybrid Composition constraint to use the pull-to-refresh feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ private Boolean isArrayEmpty(String[] arr) {

@Override
public void onPermissionRequest(final PermissionRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final WebViewChannelDelegate.PermissionRequestCallback callback = new WebViewChannelDelegate.PermissionRequestCallback() {
@Override
public boolean nonNullSuccess(@NonNull PermissionResponse response) {
Expand Down
8 changes: 7 additions & 1 deletion dev_packages/generators/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ abstract class Util {
final platformName = platform.getField("name")!.toStringValue();
final note = platform.getField("note")?.toStringValue();
if (note != null) {
platformNoteList.add("///**NOTE for $platformName**: $note");
final noteLines = note.split("\n");
var platformNote =
"///**NOTE for $platformName**: ${noteLines[0].trim()}";
for (int i = 1; i < noteLines.length; i++) {
platformNote += "\n///${noteLines[i].trim()}";
}
platformNoteList.add(platformNote);
}

final apiName = platform.getField("apiName")?.toStringValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void openAndClose() {
activityButton: ActivityButton(
templateImage: UIImage(systemName: "sun.max"),
extensionIdentifier:
"com.pichillilorenzo.flutter-inappwebview-6-Example.test")));
"com.pichillilorenzo.flutter-inappwebview6-example.test")));
await chromeSafariBrowser.opened.future;
expect(chromeSafariBrowser.isOpened(), true);
expect(() async {
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
MARKETING_VERSION = 1.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview-6-Example.test";
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview6-example.test";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
Expand Down Expand Up @@ -484,7 +484,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 1.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview-6-Example.test";
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview6-example.test";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -627,7 +627,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview-6-Example";
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview6-example";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -659,7 +659,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview-6-Example";
PRODUCT_BUNDLE_IDENTIFIER = "com.pichillilorenzo.flutter-inappwebview6-example";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
2 changes: 1 addition & 1 deletion lib/src/chrome_safari_browser/chrome_safari_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class ChromeSafariBrowser {
// ignore: deprecated_member_use_from_same_package
ChromeSafariBrowserClassOptions? options,
ChromeSafariBrowserSettings? settings}) async {
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.iOS) {
if (Util.isIOS) {
assert(url != null, 'The specified URL must not be null on iOS.');
assert(['http', 'https'].contains(url!.scheme),
'The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported on iOS.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';

import '../types/activity_button.dart';
Expand Down Expand Up @@ -341,10 +340,9 @@ class ChromeSafariBrowserClassOptions {

Map<String, dynamic> toMap() {
Map<String, dynamic> options = {};
if (defaultTargetPlatform == TargetPlatform.android)
if (Util.isAndroid)
options.addAll(this.android?.toMap() ?? {});
else if (defaultTargetPlatform == TargetPlatform.iOS)
options.addAll(this.ios?.toMap() ?? {});
else if (Util.isIOS) options.addAll(this.ios?.toMap() ?? {});

return options;
}
Expand Down
7 changes: 3 additions & 4 deletions lib/src/context_menu.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/foundation.dart';

import 'in_app_webview/webview.dart';
import 'types/main.dart';
import 'util.dart';

///Class that represents the WebView context menu. It used by [WebView.contextMenu].
///
Expand Down Expand Up @@ -89,11 +88,11 @@ class ContextMenuItem {
@Deprecated("Use id instead") this.iosId,
required this.title,
this.action}) {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Util.isAndroid) {
// ignore: deprecated_member_use_from_same_package
this.id = this.id ?? this.androidId;
assert(this.id is int);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
} else if (Util.isIOS) {
// ignore: deprecated_member_use_from_same_package
this.id = this.id ?? this.iosId;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/cookie_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'in_app_webview/headless_in_app_webview.dart';
import 'platform_util.dart';

import 'types/main.dart';
import 'util.dart';
import 'web_uri.dart';

///Class that implements a singleton object (shared instance) which manages the cookies used by WebView instances.
Expand Down Expand Up @@ -519,14 +520,13 @@ class CookieManager {
}

Future<bool> _shouldUseJavascript() async {
if (kIsWeb) {
if (Util.isWeb) {
return true;
}
if (defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS) {
if (Util.isIOS || Util.isMacOS) {
final platformUtil = PlatformUtil.instance();
final systemVersion = await platformUtil.getSystemVersion();
return defaultTargetPlatform == TargetPlatform.iOS
return Util.isIOS
? systemVersion.compareTo("11") == -1
: systemVersion.compareTo("10.13") == -1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/in_app_browser/in_app_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ class InAppBrowser {
///[permissionRequest] represents the permission request with an array of resources the web content wants to access
///and the origin of the web page which is trying to access the restricted resources.
///
///**NOTE for Android**: available only on Android 23+.
///**NOTE for Android**: available only on Android 21+.
///
///**NOTE for iOS**: available only on iOS 15.0+. The default [PermissionResponse.action] is [PermissionResponseAction.PROMPT].
///
Expand Down
8 changes: 4 additions & 4 deletions lib/src/in_app_browser/in_app_browser_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ class InAppBrowserClassOptions {

options.addAll(this.crossPlatform.toMap());
options.addAll(this.inAppWebViewGroupOptions.crossPlatform.toMap());
if (defaultTargetPlatform == TargetPlatform.android) {
if (Util.isAndroid) {
options.addAll(this.android.toMap());
options.addAll(this.inAppWebViewGroupOptions.android.toMap());
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
} else if (Util.isIOS) {
options.addAll(this.ios.toMap());
options.addAll(this.inAppWebViewGroupOptions.ios.toMap());
}
Expand All @@ -380,12 +380,12 @@ class InAppBrowserClassOptions {
InAppWebViewGroupOptions();
inAppBrowserClassOptions.inAppWebViewGroupOptions.crossPlatform =
InAppWebViewOptions.fromMap(options);
if (defaultTargetPlatform == TargetPlatform.android) {
if (Util.isAndroid) {
inAppBrowserClassOptions.android =
AndroidInAppBrowserOptions.fromMap(options);
inAppBrowserClassOptions.inAppWebViewGroupOptions.android =
AndroidInAppWebViewOptions.fromMap(options);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
} else if (Util.isIOS) {
inAppBrowserClassOptions.ios = IOSInAppBrowserOptions.fromMap(options);
inAppBrowserClassOptions.inAppWebViewGroupOptions.ios =
IOSInAppWebViewOptions.fromMap(options);
Expand Down
8 changes: 3 additions & 5 deletions lib/src/in_app_webview/in_app_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ class _InAppWebViewState extends State<InAppWebView> {
widget.pullToRefreshController?.options.toMap() ??
PullToRefreshSettings(enabled: false).toMap();

if (kIsWeb) {
if (Util.isWeb) {
return HtmlElementView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: (int viewId) {
Expand All @@ -659,7 +659,7 @@ class _InAppWebViewState extends State<InAppWebView> {
_onPlatformViewCreated(viewId);
},
);
} else if (defaultTargetPlatform == TargetPlatform.android) {
} else if (Util.isAndroid) {
var useHybridComposition = (widget.initialSettings != null
? initialSettings.useHybridComposition
:
Expand Down Expand Up @@ -710,9 +710,7 @@ class _InAppWebViewState extends State<InAppWebView> {
..create();
},
);
} else if (defaultTargetPlatform ==
TargetPlatform
.iOS /* || defaultTargetPlatform == TargetPlatform.macOS*/) {
} else if (Util.isIOS /* || Util.isMacOS*/) {
return UiKitView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: _onPlatformViewCreated,
Expand Down
33 changes: 12 additions & 21 deletions lib/src/in_app_webview/in_app_webview_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1976,8 +1976,7 @@ class InAppWebViewController {
args.putIfAbsent('source', () => source);
args.putIfAbsent('contentWorld', () => contentWorld?.toMap());
var data = await _channel.invokeMethod('evaluateJavascript', args);
if (data != null &&
(defaultTargetPlatform == TargetPlatform.android || kIsWeb)) {
if (data != null && (Util.isAndroid || Util.isWeb)) {
try {
// try to json decode the data coming from JavaScript
// otherwise return it as it is.
Expand Down Expand Up @@ -2497,10 +2496,8 @@ class InAppWebViewController {
{required double zoomFactor,
@Deprecated('Use animated instead') bool? iosAnimated,
bool animated = false}) async {
assert(defaultTargetPlatform != TargetPlatform.android ||
(defaultTargetPlatform == TargetPlatform.android &&
zoomFactor > 0.01 &&
zoomFactor <= 100.0));
assert(!Util.isAndroid ||
(Util.isAndroid && zoomFactor > 0.01 && zoomFactor <= 100.0));

Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('zoomFactor', () => zoomFactor);
Expand Down Expand Up @@ -2819,8 +2816,7 @@ class InAppWebViewController {
///- iOS ([Official API - WKUserContentController.addUserScript](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537448-adduserscript))
///- MacOS ([Official API - WKUserContentController.addUserScript](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537448-adduserscript))
Future<void> addUserScript({required UserScript userScript}) async {
assert(_webview?.windowId == null ||
defaultTargetPlatform != TargetPlatform.iOS);
assert(_webview?.windowId == null || (!Util.isIOS && !Util.isMacOS));

Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('userScript', () => userScript.toMap());
Expand All @@ -2842,8 +2838,7 @@ class InAppWebViewController {
///- iOS
///- MacOS
Future<void> addUserScripts({required List<UserScript> userScripts}) async {
assert(_webview?.windowId == null ||
defaultTargetPlatform != TargetPlatform.iOS);
assert(_webview?.windowId == null || (!Util.isIOS && !Util.isMacOS));

for (var i = 0; i < userScripts.length; i++) {
await addUserScript(userScript: userScripts[i]);
Expand All @@ -2863,8 +2858,7 @@ class InAppWebViewController {
///- iOS
///- MacOS
Future<bool> removeUserScript({required UserScript userScript}) async {
assert(_webview?.windowId == null ||
defaultTargetPlatform != TargetPlatform.iOS);
assert(_webview?.windowId == null || (!Util.isIOS && !Util.isMacOS));

var index = _userScripts[userScript.injectionTime]?.indexOf(userScript);
if (index == null || index == -1) {
Expand Down Expand Up @@ -2892,8 +2886,7 @@ class InAppWebViewController {
///- iOS
///- MacOS
Future<void> removeUserScriptsByGroupName({required String groupName}) async {
assert(_webview?.windowId == null ||
defaultTargetPlatform != TargetPlatform.iOS);
assert(_webview?.windowId == null || (!Util.isIOS && !Util.isMacOS));

final List<UserScript> userScriptsAtDocumentStart = List.from(
_userScripts[UserScriptInjectionTime.AT_DOCUMENT_START] ?? []);
Expand Down Expand Up @@ -2929,8 +2922,7 @@ class InAppWebViewController {
///- MacOS
Future<void> removeUserScripts(
{required List<UserScript> userScripts}) async {
assert(_webview?.windowId == null ||
defaultTargetPlatform != TargetPlatform.iOS);
assert(_webview?.windowId == null || (!Util.isIOS && !Util.isMacOS));

for (final userScript in userScripts) {
await removeUserScript(userScript: userScript);
Expand All @@ -2948,8 +2940,7 @@ class InAppWebViewController {
///- iOS ([Official API - WKUserContentController.removeAllUserScripts](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1536540-removealluserscripts))
///- MacOS ([Official API - WKUserContentController.removeAllUserScripts](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1536540-removealluserscripts))
Future<void> removeAllUserScripts() async {
assert(_webview?.windowId == null ||
defaultTargetPlatform != TargetPlatform.iOS);
assert(_webview?.windowId == null || (!Util.isIOS && !Util.isMacOS));

_userScripts[UserScriptInjectionTime.AT_DOCUMENT_START]?.clear();
_userScripts[UserScriptInjectionTime.AT_DOCUMENT_END]?.clear();
Expand Down Expand Up @@ -3003,7 +2994,7 @@ class InAppWebViewController {
if (data == null) {
return null;
}
if (defaultTargetPlatform == TargetPlatform.android) {
if (Util.isAndroid) {
data = json.decode(data);
}
return CallAsyncJavaScriptResult(
Expand Down Expand Up @@ -3031,9 +3022,9 @@ class InAppWebViewController {
Future<String?> saveWebArchive(
{required String filePath, bool autoname = false}) async {
if (!autoname) {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Util.isAndroid) {
assert(filePath.endsWith("." + WebArchiveFormat.MHT.toNativeValue()));
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
} else if (Util.isIOS || Util.isMacOS) {
assert(filePath
.endsWith("." + WebArchiveFormat.WEBARCHIVE.toNativeValue()));
}
Expand Down
Loading

0 comments on commit fc98712

Please sign in to comment.