forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 8
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] Adds a WebViewFlutterApi (flutter#3324)
[webview_flutter_android] Adds a WebViewFlutterApi
- Loading branch information
1 parent
9bfef95
commit a4d3d16
Showing
14 changed files
with
271 additions
and
56 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
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
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
59 changes: 59 additions & 0 deletions
59
...ndroid/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterApiImpl.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,59 @@ | ||
// 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.WebView; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.VisibleForTesting; | ||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewFlutterApi; | ||
|
||
/** | ||
* Flutter API implementation for `WebView`. | ||
* | ||
* <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 WebViewFlutterApiImpl { | ||
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; | ||
|
||
private final InstanceManager instanceManager; | ||
private WebViewFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link WebViewFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public WebViewFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { | ||
this.binaryMessenger = binaryMessenger; | ||
this.instanceManager = instanceManager; | ||
api = new WebViewFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `WebView` instance and notifies Dart to create and store a new `WebView` instance | ||
* that is attached to this one. If `instance` has already been added, this method does nothing. | ||
*/ | ||
public void create(@NonNull WebView instance, @NonNull WebViewFlutterApi.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 WebViewFlutterApi api) { | ||
this.api = api; | ||
} | ||
} |
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.