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); |
} |