Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[flutter_webview] Migrate to the new embedding #2169

Merged
merged 4 commits into from Oct 15, 2019
Merged

[flutter_webview] Migrate to the new embedding #2169

merged 4 commits into from Oct 15, 2019

Conversation

mklim
Copy link
Contributor

@mklim mklim commented Oct 9, 2019

Description

This depends on a new bugfix on the engine for text input to work with
the new embedding (flutter/engine#13015).

This also introduces some interesting and strange new failure cases.
With the new embedding, a FlutterView can be attached and detached from
the plugin at any point. It "should never" but technically can happen
that the plugin gets into a state where there is an active proxy adapter
view but no valid FlutterView to use for input proxying. For now I've
mostly added error logs and guards against NPEs detecting whenever we've
gotten into one of this situations. But I think we should probably
rigorously test this in an a2a specific situation to truly vet for a2a
support.

Related Issues

Fixes flutter/flutter#41851.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@mklim mklim requested a review from amirh October 9, 2019 01:01
@mklim
Copy link
Contributor Author

mklim commented Oct 9, 2019

I haven't decided how to handle the fact that we need a new version of the engine for this work with the new embedding yet. Naively we can try to check the version and then log the error but that's not great. Without the engine patch text input doesn't work on older Android versions at all with the new embedding.

android.useAndroidX=trueandroid.enableR8=true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a newline here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you.

@mklim mklim changed the title Migrate flutter_webview to the new embedding [flutter_webview] Migrate to the new embedding Oct 14, 2019
@mklim
Copy link
Contributor Author

mklim commented Oct 14, 2019

I believe this PR is ready to merge, after review. The latest commit added the new e2e tests and updated the pubspec.yaml.

ETA: On second thought, @amirh we should probably sync up about how to define "minimum version" here. The new embedding is only going to be functional in flutter versions after flutter/engine#13015 lands. Can we get the flutter version at runtime from the Java files? We may want to log an error if the new embedding is used with an older version of flutter.

@@ -5,6 +5,7 @@ version: 1.0.1

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
flutter: ">=1.9.1+hotfix.2 <2.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why you picked hotfix 2? is the intention to bump it to the next stable once it's there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My local branch is out of date, I just meant to pick the most recent stable. Changed it to .4.

I think so, especially since we'll need the v2 Registrant.

@@ -0,0 +1 @@
include ':app'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was automatically created by the tool at some point. I'll revert it since it's not related to this PR.

// Copyright 2018 The Chromium 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.webviewflutterexample;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add license header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

public class WebViewFlutterPlugin implements FlutterPlugin {
private @Nullable FlutterCookieManager flutterCookieManager;

/**
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new WebViewFlutterPlugin());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a TODO to remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* Java platform implementation of the webview_flutter plugin.
*
* <p>Instantiate this in an add to app scenario to gracefully handle activity and context changes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether we want to include these kind of instructions as users shouldn't really need to do that...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded.


Log.e(TAG, "The containerView has changed while the proxyAdapterView exists.");
if (containerView != null) {
setInputConnectionTarget(proxyAdapterView);
Copy link
Contributor

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?)

Copy link
Contributor Author

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.

// Use FlutterCookieManager#registerWith instead.
FlutterCookieManager(BinaryMessenger messenger) {
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/cookie_manager");
methodChannel.setMethodCallHandler(this);
}

static void registerWith(BinaryMessenger messenger) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could completely remove this method...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, done.

Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as it was all nites (modulo nits :) )

Michael Klimushyn added 4 commits October 14, 2019 16:49
This depends on a new bugfix on the engine for text input to work with
the new embedding (flutter/engine#13015).

This also introduces some interesting and strange new failure cases.
With the new embedding, a FlutterView can be attached and detached from
the plugin at any point. It "should never" but technically can happen
that the plugin gets into a state where there is an active proxy adapter
view but no valid FlutterView to use for input proxying. For now I've
mostly added error logs and guards against NPEs detecting whenever we've
gotten into one of this situations. But I think we should probably
rigorously test this in an a2a specific situation to truly vet for a2a
support.

DO NOT MERGE until we can land tests for this.
- Add the required lifecycle files into the dynamic Gradle inclusion
script
- Convert the FlutterDriver test to use the e2e package
- Update the pubspec and CHANGELOG, including incrementing the minimum
SDK version
@mklim mklim merged commit 573c9ff into flutter:master Oct 15, 2019
@mklim mklim deleted the webview_migrate_embedding branch October 15, 2019 00:13
mormih pushed a commit to mormih/plugins that referenced this pull request Nov 17, 2019
This depends on a new bugfix on the engine for text input to work with
the new embedding (flutter/engine#13015).
sungmin-park pushed a commit to sungmin-park/flutter-plugins that referenced this pull request Dec 17, 2019
This depends on a new bugfix on the engine for text input to work with
the new embedding (flutter/engine#13015).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants