 Chromium Code Reviews
 Chromium Code Reviews Issue 2775373002:
  Add a Share Icon to Tabular Context Menu  (Closed)
    
  
    Issue 2775373002:
  Add a Share Icon to Tabular Context Menu  (Closed) 
  | Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java | 
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java | 
| index 19430cd48b29ff73166b410ec42353f4651c4902..241ec0d4541feeb38bebc4d9b88c636303eb35e3 100644 | 
| --- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java | 
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java | 
| @@ -5,7 +5,7 @@ | 
| package org.chromium.chrome.browser.contextmenu; | 
| import android.app.Activity; | 
| -import android.content.Context; | 
| +import android.content.ComponentName; | 
| import android.graphics.Bitmap; | 
| import android.graphics.BitmapFactory; | 
| import android.util.Pair; | 
| @@ -35,11 +35,12 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { | 
| private ContextMenuPopulator mPopulator; | 
| private ContextMenuParams mCurrentContextMenuParams; | 
| - private Context mContext; | 
| + private Activity mActivity; | 
| private Callback<Integer> mCallback; | 
| private Runnable mOnMenuShown; | 
| private Runnable mOnMenuClosed; | 
| private OnThumbnailReceivedListener mOnThumbnailReceivedListener; | 
| + private ComponentName mComponentName; | 
| /** | 
| * This waits for a thumbnail to be retrieved by the native code. | 
| @@ -93,13 +94,13 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { | 
| final WindowAndroid windowAndroid = contentViewCore.getWindowAndroid(); | 
| if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null | 
| - || windowAndroid == null || windowAndroid.getContext().get() == null | 
| + || windowAndroid == null || windowAndroid.getActivity().get() == null | 
| || mPopulator == null) { | 
| return; | 
| } | 
| mCurrentContextMenuParams = params; | 
| - mContext = windowAndroid.getContext().get(); | 
| + mActivity = windowAndroid.getActivity().get(); | 
| mCallback = new Callback<Integer>() { | 
| @Override | 
| public void onResult(Integer result) { | 
| @@ -124,10 +125,10 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { | 
| if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) { | 
| List<Pair<Integer, List<ContextMenuItem>>> items = | 
| - mPopulator.buildContextMenu(null, mContext, mCurrentContextMenuParams); | 
| + mPopulator.buildContextMenu(null, mActivity, mCurrentContextMenuParams); | 
| ContextMenuUi menuUi = new TabularContextMenuUi(this); | 
| - menuUi.displayMenu(mContext, mCurrentContextMenuParams, items, mCallback, mOnMenuShown, | 
| + menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallback, mOnMenuShown, | 
| mOnMenuClosed); | 
| return; | 
| } | 
| @@ -179,7 +180,19 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { | 
| Activity activity = windowAndroid.getActivity().get(); | 
| if (activity == null) return; | 
| - ShareHelper.shareImage(activity, jpegImageData); | 
| + ShareHelper.shareImage(activity, jpegImageData, mComponentName); | 
| + // This needs to be reset to null after a share. This way the next time a user shares an | 
| + // image it won't share with the last shared app unless explicitly told. | 
| + mComponentName = null; | 
| + } | 
| + | 
| + /** | 
| + * Share image triggered with the current context menu directly with a specific app. | 
| + * @param name The {@link ComponentName} of the app to share the image directly with. | 
| + */ | 
| + public void shareImageDirectly(ComponentName name) { | 
| + mComponentName = name; | 
| 
David Trainor- moved to gerrit
2017/03/30 23:50:22
This would be cleaner if we used final and magical
 
JJ
2017/03/31 20:58:54
Acknowledged.
 | 
| + shareImage(); | 
| } | 
| /** | 
| @@ -205,8 +218,8 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { | 
| List<Pair<Integer, List<ContextMenuItem>>> items = | 
| mPopulator.buildContextMenu(menu, v.getContext(), mCurrentContextMenuParams); | 
| ContextMenuUi menuUi = new PlatformContextMenuUi(menu); | 
| - menuUi.displayMenu( | 
| - mContext, mCurrentContextMenuParams, items, mCallback, mOnMenuShown, mOnMenuClosed); | 
| + menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallback, mOnMenuShown, | 
| + mOnMenuClosed); | 
| } | 
| /** |