summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhush <hush@chromium.org>2015-10-28 14:45:54 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-28 21:46:33 +0000
commit0d797bcaede9cad87da956ca26e8a0159a71732a (patch)
treeafb76c07faab7eb8adcdf983e571d6988c680b87
parent83a4b3aa72d98fe4176b4a54c8cea227ed966570 (diff)
downloadchromium_src-0d797bcaede9cad87da956ca26e8a0159a71732a.zip
chromium_src-0d797bcaede9cad87da956ca26e8a0159a71732a.tar.gz
chromium_src-0d797bcaede9cad87da956ca26e8a0159a71732a.tar.bz2
Allow customization of menu items in WebView
This CL takes the flags from WebSettings and enforces them when an action mode is created. BUG=546762 Review URL: https://codereview.chromium.org/1418113005 Cr-Commit-Position: refs/heads/master@{#356655}
-rw-r--r--android_webview/apk/java/proguard.flags6
-rw-r--r--android_webview/glue/java/src/com/android/webview/chromium/ContentSettingsAdapter.java8
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java5
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java4
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwSettings.java18
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java11
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java29
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/WebActionModeCallback.java35
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/input/FloatingPastePopupMenu.java9
9 files changed, 97 insertions, 28 deletions
diff --git a/android_webview/apk/java/proguard.flags b/android_webview/apk/java/proguard.flags
index 43eb85b..4e571c4 100644
--- a/android_webview/apk/java/proguard.flags
+++ b/android_webview/apk/java/proguard.flags
@@ -85,6 +85,12 @@
public void onActivityResult(int,int,android.content.Intent);
}
+#TODO(hush): remove after N release. crbug.com/546762
+-keep class com.android.webview.chromium.ContentSettingsAdapter {
+ public void setDisabledActionModeMenuItems(int);
+ public int getDisabledActionModeMenuItems();
+}
+
# Ignore notes and warnings about the support library, which uses reflection and
# may reference classes no longer in the SDK.
-dontnote android.support.**
diff --git a/android_webview/glue/java/src/com/android/webview/chromium/ContentSettingsAdapter.java b/android_webview/glue/java/src/com/android/webview/chromium/ContentSettingsAdapter.java
index 4032667..95d316f 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/ContentSettingsAdapter.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/ContentSettingsAdapter.java
@@ -543,6 +543,14 @@ public class ContentSettingsAdapter extends android.webkit.WebSettings {
return mAwSettings.getOffscreenPreRaster();
}
+ public void setDisabledActionModeMenuItems(int menuItems) {
+ mAwSettings.setDisabledActionModeMenuItems(menuItems);
+ }
+
+ public int getDisabledActionModeMenuItems() {
+ return mAwSettings.getDisabledActionModeMenuItems();
+ }
+
@Override
public void setVideoOverlayForEmbeddedEncryptedVideoEnabled(boolean flag) {
mAwSettings.setVideoOverlayForEmbeddedVideoEnabled(flag);
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
index cf39c5b..935f3e4 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
@@ -114,6 +114,11 @@ public class AwContentViewClient extends ContentViewClient implements ContentVid
mAwContents.startProcessTextIntent(intent);
}
+ @Override
+ public boolean isSelectActionModeAllowed(int actionModeItem) {
+ return mAwContents.isSelectActionModeAllowed(actionModeItem);
+ }
+
/**
* Called to show the web contents in fullscreen mode.
*
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 6f3b8d0..42f9a50 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -2204,6 +2204,10 @@ public class AwContents implements SmartClipProvider,
mWebContents.requestAccessibilitySnapshot(callback, 0, 0);
}
+ public boolean isSelectActionModeAllowed(int actionModeItem) {
+ return (mSettings.getDisabledActionModeMenuItems() & actionModeItem) != actionModeItem;
+ }
+
//--------------------------------------------------------------------------------------------
// View and ViewGroup method implementations
//--------------------------------------------------------------------------------------------
diff --git a/android_webview/java/src/org/chromium/android_webview/AwSettings.java b/android_webview/java/src/org/chromium/android_webview/AwSettings.java
index c9c5686..8a363dd 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwSettings.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwSettings.java
@@ -34,6 +34,9 @@ public class AwSettings {
private static final String LOGTAG = AwSettings.class.getSimpleName();
private static final boolean TRACE = false;
+ // TODO(hush): Use android.webkit.WebSettings.MENU_ITEM_*. crbug.com/546762.
+ private static final int MENU_ITEM_NONE = 0;
+
private static final String TAG = "AwSettings";
// This class must be created on the UI thread. Afterwards, it can be
@@ -87,6 +90,7 @@ public class AwSettings {
private boolean mVideoOverlayForEmbeddedVideoEnabled = false;
private boolean mForceVideoOverlayForTests = false;
private boolean mOffscreenPreRaster = false;
+ private int mDisabledMenuItems = MENU_ITEM_NONE;
// Although this bit is stored on AwSettings it is actually controlled via the CookieManager.
private boolean mAcceptThirdPartyCookies = false;
@@ -1660,6 +1664,20 @@ public class AwSettings {
}
}
+ public int getDisabledActionModeMenuItems() {
+ synchronized (mAwSettingsLock) {
+ return mDisabledMenuItems;
+ }
+ }
+
+ public void setDisabledActionModeMenuItems(int menuItems) {
+ synchronized (mAwSettingsLock) {
+ if (menuItems != mDisabledMenuItems) {
+ mDisabledMenuItems = menuItems;
+ }
+ }
+ }
+
/**
* Sets whether to use the video overlay for the embedded video.
* @param flag whether to enable the video overlay for the embedded video.
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java
index a95acdd..885bc23 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java
@@ -122,6 +122,17 @@ public class ContentViewClient {
public void startProcessTextIntent(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) {
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 98a5479..276c7a8 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -2167,15 +2167,33 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
}
@Override
- public boolean isShareAvailable() {
+ public boolean isIncognito() {
+ return mWebContents.isIncognito();
+ }
+
+ @Override
+ public boolean isSelectActionModeAllowed(int actionModeItem) {
+ boolean isAllowedByClient =
+ getContentViewClient().isSelectActionModeAllowed(actionModeItem);
+ if (actionModeItem == WebActionModeCallback.MENU_ITEM_SHARE) {
+ return isAllowedByClient && isShareAvailable();
+ }
+
+ if (actionModeItem == WebActionModeCallback.MENU_ITEM_WEB_SEARCH) {
+ return isAllowedByClient && isWebSearchAvailable();
+ }
+
+ return isAllowedByClient;
+ }
+
+ private boolean isShareAvailable() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
return getContext().getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
- @Override
- public boolean isWebSearchAvailable() {
+ private boolean isWebSearchAvailable() {
if (getContentViewClient().doesPerformWebSearch()) return true;
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.EXTRA_NEW_SEARCH, true);
@@ -2183,11 +2201,6 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
- @Override
- public boolean isIncognito() {
- return mWebContents.isIncognito();
- }
-
private String sanitizeQuery(String query, int maxLength) {
if (TextUtils.isEmpty(query) || query.length() < maxLength) return query;
Log.w(TAG, "Truncating oversized query (" + query.length() + ").");
diff --git a/content/public/android/java/src/org/chromium/content/browser/WebActionModeCallback.java b/content/public/android/java/src/org/chromium/content/browser/WebActionModeCallback.java
index 9477fce..b890790 100644
--- a/content/public/android/java/src/org/chromium/content/browser/WebActionModeCallback.java
+++ b/content/public/android/java/src/org/chromium/content/browser/WebActionModeCallback.java
@@ -86,16 +86,6 @@ public class WebActionModeCallback implements ActionMode.Callback {
void onGetContentRect(Rect outRect);
/**
- * @return Whether or not share is available.
- */
- boolean isShareAvailable();
-
- /**
- * @return Whether or not web search is available.
- */
- boolean isWebSearchAvailable();
-
- /**
* @return true if the current selection is of password type.
*/
boolean isSelectionPassword();
@@ -110,8 +100,23 @@ public class WebActionModeCallback implements ActionMode.Callback {
* Note: This should remain constant for the callback's lifetime.
*/
boolean isIncognito();
+
+ /**
+ * @param actionModeItem the flag for the action mode item in question. The valid flags are
+ * {@link #MENU_ITEM_SHARE}, {@link #MENU_ITEM_WEB_SEARCH}, and
+ * {@link #MENU_ITEM_PROCESS_TEXT}.
+ * @return true if the menu item action is allowed. Otherwise, the menu item
+ * should be removed from the menu.
+ */
+ boolean isSelectActionModeAllowed(int actionModeItem);
}
+ // TODO(hush): Use these constants from android.webkit.WebSettings, when they are made
+ // available. crbug.com/546762.
+ public static final int MENU_ITEM_SHARE = 1 << 0;
+ public static final int MENU_ITEM_WEB_SEARCH = 1 << 1;
+ public static final int MENU_ITEM_PROCESS_TEXT = 1 << 2;
+
protected final ActionHandler mActionHandler;
private final Context mContext;
private boolean mEditable;
@@ -186,11 +191,12 @@ public class WebActionModeCallback implements ActionMode.Callback {
menu.removeItem(R.id.select_action_menu_cut);
}
- if (mEditable || !mActionHandler.isShareAvailable()) {
+ if (mEditable || !mActionHandler.isSelectActionModeAllowed(MENU_ITEM_SHARE)) {
menu.removeItem(R.id.select_action_menu_share);
}
- if (mEditable || mActionHandler.isIncognito() || !mActionHandler.isWebSearchAvailable()) {
+ if (mEditable || mActionHandler.isIncognito()
+ || !mActionHandler.isSelectActionModeAllowed(MENU_ITEM_WEB_SEARCH)) {
menu.removeItem(R.id.select_action_menu_web_search);
}
@@ -267,7 +273,10 @@ public class WebActionModeCallback implements ActionMode.Callback {
* Intialize the menu items for processing text, if there is any.
*/
private void initializeTextProcessingMenu(Menu menu) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
+ || !mActionHandler.isSelectActionModeAllowed(MENU_ITEM_PROCESS_TEXT)) {
+ return;
+ }
PackageManager packageManager = getContext().getPackageManager();
List<ResolveInfo> supportedActivities =
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/FloatingPastePopupMenu.java b/content/public/android/java/src/org/chromium/content/browser/input/FloatingPastePopupMenu.java
index 629773a..7f7723b 100644
--- a/content/public/android/java/src/org/chromium/content/browser/input/FloatingPastePopupMenu.java
+++ b/content/public/android/java/src/org/chromium/content/browser/input/FloatingPastePopupMenu.java
@@ -173,17 +173,12 @@ public class FloatingPastePopupMenu implements PastePopupMenu {
}
@Override
- public boolean isShareAvailable() {
- return false;
- }
-
- @Override
- public boolean isWebSearchAvailable() {
+ public boolean isIncognito() {
return false;
}
@Override
- public boolean isIncognito() {
+ public boolean isSelectActionModeAllowed(int actionModeItem) {
return false;
}
};