-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[webview_flutter_android] Adds a WebViewFlutterApi #3324
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1bcc89d
add webview flutter api
bparrishMines ba855fe
improve changelog message
bparrishMines 1d03c8f
updates
bparrishMines 3cb2727
revert pigeon version so to get lower analyzer
bparrishMines 413ab3a
formatting
bparrishMines 7c5e6cf
Merge branch 'main' of github.com:flutter/packages into webview_flutt…
bparrishMines 327b0bc
add a webviewFlutterApi variable
bparrishMines 4595e8f
Merge branch 'main' of github.com:flutter/packages into webview_flutt…
bparrishMines 75c8921
formatting
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,6 @@ public class WebChromeClientTest { | |
public void setUp() { | ||
instanceManager = InstanceManager.open(identifier -> {}); | ||
|
||
instanceManager.addDartCreatedInstance(mockWebView, 0L); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed so that it is tested that it can handle adding the |
||
|
||
final WebChromeClientCreator webChromeClientCreator = | ||
new WebChromeClientCreator() { | ||
@Override | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Should we just make a private field with this API on object construction, so we don't need the boilerplate of creating one in every single callback? I know it's cheap to create, but it should also be very cheap to just keep it around.