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

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

Issue 2945903002: Rendering the image in the sandbox for security (Closed)
Patch Set: Created 3 years, 6 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.ComponentName; 8 import android.content.ComponentName;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.graphics.BitmapFactory;
11 import android.util.Pair; 10 import android.util.Pair;
12 import android.view.ContextMenu; 11 import android.view.ContextMenu;
13 import android.view.ContextMenu.ContextMenuInfo; 12 import android.view.ContextMenu.ContextMenuInfo;
14 import android.view.View; 13 import android.view.View;
15 import android.view.View.OnCreateContextMenuListener; 14 import android.view.View.OnCreateContextMenuListener;
16 15
17 import org.chromium.base.Callback; 16 import org.chromium.base.Callback;
18 import org.chromium.base.ThreadUtils; 17 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.VisibleForTesting; 18 import org.chromium.base.VisibleForTesting;
20 import org.chromium.base.annotations.CalledByNative; 19 import org.chromium.base.annotations.CalledByNative;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 public void onResult(byte[] result) { 190 public void onResult(byte[] result) {
192 WebContents webContents = nativeGetJavaWebContents(mNativeContex tMenuHelper); 191 WebContents webContents = nativeGetJavaWebContents(mNativeContex tMenuHelper);
193 WindowAndroid windowAndroid = webContents.getTopLevelNativeWindo w(); 192 WindowAndroid windowAndroid = webContents.getTopLevelNativeWindo w();
194 193
195 Activity activity = windowAndroid.getActivity().get(); 194 Activity activity = windowAndroid.getActivity().get();
196 if (activity == null) return; 195 if (activity == null) return;
197 196
198 ShareHelper.shareImage(activity, result, name); 197 ShareHelper.shareImage(activity, result, name);
199 } 198 }
200 }; 199 };
201 nativeRetrieveImage(mNativeContextMenuHelper, callback, MAX_SHARE_DIMEN_ PX); 200 nativeRetrieveImageForShare(mNativeContextMenuHelper, callback, MAX_SHAR E_DIMEN_PX);
202 } 201 }
203 202
204 /** 203 /**
205 * Gets the thumbnail of the current image that triggered the context menu. 204 * Gets the thumbnail of the current image that triggered the context menu.
206 * @param callback Called once the the thumbnail is received. 205 * @param callback Called once the the thumbnail is received.
207 */ 206 */
208 private void getThumbnail(final Callback<Bitmap> callback) { 207 private void getThumbnail(final Callback<Bitmap> callback) {
209 if (mNativeContextMenuHelper == 0) return; 208 if (mNativeContextMenuHelper == 0) return;
210 int maxSizePx = mActivity.getResources().getDimensionPixelSize( 209 int maxSizePx = mActivity.getResources().getDimensionPixelSize(
211 R.dimen.context_menu_header_image_max_size); 210 R.dimen.context_menu_header_image_max_size);
212 Callback<byte[]> rawDataCallback = new Callback<byte[]>() { 211 Callback<Bitmap> rawDataCallback = new Callback<Bitmap>() {
Ted C 2017/06/21 00:18:02 let's rename rawData to bitmapCallback
Daniel Park 2017/06/22 00:54:09 Done.
213 @Override 212 @Override
214 public void onResult(byte[] result) { 213 public void onResult(Bitmap result) {
215 // TODO(tedchoc): Decode in separate process before launch. 214 callback.onResult(result);
216 Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result. length);
217 callback.onResult(bitmap);
218 } 215 }
219 }; 216 };
220 nativeRetrieveImage(mNativeContextMenuHelper, rawDataCallback, maxSizePx ); 217 nativeRetrieveImageForContextMenu(mNativeContextMenuHelper, rawDataCallb ack, maxSizePx);
221 } 218 }
222 219
223 @Override 220 @Override
224 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo me nuInfo) { 221 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo me nuInfo) {
225 List<Pair<Integer, List<ContextMenuItem>>> items = 222 List<Pair<Integer, List<ContextMenuItem>>> items =
226 mPopulator.buildContextMenu(menu, v.getContext(), mCurrentContex tMenuParams); 223 mPopulator.buildContextMenu(menu, v.getContext(), mCurrentContex tMenuParams);
227 if (items.isEmpty()) { 224 if (items.isEmpty()) {
228 ThreadUtils.postOnUiThread(mOnMenuClosed); 225 ThreadUtils.postOnUiThread(mOnMenuClosed);
229 return; 226 return;
230 } 227 }
231 ContextMenuUi menuUi = new PlatformContextMenuUi(menu); 228 ContextMenuUi menuUi = new PlatformContextMenuUi(menu);
232 menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallbac k, mOnMenuShown, 229 menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallbac k, mOnMenuShown,
233 mOnMenuClosed); 230 mOnMenuClosed);
234 } 231 }
235 232
236 /** 233 /**
237 * @return The {@link ContextMenuPopulator} responsible for populating the c ontext menu. 234 * @return The {@link ContextMenuPopulator} responsible for populating the c ontext menu.
238 */ 235 */
239 @VisibleForTesting 236 @VisibleForTesting
240 public ContextMenuPopulator getPopulator() { 237 public ContextMenuPopulator getPopulator() {
241 return mPopulator; 238 return mPopulator;
242 } 239 }
243 240
244 private native WebContents nativeGetJavaWebContents(long nativeContextMenuHe lper); 241 private native WebContents nativeGetJavaWebContents(long nativeContextMenuHe lper);
245 private native void nativeOnStartDownload( 242 private native void nativeOnStartDownload(
246 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio nProxyEnabled); 243 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio nProxyEnabled);
247 private native void nativeSearchForImage(long nativeContextMenuHelper); 244 private native void nativeSearchForImage(long nativeContextMenuHelper);
248 private native void nativeRetrieveImage( 245 private native void nativeRetrieveImageForShare(
249 long nativeContextMenuHelper, Callback<byte[]> callback, int maxSize Px); 246 long nativeContextMenuHelper, Callback<byte[]> callback, int maxSize Px);
247 private native void nativeRetrieveImageForContextMenu(
248 long nativeContextMenuHelper, Callback<Bitmap> callback, int maxSize Px);
250 private native void nativeOnContextMenuClosed(long nativeContextMenuHelper); 249 private native void nativeOnContextMenuClosed(long nativeContextMenuHelper);
251 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698