Commit ad3fbb98 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

Autofill: Send VIRTUAL_STRUCTURE_PROVIDER info to autofill service

Bug: 1067334
Change-Id: Ibf64b31d7ad6289a9a1ab5f4aab1fcf4dcbd14eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134611
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756459}
parent 1c8c016a
......@@ -611,7 +611,7 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
AutofillProvider createAutofillProvider(Context context, ViewGroup containerView) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return null;
return new AutofillProviderImpl(context, containerView);
return new AutofillProviderImpl(context, containerView, "Android WebView");
}
void startYourEngines(boolean onMainThread) {
......
......@@ -194,12 +194,13 @@ public class AwAutofillTest {
@Override
public Bundle getExtras() {
return null;
if (mBundle == null) mBundle = new Bundle();
return mBundle;
}
@Override
public boolean hasExtras() {
return false;
return mBundle != null;
}
@Override
......@@ -443,6 +444,7 @@ public class AwAutofillTest {
private Rect mDimensRect;
private int mDimensScrollX;
private int mDimensScrollY;
private Bundle mBundle;
}
// crbug.com/776230: On Android L, declaring variables of unsupported classes causes an error.
......@@ -752,8 +754,8 @@ public class AwAutofillTest {
public AutofillProvider createAutofillProvider(
Context context, ViewGroup containerView) {
mTestAutofillManagerWrapper = new TestAutofillManagerWrapper(context);
return new AutofillProviderImpl(
containerView, mTestAutofillManagerWrapper, context);
return new AutofillProviderImpl(containerView, mTestAutofillManagerWrapper,
context, "AwAutofillTest");
}
});
mAwContents = mTestContainerView.getAwContents();
......@@ -851,6 +853,10 @@ public class AwAutofillTest {
assertEquals(webDomain, viewStructure.getWebDomain());
// WebView shouldn't set class name.
assertNull(viewStructure.getClassName());
Bundle extras = viewStructure.getExtras();
assertEquals(
"AwAutofillTest", extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_NAME"));
assertTrue(0 < extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_VERSION").length());
TestViewStructure.AwHtmlInfo htmlInfoForm = viewStructure.getHtmlInfo();
assertEquals("form", htmlInfoForm.getTag());
assertEquals("formname", htmlInfoForm.getAttribute("name"));
......
......@@ -58,6 +58,7 @@ android_library("provider_java") {
"//base:base_java",
"//base:jni_java",
"//components/autofill/core/common/mojom:mojo_types_java",
"//components/version_info/android:version_constants_java",
"//content/public/android:content_java",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//ui/android:ui_java",
......
......@@ -10,6 +10,7 @@ import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
......@@ -21,6 +22,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.DoNotInline;
import org.chromium.base.metrics.ScopedSysTraceEvent;
import org.chromium.components.version_info.VersionConstants;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.display.DisplayAndroid;
......@@ -220,6 +222,7 @@ public class AutofillProviderImpl extends AutofillProvider {
}
}
private final String mProviderName;
private AutofillManagerWrapper mAutofillManager;
private ViewGroup mContainerView;
private WebContents mWebContents;
......@@ -230,13 +233,14 @@ public class AutofillProviderImpl extends AutofillProvider {
private AutofillManagerWrapper.InputUIObserver mInputUIObserver;
private long mAutofillTriggeredTimeMillis;
public AutofillProviderImpl(Context context, ViewGroup containerView) {
this(containerView, new AutofillManagerWrapper(context), context);
public AutofillProviderImpl(Context context, ViewGroup containerView, String providerName) {
this(containerView, new AutofillManagerWrapper(context), context, providerName);
}
@VisibleForTesting
public AutofillProviderImpl(
ViewGroup containerView, AutofillManagerWrapper manager, Context context) {
public AutofillProviderImpl(ViewGroup containerView, AutofillManagerWrapper manager,
Context context, String providerName) {
mProviderName = providerName;
try (ScopedSysTraceEvent e =
ScopedSysTraceEvent.scoped("AutofillProviderImpl.constructor")) {
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
......@@ -268,6 +272,13 @@ public class AutofillProviderImpl extends AutofillProvider {
// control outside of the scope of autofill, e.g. the URL bar, in this case, we simply
// return.
if (mRequest == null) return;
Bundle bundle = structure.getExtras();
if (bundle != null) {
bundle.putCharSequence("VIRTUAL_STRUCTURE_PROVIDER_NAME", mProviderName);
bundle.putCharSequence(
"VIRTUAL_STRUCTURE_PROVIDER_VERSION", VersionConstants.PRODUCT_VERSION);
}
mRequest.fillViewStructure(structure);
if (AutofillManagerWrapper.isLoggable()) {
AutofillManagerWrapper.log(
......
......@@ -204,8 +204,8 @@ public final class TabImpl extends ITab.Stub {
selectionController.setNonSelectionActionModeCallback(null);
} else {
// Set up |mAutofillProvider| to operate in the new Context.
mAutofillProvider = new AutofillProviderImpl(
mBrowser.getContext(), mBrowser.getViewAndroidDelegateContainerView());
mAutofillProvider = new AutofillProviderImpl(mBrowser.getContext(),
mBrowser.getViewAndroidDelegateContainerView(), "WebLayer");
mAutofillProvider.setWebContents(mWebContents);
selectionController.setNonSelectionActionModeCallback(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment