Chromium Code Reviews| 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 7410ca676f3726ecef35c6de8edcbbe2e5ccd691..544b20e79333b00c46202f282ff67c8a0600df4c 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; |
|
Theresa
2017/03/30 15:12:45
Typically we recommend against caching the activit
JJ
2017/03/30 16:20:17
It works!
|
| 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 item unless explicitly told. |
|
Theresa
2017/03/30 15:12:45
nit: ...won't share with the last shared app...?
JJ
2017/03/30 16:20:17
Done.
|
| + mComponentName = null; |
| + } |
| + |
| + /** |
| + * Share image triggered with the current context menu directly with a specific app. |
| + * @param name The app to share the image directly with. |
|
Theresa
2017/03/30 15:12:45
nit: The {@link ComponentName} of the app to share
JJ
2017/03/30 16:20:17
Done.
|
| + */ |
| + public void shareImageDirectly(ComponentName name) { |
| + mComponentName = name; |
| + shareImage(); |
| } |
| /** |
| @@ -203,8 +216,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); |
| } |
| /** |