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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/TabBase.java

Issue 73173002: Add ContextMenu support upstream for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bug in clipboard Created 7 years, 1 month 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: chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java b/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
index a881e84b962a09b9f7f0640b34a0c2b4ca7d97f9..930743b57fe1e34a44666ec4a9c84b2e1b3e0cae 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
@@ -11,6 +11,9 @@ import android.view.View;
import org.chromium.base.CalledByNative;
import org.chromium.base.ObserverList;
+import org.chromium.chrome.browser.context_menu.ChromeContextMenuPopulator;
+import org.chromium.chrome.browser.context_menu.ContextMenuPopulator;
+import org.chromium.chrome.browser.context_menu.EmptyChromeContextMenuItemDelegate;
import org.chromium.chrome.browser.infobar.AutoLoginProcessor;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.profiles.Profile;
@@ -22,9 +25,9 @@ import org.chromium.content.browser.NavigationClient;
import org.chromium.content.browser.NavigationHistory;
import org.chromium.content.browser.PageInfo;
import org.chromium.content.browser.WebContentsObserverAndroid;
+import org.chromium.ui.Clipboard;
import org.chromium.ui.WindowAndroid;
-import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -94,6 +97,44 @@ public abstract class TabBase implements NavigationClient {
private TabBaseChromeWebContentsDelegateAndroid mWebContentsDelegate;
/**
+ * A default {@link ChromeContextMenuItemDelegate} that supports some of the context menu
+ * functionality.
+ */
+ protected class TabBaseChromeContextMenuItemDelegate
+ extends EmptyChromeContextMenuItemDelegate {
+ private final Clipboard mClipboard;
+
+ /**
+ * Builds a {@link TabBaseChromeContextMenuItemDelegate} instance.
+ */
+ public TabBaseChromeContextMenuItemDelegate() {
+ mClipboard = new Clipboard(getApplicationContext());
+ }
+
+ @Override
+ public boolean isIncognito() {
+ return mIncognito;
+ }
+
+ @Override
+ public void onSaveToClipboard(String text, boolean isUrl) {
+ mClipboard.setText(text, text);
+ }
+
+ @Override
+ public void onSaveImageToClipboard(String url) {
+ mClipboard.setHTMLText("<img src=\"" + url + "\">", url, url);
+ }
+
+ @Override
+ public void onStartDownload(String url, boolean isLink) {
+ if (mNativeTabAndroid == 0) return;
+
+ nativeOnContextMenuDownload(mNativeTabAndroid, url, isLink);
+ }
+ }
+
+ /**
* A basic {@link ChromeWebContentsDelegateAndroid} that forwards some calls to the registered
* {@link TabObserver}s. Meant to be overridden by subclasses.
*/
@@ -462,7 +503,8 @@ public abstract class TabBase implements NavigationClient {
/**
* @return An {@link ObserverList.RewindableIterator} instance that points to all of
* the current {@link TabObserver}s on this class. Note that calling
- * {@link Iterator#remove()} will throw an {@link UnsupportedOperationException}.
+ * {@link java.util.Iterator#remove()} will throw an
+ * {@link UnsupportedOperationException}.
*/
protected ObserverList.RewindableIterator<TabObserver> getTabObservers() {
return mObservers.rewindableIterator();
@@ -558,7 +600,8 @@ public abstract class TabBase implements NavigationClient {
assert mNativeTabAndroid != 0;
nativeInitWebContents(
- mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDelegate);
+ mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDelegate,
+ createContextMenuPopulator());
// In the case where restoring a Tab or showing a prerendered one we already have a
// valid infobar container, no need to recreate one.
@@ -664,6 +707,14 @@ public abstract class TabBase implements NavigationClient {
}
/**
+ * A helper method to allow subclasses to build their own menu populator.
+ * @return An instance of a {@link ContextMenuPopulator}.
+ */
+ protected ContextMenuPopulator createContextMenuPopulator() {
+ return new ChromeContextMenuPopulator(new TabBaseChromeContextMenuItemDelegate());
+ }
+
+ /**
* @return The {@link WindowAndroid} associated with this {@link TabBase}.
*/
protected WindowAndroid getWindowAndroid() {
@@ -763,10 +814,14 @@ public abstract class TabBase implements NavigationClient {
}
private native void nativeInitWebContents(int nativeTabAndroid, boolean incognito,
- ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid delegate);
+ ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid delegate,
+ ContextMenuPopulator contextMenuPopulator);
private native void nativeDestroyWebContents(int nativeTabAndroid, boolean deleteNative);
private native Profile nativeGetProfileAndroid(int nativeTabAndroid);
private native int nativeGetSecurityLevel(int nativeTabAndroid);
private native void nativeSetActiveNavigationEntryTitleForUrl(int nativeTabAndroid, String url,
String title);
+
Ted C 2013/11/19 02:44:03 there isn't any blank lines between the other nati
David Trainor- moved to gerrit 2013/11/25 19:42:50 Done.
+ private native void nativeOnContextMenuDownload(int nativeTabAndroid, String url,
+ boolean isLink);
}

Powered by Google App Engine
This is Rietveld 408576698