[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_ANDROID_CONTEXT_MENU_HELPER_H_ |
| 6 | #define CHROME_BROWSER_UI_ANDROID_CONTEXT_MENU_HELPER_H_ |
| 7 | |
dcheng | 9603ab9 | 2016-04-08 04:17:32 | [diff] [blame] | 8 | #include <memory> |
tedchoc | 23990ba | 2015-10-29 18:48:48 | [diff] [blame] | 9 | #include <string> |
watk | 2c47200 | 2017-03-14 05:52:28 | [diff] [blame] | 10 | #include <vector> |
tedchoc | 23990ba | 2015-10-29 18:48:48 | [diff] [blame] | 11 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 12 | #include "base/android/jni_android.h" |
| 13 | #include "base/callback.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 14 | #include "base/macros.h" |
watk | 2c47200 | 2017-03-14 05:52:28 | [diff] [blame] | 15 | #include "chrome/common/thumbnail_capturer.mojom.h" |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 16 | #include "content/public/browser/web_contents_user_data.h" |
| 17 | #include "content/public/common/context_menu_params.h" |
tedchoc | 23990ba | 2015-10-29 18:48:48 | [diff] [blame] | 18 | #include "ui/gfx/geometry/size.h" |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 19 | |
| 20 | namespace content { |
| 21 | struct ContextMenuParams; |
tedchoc | cd0bf1f | 2015-12-15 21:23:10 | [diff] [blame] | 22 | class RenderFrameHost; |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 23 | class WebContents; |
| 24 | } |
| 25 | |
| 26 | class ContextMenuHelper |
| 27 | : public content::WebContentsUserData<ContextMenuHelper> { |
| 28 | public: |
dcheng | 361fdb3 | 2015-02-04 02:56:07 | [diff] [blame] | 29 | ~ContextMenuHelper() override; |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 30 | |
amaralp | dbb23e2 | 2016-09-26 22:40:11 | [diff] [blame] | 31 | void ShowContextMenu(content::RenderFrameHost* render_frame_host, |
tedchoc | cd0bf1f | 2015-12-15 21:23:10 | [diff] [blame] | 32 | const content::ContextMenuParams& params); |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 33 | |
shaktisahu | 3a2f73d | 2016-12-06 04:34:31 | [diff] [blame] | 34 | void OnContextMenuClosed(JNIEnv* env, |
| 35 | const base::android::JavaParamRef<jobject>& obj); |
| 36 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 37 | void SetPopulator(jobject jpopulator); |
| 38 | |
| 39 | // Methods called from Java via JNI ------------------------------------------ |
torne | ebcfa226 | 2015-11-25 17:47:24 | [diff] [blame] | 40 | void OnStartDownload(JNIEnv* env, |
| 41 | const base::android::JavaParamRef<jobject>& obj, |
| 42 | jboolean jis_link, |
bauerb | f6d2732 | 2016-03-30 17:02:48 | [diff] [blame] | 43 | jboolean jis_data_reduction_proxy_enabled); |
torne | ebcfa226 | 2015-11-25 17:47:24 | [diff] [blame] | 44 | void SearchForImage(JNIEnv* env, |
| 45 | const base::android::JavaParamRef<jobject>& obj); |
| 46 | void ShareImage(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 47 | |
jwanda | 8817202 | 2017-03-31 22:28:34 | [diff] [blame^] | 48 | void RetrieveHeaderThumbnail(JNIEnv* env, |
| 49 | const base::android::JavaParamRef<jobject>& obj, |
| 50 | jint j_max_size_px); |
| 51 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 52 | private: |
| 53 | explicit ContextMenuHelper(content::WebContents* web_contents); |
| 54 | friend class content::WebContentsUserData<ContextMenuHelper>; |
| 55 | |
| 56 | static base::android::ScopedJavaLocalRef<jobject> CreateJavaContextMenuParams( |
| 57 | const content::ContextMenuParams& params); |
| 58 | |
watk | 2c47200 | 2017-03-14 05:52:28 | [diff] [blame] | 59 | void OnShareImage(chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer, |
| 60 | const std::vector<uint8_t>& thumbnail_data, |
tedchoc | 23990ba | 2015-10-29 18:48:48 | [diff] [blame] | 61 | const gfx::Size& original_size); |
| 62 | |
jwanda | 8817202 | 2017-03-31 22:28:34 | [diff] [blame^] | 63 | void OnHeaderThumbnailReceived( |
| 64 | chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer, |
| 65 | const std::vector<uint8_t>& thumbnail_data, |
| 66 | const gfx::Size& original_size); |
| 67 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 68 | base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
| 69 | content::WebContents* web_contents_; |
| 70 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 71 | content::ContextMenuParams context_menu_params_; |
tedchoc | cd0bf1f | 2015-12-15 21:23:10 | [diff] [blame] | 72 | int render_frame_id_; |
| 73 | int render_process_id_; |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 74 | |
watk | 2c47200 | 2017-03-14 05:52:28 | [diff] [blame] | 75 | base::WeakPtrFactory<ContextMenuHelper> weak_factory_; |
| 76 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(ContextMenuHelper); |
| 78 | }; |
| 79 | |
| 80 | bool RegisterContextMenuHelper(JNIEnv* env); |
| 81 | |
| 82 | #endif // CHROME_BROWSER_UI_ANDROID_CONTEXT_MENU_HELPER_H_ |