Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java

Issue 2777773002: Show the image header for the Context Menu (Closed)
Patch Set: Fixed based off dtrainor's comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.contextmenu; 5 package org.chromium.chrome.browser.contextmenu;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.Context; 8 import android.content.Context;
9 import android.graphics.Bitmap;
10 import android.graphics.BitmapFactory;
9 import android.util.Pair; 11 import android.util.Pair;
10 import android.view.ContextMenu; 12 import android.view.ContextMenu;
11 import android.view.ContextMenu.ContextMenuInfo; 13 import android.view.ContextMenu.ContextMenuInfo;
12 import android.view.View; 14 import android.view.View;
13 import android.view.View.OnCreateContextMenuListener; 15 import android.view.View.OnCreateContextMenuListener;
14 16
15 import org.chromium.base.Callback; 17 import org.chromium.base.Callback;
16 import org.chromium.base.VisibleForTesting; 18 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.annotations.CalledByNative; 19 import org.chromium.base.annotations.CalledByNative;
18 import org.chromium.base.metrics.RecordHistogram; 20 import org.chromium.base.metrics.RecordHistogram;
21 import org.chromium.chrome.R;
19 import org.chromium.chrome.browser.ChromeFeatureList; 22 import org.chromium.chrome.browser.ChromeFeatureList;
20 import org.chromium.chrome.browser.share.ShareHelper; 23 import org.chromium.chrome.browser.share.ShareHelper;
21 import org.chromium.content.browser.ContentViewCore; 24 import org.chromium.content.browser.ContentViewCore;
22 import org.chromium.content_public.browser.WebContents; 25 import org.chromium.content_public.browser.WebContents;
23 import org.chromium.ui.base.WindowAndroid; 26 import org.chromium.ui.base.WindowAndroid;
24 import org.chromium.ui.base.WindowAndroid.OnCloseContextMenuListener; 27 import org.chromium.ui.base.WindowAndroid.OnCloseContextMenuListener;
25 28
26 import java.util.List; 29 import java.util.List;
27 30
28 /** 31 /**
29 * A helper class that handles generating context menus for {@link ContentViewCo re}s. 32 * A helper class that handles generating context menus for {@link ContentViewCo re}s.
30 */ 33 */
31 public class ContextMenuHelper implements OnCreateContextMenuListener { 34 public class ContextMenuHelper implements OnCreateContextMenuListener {
32 private long mNativeContextMenuHelper; 35 private long mNativeContextMenuHelper;
33 36
34 private ContextMenuPopulator mPopulator; 37 private ContextMenuPopulator mPopulator;
35 private ContextMenuParams mCurrentContextMenuParams; 38 private ContextMenuParams mCurrentContextMenuParams;
36 private Context mContext; 39 private Context mContext;
37 private Callback<Integer> mCallback; 40 private Callback<Integer> mCallback;
38 private Runnable mOnMenuShown; 41 private Runnable mOnMenuShown;
39 private Runnable mOnMenuClosed; 42 private Runnable mOnMenuClosed;
43 private OnThumbnailReceivedListener mOnThumbnailReceivedListener;
44
45 /**
46 * This waits for a thumbnail to be retrieved by the native code.
47 */
48 interface OnThumbnailReceivedListener {
Ted C 2017/03/31 16:19:32 FWIW, you can just use Callback.java from base/ to
JJ 2017/03/31 18:43:59 Done.
49 /**
50 * When the thumbnail is received it will send the thumbnail via this me thod. This is
51 * activated after calling {@link #getThumbnail(OnThumbnailReceivedListe ner)}.
52 * @param bitmap The bitmap that is retrieved from native code.
53 */
54 void onThumbnailReceived(Bitmap bitmap);
55 }
56
57 @VisibleForTesting
58 ContextMenuHelper() {}
40 59
41 private ContextMenuHelper(long nativeContextMenuHelper) { 60 private ContextMenuHelper(long nativeContextMenuHelper) {
42 mNativeContextMenuHelper = nativeContextMenuHelper; 61 mNativeContextMenuHelper = nativeContextMenuHelper;
43 } 62 }
44 63
45 @CalledByNative 64 @CalledByNative
46 private static ContextMenuHelper create(long nativeContextMenuHelper) { 65 private static ContextMenuHelper create(long nativeContextMenuHelper) {
47 return new ContextMenuHelper(nativeContextMenuHelper); 66 return new ContextMenuHelper(nativeContextMenuHelper);
48 } 67 }
49 68
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 public void run() { 120 public void run() {
102 if (mNativeContextMenuHelper == 0) return; 121 if (mNativeContextMenuHelper == 0) return;
103 nativeOnContextMenuClosed(mNativeContextMenuHelper); 122 nativeOnContextMenuClosed(mNativeContextMenuHelper);
104 } 123 }
105 }; 124 };
106 125
107 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) { 126 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) {
108 List<Pair<Integer, List<ContextMenuItem>>> items = 127 List<Pair<Integer, List<ContextMenuItem>>> items =
109 mPopulator.buildContextMenu(null, mContext, mCurrentContextM enuParams); 128 mPopulator.buildContextMenu(null, mContext, mCurrentContextM enuParams);
110 129
111 ContextMenuUi menuUi = new TabularContextMenuUi(); 130 ContextMenuUi menuUi = new TabularContextMenuUi(this);
112 menuUi.displayMenu(mContext, mCurrentContextMenuParams, items, mCall back, mOnMenuShown, 131 menuUi.displayMenu(mContext, mCurrentContextMenuParams, items, mCall back, mOnMenuShown,
113 mOnMenuClosed); 132 mOnMenuClosed);
Ted C 2017/03/31 16:19:33 from my comment in the other file, I think we shou
JJ 2017/03/31 18:43:59 Done.
114 return; 133 return;
115 } 134 }
116 135
117 // The Platform Context Menu requires the listener within this hepler si nce this helper and 136 // The Platform Context Menu requires the listener within this hepler si nce this helper and
118 // provides context menu for us to show. 137 // provides context menu for us to show.
119 view.setOnCreateContextMenuListener(this); 138 view.setOnCreateContextMenuListener(this);
120 if (view.showContextMenu()) { 139 if (view.showContextMenu()) {
121 mOnMenuShown.run(); 140 mOnMenuShown.run();
122 windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuList ener() { 141 windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuList ener() {
123 @Override 142 @Override
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 176
158 @CalledByNative 177 @CalledByNative
159 private void onShareImageReceived( 178 private void onShareImageReceived(
160 WindowAndroid windowAndroid, byte[] jpegImageData) { 179 WindowAndroid windowAndroid, byte[] jpegImageData) {
161 Activity activity = windowAndroid.getActivity().get(); 180 Activity activity = windowAndroid.getActivity().get();
162 if (activity == null) return; 181 if (activity == null) return;
163 182
164 ShareHelper.shareImage(activity, jpegImageData); 183 ShareHelper.shareImage(activity, jpegImageData);
165 } 184 }
166 185
186 /**
187 * Gets the thumbnail of the current image that triggered the context menu.
188 * @param listener Called once the the thumbnail is received
189 */
190 public void getThumbnail(final OnThumbnailReceivedListener listener) {
191 mOnThumbnailReceivedListener = listener;
192 if (mNativeContextMenuHelper == 0) return;
193 int maxSizePx = mContext.getResources().getDimensionPixelSize(
194 R.dimen.context_menu_header_image_max_size);
195 nativeRetrieveHeaderThumbnail(mNativeContextMenuHelper, maxSizePx);
196 }
197
198 @CalledByNative
199 private void onHeaderThumbnailReceived(WindowAndroid windowAndroid, byte[] j pegImageData) {
200 Bitmap bitmap = BitmapFactory.decodeByteArray(jpegImageData, 0, jpegImag eData.length);
Ted C 2017/03/31 16:19:33 Can you add another: // TODO(tedchoc): Decode in
JJ 2017/03/31 18:43:59 Done.
201 if (mOnThumbnailReceivedListener != null) {
202 mOnThumbnailReceivedListener.onThumbnailReceived(bitmap);
203 }
204 }
205
167 @Override 206 @Override
168 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo me nuInfo) { 207 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo me nuInfo) {
169 List<Pair<Integer, List<ContextMenuItem>>> items = 208 List<Pair<Integer, List<ContextMenuItem>>> items =
170 mPopulator.buildContextMenu(menu, v.getContext(), mCurrentContex tMenuParams); 209 mPopulator.buildContextMenu(menu, v.getContext(), mCurrentContex tMenuParams);
171 ContextMenuUi menuUi = new PlatformContextMenuUi(menu); 210 ContextMenuUi menuUi = new PlatformContextMenuUi(menu);
172 menuUi.displayMenu( 211 menuUi.displayMenu(
173 mContext, mCurrentContextMenuParams, items, mCallback, mOnMenuSh own, mOnMenuClosed); 212 mContext, mCurrentContextMenuParams, items, mCallback, mOnMenuSh own, mOnMenuClosed);
174 } 213 }
175 214
176 /** 215 /**
177 * @return The {@link ContextMenuPopulator} responsible for populating the c ontext menu. 216 * @return The {@link ContextMenuPopulator} responsible for populating the c ontext menu.
178 */ 217 */
179 @VisibleForTesting 218 @VisibleForTesting
180 public ContextMenuPopulator getPopulator() { 219 public ContextMenuPopulator getPopulator() {
181 return mPopulator; 220 return mPopulator;
182 } 221 }
183 222
184 private native void nativeOnStartDownload( 223 private native void nativeOnStartDownload(
185 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio nProxyEnabled); 224 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio nProxyEnabled);
186 private native void nativeSearchForImage(long nativeContextMenuHelper); 225 private native void nativeSearchForImage(long nativeContextMenuHelper);
187 private native void nativeShareImage(long nativeContextMenuHelper); 226 private native void nativeShareImage(long nativeContextMenuHelper);
188 private native void nativeOnContextMenuClosed(long nativeContextMenuHelper); 227 private native void nativeOnContextMenuClosed(long nativeContextMenuHelper);
228 private native void nativeRetrieveHeaderThumbnail(long nativeContextMenuHelp er, int maxSizePx);
189 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698