Skip to content

Commit 252b4ff

Browse files
Michael KlimushynPark Sung Min
authored andcommitted
[flutter_webview] Revert v2 embedder support (flutter#2200)
The flutter_webview plugin needs an API in the v2 embedder that didn't roll into Flutter until `v1.10.9`, and the latest stable is `v.1.9.1`. In addition to this the migration already relied on some bugfixes that weren't really in stable, so the migration was shaky to begin with.
1 parent 9fa7bef commit 252b4ff

File tree

19 files changed

+108
-290
lines changed

19 files changed

+108
-290
lines changed

packages/webview_flutter/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.15+1
2+
3+
* Revert the prior embedding support add since it requires an API that hasn't
4+
rolled to stable.
5+
16
## 0.3.15
27

38
* Add support for the v2 Android embedding. This shouldn't affect existing

packages/webview_flutter/android/build.gradle

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,3 @@ android {
5050
implementation 'androidx.webkit:webkit:1.0.0'
5151
}
5252
}
53-
54-
// TODO(mklim): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
55-
afterEvaluate {
56-
def containsEmbeddingDependencies = false
57-
for (def configuration : configurations.all) {
58-
for (def dependency : configuration.dependencies) {
59-
if (dependency.group == 'io.flutter' &&
60-
dependency.name.startsWith('flutter_embedding') &&
61-
dependency.isTransitive())
62-
{
63-
containsEmbeddingDependencies = true
64-
break
65-
}
66-
}
67-
}
68-
if (!containsEmbeddingDependencies) {
69-
android {
70-
dependencies {
71-
def lifecycle_version = "2.1.0"
72-
api "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
73-
api "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
74-
}
75-
}
76-
}
77-
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
org.gradle.jvmargs=-Xmx1536M
2-
android.enableJetifier=true
3-
android.useAndroidX=true

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterCookieManager.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515
import io.flutter.plugin.common.MethodChannel.Result;
1616

1717
class FlutterCookieManager implements MethodCallHandler {
18-
private final MethodChannel methodChannel;
1918

20-
FlutterCookieManager(BinaryMessenger messenger) {
21-
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/cookie_manager");
22-
methodChannel.setMethodCallHandler(this);
19+
private FlutterCookieManager() {
20+
// Do not instantiate.
21+
// This class should only be used in context of a BinaryMessenger.
22+
// Use FlutterCookieManager#registerWith instead.
23+
}
24+
25+
static void registerWith(BinaryMessenger messenger) {
26+
MethodChannel methodChannel = new MethodChannel(messenger, "plugins.flutter.io/cookie_manager");
27+
FlutterCookieManager cookieManager = new FlutterCookieManager();
28+
methodChannel.setMethodCallHandler(cookieManager);
2329
}
2430

2531
@Override
@@ -33,10 +39,6 @@ public void onMethodCall(MethodCall methodCall, Result result) {
3339
}
3440
}
3541

36-
void dispose() {
37-
methodChannel.setMethodCallHandler(null);
38-
}
39-
4042
private static void clearCookies(final Result result) {
4143
CookieManager cookieManager = CookieManager.getInstance();
4244
final boolean hasCookies = cookieManager.hasCookies();

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import android.view.View;
1313
import android.webkit.WebStorage;
1414
import android.webkit.WebViewClient;
15-
import androidx.annotation.NonNull;
16-
import androidx.annotation.Nullable;
1715
import io.flutter.plugin.common.BinaryMessenger;
1816
import io.flutter.plugin.common.MethodCall;
1917
import io.flutter.plugin.common.MethodChannel;
@@ -38,7 +36,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
3836
BinaryMessenger messenger,
3937
int id,
4038
Map<String, Object> params,
41-
@Nullable View containerView) {
39+
final View containerView) {
4240

4341
DisplayListenerProxy displayListenerProxy = new DisplayListenerProxy();
4442
DisplayManager displayManager =
@@ -97,16 +95,6 @@ public void onInputConnectionLocked() {
9795
webView.lockInputConnection();
9896
}
9997

100-
@Override
101-
public void onFlutterViewAttached(@NonNull View flutterView) {
102-
webView.setContainerView(flutterView);
103-
}
104-
105-
@Override
106-
public void onFlutterViewDetached() {
107-
webView.setContainerView(null);
108-
}
109-
11098
@Override
11199
public void onMethodCall(MethodCall methodCall, Result result) {
112100
switch (methodCall.method) {

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import static android.content.Context.INPUT_METHOD_SERVICE;
88

99
import android.content.Context;
10-
import android.util.Log;
1110
import android.view.View;
1211
import android.view.inputmethod.InputMethodManager;
1312
import android.webkit.WebView;
14-
import androidx.annotation.Nullable;
1513

1614
/**
1715
* A WebView subclass that mirrors the same implementation hacks that the system WebView does in
@@ -24,29 +22,16 @@
2422
* <p>See also {@link ThreadedInputConnectionProxyAdapterView}.
2523
*/
2624
final class InputAwareWebView extends WebView {
27-
private static final String TAG = "InputAwareWebView";
25+
private final View containerView;
26+
2827
private View threadedInputConnectionProxyView;
2928
private ThreadedInputConnectionProxyAdapterView proxyAdapterView;
30-
private @Nullable View containerView;
3129

32-
InputAwareWebView(Context context, @Nullable View containerView) {
30+
InputAwareWebView(Context context, View containerView) {
3331
super(context);
3432
this.containerView = containerView;
3533
}
3634

37-
void setContainerView(@Nullable View containerView) {
38-
this.containerView = containerView;
39-
40-
if (proxyAdapterView == null) {
41-
return;
42-
}
43-
44-
Log.w(TAG, "The containerView has changed while the proxyAdapterView exists.");
45-
if (containerView != null) {
46-
setInputConnectionTarget(proxyAdapterView);
47-
}
48-
}
49-
5035
/**
5136
* Set our proxy adapter view to use its cached input connection instead of creating new ones.
5237
*
@@ -96,12 +81,6 @@ public boolean checkInputConnectionProxy(final View view) {
9681
// This isn't a new ThreadedInputConnectionProxyView. Ignore it.
9782
return super.checkInputConnectionProxy(view);
9883
}
99-
if (containerView == null) {
100-
Log.e(
101-
TAG,
102-
"Can't create a proxy view because there's no container view. Text input may not work.");
103-
return super.checkInputConnectionProxy(view);
104-
}
10584

10685
// We've never seen this before, so we make the assumption that this is WebView's
10786
// ThreadedInputConnectionProxyView. We are making the assumption that the only view that could
@@ -141,10 +120,6 @@ private void resetInputConnection() {
141120
// No need to reset the InputConnection to the default thread if we've never changed it.
142121
return;
143122
}
144-
if (containerView == null) {
145-
Log.e(TAG, "Can't reset the input connection to the container view because there is none.");
146-
return;
147-
}
148123
setInputConnectionTarget(/*targetView=*/ containerView);
149124
}
150125

@@ -157,13 +132,6 @@ private void resetInputConnection() {
157132
* InputConnections should be created on.
158133
*/
159134
private void setInputConnectionTarget(final View targetView) {
160-
if (containerView == null) {
161-
Log.e(
162-
TAG,
163-
"Can't set the input connection target because there is no containerView to use as a handler.");
164-
return;
165-
}
166-
167135
targetView.requestFocus();
168136
containerView.post(
169137
new Runnable() {

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import android.content.Context;
88
import android.view.View;
9-
import androidx.annotation.Nullable;
109
import io.flutter.plugin.common.BinaryMessenger;
1110
import io.flutter.plugin.common.StandardMessageCodec;
1211
import io.flutter.plugin.platform.PlatformView;
@@ -15,9 +14,9 @@
1514

1615
public final class WebViewFactory extends PlatformViewFactory {
1716
private final BinaryMessenger messenger;
18-
private @Nullable final View containerView;
17+
private final View containerView;
1918

20-
WebViewFactory(BinaryMessenger messenger, @Nullable View containerView) {
19+
WebViewFactory(BinaryMessenger messenger, View containerView) {
2120
super(StandardMessageCodec.INSTANCE);
2221
this.messenger = messenger;
2322
this.containerView = containerView;

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,17 @@
44

55
package io.flutter.plugins.webviewflutter;
66

7-
import androidx.annotation.NonNull;
8-
import androidx.annotation.Nullable;
9-
import io.flutter.embedding.engine.plugins.FlutterPlugin;
10-
import io.flutter.plugin.common.BinaryMessenger;
117
import io.flutter.plugin.common.PluginRegistry.Registrar;
128

13-
/**
14-
* Java platform implementation of the webview_flutter plugin.
15-
*
16-
* <p>Register this in an add to app scenario to gracefully handle activity and context changes.
17-
*
18-
* <p>Call {@link #registerWith(Registrar)} to use the stable {@code io.flutter.plugin.common}
19-
* package instead.
20-
*/
21-
public class WebViewFlutterPlugin implements FlutterPlugin {
22-
23-
private @Nullable FlutterCookieManager flutterCookieManager;
24-
25-
/**
26-
* Add an instance of this to {@link io.flutter.embedding.engine.plugins.PluginRegistry} to
27-
* register it.
28-
*
29-
* <p>THIS PLUGIN CODE PATH DEPENDS ON A NEWER VERSION OF FLUTTER THAN THE ONE DEFINED IN THE
30-
* PUBSPEC.YAML. Text input will fail on some Android devices unless this is used with at least
31-
* flutter/flutter@1d4d63ace1f801a022ea9ec737bf8c15395588b9. Use the V1 embedding with {@link
32-
* #registerWith(Registrar)} to use this plugin with older Flutter versions.
33-
*
34-
* <p>Registration should eventually be handled automatically by v2 of the
35-
* GeneratedPluginRegistrant. https://github.com/flutter/flutter/issues/42694
36-
*/
37-
public WebViewFlutterPlugin() {}
38-
39-
/**
40-
* Registers a plugin implementation that uses the stable {@code io.flutter.plugin.common}
41-
* package.
42-
*
43-
* <p>Calling this automatically initializes the plugin. However plugins initialized this way
44-
* won't react to changes in activity or context, unlike {@link CameraPlugin}.
45-
*/
9+
/** WebViewFlutterPlugin */
10+
public class WebViewFlutterPlugin {
11+
/** Plugin registration. */
4612
public static void registerWith(Registrar registrar) {
4713
registrar
4814
.platformViewRegistry()
4915
.registerViewFactory(
5016
"plugins.flutter.io/webview",
5117
new WebViewFactory(registrar.messenger(), registrar.view()));
52-
new FlutterCookieManager(registrar.messenger());
53-
}
54-
55-
@Override
56-
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
57-
BinaryMessenger messenger = binding.getFlutterEngine().getDartExecutor();
58-
binding
59-
.getFlutterEngine()
60-
.getPlatformViewsController()
61-
.getRegistry()
62-
.registerViewFactory(
63-
"plugins.flutter.io/webview", new WebViewFactory(messenger, /*containerView=*/ null));
64-
flutterCookieManager = new FlutterCookieManager(messenger);
65-
}
66-
67-
@Override
68-
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
69-
if (flutterCookieManager == null) {
70-
return;
71-
}
72-
73-
flutterCookieManager.dispose();
74-
flutterCookieManager = null;
18+
FlutterCookieManager.registerWith(registrar.messenger());
7519
}
7620
}

packages/webview_flutter/example/android/app/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ flutter {
5656

5757
dependencies {
5858
testImplementation 'junit:junit:4.12'
59-
androidTestImplementation 'androidx.test:runner:1.2.0'
60-
androidTestImplementation 'androidx.test:rules:1.2.0'
61-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
59+
androidTestImplementation 'androidx.test:runner:1.1.1'
60+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
6261
}

packages/webview_flutter/example/android/app/src/androidTestDebug/java/io/flutter/plugins/webviewflutterexample/EmbeddingV1ActivityTest.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)