-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webview_flutter_android] [webview_flutter_wkwebview] Platform implem…
- Loading branch information
1 parent
0939198
commit b9c1d93
Showing
60 changed files
with
2,625 additions
and
235 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/webview_flutter/webview_flutter_android/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...roid/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestFlutterApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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.PermissionRequest; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.VisibleForTesting; | ||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.PermissionRequestFlutterApi; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Flutter API implementation for `PermissionRequest`. | ||
* | ||
* <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 PermissionRequestFlutterApiImpl { | ||
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; | ||
|
||
private final InstanceManager instanceManager; | ||
private PermissionRequestFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link PermissionRequestFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public PermissionRequestFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { | ||
this.binaryMessenger = binaryMessenger; | ||
this.instanceManager = instanceManager; | ||
api = new PermissionRequestFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `PermissionRequest` instance and notifies Dart to create and store a new | ||
* `PermissionRequest` instance that is attached to this one. If `instance` has already been | ||
* added, this method does nothing. | ||
*/ | ||
public void create( | ||
@NonNull PermissionRequest instance, | ||
@NonNull String[] resources, | ||
@NonNull PermissionRequestFlutterApi.Reply<Void> callback) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
api.create( | ||
instanceManager.addHostCreatedInstance(instance), Arrays.asList(resources), callback); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the Flutter API used to send messages to Dart. | ||
* | ||
* <p>This is only visible for testing. | ||
*/ | ||
@VisibleForTesting | ||
void setApi(@NonNull PermissionRequestFlutterApi api) { | ||
this.api = api; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestHostApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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.PermissionRequest; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.PermissionRequestHostApi; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Host API implementation for `PermissionRequest`. | ||
* | ||
* <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. | ||
*/ | ||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | ||
public class PermissionRequestHostApiImpl implements PermissionRequestHostApi { | ||
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; | ||
|
||
private final InstanceManager instanceManager; | ||
|
||
/** | ||
* Constructs a {@link PermissionRequestHostApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public PermissionRequestHostApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { | ||
this.binaryMessenger = binaryMessenger; | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
@Override | ||
public void grant(@NonNull Long instanceId, @NonNull List<String> resources) { | ||
getPermissionRequestInstance(instanceId).grant(resources.toArray(new String[0])); | ||
} | ||
|
||
@Override | ||
public void deny(@NonNull Long instanceId) { | ||
getPermissionRequestInstance(instanceId).deny(); | ||
} | ||
|
||
private PermissionRequest getPermissionRequestInstance(@NonNull Long identifier) { | ||
return Objects.requireNonNull(instanceManager.getInstance(identifier)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.