This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[flutter_webview] Migrate to the new embedding #2169
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| org.gradle.jvmargs=-Xmx1536M | ||
| android.enableJetifier=true | ||
| android.useAndroidX=true |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,17 +4,68 @@ | |
|
|
||
| package io.flutter.plugins.webviewflutter; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import io.flutter.embedding.engine.plugins.FlutterPlugin; | ||
| import io.flutter.plugin.common.BinaryMessenger; | ||
| import io.flutter.plugin.common.PluginRegistry.Registrar; | ||
|
|
||
| /** WebViewFlutterPlugin */ | ||
| public class WebViewFlutterPlugin { | ||
| /** Plugin registration. */ | ||
| /** | ||
| * Java platform implementation of the webview_flutter plugin. | ||
| * | ||
| * <p>Register this in an add to app scenario to gracefully handle activity and context changes. | ||
| * | ||
| * <p>Call {@link #registerWith(Registrar)} to use the stable {@code io.flutter.plugin.common} | ||
| * package instead. | ||
| */ | ||
| public class WebViewFlutterPlugin implements FlutterPlugin { | ||
|
|
||
| private @Nullable FlutterCookieManager flutterCookieManager; | ||
|
|
||
| /** | ||
|
Contributor
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. I'd think we don't want to direct users to do that. They should rely on the generated registrant (if it's not there it probably means their engine is old enough to not run this plugin properly anyway)
Contributor
Author
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. Reworded. I linked to the tracking issue here and removed the reference to MainActivity. |
||
| * Add an instance of this to {@link io.flutter.embedding.engine.plugins.PluginRegistry} to | ||
| * register it. | ||
| * | ||
| * <p>Registration should eventually be handled automatically by v2 of the | ||
| * GeneratedPluginRegistrant. https://github.com/flutter/flutter/issues/42694 | ||
| */ | ||
| public WebViewFlutterPlugin() {} | ||
|
|
||
| /** | ||
| * Registers a plugin implementation that uses the stable {@code io.flutter.plugin.common} | ||
| * package. | ||
| * | ||
| * <p>Calling this automatically initializes the plugin. However plugins initialized this way | ||
| * won't react to changes in activity or context, unlike {@link CameraPlugin}. | ||
| */ | ||
| public static void registerWith(Registrar registrar) { | ||
| registrar | ||
| .platformViewRegistry() | ||
| .registerViewFactory( | ||
| "plugins.flutter.io/webview", | ||
| new WebViewFactory(registrar.messenger(), registrar.view())); | ||
| FlutterCookieManager.registerWith(registrar.messenger()); | ||
| new FlutterCookieManager(registrar.messenger()); | ||
| } | ||
|
|
||
| @Override | ||
| public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { | ||
| BinaryMessenger messenger = binding.getFlutterEngine().getDartExecutor(); | ||
| binding | ||
| .getFlutterEngine() | ||
| .getPlatformViewsController() | ||
| .getRegistry() | ||
| .registerViewFactory( | ||
| "plugins.flutter.io/webview", new WebViewFactory(messenger, /*containerView=*/ null)); | ||
| flutterCookieManager = new FlutterCookieManager(messenger); | ||
| } | ||
|
|
||
| @Override | ||
| public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { | ||
| if (flutterCookieManager == null) { | ||
| return; | ||
| } | ||
|
|
||
| flutterCookieManager.dispose(); | ||
| flutterCookieManager = null; | ||
| } | ||
| } | ||
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
...droidTestDebug/java/io/flutter/plugins/webviewflutterexample/EmbeddingV1ActivityTest.java
This file contains hidden or 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,13 @@ | ||
| package io.flutter.plugins.webviewflutterexample; | ||
|
|
||
| import androidx.test.rule.ActivityTestRule; | ||
| import dev.flutter.plugins.e2e.FlutterRunner; | ||
| import org.junit.Rule; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(FlutterRunner.class) | ||
| public class EmbeddingV1ActivityTest { | ||
| @Rule | ||
| public ActivityTestRule<EmbeddingV1Activity> rule = | ||
| new ActivityTestRule<>(EmbeddingV1Activity.class); | ||
| } |
11 changes: 11 additions & 0 deletions
11
.../src/androidTestDebug/java/io/flutter/plugins/webviewflutterexample/MainActivityTest.java
This file contains hidden or 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,11 @@ | ||
| package io.flutter.plugins.webviewflutterexample; | ||
|
|
||
| import androidx.test.rule.ActivityTestRule; | ||
| import dev.flutter.plugins.e2e.FlutterRunner; | ||
| import org.junit.Rule; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(FlutterRunner.class) | ||
| public class MainActivityTest { | ||
| @Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class); | ||
| } |
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.
Does it work? (if so should we log an error?)
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.
Yeah, this does work from my testing. Semantically this seems "wrong" to me, because we're changing the view after it's already been launched. I'm worried that there may be other bugs under the hood. But it is spammy to log this without a confirmed error. I downgraded to
WARNING.