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

[webview_flutter_android] Adds support for receiving Java callback WebChromeClient.onShowFileChooser #6881

Merged
merged 36 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a81107b
some progress
bparrishMines Dec 19, 2022
fff4697
more work
bparrishMines Dec 21, 2022
735015f
Merge branch 'main' of github.com:flutter/plugins into onShowFileChooser
bparrishMines Dec 22, 2022
5ba566a
compiling code
bparrishMines Dec 22, 2022
829982b
dart side should be correct
bparrishMines Dec 23, 2022
cd37e4a
maybe working code
bparrishMines Dec 23, 2022
2f28144
fix plugin class
bparrishMines Dec 24, 2022
3bdfaf2
formatting
bparrishMines Dec 24, 2022
98ebdca
some docs and polish
bparrishMines Dec 24, 2022
9f7e891
foramtting tests and docs
bparrishMines Dec 24, 2022
2ef08bd
version bump
bparrishMines Dec 24, 2022
a11d012
doc improvements
bparrishMines Dec 24, 2022
7311007
flutterapi create test
bparrishMines Dec 24, 2022
07b866c
working java test
bparrishMines Dec 24, 2022
3665866
unused imports
bparrishMines Dec 24, 2022
56467e6
formatting and more tests
bparrishMines Dec 24, 2022
a15a2dc
formatting and more tests
bparrishMines Dec 24, 2022
94c4032
formatting
bparrishMines Dec 24, 2022
d4f818a
copy and tests
bparrishMines Dec 24, 2022
0bdf90a
add more description to the custom method
bparrishMines Dec 24, 2022
b57f39f
formatting
bparrishMines Dec 25, 2022
6e7c334
change doc wording
bparrishMines Dec 25, 2022
8685a9e
more docs
bparrishMines Dec 25, 2022
ac60b45
null out result early
bparrishMines Dec 26, 2022
2748273
remove the open option
bparrishMines Jan 3, 2023
984c49f
fix spelling
bparrishMines Jan 3, 2023
9e17836
interface implementation
bparrishMines Jan 4, 2023
e66649c
version bump
bparrishMines Jan 4, 2023
cf4e79d
move webchromeclient to webview controller
bparrishMines Jan 4, 2023
d015bb5
tests
bparrishMines Jan 4, 2023
3184656
reference method in changelong
bparrishMines Jan 4, 2023
6374117
missing typed data import
bparrishMines Jan 9, 2023
c522e4a
undo changes
bparrishMines Jan 9, 2023
e5a063c
use stateerror instead
bparrishMines Jan 19, 2023
bcf94e0
version bump
bparrishMines Jan 19, 2023
7b83113
updated lints
bparrishMines Jan 19, 2023
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
@@ -1,3 +1,8 @@
## 3.2.0

* Adds support for handling file selection. See `AndroidWebViewController.setOnShowFileSelector`.
* Updates pigeon dev dependency to `4.2.14`.

## 3.1.3

* Fixes crash when the Java `InstanceManager` was used after plugin was removed from the engine.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;

import android.os.Build;
import android.webkit.WebChromeClient;
import androidx.annotation.RequiresApi;
import io.flutter.plugin.common.BinaryMessenger;
import java.util.Arrays;

/**
* Flutter Api implementation for {@link android.webkit.WebChromeClient.FileChooserParams}.
*
* <p>Passes arguments of callbacks methods from a {@link
* android.webkit.WebChromeClient.FileChooserParams} to Dart.
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class FileChooserParamsFlutterApiImpl
extends GeneratedAndroidWebView.FileChooserParamsFlutterApi {
private final InstanceManager instanceManager;

/**
* Creates a Flutter api that sends messages to Dart.
*
* @param binaryMessenger handles sending messages to Dart
* @param instanceManager maintains instances stored to communicate with Dart objects
*/
public FileChooserParamsFlutterApiImpl(
BinaryMessenger binaryMessenger, InstanceManager instanceManager) {
super(binaryMessenger);
this.instanceManager = instanceManager;
}

private static GeneratedAndroidWebView.FileChooserModeEnumData toFileChooserEnumData(int mode) {
final GeneratedAndroidWebView.FileChooserModeEnumData.Builder builder =
new GeneratedAndroidWebView.FileChooserModeEnumData.Builder();

switch (mode) {
case WebChromeClient.FileChooserParams.MODE_OPEN:
builder.setValue(GeneratedAndroidWebView.FileChooserMode.OPEN);
break;
case WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE:
builder.setValue(GeneratedAndroidWebView.FileChooserMode.OPEN_MULTIPLE);
break;
case WebChromeClient.FileChooserParams.MODE_SAVE:
builder.setValue(GeneratedAndroidWebView.FileChooserMode.SAVE);
break;
default:
throw new IllegalArgumentException(String.format("Unsupported FileChooserMode: %d", mode));
}

return builder.build();
}

/**
* Stores the FileChooserParams instance and notifies Dart to create a new FileChooserParams
* instance that is attached to this one.
*
* @return the instanceId of the stored instance
*/
public long create(WebChromeClient.FileChooserParams instance, Reply<Void> callback) {
final long instanceId = instanceManager.addHostCreatedInstance(instance);
create(
instanceId,
instance.isCaptureEnabled(),
Arrays.asList(instance.getAcceptTypes()),
toFileChooserEnumData(instance.getMode()),
instance.getFilenameHint(),
callback);
return instanceId;
}
}
Loading