Skip to content
Closed
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
4 changes: 4 additions & 0 deletions packages/webview_flutter/webview_flutter_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.11.1

* Adds `headers` to `NavigationRequest` to tell if it `isDownloadRequest` from `onDownloadStart`.

## 4.11.0

* Adds support to opt out of Android inset changes. See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,18 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate {
int contentLength,
) {
if (weakThis.target != null) {
weakThis.target?._handleNavigation(url, isForMainFrame: true);
if (!contentDisposition.toLowerCase().startsWith('attachment')) {
contentDisposition = 'attachment; $contentDisposition'.trim();
}
weakThis.target?._handleNavigation(
url,
isForMainFrame: true,
headers: {
'content-disposition': contentDisposition,
'content-type': mimetype,
'content-length': contentLength.toString(),
},
);
}
},
);
Expand Down Expand Up @@ -1744,7 +1755,7 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate {
}

final FutureOr<NavigationDecision> returnValue = onNavigationRequest(
NavigationRequest(url: url, isMainFrame: isForMainFrame),
NavigationRequest(url: url, isMainFrame: isForMainFrame, headers: headers),
);

if (returnValue is NavigationDecision &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: webview_flutter_android
description: A Flutter plugin that provides a WebView widget on Android.
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
version: 4.11.0
version: 4.11.1

environment:
sdk: ^3.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,39 @@ void main() {
},
);

test(
'isDownloadRequest from onDownloadStart should be true',
() {
final androidNavigationDelegate = AndroidNavigationDelegate(
_buildCreationParams(),
);

androidNavigationDelegate.setOnLoadRequest((_) {
return Future.value();
});

late final NavigationRequest callbackNavigationRequest;
androidNavigationDelegate.setOnNavigationRequest((
NavigationRequest navigationRequest,
) {
callbackNavigationRequest = navigationRequest;
return NavigationDecision.navigate;
});

CapturingDownloadListener.lastCreatedListener.onDownloadStart(
MockDownloadListener(),
'https://www.google.com',
'',
'',
'',
0,
);

expect(callbackNavigationRequest.url, 'https://www.google.com');
expect(callbackNavigationRequest.isDownloadRequest, true);
},
);

test('onUrlChange', () {
final androidNavigationDelegate = AndroidNavigationDelegate(
_buildCreationParams(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.15.2

* Adds `headers` and `isDownloadRequest` to `NavigationRequest`,so we can easily tell if it was made to download an attachment from `onDownloadStart`.

## 2.15.1

* Fixes dartdoc comments that accidentally used HTML.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
/// Defines the parameters of the pending navigation callback.
class NavigationRequest {
/// Creates a [NavigationRequest].
const NavigationRequest({required this.url, required this.isMainFrame});
const NavigationRequest({required this.url, required this.isMainFrame, this.headers});

/// The URL of the pending navigation request.
final String url;

/// Indicates whether the request was made in the web site's main frame or a subframe.
final bool isMainFrame;

/// Headers for the request.
final Map<String, String>? headers;

/// Indicates whether the request was made to download an attachment.
bool get isDownloadRequest =>
headers?['content-disposition']?.toLowerCase().startsWith('attachment') ?? false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.15.1
version: 2.15.2

environment:
sdk: ^3.9.0
Expand Down