|
11 | 11 | import android.os.Handler;
|
12 | 12 | import android.os.Message;
|
13 | 13 | import android.view.View;
|
| 14 | +import android.webkit.DownloadListener; |
14 | 15 | import android.webkit.WebChromeClient;
|
15 | 16 | import android.webkit.WebResourceRequest;
|
16 | 17 | import android.webkit.WebStorage;
|
17 | 18 | import android.webkit.WebView;
|
18 | 19 | import android.webkit.WebViewClient;
|
19 | 20 | import androidx.annotation.NonNull;
|
| 21 | +import androidx.annotation.Nullable; |
20 | 22 | import androidx.annotation.VisibleForTesting;
|
21 | 23 | import io.flutter.plugin.common.MethodCall;
|
22 | 24 | import io.flutter.plugin.common.MethodChannel;
|
@@ -94,18 +96,25 @@ public void onProgressChanged(WebView view, int progress) {
|
94 | 96 | (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
|
95 | 97 | displayListenerProxy.onPreWebViewInitialization(displayManager);
|
96 | 98 |
|
| 99 | + this.methodChannel = methodChannel; |
| 100 | + this.methodChannel.setMethodCallHandler(this); |
| 101 | + |
| 102 | + flutterWebViewClient = new FlutterWebViewClient(methodChannel); |
| 103 | + |
| 104 | + FlutterDownloadListener flutterDownloadListener = |
| 105 | + new FlutterDownloadListener(flutterWebViewClient); |
97 | 106 | webView =
|
98 | 107 | createWebView(
|
99 |
| - new WebViewBuilder(context, containerView), params, new FlutterWebChromeClient()); |
| 108 | + new WebViewBuilder(context, containerView), |
| 109 | + params, |
| 110 | + new FlutterWebChromeClient(), |
| 111 | + flutterDownloadListener); |
| 112 | + flutterDownloadListener.setWebView(webView); |
100 | 113 |
|
101 | 114 | displayListenerProxy.onPostWebViewInitialization(displayManager);
|
102 | 115 |
|
103 | 116 | platformThreadHandler = new Handler(context.getMainLooper());
|
104 | 117 |
|
105 |
| - this.methodChannel = methodChannel; |
106 |
| - this.methodChannel.setMethodCallHandler(this); |
107 |
| - |
108 |
| - flutterWebViewClient = new FlutterWebViewClient(methodChannel); |
109 | 118 | Map<String, Object> settings = (Map<String, Object>) params.get("settings");
|
110 | 119 | if (settings != null) {
|
111 | 120 | applySettings(settings);
|
@@ -156,16 +165,20 @@ public void onProgressChanged(WebView view, int progress) {
|
156 | 165 | */
|
157 | 166 | @VisibleForTesting
|
158 | 167 | static WebView createWebView(
|
159 |
| - WebViewBuilder webViewBuilder, Map<String, Object> params, WebChromeClient webChromeClient) { |
| 168 | + WebViewBuilder webViewBuilder, |
| 169 | + Map<String, Object> params, |
| 170 | + WebChromeClient webChromeClient, |
| 171 | + @Nullable DownloadListener downloadListener) { |
160 | 172 | boolean usesHybridComposition = Boolean.TRUE.equals(params.get("usesHybridComposition"));
|
161 | 173 | webViewBuilder
|
162 | 174 | .setUsesHybridComposition(usesHybridComposition)
|
163 | 175 | .setDomStorageEnabled(true) // Always enable DOM storage API.
|
164 | 176 | .setJavaScriptCanOpenWindowsAutomatically(
|
165 | 177 | true) // Always allow automatically opening of windows.
|
166 | 178 | .setSupportMultipleWindows(true) // Always support multiple windows.
|
167 |
| - .setWebChromeClient( |
168 |
| - webChromeClient); // Always use {@link FlutterWebChromeClient} as web Chrome client. |
| 179 | + .setWebChromeClient(webChromeClient) |
| 180 | + .setDownloadListener( |
| 181 | + downloadListener); // Always use {@link FlutterWebChromeClient} as web Chrome client. |
169 | 182 |
|
170 | 183 | return webViewBuilder.build();
|
171 | 184 | }
|
|
0 commit comments