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

Commit 5f44021

Browse files
[webview_flutter_android] Adds support for receiving Java callback WebChromeClient.onShowFileChooser (#6881)
* some progress * more work * compiling code * dart side should be correct * maybe working code * fix plugin class * formatting * some docs and polish * foramtting tests and docs * version bump * doc improvements * flutterapi create test * working java test * unused imports * formatting and more tests * formatting and more tests * formatting * copy and tests * add more description to the custom method * formatting * change doc wording * more docs * null out result early * remove the open option * fix spelling * interface implementation * version bump * move webchromeclient to webview controller * tests * reference method in changelong * missing typed data import * undo changes * use stateerror instead * updated lints
1 parent dc2e4a0 commit 5f44021

27 files changed

+2340
-1183
lines changed

packages/webview_flutter/webview_flutter_android/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.2.0
2+
3+
* Adds support for handling file selection. See `AndroidWebViewController.setOnShowFileSelector`.
4+
* Updates pigeon dev dependency to `4.2.14`.
5+
16
## 3.1.3
27

38
* Fixes crash when the Java `InstanceManager` was used after plugin was removed from the engine.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.os.Build;
8+
import android.webkit.WebChromeClient;
9+
import androidx.annotation.RequiresApi;
10+
import io.flutter.plugin.common.BinaryMessenger;
11+
import java.util.Arrays;
12+
13+
/**
14+
* Flutter Api implementation for {@link android.webkit.WebChromeClient.FileChooserParams}.
15+
*
16+
* <p>Passes arguments of callbacks methods from a {@link
17+
* android.webkit.WebChromeClient.FileChooserParams} to Dart.
18+
*/
19+
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
20+
public class FileChooserParamsFlutterApiImpl
21+
extends GeneratedAndroidWebView.FileChooserParamsFlutterApi {
22+
private final InstanceManager instanceManager;
23+
24+
/**
25+
* Creates a Flutter api that sends messages to Dart.
26+
*
27+
* @param binaryMessenger handles sending messages to Dart
28+
* @param instanceManager maintains instances stored to communicate with Dart objects
29+
*/
30+
public FileChooserParamsFlutterApiImpl(
31+
BinaryMessenger binaryMessenger, InstanceManager instanceManager) {
32+
super(binaryMessenger);
33+
this.instanceManager = instanceManager;
34+
}
35+
36+
private static GeneratedAndroidWebView.FileChooserModeEnumData toFileChooserEnumData(int mode) {
37+
final GeneratedAndroidWebView.FileChooserModeEnumData.Builder builder =
38+
new GeneratedAndroidWebView.FileChooserModeEnumData.Builder();
39+
40+
switch (mode) {
41+
case WebChromeClient.FileChooserParams.MODE_OPEN:
42+
builder.setValue(GeneratedAndroidWebView.FileChooserMode.OPEN);
43+
break;
44+
case WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE:
45+
builder.setValue(GeneratedAndroidWebView.FileChooserMode.OPEN_MULTIPLE);
46+
break;
47+
case WebChromeClient.FileChooserParams.MODE_SAVE:
48+
builder.setValue(GeneratedAndroidWebView.FileChooserMode.SAVE);
49+
break;
50+
default:
51+
throw new IllegalArgumentException(String.format("Unsupported FileChooserMode: %d", mode));
52+
}
53+
54+
return builder.build();
55+
}
56+
57+
/**
58+
* Stores the FileChooserParams instance and notifies Dart to create a new FileChooserParams
59+
* instance that is attached to this one.
60+
*
61+
* @return the instanceId of the stored instance
62+
*/
63+
public long create(WebChromeClient.FileChooserParams instance, Reply<Void> callback) {
64+
final long instanceId = instanceManager.addHostCreatedInstance(instance);
65+
create(
66+
instanceId,
67+
instance.isCaptureEnabled(),
68+
Arrays.asList(instance.getAcceptTypes()),
69+
toFileChooserEnumData(instance.getMode()),
70+
instance.getFilenameHint(),
71+
callback);
72+
return instanceId;
73+
}
74+
}

0 commit comments

Comments
 (0)