Skip to content

[webview_flutter][webview_flutter_android] Add android support for handling geolocation permissions #3795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 109 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
1bffe06
Adds support for handling geolocation permissions.
yk3372 Mar 16, 2023
463da59
Merge branch 'flutter:main' into main
yk3372 Mar 16, 2023
233543d
remove unused result
yk3372 Mar 16, 2023
1dc6317
format code
yk3372 Mar 16, 2023
429e892
fix code format
yk3372 Mar 16, 2023
7acd43a
format java
yk3372 Mar 16, 2023
e80002a
format java
yk3372 Mar 16, 2023
9d8768f
Merge branch 'main' into main
yk3372 Mar 16, 2023
0825a8c
Merge branch 'main' into main
yk3372 Mar 22, 2023
020fecc
update version
yk3372 Mar 22, 2023
5e620d7
Merge branch 'main' into main
yk3372 Mar 23, 2023
516088d
Merge branch 'main' into main
yk3372 Mar 23, 2023
4a9a56b
Merge branch 'main' into main
yk3372 Mar 24, 2023
8916c72
Merge branch 'main' into main
yk3372 Mar 26, 2023
f72f9e7
Merge branch 'main' into main
yk3372 Mar 27, 2023
aca8e48
Merge branch 'main' into main
yk3372 Mar 28, 2023
a3c9bee
update change
yk3372 Apr 5, 2023
5438f05
update code
yk3372 Apr 5, 2023
8a62deb
add geolocationpermissionscallback
bparrishMines Apr 5, 2023
c718a21
formatting and hidepromt method
bparrishMines Apr 5, 2023
f064a91
Merge branch 'main' of github.com:flutter/packages into yk3372/main
bparrishMines Apr 5, 2023
3a74864
Merge branch 'main' into main
yk3372 Apr 6, 2023
806f956
Merge branch 'main' into main
yk3372 Apr 7, 2023
9341e3b
Merge branch 'main' into main
yk3372 Apr 7, 2023
bd5697b
add onGeolocationPermissionsHidePrompt callback
yk3372 Apr 7, 2023
1e57170
remove unused code
yk3372 Apr 7, 2023
9dc021c
format code
yk3372 Apr 7, 2023
44df75a
update code
yk3372 Apr 7, 2023
034a12d
format code
yk3372 Apr 7, 2023
8738853
format code
yk3372 Apr 7, 2023
2d58832
更改为callback方式
yk3372 Apr 7, 2023
6d9d1b3
format code
yk3372 Apr 7, 2023
4b0b08b
reformat
yk3372 Apr 7, 2023
666e962
reformat
yk3372 Apr 7, 2023
0634657
reformat
yk3372 Apr 7, 2023
b7e13a8
Merge branch 'main' into main
yk3372 Apr 7, 2023
1b4f289
format code
yk3372 Apr 7, 2023
45fde40
format code
yk3372 Apr 7, 2023
5ec1a29
Merge branch 'main' into main
yk3372 Apr 9, 2023
f6d7187
Merge branch 'main' into main
yk3372 Apr 10, 2023
1dd01c3
Merge branch 'main' into main
yk3372 Apr 11, 2023
b26d529
update doc
yk3372 Apr 11, 2023
4b8e0cf
setup geocallback api
yk3372 Apr 11, 2023
aac5278
format code
yk3372 Apr 11, 2023
397de9e
Merge branch 'main' into main
yk3372 Apr 11, 2023
9252092
Merge branch 'main' into main
yk3372 Apr 12, 2023
d811766
Merge branch 'main' into main
yk3372 Apr 13, 2023
d520901
update android version
yk3372 Apr 13, 2023
b9ed0b2
Merge branch 'main' into main
yk3372 Apr 14, 2023
e5ec59d
Merge branch 'main' into main
yk3372 Apr 17, 2023
f4ea10c
Merge branch 'main' into main
yk3372 Apr 18, 2023
fe19a96
Merge branch 'main' of github.com:flutter/packages into yk3372/main
bparrishMines Apr 20, 2023
a8115cc
handle lint warnings
bparrishMines Apr 20, 2023
4b767e3
fix test methods
bparrishMines Apr 20, 2023
08c1bb6
Merge branch 'main' into main
yk3372 Apr 21, 2023
167ee0f
Update packages/webview_flutter/webview_flutter_android/lib/src/andro…
yk3372 Apr 21, 2023
31c8c9e
modify code
yk3372 Apr 21, 2023
20b554c
format code
yk3372 Apr 21, 2023
29fd81d
Merge branch 'test'
yk3372 Apr 22, 2023
8870c5b
format code
yk3372 Apr 22, 2023
347a594
format code
yk3372 Apr 22, 2023
873efad
format code
yk3372 Apr 22, 2023
4851765
Merge branch 'main' into main
yk3372 Apr 23, 2023
7384705
Merge branch 'main' into main
yk3372 Apr 25, 2023
101fd96
Update packages/webview_flutter/webview_flutter_android/CHANGELOG.md
yk3372 Apr 28, 2023
85d8878
Update packages/webview_flutter/webview_flutter_android/CHANGELOG.md
yk3372 Apr 28, 2023
b43a269
Update packages/webview_flutter/webview_flutter_android/lib/src/andro…
yk3372 Apr 28, 2023
15764b6
Update packages/webview_flutter/webview_flutter_android/lib/src/andro…
yk3372 Apr 28, 2023
e04a91d
Merge branch 'main' into main
yk3372 Apr 28, 2023
d92ff2e
Merge branch 'main' into main
yk3372 May 4, 2023
121bf28
Update pubspec.yaml
yk3372 May 4, 2023
8c2a992
Merge branch 'main' into main
yk3372 May 4, 2023
fed594e
Merge branch 'main' into main
yk3372 May 8, 2023
9bcbe6f
Merge branch 'main' into main
yk3372 May 10, 2023
3486b6e
modify use way
yk3372 May 11, 2023
2c2f053
format
yk3372 May 11, 2023
83111ef
update
yk3372 May 12, 2023
91a3fc8
Merge branch 'main' into main
yk3372 May 12, 2023
da19b06
update code
yk3372 May 13, 2023
be240f6
update
yk3372 May 13, 2023
d9ca433
Merge branch 'main' into main
yk3372 May 14, 2023
6a10a58
Merge branch 'main' into main
yk3372 May 16, 2023
6347d82
Merge branch 'main' into main
yk3372 May 16, 2023
346605d
Merge branch 'main' into main
yk3372 May 17, 2023
3ceb4ca
Merge branch 'main' into main
yk3372 May 17, 2023
e8e0358
Merge branch 'main' into main
yk3372 May 18, 2023
12c3d5f
Merge branch 'main' into main
yk3372 May 20, 2023
e6f01be
Merge branch 'main' into main
yk3372 May 23, 2023
3a8a936
Merge branch 'main' into main
yk3372 May 24, 2023
de5b648
Merge branch 'main' into main
yk3372 May 24, 2023
7a833b9
add typedefs
yk3372 May 25, 2023
bfbd9d8
format code
yk3372 May 25, 2023
36456a2
format
yk3372 May 25, 2023
f852702
Merge branch 'main' into main
yk3372 Jun 1, 2023
d6ab611
Merge branch 'main' into main
yk3372 Jun 3, 2023
a611cd7
update test
yk3372 Jun 3, 2023
ea4ad01
fix test
yk3372 Jun 3, 2023
0a8dff3
Merge branch 'main' into main
yk3372 Jun 5, 2023
3ef9bc4
Merge branch 'main' into main
yk3372 Jun 6, 2023
59ce9b6
Merge branch 'main' of github.com:flutter/packages into yk3372/main
bparrishMines Jun 6, 2023
a71119e
Merge branch 'main' into main
yk3372 Jun 7, 2023
6087916
Merge branch 'main' of github.com:yk3372/packages into yk3372/main
bparrishMines Jun 7, 2023
9072bf0
add java test for onGeolocationPermissionsShowPrompt
bparrishMines Jun 7, 2023
f137811
Merge branch 'main' of github.com:flutter/packages into yk3372/main
bparrishMines Jun 7, 2023
05e544f
add nonnull
yk3372 Jun 9, 2023
5717eaa
Merge branch 'main' into main
yk3372 Jun 9, 2023
ea5b08c
Merge branch 'main' into main
yk3372 Jun 12, 2023
2069f1e
Merge branch 'main' into main
yk3372 Jun 13, 2023
f9a5b01
Merge branch 'main' into main
yk3372 Jun 15, 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
1 change: 1 addition & 0 deletions packages/webview_flutter/webview_flutter_android/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ Alex Li <[email protected]>
Rahul Raj <[email protected]>
Maurits van Beusekom <[email protected]>
Nick Bradshaw <[email protected]>
Kai Yu <[email protected]>

Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.8.0

