Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2255)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 2380743003: Refactor ContentViewClient (2/6) (Closed)
Patch Set: tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwContents.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index 6735b00476a4700c1d3b8bce923ce04db846676d..6bf11dc366f85003b445cbc369e5eaed973b9a83 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -78,6 +78,7 @@ import org.chromium.ui.base.WindowAndroid;
import java.io.File;
import java.lang.annotation.Annotation;
+import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
@@ -988,28 +989,75 @@ public class AwContents implements SmartClipProvider,
return mWindowAndroid;
}
}
+
+ // WindowsAndroid action delegate for WebView.
+ private static class WindowAndroidAction extends WindowAndroid.ActionDelegate {
+ // AwContents to which the action delegate forwards the interfaces.
+ // Weak reference is used to relax the cross-reference and allow for clean up after gc.
+ private final WeakReference<AwContents> mAwContentsRef;
+
+ public WindowAndroidAction(AwContents contents) {
+ mAwContentsRef = new WeakReference<>(contents);
+ }
+
+ @Override
+ public boolean isSelectActionModeAllowed(int actionModeItem) {
+ AwContents awContents = mAwContentsRef.get();
+ return awContents != null ? awContents.isSelectActionModeAllowed(actionModeItem) : true;
+ }
+
+ @Override
+ public boolean isProcessTextSupported() {
+ return true;
+ }
+
+ @Override
+ public void performProcessText(Intent intent) {
+ AwContents awContents = mAwContentsRef.get();
+ if (awContents == null) return;
+ awContents.startProcessTextIntent(intent);
+ }
+
+ @Override
+ public void onStartContentIntent(Context context, String intentUrl, boolean isMainFrame) {
+ AwContents awContents = mAwContentsRef.get();
+ if (awContents == null) return;
+ awContents.startContentIntent(intentUrl, isMainFrame);
+ }
+ };
+
+ private void startContentIntent(String intentUrl, boolean isMainFrame) {
+ // Comes from WebViewImpl::detectContentOnTouch in Blink,
+ // so must be user-initiated and isn't a redirect.
+ mContentsClient.shouldIgnoreNavigation(mContext, intentUrl, isMainFrame, true, false);
+ }
+
private static WeakHashMap<Context, WindowAndroidWrapper> sContextWindowMap;
// getWindowAndroid is only called on UI thread, so there are no threading issues with lazy
// initialization.
@SuppressFBWarnings("LI_LAZY_INIT_STATIC")
- private static WindowAndroidWrapper getWindowAndroid(Context context) {
+ private static WindowAndroidWrapper getWindowAndroid(AwContents contents) {
boliu 2016/09/30 22:34:16 this doesn't work Android is by design not per-Aw
if (sContextWindowMap == null) sContextWindowMap = new WeakHashMap<>();
+ Context context = contents.getContext();
WindowAndroidWrapper wrapper = sContextWindowMap.get(context);
if (wrapper != null) return wrapper;
boolean contextWrapsActivity = activityFromContext(context) != null;
- if (contextWrapsActivity) {
- final boolean listenToActivityState = false;
- wrapper = new WindowAndroidWrapper(
- new ActivityWindowAndroid(context, listenToActivityState));
- } else {
- wrapper = new WindowAndroidWrapper(new WindowAndroid(context));
- }
+ final boolean listenToActivityState = false;
+ WindowAndroid windowAndroid = contextWrapsActivity
+ ? new ActivityWindowAndroid(context, listenToActivityState)
+ : new WindowAndroid(context);
+ windowAndroid.setActionDelegate(new WindowAndroidAction(contents));
+ wrapper = new WindowAndroidWrapper(windowAndroid);
sContextWindowMap.put(context, wrapper);
return wrapper;
}
+ private Context getContext() {
+ return mContext;
+ }
+
@VisibleForTesting
public static void setLocale(String locale) {
if (!sCurrentLocale.equals(locale)) {
@@ -1048,7 +1096,7 @@ public class AwContents implements SmartClipProvider,
WebContents webContents = nativeGetWebContents(mNativeAwContents);
- mWindowAndroid = getWindowAndroid(mContext);
+ mWindowAndroid = getWindowAndroid(this);
mContentViewCore = new ContentViewCore(mContext, PRODUCT_VERSION);
mViewAndroidDelegate = new AwViewAndroidDelegate(mContainerView,
mContentViewCore.getRenderCoordinates());
@@ -2301,7 +2349,7 @@ public class AwContents implements SmartClipProvider,
mContentViewCore.onProvideVirtualStructure(structure, true);
}
- public boolean isSelectActionModeAllowed(int actionModeItem) {
+ private boolean isSelectActionModeAllowed(int actionModeItem) {
return (mSettings.getDisabledActionModeMenuItems() & actionModeItem) != actionModeItem;
}

Powered by Google App Engine
This is Rietveld 408576698