Skip to content

Commit 8f43faf

Browse files
committed
expose contentdisposition and contentlength from android
1 parent f06bcdf commit 8f43faf

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java

+4
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,10 @@ class DownloadStartListener implements DownloadListener {
11841184
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
11851185
Map<String, Object> obj = new HashMap<>();
11861186
obj.put("url", url);
1187+
obj.put("userAgent", userAgent);
1188+
obj.put("contentDisposition", contentDisposition);
1189+
obj.put("mimetype", mimetype);
1190+
obj.put("contentLength", contentLength);
11871191
channel.invokeMethod("onDownloadStart", obj);
11881192
}
11891193
}

example/integration_test/webview_flutter_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,7 @@ void main() {
27392739
onWebViewCreated: (controller) {
27402740
controllerCompleter.complete(controller);
27412741
},
2742-
onDownloadStart: (controller, url) {
2742+
onDownloadStart:(controller, url, userAgent, contentDisposition, mimeType, contentLength) {
27432743
onDownloadStartCompleter.complete(url.toString());
27442744
},
27452745
),

lib/src/in_app_browser/in_app_browser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class InAppBrowser {
377377
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#setDownloadListener(android.webkit.DownloadListener)
378378
///
379379
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455643-webview
380-
void onDownloadStart(Uri url) {}
380+
void onDownloadStart(Uri url, String userAgent, String contentDisposition, String mimeType, int contentLength) {}
381381

382382
///Event fired when the [InAppBrowser] webview finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
383383
///

lib/src/in_app_webview/headless_in_app_webview.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,13 @@ class HeadlessInAppWebView implements WebView {
299299
void Function(InAppWebViewController controller)? onWindowBlur;
300300

301301
@override
302-
void Function(InAppWebViewController controller, Uri url)? onDownloadStart;
302+
void Function(
303+
InAppWebViewController controller,
304+
Uri url,
305+
String userAgent,
306+
String contentDisposition,
307+
String mimeType,
308+
int contentLength)? onDownloadStart;
303309

304310
@override
305311
void Function(InAppWebViewController controller, int activeMatchOrdinal,

lib/src/in_app_webview/in_app_webview.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class InAppWebView extends StatefulWidget implements WebView {
208208
androidOnReceivedTouchIconUrl;
209209

210210
@override
211-
final void Function(InAppWebViewController controller, Uri url)?
211+
final void Function(InAppWebViewController controller, Uri url, String userAgent, String contentDisposition, String mimeType, int contentLength)?
212212
onDownloadStart;
213213

214214
@override

lib/src/in_app_webview/in_app_webview_controller.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,16 @@ class InAppWebViewController {
205205
if ((_webview != null && _webview!.onDownloadStart != null) ||
206206
_inAppBrowser != null) {
207207
String url = call.arguments["url"];
208+
String userAgent = call.arguments["userAgent"];
209+
String contentDisposition = call.arguments["contentDisposition"];
210+
String mimeType = call.arguments["mimetype"];
211+
int contentLength = call.arguments["contentLength"] as int;
208212
Uri uri = Uri.parse(url);
213+
209214
if (_webview != null && _webview!.onDownloadStart != null)
210-
_webview!.onDownloadStart!(this, uri);
215+
_webview!.onDownloadStart!(this, uri, userAgent, contentDisposition, mimeType, contentLength);
211216
else
212-
_inAppBrowser!.onDownloadStart(uri);
217+
_inAppBrowser!.onDownloadStart(uri, userAgent, contentDisposition, mimeType, contentLength);
213218
}
214219
break;
215220
case "onLoadResourceCustomScheme":

lib/src/in_app_webview/webview.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ abstract class WebView {
120120
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#setDownloadListener(android.webkit.DownloadListener)
121121
///
122122
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455643-webview
123-
final void Function(InAppWebViewController controller, Uri url)?
123+
final void Function(InAppWebViewController controller, Uri url, String userAgent, String contentDisposition, String mimeType, int contentLength)?
124124
onDownloadStart;
125125

126126
///Event fired when the [WebView] finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.

0 commit comments

Comments
 (0)