* Adds support for handling geolocation permissions. See
`AndroidWebViewController.setGeolocationPermissionsPromptCallbacks`.

## 3.7.1

* Removes obsolete null checks on non-nullable values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,33 @@ public void onPermissionRequest(
new ArrayList<Object>(Arrays.asList(instanceIdArg, requestInstanceIdArg)),
channelReply -> callback.reply(null));
}
/** Callback to Dart function `WebChromeClient.onGeolocationPermissionsShowPrompt`. */
public void onGeolocationPermissionsShowPrompt(
@NonNull Long instanceIdArg,
@NonNull Long paramsInstanceIdArg,
@NonNull String originArg,
@NonNull Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.WebChromeClientFlutterApi.onGeolocationPermissionsShowPrompt",
getCodec());
channel.send(
new ArrayList<Object>(Arrays.asList(instanceIdArg, paramsInstanceIdArg, originArg)),
channelReply -> callback.reply(null));
}
/** Callback to Dart function `WebChromeClient.onGeolocationPermissionsHidePrompt`. */
public void onGeolocationPermissionsHidePrompt(
@NonNull Long identifierArg, @NonNull Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.WebChromeClientFlutterApi.onGeolocationPermissionsHidePrompt",
getCodec());
channel.send(
new ArrayList<Object>(Collections.singletonList(identifierArg)),
channelReply -> callback.reply(null));
}
}
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface WebStorageHostApi {
Expand Down Expand Up @@ -2839,4 +2866,106 @@ public void create(
channelReply -> callback.reply(null));
}
}
/**
* Host API for `GeolocationPermissionsCallback`.
*
* <p>This class may handle instantiating and adding native object instances that are attached to
* a Dart instance or handle method calls on the associated native class or an instance of the
* class.
*
* <p>See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback.
*
* <p>Generated interface from Pigeon that represents a handler of messages from Flutter.
*/
public interface GeolocationPermissionsCallbackHostApi {
/** Handles Dart method `GeolocationPermissionsCallback.invoke`. */
void invoke(
@NonNull Long instanceId,
@NonNull String origin,
@NonNull Boolean allow,
@NonNull Boolean retain);

/** The codec used by GeolocationPermissionsCallbackHostApi. */
static @NonNull MessageCodec<Object> getCodec() {
return new StandardMessageCodec();
}
/**
* Sets up an instance of `GeolocationPermissionsCallbackHostApi` to handle messages through the
* `binaryMessenger`.
*/
static void setup(
@NonNull BinaryMessenger binaryMessenger,
@Nullable GeolocationPermissionsCallbackHostApi api) {
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.GeolocationPermissionsCallbackHostApi.invoke",
getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
Number instanceIdArg = (Number) args.get(0);
String originArg = (String) args.get(1);
Boolean allowArg = (Boolean) args.get(2);
Boolean retainArg = (Boolean) args.get(3);
try {
api.invoke(
(instanceIdArg == null) ? null : instanceIdArg.longValue(),
originArg,
allowArg,
retainArg);
wrapped.add(0, null);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
}
}
/**
* Flutter API for `GeolocationPermissionsCallback`.
*
* <p>This class may handle instantiating and adding Dart instances that are attached to a native
* instance or receiving callback methods from an overridden native class.
*
* <p>See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback.
*
* <p>Generated class from Pigeon that represents Flutter messages that can be called from Java.
*/
public static class GeolocationPermissionsCallbackFlutterApi {
private final @NonNull BinaryMessenger binaryMessenger;

public GeolocationPermissionsCallbackFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) {
this.binaryMessenger = argBinaryMessenger;
}

/** Public interface for sending reply. */
@SuppressWarnings("UnknownNullness")
public interface Reply<T> {
void reply(T reply);
}
/** The codec used by GeolocationPermissionsCallbackFlutterApi. */
static @NonNull MessageCodec<Object> getCodec() {
return new StandardMessageCodec();
}
/** Create a new Dart instance and add it to the `InstanceManager`. */
public void create(@NonNull Long instanceIdArg, @NonNull Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.GeolocationPermissionsCallbackFlutterApi.create",
getCodec());
channel.send(
new ArrayList<Object>(Collections.singletonList(instanceIdArg)),
channelReply -> callback.reply(null));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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.webkit.GeolocationPermissions;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.GeolocationPermissionsCallbackFlutterApi;

/**
* Flutter API implementation for `GeolocationPermissionsCallback`.
*
* <p>This class may handle adding native instances that are attached to a Dart instance or passing
* arguments of callbacks methods to a Dart instance.
*/
public class GeolocationPermissionsCallbackFlutterApiImpl {
// To ease adding additional methods, this value is added prematurely.
@SuppressWarnings({"unused", "FieldCanBeLocal"})
private final BinaryMessenger binaryMessenger;

private final InstanceManager instanceManager;
private GeolocationPermissionsCallbackFlutterApi api;

/**
* Constructs a {@link GeolocationPermissionsCallbackFlutterApiImpl}.
*
* @param binaryMessenger used to communicate with Dart over asynchronous messages
* @param instanceManager maintains instances stored to communicate with attached Dart objects
*/
public GeolocationPermissionsCallbackFlutterApiImpl(
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
this.binaryMessenger = binaryMessenger;
this.instanceManager = instanceManager;
api = new GeolocationPermissionsCallbackFlutterApi(binaryMessenger);
}

/**
* Stores the `GeolocationPermissionsCallback` instance and notifies Dart to create and store a
* new `GeolocationPermissionsCallback` instance that is attached to this one. If `instance` has
* already been added, this method does nothing.
*/
public void create(
@NonNull GeolocationPermissions.Callback instance,
@NonNull GeolocationPermissionsCallbackFlutterApi.Reply<Void> callback) {
if (!instanceManager.containsInstance(instance)) {
api.create(instanceManager.addHostCreatedInstance(instance), callback);
}
}

/**
* Sets the Flutter API used to send messages to Dart.
*
* <p>This is only visible for testing.
*/
@VisibleForTesting
void setApi(@NonNull GeolocationPermissionsCallbackFlutterApi api) {
this.api = api;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.webkit.GeolocationPermissions;
import androidx.annotation.NonNull;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.GeolocationPermissionsCallbackHostApi;
import java.util.Objects;

/**
* Host API implementation for `GeolocationPermissionsCallback`.
*
* <p>This class may handle instantiating and adding native object instances that are attached to a
* Dart instance or handle method calls on the associated native class or an instance of the class.
*/
public class GeolocationPermissionsCallbackHostApiImpl
implements GeolocationPermissionsCallbackHostApi {
// To ease adding additional methods, this value is added prematurely.
@SuppressWarnings({"unused", "FieldCanBeLocal"})
private final BinaryMessenger binaryMessenger;

private final InstanceManager instanceManager;

/**
* Constructs a {@link GeolocationPermissionsCallbackHostApiImpl}.
*
* @param binaryMessenger used to communicate with Dart over asynchronous messages
* @param instanceManager maintains instances stored to communicate with attached Dart objects
*/
public GeolocationPermissionsCallbackHostApiImpl(
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
this.binaryMessenger = binaryMessenger;
this.instanceManager = instanceManager;
}

@Override
public void invoke(
@NonNull Long instanceId,
@NonNull String origin,
@NonNull Boolean allow,
@NonNull Boolean retain) {
getGeolocationPermissionsCallbackInstance(instanceId).invoke(origin, allow, retain);
}

private GeolocationPermissions.Callback getGeolocationPermissionsCallbackInstance(
@NonNull Long identifier) {
return Objects.requireNonNull(instanceManager.getInstance(identifier));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.flutter.plugins.webviewflutter;

import android.os.Build;
import android.webkit.GeolocationPermissions;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
Expand Down Expand Up @@ -72,6 +73,32 @@ public void onShowFileChooser(
callback);
}

/** Passes arguments from {@link WebChromeClient#onGeolocationPermissionsShowPrompt} to Dart. */
public void onGeolocationPermissionsShowPrompt(
@NonNull WebChromeClient webChromeClient,
@NonNull String origin,
@NonNull GeolocationPermissions.Callback callback,
@NonNull WebChromeClientFlutterApi.Reply<Void> replyCallback) {
new GeolocationPermissionsCallbackFlutterApiImpl(binaryMessenger, instanceManager)
.create(callback, reply -> {});
onGeolocationPermissionsShowPrompt(
Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webChromeClient)),
Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(callback)),
origin,
replyCallback);
}

/**
* Sends a message to Dart to call `WebChromeClient.onGeolocationPermissionsHidePrompt` on the
* Dart object representing `instance`.
*/
public void onGeolocationPermissionsHidePrompt(
@NonNull WebChromeClient instance, @NonNull WebChromeClientFlutterApi.Reply<Void> callback) {
super.onGeolocationPermissionsHidePrompt(
Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)),
callback);
}

