Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - expose content-disposition and content-length from android #1088

Merged
merged 1 commit into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,10 @@ class DownloadStartListener implements DownloadListener {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Map<String, Object> obj = new HashMap<>();
obj.put("url", url);
obj.put("userAgent", userAgent);
obj.put("contentDisposition", contentDisposition);
obj.put("mimetype", mimetype);
obj.put("contentLength", contentLength);
channel.invokeMethod("onDownloadStart", obj);
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/integration_test/webview_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,7 @@ void main() {
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onDownloadStart: (controller, url) {
onDownloadStart:(controller, url, userAgent, contentDisposition, mimeType, contentLength) {
onDownloadStartCompleter.complete(url.toString());
},
),
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 @@ -377,7 +377,7 @@ class InAppBrowser {
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#setDownloadListener(android.webkit.DownloadListener)
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455643-webview
void onDownloadStart(Uri url) {}
void onDownloadStart(Uri url, String userAgent, String contentDisposition, String mimeType, int contentLength) {}

///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`.
///
Expand Down
8 changes: 7 additions & 1 deletion lib/src/in_app_webview/headless_in_app_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ class HeadlessInAppWebView implements WebView {
void Function(InAppWebViewController controller)? onWindowBlur;

@override
void Function(InAppWebViewController controller, Uri url)? onDownloadStart;
void Function(
InAppWebViewController controller,
Uri url,
String userAgent,
String contentDisposition,
String mimeType,
int contentLength)? onDownloadStart;

@override
void Function(InAppWebViewController controller, int activeMatchOrdinal,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/in_app_webview/in_app_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class InAppWebView extends StatefulWidget implements WebView {
androidOnReceivedTouchIconUrl;

@override
final void Function(InAppWebViewController controller, Uri url)?
final void Function(InAppWebViewController controller, Uri url, String userAgent, String contentDisposition, String mimeType, int contentLength)?
onDownloadStart;

@override
Expand Down
9 changes: 7 additions & 2 deletions lib/src/in_app_webview/in_app_webview_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,16 @@ class InAppWebViewController {
if ((_webview != null && _webview!.onDownloadStart != null) ||
_inAppBrowser != null) {
String url = call.arguments["url"];
String userAgent = call.arguments["userAgent"];
String contentDisposition = call.arguments["contentDisposition"];
String mimeType = call.arguments["mimetype"];
int contentLength = call.arguments["contentLength"] as int;
Uri uri = Uri.parse(url);

if (_webview != null && _webview!.onDownloadStart != null)
_webview!.onDownloadStart!(this, uri);
_webview!.onDownloadStart!(this, uri, userAgent, contentDisposition, mimeType, contentLength);
else
_inAppBrowser!.onDownloadStart(uri);
_inAppBrowser!.onDownloadStart(uri, userAgent, contentDisposition, mimeType, contentLength);
}
break;
case "onLoadResourceCustomScheme":
Expand Down
2 changes: 1 addition & 1 deletion lib/src/in_app_webview/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ abstract class WebView {
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#setDownloadListener(android.webkit.DownloadListener)
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455643-webview
final void Function(InAppWebViewController controller, Uri url)?
final void Function(InAppWebViewController controller, Uri url, String userAgent, String contentDisposition, String mimeType, int contentLength)?
onDownloadStart;

///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`.
Expand Down