-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[webview_flutter_android] Adds a workaround fix for autofill #3588
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
49bec43
start of autofill fix
bparrishMines df6ebe0
add engine issue
bparrishMines bac9bc7
Merge branch 'main' of github.com:flutter/packages into webview_autofill
bparrishMines 3478067
formatting
bparrishMines e329c74
fix mistake
bparrishMines 4ba04e7
add test
bparrishMines 977b7be
fix dumb name
bparrishMines e430245
use onAttachedToWindow
bparrishMines 2582d71
Merge branch 'main' of github.com:flutter/packages into webview_autofill
bparrishMines 71a3f16
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
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 |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 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; | ||
| } | ||
|
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. 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); | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Alternative considered:
According to autofill docs, a view can get around a parent view setting
IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS, if you doHowever, this would require a call to
requestAutofillevery 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 allowWebViewto handle the autofill importance.