/**
* Sends a message to Dart to call `WebChromeClient.onPermissionRequest` on the Dart object
* representing `instance`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Message;
import android.webkit.GeolocationPermissions;
import android.webkit.PermissionRequest;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
Expand Down Expand Up @@ -51,6 +52,17 @@ public void onProgressChanged(@NonNull WebView view, int progress) {
flutterApi.onProgressChanged(this, view, (long) progress, reply -> {});
}

@Override
public void onGeolocationPermissionsShowPrompt(
@NonNull String origin, @NonNull GeolocationPermissions.Callback callback) {
flutterApi.onGeolocationPermissionsShowPrompt(this, origin, callback, reply -> {});
}

@Override
public void onGeolocationPermissionsHidePrompt() {
flutterApi.onGeolocationPermissionsHidePrompt(this, reply -> {});
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@SuppressWarnings("LambdaLast")
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CookieManagerHostApi;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerHostApi;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.FlutterAssetManagerHostApi;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.GeolocationPermissionsCallbackHostApi;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.InstanceManagerHostApi;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.JavaObjectHostApi;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.JavaScriptChannelHostApi;
Expand Down Expand Up @@ -137,6 +138,9 @@ private void setUp(
PermissionRequestHostApi.setup(
binaryMessenger, new PermissionRequestHostApiImpl(binaryMessenger, instanceManager));
}
GeolocationPermissionsCallbackHostApi.setup(
binaryMessenger,
new GeolocationPermissionsCallbackHostApiImpl(binaryMessenger, instanceManager));
}

@Override
Expand Down
Loading