Skip to content

Commit 3101b44

Browse files
All PrintJobSettings properties are optionals, All PullToRefreshSettings properties are optionals, All WebAuthenticationSessionSettings properties are optionals, Automatically infer useShouldOverrideUrlLoading, useOnLoadResource, useOnDownloadStart, useShouldInterceptAjaxRequest, useShouldInterceptFetchRequest, useShouldInterceptRequest, useOnRenderProcessGone, useOnNavigationResponse settings if their value is null and the corresponding event is implemented by the WebView (InAppWebView and HeadlessInAppWebView, not InAppBrowser) before it's native initialization
1 parent d39b1ef commit 3101b44

23 files changed

+1022
-283
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 6.0.0-beta.15
2+
3+
- Automatically infer `useShouldOverrideUrlLoading`, `useOnLoadResource`, `useOnDownloadStart`, `useShouldInterceptAjaxRequest`, `useShouldInterceptFetchRequest`, `useShouldInterceptRequest`, `useOnRenderProcessGone`, `useOnNavigationResponse` settings if their value is `null` and the corresponding event is implemented by the WebView (`InAppWebView` and `HeadlessInAppWebView`, not `InAppBrowser`) before it's native initialization.
4+
5+
### BREAKING CHANGES
6+
7+
- All `PrintJobSettings` properties are optionals
8+
- All `PullToRefreshSettings` properties are optionals
9+
- All `WebAuthenticationSessionSettings` properties are optionals
10+
111
## 6.0.0-beta.14
212

313
- Fixed User Script remove methods
@@ -135,6 +145,15 @@
135145
- Removed `URLProtectionSpace.iosIsProxy` property
136146
- `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null`
137147

148+
## 5.7.1+2
149+
150+
- Fixed Android `NullPointerException` on `InAppBrowserActivity.dispose`
151+
152+
## 5.7.1+1
153+
154+
- Fixed User Script remove methods
155+
- Fixed missing `break` statement on Android when parsing `ChromeCustomTabsOptions.displayMode` in Java code
156+
138157
## 5.7.1
139158

