Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
| diff --git a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
| index dabb468983aa8e19a23b3e5ce859786048a0485c..36295f1addac6e7b434a8ffaa6b96aa1f9aca32b 100644 |
| --- a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
| +++ b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
| @@ -10,6 +10,7 @@ import android.annotation.SuppressLint; |
| import android.annotation.TargetApi; |
| import android.app.Activity; |
| import android.app.PendingIntent; |
| +import android.content.ActivityNotFoundException; |
| import android.content.ContentResolver; |
| import android.content.Context; |
| import android.content.ContextWrapper; |
| @@ -18,7 +19,6 @@ import android.content.pm.PackageManager; |
| import android.os.Build; |
| import android.os.Bundle; |
| import android.os.Process; |
| -import android.util.Log; |
| import android.util.SparseArray; |
| import android.view.View; |
| import android.view.ViewGroup; |
| @@ -26,6 +26,7 @@ import android.view.accessibility.AccessibilityManager; |
| import org.chromium.base.ApiCompatibilityUtils; |
| import org.chromium.base.Callback; |
| +import org.chromium.base.Log; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.annotations.JNINamespace; |
| @@ -665,6 +666,133 @@ public class WindowAndroid { |
| } |
| } |
| + /** |
| + * A delegate defining the internal behavior when intent url is requested, contextual action bar |
| + * is shown/hidden, etc. Used to override the behavior for subclass and tests. The default |
| + * has empty, bare minimum implementation just to avoid null check when used without override. |
| + */ |
| + public static class ActionDelegate { |
| + /** |
| + * Called when the contextual ActionBar is shown. |
| + */ |
| + public void onContextualActionBarShown() { } |
| + |
| + /** |
| + * Called when the contextual ActionBar is hidden. |
| + */ |
| + public void onContextualActionBarHidden() { } |
| + |
| + /** |
| + * If this returns {@code true} contextual web search attempts will be forwarded to |
| + * {@link #performWebSearch(String)}. |
| + * @return {@code true} iff this {@link ContentViewClient} wants to consume |
| + * web search queries and override the default intent behavior. |
| + */ |
| + public boolean isWebSearchSupported() { |
| + return false; |
| + } |
| + |
| + /** |
| + * Perform a search on {@code searchQuery}. This method is only called if |
| + * {@link #isWebSearchSupported()} returns {@code true}. |
| + * @param searchQuery The string to search for. |
| + */ |
| + public void performWebSearch(String searchQuery) { } |
| + |
| + /** |
| + * If this returns {@code true} the text processing intents should be forwarded to |
| + * {@link * PerformProcessText(Intent)}, otherwise these intents should be sent |
| + * by WindowAndroid by default. |
| + * @return {@code true} iff this {@link ContentViewClient} wants to send |
| + * the processing intents and override the default intent behavior. |
| + */ |
| + public boolean isProcessTextSupported() { |
| + return false; |
| + } |
| + |
| + /** |
| + * Process text passed through {@code intent}. This method is only called if |
| + * {@link #isProcessTextSupported()} returns {@code true}. |
| + * @param intent intent containing the text to process. |
| + */ |
| + public void performProcessText(Intent intent) { } |
| + |
| + /** |
| + * @param actionModeItem the flag for the action mode item in question. See |
| + * {@link WebActionModeCallback.ActionHandler} for a list of valid action |
| + * mode item flags. |
| + * @return true if the action is allowed. Otherwise, the menu item |
| + * should be removed from the menu. |
| + */ |
| + public boolean isSelectActionModeAllowed(int actionModeItem) { |
| + return true; |
| + } |
| + |
| + /** |
| + * Called when a new content intent is requested to be started. |
| + */ |
| + public void onStartContentIntent(Context context, String intentUrl, boolean isMainFrame) { |
| + startActivityForIntentUrl(context, intentUrl); |
| + } |
| + } |
| + |
| + public static void startActivityForIntentUrl(Context context, String intentUrl) { |
|
David Trainor- moved to gerrit
2016/10/10 21:06:25
javadoc?
|
| + Intent intent; |
| + // Perform generic parsing of the URI to turn it into an Intent. |
| + try { |
| + intent = Intent.parseUri(intentUrl, Intent.URI_INTENT_SCHEME); |
| + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| + } catch (Exception ex) { |
| + Log.w(TAG, "Bad URI %s", intentUrl); |
| + return; |
| + } |
| + |
| + try { |
| + if (context != null) context.startActivity(intent); |
| + } catch (ActivityNotFoundException ex) { |
| + Log.w(TAG, "No application can handle %s", intentUrl); |
| + } |
| + } |
| + |
| + private ActionDelegate mActionDelegate = new ActionDelegate(); |
|
boliu
2016/09/30 22:34:16
do the assignment in the constructor, also maybe m
|
| + |
| + public void setActionDelegate(ActionDelegate delegate) { |
|
David Trainor- moved to gerrit
2016/10/10 21:06:25
Simple javadoc
|
| + mActionDelegate = delegate; |
| + } |
| + |
| + public void onContextualActionBarShown() { |
|
David Trainor- moved to gerrit
2016/10/10 21:06:25
Should we have javadocs on these? I'd be fine wit
|
| + mActionDelegate.onContextualActionBarShown(); |
| + } |
| + |
| + public void onContextualActionBarHidden() { |
| + mActionDelegate.onContextualActionBarHidden(); |
| + } |
| + |
| + public boolean isSelectActionModeAllowed(int actionModeItem) { |
| + return mActionDelegate.isSelectActionModeAllowed(actionModeItem); |
| + } |
| + |
| + public boolean doesPerformWebSearch() { |
| + return mActionDelegate.isWebSearchSupported(); |
| + } |
| + |
| + public void performWebSearch(String searchQuery) { |
| + mActionDelegate.performWebSearch(searchQuery); |
| + } |
| + |
| + public boolean doesPerformProcessText() { |
| + return mActionDelegate.isProcessTextSupported(); |
| + } |
| + |
| + public void startProcessTextIntent(Intent intent) { |
| + mActionDelegate.performProcessText(intent); |
| + } |
| + |
| + @CalledByNative |
| + private void onStartContentIntent(String intentUrl, boolean isMainFrame) { |
| + mActionDelegate.onStartContentIntent(getContext().get(), intentUrl, isMainFrame); |
| + } |
| + |
| private native long nativeInit(); |
| private native void nativeOnVSync(long nativeWindowAndroid, |
| long vsyncTimeMicros, |