Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 3.4.4

* Fixes a bug where the native `WebView` wouldn't be traversed for autofill automatically.
* Updates minimum Flutter version to 3.3.

## 3.4.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.view.View;
import android.view.ViewParent;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewHostApi;
Expand Down Expand Up @@ -104,6 +107,35 @@ public View getView() {
@Override
public void dispose() {}

// TODO(bparrishMines): This should be removed once https://github.com/flutter/engine/pull/40771 makes it to stable.
// Temporary fix for https://github.com/flutter/flutter/issues/92165. The FlutterView is setting
// setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS) which prevents this
// view from automatically being traversed for autofill.
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final FlutterView flutterView = tryFindFlutterView();
if (flutterView != null) {
flutterView.setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
}
}
}
Copy link
Contributor Author

@bparrishMines bparrishMines Mar 29, 2023

Choose a reason for hiding this comment

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

Alternative considered:

According to autofill docs, a view can get around a parent view setting IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS, if you do

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  final AutofillManager manager = getContext().getSystemService(AutofillManager.class);
  manager.requestAutofill(webView);
}

However, this would require a call to requestAutofill every time a page finished loading. I tried to call it when the view was instantiated, but autofill still didn't work. It only seemed to work if you call it once a page is loaded. My instinct is that it would be best to change the value of the parent and allow WebView to handle the autofill importance.


// Attempt to traverse the parents of this view until a FlutterView is found.
private FlutterView tryFindFlutterView() {
ViewParent currentView = this;

while (currentView.getParent() != null) {
currentView = currentView.getParent();
if (currentView instanceof FlutterView) {
return (FlutterView) currentView;
}
}

return null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parents structure of Hybrid Composition and TLHC are different, so this should handle both cases.


@Override
public void setWebViewClient(WebViewClient webViewClient) {
super.setWebViewClient(webViewClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebViewClient;
import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewFlutterApi;
import io.flutter.plugins.webviewflutter.WebViewHostApiImpl.WebViewPlatformView;
import io.flutter.plugins.webviewflutter.utils.TestUtils;
import java.util.HashMap;
import java.util.Objects;
import org.junit.After;
Expand Down Expand Up @@ -335,4 +340,19 @@ public void flutterApiCreate() {

instanceManager.close();
}

@Test
public void setImportantForAutofillForParentFlutterView() {
final WebViewPlatformView webView =
new WebViewPlatformView(mockContext, mockBinaryMessenger, testInstanceManager);

final WebViewPlatformView webViewSpy = spy(webView);
final FlutterView mockFlutterView = mock(FlutterView.class);
when(webViewSpy.getParent()).thenReturn(mockFlutterView);

TestUtils.setFinalStatic(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.O);
webViewSpy.onAttachedToWindow();

verify(mockFlutterView).setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_YES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: webview_flutter_android
description: A Flutter plugin that provides a WebView widget on Android.
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
version: 3.4.3
version: 3.4.4

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down