Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 42364e4

Browse files
Implement Android WebView api with pigeon (Java portion) (#4441)
1 parent 0d33094 commit 42364e4

20 files changed

+3302
-4
lines changed

packages/webview_flutter/webview_flutter_android/android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ android {
4242
testImplementation 'androidx.test:core:1.3.0'
4343
}
4444

45+
compileOptions {
46+
sourceCompatibility JavaVersion.VERSION_1_8
47+
targetCompatibility JavaVersion.VERSION_1_8
48+
}
4549

4650
testOptions {
4751
unitTests.includeAndroidResources = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.webviewflutter;
6+
7+
import android.webkit.DownloadListener;
8+
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerFlutterApi;
9+
10+
class DownloadListenerHostApiImpl implements GeneratedAndroidWebView.DownloadListenerHostApi {
11+
private final InstanceManager instanceManager;
12+
private final DownloadListenerCreator downloadListenerCreator;
13+
private final GeneratedAndroidWebView.DownloadListenerFlutterApi downloadListenerFlutterApi;
14+
15+
static class DownloadListenerCreator {
16+
DownloadListener createDownloadListener(
17+
Long instanceId, DownloadListenerFlutterApi downloadListenerFlutterApi) {
18+
return (url, userAgent, contentDisposition, mimetype, contentLength) ->
19+
downloadListenerFlutterApi.onDownloadStart(
20+
instanceId, url, userAgent, contentDisposition, mimetype, contentLength, reply -> {});
21+
}
22+
}
23+
24+
DownloadListenerHostApiImpl(
25+
InstanceManager instanceManager,
26+
DownloadListenerCreator downloadListenerCreator,
27+
DownloadListenerFlutterApi downloadListenerFlutterApi) {
28+
this.instanceManager = instanceManager;
29+
this.downloadListenerCreator = downloadListenerCreator;
30+
this.downloadListenerFlutterApi = downloadListenerFlutterApi;
31+
}
32+
33+
@Override
34+
public void create(Long instanceId) {
35+
final DownloadListener downloadListener =
36+
downloadListenerCreator.createDownloadListener(instanceId, downloadListenerFlutterApi);
37+
instanceManager.addInstance(downloadListener, instanceId);
38+
}
39+
40+
@Override
41+
public void dispose(Long instanceId) {
42+
instanceManager.removeInstance(instanceId);
43+
}
44+
}

packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ boolean shouldOverrideUrlLoading(WebView view, String url) {
104104
return false;
105105
}
106106
// This version of shouldOverrideUrlLoading is only invoked by the webview on devices with
107-
// webview versions earlier than 67(it is also invoked when hasNavigationDelegate is false).
107+
// webview versions earlier than 67(it is also invoked when hasNavigationDelegate is false).
108108
// On these devices we cannot tell whether the navigation is targeted to the main frame or not.
109109
// We proceed assuming that the navigation is targeted to the main frame. If the page had any
110110
// frames they will be loaded in the main frame instead.

0 commit comments

Comments
 (0)