This commit is contained in:
Lorenzo Pichilli 2022-04-22 16:57:29 +02:00
commit db58205ca1
7 changed files with 335 additions and 226 deletions

View File

@ -6,6 +6,10 @@
- Added support for `onPermissionRequest` event on iOS 15.0+
- Updated `getMetaThemeColor` on iOS 15.0+
## 5.4.0+3
- Fixed Android error in some cases when calling `setServiceWorkerClient` java method on `ServiceWorkerManager` initialization
## 5.4.0+2
- Fixed Android `ChromeCustomTabsActivity` not responding to the `ActionBroadcastReceiver`

View File

@ -59,6 +59,4 @@ Add `flutter_inappwebview` as a [dependency in your pubspec.yaml file](https://f
## Support
Use the [develop branch](https://github.com/pichillilorenzo/flutter_inappwebview/tree/develop) when making a pull request.
Did you find this plugin useful? Please consider to [make a donation](https://inappwebview.dev/donate/) to help improve it!

View File

@ -38,50 +38,6 @@ public class ServiceWorkerManager implements MethodChannel.MethodCallHandler {
channel.setMethodCallHandler(this);
if (WebViewFeature.isFeatureSupported(WebViewFeature.SERVICE_WORKER_BASIC_USAGE)) {
serviceWorkerController = ServiceWorkerControllerCompat.getInstance();
serviceWorkerController.setServiceWorkerClient(new ServiceWorkerClientCompat() {
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest request) {
final Map<String, Object> obj = new HashMap<>();
obj.put("url", request.getUrl().toString());
obj.put("method", request.getMethod());
obj.put("headers", request.getRequestHeaders());
obj.put("isForMainFrame", request.isForMainFrame());
obj.put("hasGesture", request.hasGesture());
obj.put("isRedirect", request.isRedirect());
Util.WaitFlutterResult flutterResult;
try {
flutterResult = Util.invokeMethodAndWait(channel, "shouldInterceptRequest", obj);
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
if (flutterResult.error != null) {
Log.e(LOG_TAG, flutterResult.error);
}
else if (flutterResult.result != null) {
Map<String, Object> res = (Map<String, Object>) flutterResult.result;
String contentType = (String) res.get("contentType");
String contentEncoding = (String) res.get("contentEncoding");
byte[] data = (byte[]) res.get("data");
Map<String, String> responseHeaders = (Map<String, String>) res.get("headers");
Integer statusCode = (Integer) res.get("statusCode");
String reasonPhrase = (String) res.get("reasonPhrase");
ByteArrayInputStream inputStream = (data != null) ? new ByteArrayInputStream(data) : null;
if ((responseHeaders == null && statusCode == null && reasonPhrase == null) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return new WebResourceResponse(contentType, contentEncoding, inputStream);
} else {
return new WebResourceResponse(contentType, contentEncoding, statusCode, reasonPhrase, responseHeaders, inputStream);
}
}
return null;
}
});
} else {
serviceWorkerController = null;
}
@ -92,6 +48,13 @@ public class ServiceWorkerManager implements MethodChannel.MethodCallHandler {
ServiceWorkerWebSettingsCompat serviceWorkerWebSettings = (serviceWorkerController != null) ? serviceWorkerController.getServiceWorkerWebSettings() : null;
switch (call.method) {
case "setServiceWorkerClient":
{
Boolean isNull = (Boolean) call.argument("isNull");
setServiceWorkerClient(isNull);
}
result.success(true);
break;
case "getAllowContentAccess":
if (serviceWorkerWebSettings != null && WebViewFeature.isFeatureSupported(WebViewFeature.SERVICE_WORKER_CONTENT_ACCESS)) {
result.success(serviceWorkerWebSettings.getAllowContentAccess());
@ -153,8 +116,61 @@ public class ServiceWorkerManager implements MethodChannel.MethodCallHandler {
}
}
private void setServiceWorkerClient(Boolean isNull) {
if (serviceWorkerController != null) {
serviceWorkerController.setServiceWorkerClient(isNull ? null : new ServiceWorkerClientCompat() {
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest request) {
final Map<String, Object> obj = new HashMap<>();
obj.put("url", request.getUrl().toString());
obj.put("method", request.getMethod());
obj.put("headers", request.getRequestHeaders());
obj.put("isForMainFrame", request.isForMainFrame());
obj.put("hasGesture", request.hasGesture());
obj.put("isRedirect", request.isRedirect());
Util.WaitFlutterResult flutterResult;
try {
flutterResult = Util.invokeMethodAndWait(channel, "shouldInterceptRequest", obj);
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
if (flutterResult.error != null) {
Log.e(LOG_TAG, flutterResult.error);
}
else if (flutterResult.result != null) {
Map<String, Object> res = (Map<String, Object>) flutterResult.result;
String contentType = (String) res.get("contentType");
String contentEncoding = (String) res.get("contentEncoding");
byte[] data = (byte[]) res.get("data");
Map<String, String> responseHeaders = (Map<String, String>) res.get("headers");
Integer statusCode = (Integer) res.get("statusCode");
String reasonPhrase = (String) res.get("reasonPhrase");
ByteArrayInputStream inputStream = (data != null) ? new ByteArrayInputStream(data) : null;
if ((responseHeaders == null && statusCode == null && reasonPhrase == null) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return new WebResourceResponse(contentType, contentEncoding, inputStream);
} else {
return new WebResourceResponse(contentType, contentEncoding, statusCode, reasonPhrase, responseHeaders, inputStream);
}
}
return null;
}
});
}
}
public void dispose() {
channel.setMethodCallHandler(null);
if (serviceWorkerController != null) {
serviceWorkerController.setServiceWorkerClient(null);
serviceWorkerController = null;
}
plugin = null;
}
}

View File

@ -1709,7 +1709,8 @@ void main() {
group('intercept ajax request', () {
testWidgets('send string data', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer shouldInterceptAjaxPostRequestCompleter =
Completer<void>();
final Completer<Map<String, dynamic>> onAjaxReadyStateChangeCompleter =
@ -1795,7 +1796,8 @@ void main() {
});
testWidgets('send json data', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer shouldInterceptAjaxPostRequestCompleter =
Completer<void>();
final Completer<Map<String, dynamic>> onAjaxReadyStateChangeCompleter =
@ -1843,7 +1845,8 @@ void main() {
},
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
String data = ajaxRequest.data;
assert(data.contains('"firstname":"Foo"') && data.contains('"lastname":"Bar"'));
assert(data.contains('"firstname":"Foo"') &&
data.contains('"lastname":"Bar"'));
ajaxRequest.responseType = 'json';
ajaxRequest.data = '{"firstname": "Foo2", "lastname": "Bar2"}';
@ -1886,7 +1889,8 @@ void main() {
});
testWidgets('send URLSearchParams data', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer shouldInterceptAjaxPostRequestCompleter =
Completer<void>();
final Completer<Map<String, dynamic>> onAjaxReadyStateChangeCompleter =
@ -1974,7 +1978,8 @@ void main() {
});
testWidgets('send FormData', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer shouldInterceptAjaxPostRequestCompleter =
Completer<void>();
final Completer<Map<String, dynamic>> onAjaxReadyStateChangeCompleter =
@ -2025,7 +2030,9 @@ void main() {
var bodyString = String.fromCharCodes(body);
assert(bodyString.indexOf("WebKitFormBoundary") >= 0);
ajaxRequest.data = utf8.encode(bodyString.replaceFirst("Foo", "Foo2").replaceFirst("Bar", "Bar2"));
ajaxRequest.data = utf8.encode(bodyString
.replaceFirst("Foo", "Foo2")
.replaceFirst("Bar", "Bar2"));
ajaxRequest.responseType = 'json';
shouldInterceptAjaxPostRequestCompleter.complete(controller);
return ajaxRequest;
@ -2068,7 +2075,8 @@ void main() {
group('intercept fetch request', () {
testWidgets('send string data', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer<Map<String, dynamic>> fetchPostCompleter =
Completer<Map<String, dynamic>>();
final Completer<void> shouldInterceptFetchPostRequestCompleter =
@ -2147,7 +2155,8 @@ void main() {
});
testWidgets('send json data', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer<Map<String, dynamic>> fetchPostCompleter =
Completer<Map<String, dynamic>>();
final Completer<void> shouldInterceptFetchPostRequestCompleter =
@ -2211,7 +2220,8 @@ void main() {
},
shouldInterceptFetchRequest: (controller, fetchRequest) async {
String body = fetchRequest.body;
assert(body.contains('"firstname":"Foo"') && body.contains('"lastname":"Bar"'));
assert(body.contains('"firstname":"Foo"') &&
body.contains('"lastname":"Bar"'));
fetchRequest.body = '{"firstname": "Foo2", "lastname": "Bar2"}';
shouldInterceptFetchPostRequestCompleter.complete();
@ -2231,7 +2241,8 @@ void main() {
});
testWidgets('send URLSearchParams data', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer<Map<String, dynamic>> fetchPostCompleter =
Completer<Map<String, dynamic>>();
final Completer<void> shouldInterceptFetchPostRequestCompleter =
@ -2312,7 +2323,8 @@ void main() {
});
testWidgets('send FormData', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer<Map<String, dynamic>> fetchPostCompleter =
Completer<Map<String, dynamic>>();
final Completer<void> shouldInterceptFetchPostRequestCompleter =
@ -2377,7 +2389,9 @@ void main() {
var bodyString = String.fromCharCodes(body);
assert(bodyString.indexOf("WebKitFormBoundary") >= 0);
fetchRequest.body = utf8.encode(bodyString.replaceFirst("Foo", "Foo2").replaceFirst("Bar", "Bar2"));
fetchRequest.body = utf8.encode(bodyString
.replaceFirst("Foo", "Foo2")
.replaceFirst("Bar", "Bar2"));
shouldInterceptFetchPostRequestCompleter.complete();
return fetchRequest;
},
@ -4167,10 +4181,14 @@ setTimeout(function() {
await pageLoaded.future;
await controller.injectJavascriptFileFromUrl(
urlFile: Uri.parse('https://www.notawebsite..com/jquery-3.3.1.min.js'),
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(id: 'jquery-error', onError: () {
urlFile:
Uri.parse('https://www.notawebsite..com/jquery-3.3.1.min.js'),
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(
id: 'jquery-error',
onError: () {
jQueryLoadError.complete();
},));
},
));
await jQueryLoadError.future;
expect(
await controller.evaluateJavascript(
@ -4182,9 +4200,12 @@ setTimeout(function() {
await controller.injectJavascriptFileFromUrl(
urlFile: Uri.parse('https://code.jquery.com/jquery-3.3.1.min.js'),
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(id: 'jquery', onLoad: () {
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(
id: 'jquery',
onLoad: () {
jQueryLoaded.complete();
},));
},
));
await jQueryLoaded.future;
expect(
await controller.evaluateJavascript(
@ -4903,7 +4924,8 @@ setTimeout(function() {
expect(await InAppWebViewController.getDefaultUserAgent(), isNotNull);
});
testWidgets('launches with pull-to-refresh feature', (WidgetTester tester) async {
testWidgets('launches with pull-to-refresh feature',
(WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final pullToRefreshController = PullToRefreshController(
options: PullToRefreshOptions(
@ -4913,11 +4935,8 @@ setTimeout(function() {
enabled: true,
slingshotDistance: 150,
distanceToTriggerSync: 150,
attributedTitle: IOSNSAttributedString(string: "test")
),
onRefresh: () {
},
attributedTitle: IOSNSAttributedString(string: "test")),
onRefresh: () {},
);
await tester.pumpWidget(
@ -4925,12 +4944,11 @@ setTimeout(function() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: Uri.parse('https://github.com/flutter')),
initialUrlRequest:
URLRequest(url: Uri.parse('https://github.com/flutter')),
initialOptions: InAppWebViewGroupOptions(
android: AndroidInAppWebViewOptions(
useHybridComposition: true
)
),
android:
AndroidInAppWebViewOptions(useHybridComposition: true)),
pullToRefreshController: pullToRefreshController,
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -4946,15 +4964,15 @@ setTimeout(function() {
group('WebMessage', () {
testWidgets('WebMessageChannel', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer webMessageCompleter = Completer<String>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialData: InAppWebViewInitialData(
data: """
initialData: InAppWebViewInitialData(data: """
<!DOCTYPE html>
<html lang="en">
<head>
@ -4989,15 +5007,20 @@ setTimeout(function() {
webMessageCompleter.complete(consoleMessage.message);
},
onLoadStop: (controller, url) async {
var webMessageChannel = await controller.createWebMessageChannel();
var webMessageChannel =
await controller.createWebMessageChannel();
var port1 = webMessageChannel!.port1;
var port2 = webMessageChannel.port2;
await port1.setWebMessageCallback((message) async {
await port1.postMessage(WebMessage(data: message! + " and back"));
await port1
.postMessage(WebMessage(data: message! + " and back"));
});
await controller.postWebMessage(message: WebMessage(data: "capturePort", ports: [port2]), targetOrigin: Uri.parse("*"));
await controller.evaluateJavascript(source: "document.getElementById('button').click();");
await controller.postWebMessage(
message: WebMessage(data: "capturePort", ports: [port2]),
targetOrigin: Uri.parse("*"));
await controller.evaluateJavascript(
source: "document.getElementById('button').click();");
},
),
),
@ -5009,7 +5032,8 @@ setTimeout(function() {
});
testWidgets('WebMessageListener', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
final Completer webMessageCompleter = Completer<String>();
await tester.pumpWidget(
@ -5021,8 +5045,10 @@ setTimeout(function() {
await controller.addWebMessageListener(WebMessageListener(
jsObjectName: "myTestObj",
allowedOriginRules: Set.from(["https://*.example.com"]),
onPostMessage: (message, sourceOrigin, isMainFrame, replyProxy) {
assert(sourceOrigin.toString() == "https://www.example.com");
onPostMessage:
(message, sourceOrigin, isMainFrame, replyProxy) {
assert(
sourceOrigin.toString() == "https://www.example.com");
assert(isMainFrame);
replyProxy.postMessage(message! + " and back");
@ -5042,7 +5068,8 @@ setTimeout(function() {
),
);
final controller = await controllerCompleter.future;
await controller.loadUrl(urlRequest: URLRequest(url: Uri.parse("https://www.example.com/")));
await controller.loadUrl(
urlRequest: URLRequest(url: Uri.parse("https://www.example.com/")));
await pageLoaded.future;
await controller.evaluateJavascript(source: """
@ -5273,7 +5300,9 @@ setTimeout(function() {
}, skip: !Platform.isAndroid);
test('setWebContentsDebuggingEnabled', () async {
expect(AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true), completes);
expect(
AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true),
completes);
}, skip: !Platform.isAndroid);
}, skip: !Platform.isAndroid);
@ -5377,8 +5406,7 @@ setTimeout(function() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialData: InAppWebViewInitialData(
data: """
initialData: InAppWebViewInitialData(data: """
<!DOCTYPE html>
<html lang="en">
<head>
@ -5393,8 +5421,7 @@ setTimeout(function() {
</script>
</body>
</html>
"""
),
"""),
initialOptions: InAppWebViewGroupOptions(
ios: IOSInAppWebViewOptions(
applePayAPIEnabled: true,
@ -5421,6 +5448,47 @@ setTimeout(function() {
}, skip: !Platform.isIOS);
});
group('Service Worker', () {
testWidgets('AndroidInAppWebViewController', (WidgetTester tester) async {
final Completer completer = Completer();
var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);
if (swAvailable && swInterceptAvailable) {
AndroidServiceWorkerController serviceWorkerController =
AndroidServiceWorkerController.instance();
await serviceWorkerController
.setServiceWorkerClient(AndroidServiceWorkerClient(
shouldInterceptRequest: (request) async {
if (!completer.isCompleted) {
completer.complete();
}
return null;
},
));
} else {
completer.complete();
}
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('https://mdn.github.io/sw-test/')),
),
),
);
expect(completer.future, completes);
}, skip: !Platform.isAndroid);
});
group('Cookie Manager', () {
testWidgets('set, get, delete', (WidgetTester tester) async {
CookieManager cookieManager = CookieManager.instance();
@ -5474,7 +5542,8 @@ setTimeout(function() {
final Completer<void> pageLoaded = Completer<void>();
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("https://github.com/flutter")),
initialUrlRequest:
URLRequest(url: Uri.parse("https://github.com/flutter")),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -5503,14 +5572,14 @@ setTimeout(function() {
final Completer<void> pageLoaded = Completer<void>();
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("https://github.com/flutter")),
initialUrlRequest:
URLRequest(url: Uri.parse("https://github.com/flutter")),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) async {
pageLoaded.complete();
}
);
});
await headlessWebView.run();
expect(headlessWebView.isRunning(), true);
@ -5537,7 +5606,8 @@ setTimeout(function() {
final Completer controllerCompleter = Completer<InAppWebViewController>();
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("https://github.com/flutter")),
initialUrlRequest:
URLRequest(url: Uri.parse("https://github.com/flutter")),
initialSize: Size(600, 800),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -5566,7 +5636,8 @@ setTimeout(function() {
final Completer<void> pageLoaded = Completer<void>();
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("https://github.com/flutter")),
initialUrlRequest:
URLRequest(url: Uri.parse("https://github.com/flutter")),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(javaScriptEnabled: false)),
onWebViewCreated: (controller) {
@ -5610,8 +5681,7 @@ setTimeout(function() {
expect(inAppBrowser.isOpened(), true);
expect(() async {
await inAppBrowser.openUrlRequest(
urlRequest:
URLRequest(url: Uri.parse("https://flutter.dev")));
urlRequest: URLRequest(url: Uri.parse("https://flutter.dev")));
}, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>()));
await inAppBrowser.firstPageLoaded.future;
@ -5633,7 +5703,8 @@ setTimeout(function() {
await inAppBrowser.show();
}, throwsA(isInstanceOf<InAppBrowserNotOpenedException>()));
await inAppBrowser.openFile(assetFilePath: "test_assets/in_app_webview_initial_file_test.html");
await inAppBrowser.openFile(
assetFilePath: "test_assets/in_app_webview_initial_file_test.html");
await inAppBrowser.browserCreated.future;
expect(inAppBrowser.isOpened(), true);
expect(() async {
@ -5661,7 +5732,8 @@ setTimeout(function() {
await inAppBrowser.show();
}, throwsA(isInstanceOf<InAppBrowserNotOpenedException>()));
await inAppBrowser.openData(data: """
await inAppBrowser.openData(
data: """
<!doctype html>
<html lang="en">
<head>
@ -5728,12 +5800,12 @@ setTimeout(function() {
var chromeSafariBrowser = new MyChromeSafariBrowser();
expect(chromeSafariBrowser.isOpened(), false);
await chromeSafariBrowser.open(url: Uri.parse("https://github.com/flutter"));
await chromeSafariBrowser.open(
url: Uri.parse("https://github.com/flutter"));
await chromeSafariBrowser.browserCreated.future;
expect(chromeSafariBrowser.isOpened(), true);
expect(() async {
await chromeSafariBrowser.open(
url: Uri.parse("https://flutter.dev"));
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes);
@ -5750,19 +5822,16 @@ setTimeout(function() {
await chromeSafariBrowser.open(
url: Uri.parse("https://github.com/flutter"),
options: ChromeSafariBrowserClassOptions(
android: AndroidChromeCustomTabsOptions(
isSingleInstance: true
)
)
);
android:
AndroidChromeCustomTabsOptions(isSingleInstance: true)));
await chromeSafariBrowser.browserCreated.future;
expect(chromeSafariBrowser.isOpened(), true);
expect(() async {
await chromeSafariBrowser.open(
url: Uri.parse("https://flutter.dev"));
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes);
await expectLater(
chromeSafariBrowser.firstPageLoaded.future, completes);
await chromeSafariBrowser.close();
await chromeSafariBrowser.browserClosed.future;
expect(chromeSafariBrowser.isOpened(), false);
@ -5776,18 +5845,15 @@ setTimeout(function() {
url: Uri.parse("https://github.com/flutter"),
options: ChromeSafariBrowserClassOptions(
android: AndroidChromeCustomTabsOptions(
isTrustedWebActivity: true
)
)
);
isTrustedWebActivity: true)));
await chromeSafariBrowser.browserCreated.future;
expect(chromeSafariBrowser.isOpened(), true);
expect(() async {
await chromeSafariBrowser.open(
url: Uri.parse("https://flutter.dev"));
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes);
await expectLater(
chromeSafariBrowser.firstPageLoaded.future, completes);
await chromeSafariBrowser.close();
await chromeSafariBrowser.browserClosed.future;
expect(chromeSafariBrowser.isOpened(), false);
@ -5801,19 +5867,15 @@ setTimeout(function() {
url: Uri.parse("https://github.com/flutter"),
options: ChromeSafariBrowserClassOptions(
android: AndroidChromeCustomTabsOptions(
isTrustedWebActivity: true,
isSingleInstance: true
)
)
);
isTrustedWebActivity: true, isSingleInstance: true)));
await chromeSafariBrowser.browserCreated.future;
expect(chromeSafariBrowser.isOpened(), true);
expect(() async {
await chromeSafariBrowser.open(
url: Uri.parse("https://flutter.dev"));
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes);
await expectLater(
chromeSafariBrowser.firstPageLoaded.future, completes);
await chromeSafariBrowser.close();
await chromeSafariBrowser.browserClosed.future;
expect(chromeSafariBrowser.isOpened(), false);
@ -5837,8 +5899,8 @@ setTimeout(function() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('http://localhost:8080/test_assets/index.html')),
initialUrlRequest: URLRequest(
url: Uri.parse('http://localhost:8080/test_assets/index.html')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},

View File

@ -83,7 +83,6 @@ class InAppBrowserExampleScreen extends StatefulWidget {
}
class _InAppBrowserExampleScreenState extends State<InAppBrowserExampleScreen> {
late PullToRefreshController pullToRefreshController;
@override
@ -99,7 +98,8 @@ class _InAppBrowserExampleScreenState extends State<InAppBrowserExampleScreen> {
widget.browser.webViewController.reload();
} else if (Platform.isIOS) {
widget.browser.webViewController.loadUrl(
urlRequest: URLRequest(url: await widget.browser.webViewController.getUrl()));
urlRequest: URLRequest(
url: await widget.browser.webViewController.getUrl()));
}
},
);

View File

@ -31,12 +31,13 @@ Future main() async {
ServiceWorkerController serviceWorkerController =
ServiceWorkerController.instance();
serviceWorkerController.serviceWorkerClient = ServiceWorkerClient(
await serviceWorkerController
.setServiceWorkerClient(ServiceWorkerClient(
shouldInterceptRequest: (request) async {
print(request);
return null;
},
);
));
}
}

View File

@ -14,13 +14,23 @@ class ServiceWorkerController {
static const MethodChannel _channel = const MethodChannel(
'com.pichillilorenzo/flutter_inappwebview_serviceworkercontroller');
ServiceWorkerClient? serviceWorkerClient;
///Gets the [ServiceWorkerController] shared instance.
static ServiceWorkerController instance() {
return (_instance != null) ? _instance! : _init();
}
ServiceWorkerClient? _serviceWorkerClient;
ServiceWorkerClient? get serviceWorkerClient => _serviceWorkerClient;
///Sets the service worker client
setServiceWorkerClient(ServiceWorkerClient? value) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('isNull', () => value == null);
await _channel.invokeMethod("setServiceWorkerClient", args);
_serviceWorkerClient = value;
}
static ServiceWorkerController _init() {
_channel.setMethodCallHandler(_handleMethod);
_instance = ServiceWorkerController();
@ -180,7 +190,25 @@ class AndroidServiceWorkerController {
static const MethodChannel _channel = const MethodChannel(
'com.pichillilorenzo/flutter_inappwebview_serviceworkercontroller');
AndroidServiceWorkerClient? serviceWorkerClient;
AndroidServiceWorkerClient? _serviceWorkerClient;
AndroidServiceWorkerClient? get serviceWorkerClient => _serviceWorkerClient;
@Deprecated("Use setServiceWorkerClient instead")
set serviceWorkerClient(AndroidServiceWorkerClient? value) {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('isNull', () => value == null);
_channel.invokeMethod("setServiceWorkerClient", args);
_serviceWorkerClient = value;
}
///Sets the service worker client
setServiceWorkerClient(AndroidServiceWorkerClient? value) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('isNull', () => value == null);
await _channel.invokeMethod("setServiceWorkerClient", args);
_serviceWorkerClient = value;
}
///Gets the [AndroidServiceWorkerController] shared instance.
static AndroidServiceWorkerController instance() {