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

[WebView autofill] Disable the autofill on application context

Android autofill won't work with application context, disable
Autofill if WebView is created with application context.

Also add a warning log.

Bug: 776152
Change-Id: I3b9b05b43c6359b4f5f4339699b4143b1d0b84ad
Reviewed-on: https://chromium-review.googlesource.com/726968Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510188}
parent a8faeaa7
...@@ -19,7 +19,6 @@ import java.lang.ref.WeakReference; ...@@ -19,7 +19,6 @@ import java.lang.ref.WeakReference;
/** /**
* The class to call Android's AutofillManager. * The class to call Android's AutofillManager.
*/ */
// TODO(michaelbai): Extend this class to provide instrumentation test. http://crbug.com/717658.
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
public class AwAutofillManager { public class AwAutofillManager {
private static final String TAG = "AwAutofillManager"; private static final String TAG = "AwAutofillManager";
...@@ -42,59 +41,67 @@ public class AwAutofillManager { ...@@ -42,59 +41,67 @@ public class AwAutofillManager {
private AutofillManager mAutofillManager; private AutofillManager mAutofillManager;
private boolean mIsAutofillInputUIShowing; private boolean mIsAutofillInputUIShowing;
private AutofillInputUIMonitor mMonitor; private AutofillInputUIMonitor mMonitor;
private boolean mDestroyed;
public AwAutofillManager(Context context) { public AwAutofillManager(Context context) {
if (AwContents.activityFromContext(context) == null) {
Log.w(TAG,
"WebView autofill is disabled because WebView isn't created with "
+ "activity context.");
return;
}
mAutofillManager = context.getSystemService(AutofillManager.class); mAutofillManager = context.getSystemService(AutofillManager.class);
mMonitor = new AutofillInputUIMonitor(this); mMonitor = new AutofillInputUIMonitor(this);
mAutofillManager.registerCallback(mMonitor); mAutofillManager.registerCallback(mMonitor);
} }
public void notifyVirtualValueChanged(View parent, int childId, AutofillValue value) { public void notifyVirtualValueChanged(View parent, int childId, AutofillValue value) {
if (isDestroyed()) return; if (isDestroyed() || mAutofillManager == null) return;
mAutofillManager.notifyValueChanged(parent, childId, value); mAutofillManager.notifyValueChanged(parent, childId, value);
} }
public void commit() { public void commit() {
if (isDestroyed()) return; if (isDestroyed() || mAutofillManager == null) return;
mAutofillManager.commit(); mAutofillManager.commit();
} }
public void cancel() { public void cancel() {
if (isDestroyed()) return; if (isDestroyed() || mAutofillManager == null) return;
mAutofillManager.cancel(); mAutofillManager.cancel();
} }
public void notifyVirtualViewEntered(View parent, int childId, Rect absBounds) { public void notifyVirtualViewEntered(View parent, int childId, Rect absBounds) {
if (isDestroyed()) return; if (isDestroyed() || mAutofillManager == null) return;
mAutofillManager.notifyViewEntered(parent, childId, absBounds); mAutofillManager.notifyViewEntered(parent, childId, absBounds);
} }
public void notifyVirtualViewExited(View parent, int childId) { public void notifyVirtualViewExited(View parent, int childId) {
if (isDestroyed()) return; if (isDestroyed() || mAutofillManager == null) return;
mAutofillManager.notifyViewExited(parent, childId); mAutofillManager.notifyViewExited(parent, childId);
} }
public void requestAutofill(View parent, int virtualId, Rect absBounds) { public void requestAutofill(View parent, int virtualId, Rect absBounds) {
if (isDestroyed()) return; if (isDestroyed() || mAutofillManager == null) return;
mAutofillManager.requestAutofill(parent, virtualId, absBounds); mAutofillManager.requestAutofill(parent, virtualId, absBounds);
} }
public boolean isAutofillInputUIShowing() { public boolean isAutofillInputUIShowing() {
if (isDestroyed()) return false; if (isDestroyed() || mAutofillManager == null) return false;
return mIsAutofillInputUIShowing; return mIsAutofillInputUIShowing;
} }
public void destroy() { public void destroy() {
if (isDestroyed()) return; if (isDestroyed() || mAutofillManager == null) return;
mAutofillManager.unregisterCallback(mMonitor); mAutofillManager.unregisterCallback(mMonitor);
mAutofillManager = null; mAutofillManager = null;
mDestroyed = true;
} }
private boolean isDestroyed() { private boolean isDestroyed() {
if (mAutofillManager == null) { if (mDestroyed) {
Log.w(TAG, "Application attempted to call on a destroyed AwAutofillManager", Log.w(TAG, "Application attempted to call on a destroyed AwAutofillManager",
new Throwable()); new Throwable());
} }
return mAutofillManager == null; return mDestroyed;
} }
} }
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