Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 9 import android.graphics.BitmapFactory; | 10 import android.graphics.BitmapFactory; |
| 10 import android.util.Pair; | 11 import android.util.Pair; |
| 11 import android.view.ContextMenu; | 12 import android.view.ContextMenu; |
| 12 import android.view.ContextMenu.ContextMenuInfo; | 13 import android.view.ContextMenu.ContextMenuInfo; |
| 13 import android.view.View; | 14 import android.view.View; |
| 14 import android.view.View.OnCreateContextMenuListener; | 15 import android.view.View.OnCreateContextMenuListener; |
| 15 | 16 |
| 16 import org.chromium.base.Callback; | 17 import org.chromium.base.Callback; |
| 17 import org.chromium.base.VisibleForTesting; | 18 import org.chromium.base.VisibleForTesting; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 32 public class ContextMenuHelper implements OnCreateContextMenuListener { | 33 public class ContextMenuHelper implements OnCreateContextMenuListener { |
| 33 private long mNativeContextMenuHelper; | 34 private long mNativeContextMenuHelper; |
| 34 | 35 |
| 35 private ContextMenuPopulator mPopulator; | 36 private ContextMenuPopulator mPopulator; |
| 36 private ContextMenuParams mCurrentContextMenuParams; | 37 private ContextMenuParams mCurrentContextMenuParams; |
| 37 private Activity mActivity; | 38 private Activity mActivity; |
| 38 private Callback<Integer> mCallback; | 39 private Callback<Integer> mCallback; |
| 39 private Runnable mOnMenuShown; | 40 private Runnable mOnMenuShown; |
| 40 private Runnable mOnMenuClosed; | 41 private Runnable mOnMenuClosed; |
| 41 private OnThumbnailReceivedListener mOnThumbnailReceivedListener; | 42 private OnThumbnailReceivedListener mOnThumbnailReceivedListener; |
| 43 private ComponentName mComponentName; | |
| 42 | 44 |
| 43 interface OnThumbnailReceivedListener { | 45 interface OnThumbnailReceivedListener { |
| 44 void onThumbnailReceived(Bitmap bitmap); | 46 void onThumbnailReceived(Bitmap bitmap); |
| 45 } | 47 } |
| 46 | 48 |
| 47 private ContextMenuHelper(long nativeContextMenuHelper) { | 49 private ContextMenuHelper(long nativeContextMenuHelper) { |
| 48 mNativeContextMenuHelper = nativeContextMenuHelper; | 50 mNativeContextMenuHelper = nativeContextMenuHelper; |
| 49 } | 51 } |
| 50 | 52 |
| 51 @CalledByNative | 53 @CalledByNative |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 if (mNativeContextMenuHelper == 0) return; | 162 if (mNativeContextMenuHelper == 0) return; |
| 161 nativeShareImage(mNativeContextMenuHelper); | 163 nativeShareImage(mNativeContextMenuHelper); |
| 162 } | 164 } |
| 163 | 165 |
| 164 @CalledByNative | 166 @CalledByNative |
| 165 private void onShareImageReceived( | 167 private void onShareImageReceived( |
| 166 WindowAndroid windowAndroid, byte[] jpegImageData) { | 168 WindowAndroid windowAndroid, byte[] jpegImageData) { |
| 167 Activity activity = windowAndroid.getActivity().get(); | 169 Activity activity = windowAndroid.getActivity().get(); |
| 168 if (activity == null) return; | 170 if (activity == null) return; |
| 169 | 171 |
| 170 ShareHelper.shareImage(activity, jpegImageData); | 172 ShareHelper.shareImage(activity, jpegImageData, mComponentName); |
| 173 // This needs to be reset to null after a share. This way the next time a user shares an | |
| 174 // image it won't share with the last shared item unless explicitly told . | |
|
David Trainor- moved to gerrit
2017/03/30 23:50:22
item -> app?
JJ
2017/03/31 20:58:54
Done.
| |
| 175 mComponentName = null; | |
| 171 } | 176 } |
| 172 | 177 |
| 173 /** | 178 /** |
| 179 * Share image triggered with the current context menu directly with a speci fic app. | |
| 180 * @param name The app to share the image directly with. | |
| 181 */ | |
| 182 public void shareImageDirectly(ComponentName name) { | |
| 183 mComponentName = name; | |
| 184 shareImage(); | |
| 185 } | |
| 186 | |
| 187 /** | |
| 174 * This gets the thumbnail of the current image that triggered the context m enu. | 188 * This gets the thumbnail of the current image that triggered the context m enu. |
| 175 */ | 189 */ |
| 176 public void getThumbnail() { | 190 public void getThumbnail() { |
| 177 if (mNativeContextMenuHelper == 0) return; | 191 if (mNativeContextMenuHelper == 0) return; |
| 178 nativeRetrieveHeaderThumbnail(mNativeContextMenuHelper); | 192 nativeRetrieveHeaderThumbnail(mNativeContextMenuHelper); |
| 179 } | 193 } |
| 180 | 194 |
| 181 @CalledByNative | 195 @CalledByNative |
| 182 private void onHeaderThumbnailReceived(WindowAndroid windowAndroid, byte[] j pegImageData) { | 196 private void onHeaderThumbnailReceived(WindowAndroid windowAndroid, byte[] j pegImageData) { |
| 183 Bitmap bitmap = BitmapFactory.decodeByteArray(jpegImageData, 0, jpegImag eData.length); | 197 Bitmap bitmap = BitmapFactory.decodeByteArray(jpegImageData, 0, jpegImag eData.length); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 207 return mPopulator; | 221 return mPopulator; |
| 208 } | 222 } |
| 209 | 223 |
| 210 private native void nativeOnStartDownload( | 224 private native void nativeOnStartDownload( |
| 211 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio nProxyEnabled); | 225 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio nProxyEnabled); |
| 212 private native void nativeSearchForImage(long nativeContextMenuHelper); | 226 private native void nativeSearchForImage(long nativeContextMenuHelper); |
| 213 private native void nativeShareImage(long nativeContextMenuHelper); | 227 private native void nativeShareImage(long nativeContextMenuHelper); |
| 214 private native void nativeOnContextMenuClosed(long nativeContextMenuHelper); | 228 private native void nativeOnContextMenuClosed(long nativeContextMenuHelper); |
| 215 private native void nativeRetrieveHeaderThumbnail(long nativeContextMenuHelp er); | 229 private native void nativeRetrieveHeaderThumbnail(long nativeContextMenuHelp er); |
| 216 } | 230 } |
| OLD | NEW |