140159
- Exposed "shared" property of HttpServer bind method to support more use-cases. (thanks to [LugonjaAleksandar](https://github.com/LugonjaAleksandar))

example/integration_test/in_app_webview/intercept_ajax_request.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ void interceptAjaxRequest() {
5656
"""),
5757
initialSettings: InAppWebViewSettings(
5858
clearCache: true,
59-
useShouldInterceptAjaxRequest: true,
6059
),
6160
onWebViewCreated: (controller) {
6261
controllerCompleter.complete(controller);
@@ -146,7 +145,6 @@ void interceptAjaxRequest() {
146145
"""),
147146
initialSettings: InAppWebViewSettings(
148147
clearCache: true,
149-
useShouldInterceptAjaxRequest: true,
150148
),
151149
onWebViewCreated: (controller) {
152150
controllerCompleter.complete(controller);
@@ -236,7 +234,6 @@ void interceptAjaxRequest() {
236234
"""),
237235
initialSettings: InAppWebViewSettings(
238236
clearCache: true,
239-
useShouldInterceptAjaxRequest: true,
240237
),
241238
onWebViewCreated: (controller) {
242239
controllerCompleter.complete(controller);
@@ -324,7 +321,6 @@ void interceptAjaxRequest() {
324321
"""),
325322
initialSettings: InAppWebViewSettings(
326323
clearCache: true,
327-
useShouldInterceptAjaxRequest: true,
328324
),
329325
onWebViewCreated: (controller) {
330326
controllerCompleter.complete(controller);

example/integration_test/in_app_webview/intercept_fetch_request.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ void interceptFetchRequest() {
6565
"""),
6666
initialSettings: InAppWebViewSettings(
6767
clearCache: true,
68-
useShouldInterceptFetchRequest: true,
6968
),
7069
onWebViewCreated: (controller) {
7170
controllerCompleter.complete(controller);
@@ -148,7 +147,6 @@ void interceptFetchRequest() {
148147
"""),
149148
initialSettings: InAppWebViewSettings(
150149
clearCache: true,
151-
useShouldInterceptFetchRequest: true,
152150
),
153151
onWebViewCreated: (controller) {
154152
controllerCompleter.complete(controller);
@@ -231,7 +229,6 @@ void interceptFetchRequest() {
231229
"""),
232230
initialSettings: InAppWebViewSettings(
233231
clearCache: true,
234-
useShouldInterceptFetchRequest: true,
235232
),
236233
onWebViewCreated: (controller) {
237234
controllerCompleter.complete(controller);
@@ -310,7 +307,6 @@ void interceptFetchRequest() {
310307
"""),
311308
initialSettings: InAppWebViewSettings(
312309
clearCache: true,
313-
useShouldInterceptFetchRequest: true,
314310
),
315311
onWebViewCreated: (controller) {
316312
controllerCompleter.complete(controller);

example/integration_test/in_app_webview/on_download_start_request.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void onDownloadStartRequest() {
4646
</html>
4747
"""),
4848
initialSettings:
49-
InAppWebViewSettings(clearCache: true, useOnDownloadStart: true),
49+
InAppWebViewSettings(clearCache: true),
5050
onWebViewCreated: (controller) {
5151
controllerCompleter.complete(controller);
5252
},

example/integration_test/in_app_webview/on_load_resource.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void onLoadResource() {
3333
initialFile:
3434
"test_assets/in_app_webview_on_load_resource_test.html",
3535
initialSettings:
36-
InAppWebViewSettings(clearCache: true, useOnLoadResource: true),
36+
InAppWebViewSettings(clearCache: true),
3737
onLoadStop: (controller, url) {
3838
pageLoaded.complete();
3939
},

example/integration_test/in_app_webview/on_navigation_response.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void onNavigationResponse() {
3030
key: GlobalKey(),
3131
initialUrlRequest: URLRequest(url: TEST_URL_1),
3232
initialSettings:
33-
InAppWebViewSettings(useOnNavigationResponse: true),
33+
InAppWebViewSettings(),
3434
onWebViewCreated: (controller) {
3535
controllerCompleter.complete(controller);
3636
},
@@ -65,7 +65,7 @@ void onNavigationResponse() {
6565
key: GlobalKey(),
6666
initialUrlRequest: URLRequest(url: TEST_URL_1),
6767
initialSettings:
68-
InAppWebViewSettings(useOnNavigationResponse: true),
68+
InAppWebViewSettings(),
6969
onWebViewCreated: (controller) {
7070
controllerCompleter.complete(controller);
7171
},

example/integration_test/in_app_webview/should_intercept_request.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void shouldInterceptRequest() {
4646
</html>
4747
"""),
4848
initialSettings:
49-
InAppWebViewSettings(useShouldInterceptRequest: true),
49+
InAppWebViewSettings(),
5050
onWebViewCreated: (controller) {
5151
controllerCompleter.complete(controller);
5252
},

example/integration_test/in_app_webview/should_override_url_loading.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void shouldOverrideUrlLoading() {
3939
},
4040
initialSettings: InAppWebViewSettings(
4141
javaScriptEnabled: true,
42-
useShouldOverrideUrlLoading: true,
4342
),
4443
shouldOverrideUrlLoading: (controller, navigationAction) async {
4544
return (navigationAction.request.url!.host
@@ -92,7 +91,6 @@ void shouldOverrideUrlLoading() {
9291
},
9392
initialSettings: InAppWebViewSettings(
9493
javaScriptEnabled: true,
95-
useShouldOverrideUrlLoading: true,
9694
),
9795
shouldOverrideUrlLoading: (controller, navigationAction) async {
9896
var isFirstLoad = navigationAction.request.url!.scheme == "data";
@@ -151,7 +149,6 @@ void shouldOverrideUrlLoading() {
151149
},
152150
initialSettings: InAppWebViewSettings(
153151
javaScriptEnabled: true,
154-
useShouldOverrideUrlLoading: true,
155152
),
156153
shouldOverrideUrlLoading: (controller, navigationAction) async {
157154
return (navigationAction.request.url!.host
@@ -203,7 +200,6 @@ void shouldOverrideUrlLoading() {
203200
},
204201
initialSettings: InAppWebViewSettings(
205202
javaScriptEnabled: true,
206-
useShouldOverrideUrlLoading: true,
207203
),
208204
shouldOverrideUrlLoading: (controller, navigationAction) async {
209205
var action = NavigationActionPolicy.CANCEL;

example/lib/in_app_webiew_example.screen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
1717

1818
InAppWebViewController? webViewController;
1919
InAppWebViewSettings settings = InAppWebViewSettings(
20-
useShouldOverrideUrlLoading: true,
2120
mediaPlaybackRequiresUserGesture: false,
2221
allowsInlineMediaPlayback: true,
2322
iframeAllow: "camera; microphone",

lib/src/in_app_webview/headless_in_app_webview.dart

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ class HeadlessInAppWebView implements WebView, Disposable {
214214
}
215215
_started = true;
216216

217-
Map<String, dynamic> initialSettings = this.initialSettings?.toMap() ??
217+
final initialSettings = this.initialSettings;
218+
if (initialSettings != null) {
219+
_inferInitialSettings(initialSettings);
220+
}
221+
222+
Map<String, dynamic> settingsMap = initialSettings?.toMap() ??
218223
// ignore: deprecated_member_use_from_same_package
219224
this.initialOptions?.toMap() ??
220225
{};
@@ -233,7 +238,7 @@ class HeadlessInAppWebView implements WebView, Disposable {
233238
'initialUrlRequest': this.initialUrlRequest?.toMap(),
234239
'initialFile': this.initialFile,
235240
'initialData': this.initialData?.toMap(),
236-
'initialSettings': initialSettings,
241+
'initialSettings': settingsMap,
237242
'contextMenu': this.contextMenu?.toMap() ?? {},
238243
'windowId': this.windowId,
239244
'implementation': this.implementation.toNativeValue(),
@@ -246,6 +251,40 @@ class HeadlessInAppWebView implements WebView, Disposable {
246251
_running = true;
247252
}
248253

254+
void _inferInitialSettings(InAppWebViewSettings settings) {
255+
if (this.shouldOverrideUrlLoading != null &&
256+
settings.useShouldOverrideUrlLoading == null) {
257+
settings.useShouldOverrideUrlLoading = true;
258+
}
259+
if (this.onLoadResource != null && settings.useOnLoadResource == null) {
260+
settings.useOnLoadResource = true;
261+
}
262+
if (this.onDownloadStartRequest != null &&
263+
settings.useOnDownloadStart == null) {
264+
settings.useOnDownloadStart = true;
265+
}
266+
if (this.shouldInterceptAjaxRequest != null &&
267+
settings.useShouldInterceptAjaxRequest == null) {
268+
settings.useShouldInterceptAjaxRequest = true;
269+
}
270+
if (this.shouldInterceptFetchRequest != null &&
271+
settings.useShouldInterceptFetchRequest == null) {
272+
settings.useShouldInterceptFetchRequest = true;
273+
}
274+
if (this.shouldInterceptRequest != null &&
275+
settings.useShouldInterceptRequest == null) {
276+
settings.useShouldInterceptRequest = true;
277+
}
278+
if (this.onRenderProcessGone != null &&
279+
settings.useOnRenderProcessGone == null) {
280+
settings.useOnRenderProcessGone = true;
281+
}
282+
if (this.onNavigationResponse != null &&
283+
settings.useOnNavigationResponse == null) {
284+
settings.useOnNavigationResponse = true;
285+
}
286+
}
287+
249288
///Disposes the headless WebView.
250289
///
251290
///**Supported Platforms/Implementations**:

0 commit comments

Comments
 (0)