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

Side by Side Diff: ui/android/java/src/org/chromium/ui/base/WindowAndroid.java

Issue 2380743003: Refactor ContentViewClient (2/6) (Closed)
Patch Set: tests Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.ui.base; 5 package org.chromium.ui.base;
6 6
7 import android.animation.Animator; 7 import android.animation.Animator;
8 import android.animation.AnimatorListenerAdapter; 8 import android.animation.AnimatorListenerAdapter;
9 import android.annotation.SuppressLint; 9 import android.annotation.SuppressLint;
10 import android.annotation.TargetApi; 10 import android.annotation.TargetApi;
11 import android.app.Activity; 11 import android.app.Activity;
12 import android.app.PendingIntent; 12 import android.app.PendingIntent;
13 import android.content.ActivityNotFoundException;
13 import android.content.ContentResolver; 14 import android.content.ContentResolver;
14 import android.content.Context; 15 import android.content.Context;
15 import android.content.ContextWrapper; 16 import android.content.ContextWrapper;
16 import android.content.Intent; 17 import android.content.Intent;
17 import android.content.pm.PackageManager; 18 import android.content.pm.PackageManager;
18 import android.os.Build; 19 import android.os.Build;
19 import android.os.Bundle; 20 import android.os.Bundle;
20 import android.os.Process; 21 import android.os.Process;
21 import android.util.Log;
22 import android.util.SparseArray; 22 import android.util.SparseArray;
23 import android.view.View; 23 import android.view.View;
24 import android.view.ViewGroup; 24 import android.view.ViewGroup;
25 import android.view.accessibility.AccessibilityManager; 25 import android.view.accessibility.AccessibilityManager;
26 26
27 import org.chromium.base.ApiCompatibilityUtils; 27 import org.chromium.base.ApiCompatibilityUtils;
28 import org.chromium.base.Callback; 28 import org.chromium.base.Callback;
29 import org.chromium.base.Log;
29 import org.chromium.base.VisibleForTesting; 30 import org.chromium.base.VisibleForTesting;
30 import org.chromium.base.annotations.CalledByNative; 31 import org.chromium.base.annotations.CalledByNative;
31 import org.chromium.base.annotations.JNINamespace; 32 import org.chromium.base.annotations.JNINamespace;
32 import org.chromium.ui.VSyncMonitor; 33 import org.chromium.ui.VSyncMonitor;
33 import org.chromium.ui.widget.Toast; 34 import org.chromium.ui.widget.Toast;
34 35
35 import java.lang.ref.WeakReference; 36 import java.lang.ref.WeakReference;
36 import java.util.HashMap; 37 import java.util.HashMap;
37 import java.util.HashSet; 38 import java.util.HashSet;
38 import java.util.LinkedList; 39 import java.util.LinkedList;
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 * setWillNotDraw(false) to ensure that the animation is drawn over the Surf aceView, 659 * setWillNotDraw(false) to ensure that the animation is drawn over the Surf aceView,
659 * and otherwise we call setWillNotDraw(true). 660 * and otherwise we call setWillNotDraw(true).
660 */ 661 */
661 private void refreshWillNotDraw() { 662 private void refreshWillNotDraw() {
662 boolean willNotDraw = !mIsTouchExplorationEnabled && mAnimationsOverCont ent.isEmpty(); 663 boolean willNotDraw = !mIsTouchExplorationEnabled && mAnimationsOverCont ent.isEmpty();
663 if (mAnimationPlaceholderView.willNotDraw() != willNotDraw) { 664 if (mAnimationPlaceholderView.willNotDraw() != willNotDraw) {
664 mAnimationPlaceholderView.setWillNotDraw(willNotDraw); 665 mAnimationPlaceholderView.setWillNotDraw(willNotDraw);
665 } 666 }
666 } 667 }
667 668
669 /**
670 * A delegate defining the internal behavior when intent url is requested, c ontextual action bar
671 * is shown/hidden, etc. Used to override the behavior for subclass and test s. The default
672 * has empty, bare minimum implementation just to avoid null check when used without override.
673 */
674 public static class ActionDelegate {
675 /**
676 * Called when the contextual ActionBar is shown.
677 */
678 public void onContextualActionBarShown() { }
679
680 /**
681 * Called when the contextual ActionBar is hidden.
682 */
683 public void onContextualActionBarHidden() { }
684
685 /**
686 * If this returns {@code true} contextual web search attempts will be f orwarded to
687 * {@link #performWebSearch(String)}.
688 * @return {@code true} iff this {@link ContentViewClient} wants to cons ume
689 * web search queries and override the default intent behavior.
690 */
691 public boolean isWebSearchSupported() {
692 return false;
693 }
694
695 /**
696 * Perform a search on {@code searchQuery}. This method is only called if
697 * {@link #isWebSearchSupported()} returns {@code true}.
698 * @param searchQuery The string to search for.
699 */
700 public void performWebSearch(String searchQuery) { }
701
702 /**
703 * If this returns {@code true} the text processing intents should be fo rwarded to
704 * {@link * PerformProcessText(Intent)}, otherwise these intents should be sent
705 * by WindowAndroid by default.
706 * @return {@code true} iff this {@link ContentViewClient} wants to send
707 * the processing intents and override the default intent behavior.
708 */
709 public boolean isProcessTextSupported() {
710 return false;
711 }
712
713 /**
714 * Process text passed through {@code intent}. This method is only call ed if
715 * {@link #isProcessTextSupported()} returns {@code true}.
716 * @param intent intent containing the text to process.
717 */
718 public void performProcessText(Intent intent) { }
719
720 /**
721 * @param actionModeItem the flag for the action mode item in question. See
722 * {@link WebActionModeCallback.ActionHandler} for a list of vali d action
723 * mode item flags.
724 * @return true if the action is allowed. Otherwise, the menu item
725 * should be removed from the menu.
726 */
727 public boolean isSelectActionModeAllowed(int actionModeItem) {
728 return true;
729 }
730
731 /**
732 * Called when a new content intent is requested to be started.
733 */
734 public void onStartContentIntent(Context context, String intentUrl, bool ean isMainFrame) {
735 startActivityForIntentUrl(context, intentUrl);
736 }
737 }
738
739 public static void startActivityForIntentUrl(Context context, String intentU rl) {
David Trainor- moved to gerrit 2016/10/10 21:06:25 javadoc?
740 Intent intent;
741 // Perform generic parsing of the URI to turn it into an Intent.
742 try {
743 intent = Intent.parseUri(intentUrl, Intent.URI_INTENT_SCHEME);
744 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
745 } catch (Exception ex) {
746 Log.w(TAG, "Bad URI %s", intentUrl);
747 return;
748 }
749
750 try {
751 if (context != null) context.startActivity(intent);
752 } catch (ActivityNotFoundException ex) {
753 Log.w(TAG, "No application can handle %s", intentUrl);
754 }
755 }
756
757 private ActionDelegate mActionDelegate = new ActionDelegate();
boliu 2016/09/30 22:34:16 do the assignment in the constructor, also maybe m
758
759 public void setActionDelegate(ActionDelegate delegate) {
David Trainor- moved to gerrit 2016/10/10 21:06:25 Simple javadoc
760 mActionDelegate = delegate;
761 }
762
763 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
764 mActionDelegate.onContextualActionBarShown();
765 }
766
767 public void onContextualActionBarHidden() {
768 mActionDelegate.onContextualActionBarHidden();
769 }
770
771 public boolean isSelectActionModeAllowed(int actionModeItem) {
772 return mActionDelegate.isSelectActionModeAllowed(actionModeItem);
773 }
774
775 public boolean doesPerformWebSearch() {
776 return mActionDelegate.isWebSearchSupported();
777 }
778
779 public void performWebSearch(String searchQuery) {
780 mActionDelegate.performWebSearch(searchQuery);
781 }
782
783 public boolean doesPerformProcessText() {
784 return mActionDelegate.isProcessTextSupported();
785 }
786
787 public void startProcessTextIntent(Intent intent) {
788 mActionDelegate.performProcessText(intent);
789 }
790
791 @CalledByNative
792 private void onStartContentIntent(String intentUrl, boolean isMainFrame) {
793 mActionDelegate.onStartContentIntent(getContext().get(), intentUrl, isMa inFrame);
794 }
795
668 private native long nativeInit(); 796 private native long nativeInit();
669 private native void nativeOnVSync(long nativeWindowAndroid, 797 private native void nativeOnVSync(long nativeWindowAndroid,
670 long vsyncTimeMicros, 798 long vsyncTimeMicros,
671 long vsyncPeriodMicros); 799 long vsyncPeriodMicros);
672 private native void nativeOnVisibilityChanged(long nativeWindowAndroid, bool ean visible); 800 private native void nativeOnVisibilityChanged(long nativeWindowAndroid, bool ean visible);
673 private native void nativeOnActivityStopped(long nativeWindowAndroid); 801 private native void nativeOnActivityStopped(long nativeWindowAndroid);
674 private native void nativeOnActivityStarted(long nativeWindowAndroid); 802 private native void nativeOnActivityStarted(long nativeWindowAndroid);
675 private native void nativeDestroy(long nativeWindowAndroid); 803 private native void nativeDestroy(long nativeWindowAndroid);
676 804
677 } 805 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698