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 dbb62b1694e5b2f51452d42dbae5dffa2134433f..710c20a6629462633ef7e58156b86b2c515c9772 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 |
| @@ -6,6 +6,8 @@ package org.chromium.chrome.browser.contextmenu; |
| import android.app.Activity; |
| import android.content.Context; |
| +import android.graphics.Bitmap; |
| +import android.graphics.BitmapFactory; |
| import android.util.Pair; |
| import android.view.ContextMenu; |
| import android.view.ContextMenu.ContextMenuInfo; |
| @@ -16,6 +18,7 @@ import org.chromium.base.Callback; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.metrics.RecordHistogram; |
| +import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.ChromeFeatureList; |
| import org.chromium.chrome.browser.share.ShareHelper; |
| import org.chromium.content.browser.ContentViewCore; |
| @@ -37,6 +40,10 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { |
| private Callback<Integer> mCallback; |
| private Runnable mOnMenuShown; |
| private Runnable mOnMenuClosed; |
| + private Callback<Bitmap> mOnThumbnailReceivedCallback; |
| + |
| + @VisibleForTesting |
| + ContextMenuHelper() {} |
|
Ted C
2017/03/31 18:48:32
is this still needed?
JJ
2017/03/31 19:01:19
Sorry, deleted in another branch.
|
| private ContextMenuHelper(long nativeContextMenuHelper) { |
| mNativeContextMenuHelper = nativeContextMenuHelper; |
| @@ -108,9 +115,17 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { |
| List<Pair<Integer, List<ContextMenuItem>>> items = |
| mPopulator.buildContextMenu(null, mContext, mCurrentContextMenuParams); |
| - ContextMenuUi menuUi = new TabularContextMenuUi(); |
| + final ContextMenuUi menuUi = new TabularContextMenuUi(); |
| menuUi.displayMenu(mContext, mCurrentContextMenuParams, items, mCallback, mOnMenuShown, |
| mOnMenuClosed); |
| + if (mCurrentContextMenuParams.isImage()) { |
| + getThumbnail(new Callback<Bitmap>() { |
| + @Override |
| + public void onResult(Bitmap result) { |
| + ((TabularContextMenuUi) menuUi).onImageThumbnailRetrieved(result); |
| + } |
| + }); |
| + } |
| return; |
| } |
| @@ -164,6 +179,27 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { |
| ShareHelper.shareImage(activity, jpegImageData); |
| } |
| + /** |
| + * Gets the thumbnail of the current image that triggered the context menu. |
| + * @param callback Called once the the thumbnail is received. |
| + */ |
| + public void getThumbnail(Callback<Bitmap> callback) { |
| + mOnThumbnailReceivedCallback = callback; |
| + if (mNativeContextMenuHelper == 0) return; |
| + int maxSizePx = mContext.getResources().getDimensionPixelSize( |
| + R.dimen.context_menu_header_image_max_size); |
| + nativeRetrieveHeaderThumbnail(mNativeContextMenuHelper, maxSizePx); |
| + } |
| + |
| + @CalledByNative |
| + private void onHeaderThumbnailReceived(WindowAndroid windowAndroid, byte[] jpegImageData) { |
| + Bitmap bitmap = BitmapFactory.decodeByteArray(jpegImageData, 0, jpegImageData.length); |
| + // TODO(tedchoc): Decode in separate process before launch. |
|
Ted C
2017/03/31 18:48:31
nit, should go above previous line
JJ
2017/03/31 19:01:19
Done.
|
| + if (mOnThumbnailReceivedCallback != null) { |
| + mOnThumbnailReceivedCallback.onResult(bitmap); |
| + } |
| + } |
| + |
| @Override |
| public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| List<Pair<Integer, List<ContextMenuItem>>> items = |
| @@ -186,4 +222,5 @@ public class ContextMenuHelper implements OnCreateContextMenuListener { |
| private native void nativeSearchForImage(long nativeContextMenuHelper); |
| private native void nativeShareImage(long nativeContextMenuHelper); |
| private native void nativeOnContextMenuClosed(long nativeContextMenuHelper); |
| + private native void nativeRetrieveHeaderThumbnail(long nativeContextMenuHelper, int maxSizePx); |
| } |