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 f80940926ffa39ff634c7ae5ce73d89f7bce5ead..b7490996d55c4529d46cb1f1331f4a0d656613b6 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java |
@@ -7,10 +7,16 @@ package org.chromium.chrome.browser; |
import android.app.Activity; |
import android.content.Context; |
import android.graphics.Color; |
+import android.view.ContextMenu; |
import android.view.View; |
import org.chromium.base.CalledByNative; |
import org.chromium.base.ObserverList; |
+import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; |
+import org.chromium.chrome.browser.contextmenu.ContextMenuParams; |
+import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; |
+import org.chromium.chrome.browser.contextmenu.ContextMenuPopulatorWrapper; |
+import org.chromium.chrome.browser.contextmenu.EmptyChromeContextMenuItemDelegate; |
import org.chromium.chrome.browser.infobar.AutoLoginProcessor; |
import org.chromium.chrome.browser.infobar.InfoBarContainer; |
import org.chromium.chrome.browser.profiles.Profile; |
@@ -22,6 +28,7 @@ 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.base.Clipboard; |
import org.chromium.ui.base.WindowAndroid; |
import java.util.concurrent.atomic.AtomicInteger; |
@@ -93,6 +100,37 @@ 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); |
+ } |
+ } |
+ |
+ /** |
* A basic {@link ChromeWebContentsDelegateAndroid} that forwards some calls to the registered |
* {@link TabObserver}s. Meant to be overridden by subclasses. |
*/ |
@@ -136,6 +174,18 @@ public abstract class TabBase implements NavigationClient { |
} |
} |
+ private class TabBaseContextMenuPopulator extends ContextMenuPopulatorWrapper { |
+ public TabBaseContextMenuPopulator(ContextMenuPopulator populator) { |
+ super(populator); |
+ } |
+ |
+ @Override |
+ public void buildContextMenu(ContextMenu menu, Context context, ContextMenuParams params) { |
+ super.buildContextMenu(menu, context, params); |
+ for (TabObserver observer : mObservers) observer.onContextMenuShown(TabBase.this, menu); |
+ } |
+ } |
+ |
private class TabBaseWebContentsObserverAndroid extends WebContentsObserverAndroid { |
public TabBaseWebContentsObserverAndroid(ContentViewCore contentViewCore) { |
super(contentViewCore); |
@@ -470,7 +520,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(); |
@@ -566,7 +617,8 @@ public abstract class TabBase implements NavigationClient { |
assert mNativeTabAndroid != 0; |
nativeInitWebContents( |
- mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDelegate); |
+ mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDelegate, |
+ new TabBaseContextMenuPopulator(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. |
@@ -672,6 +724,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() { |
@@ -775,7 +835,8 @@ public abstract class TabBase implements NavigationClient { |
} |
private native void nativeInitWebContents(long nativeTabAndroid, boolean incognito, |
- ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid delegate); |
+ ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid delegate, |
+ ContextMenuPopulator contextMenuPopulator); |
private native void nativeDestroyWebContents(long nativeTabAndroid, boolean deleteNative); |
private native Profile nativeGetProfileAndroid(long nativeTabAndroid); |
private native int nativeGetSecurityLevel(long nativeTabAndroid); |