[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" |
tedchoc | 69a502c | 2017-04-07 18:11:36 | [diff] [blame] | 13 | #include "base/android/scoped_java_ref.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 14 | #include "base/macros.h" |
Nicholas Verne | c6b829a | 2017-10-24 13:43:56 | [diff] [blame] | 15 | #include "chrome/common/chrome_render_frame.mojom.h" |
Josh Simmons | 6067fdb | 2020-01-17 08:56:50 | [diff] [blame] | 16 | #include "components/optimization_guide/proto/performance_hints_metadata.pb.h" |
Lukasz Anforowicz | 8c4446dc | 2020-03-11 22:16:42 | [diff] [blame^] | 17 | #include "content/public/browser/context_menu_params.h" |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 18 | #include "content/public/browser/web_contents_user_data.h" |
Shimi Zhang | 4570d12 | 2019-09-06 22:50:55 | [diff] [blame] | 19 | #include "mojo/public/cpp/bindings/associated_remote.h" |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 20 | |
| 21 | namespace content { |
| 22 | struct ContextMenuParams; |
tedchoc | cd0bf1f | 2015-12-15 21:23:10 | [diff] [blame] | 23 | class RenderFrameHost; |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 24 | class WebContents; |
| 25 | } |
| 26 | |
| 27 | class ContextMenuHelper |
| 28 | : public content::WebContentsUserData<ContextMenuHelper> { |
injae | d698fa9 | 2017-06-23 19:39:30 | [diff] [blame] | 29 | protected: |
| 30 | using ImageRetrieveCallback = base::Callback<void( |
Shimi Zhang | 4570d12 | 2019-09-06 22:50:55 | [diff] [blame] | 31 | mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame> |
| 32 | chrome_render_frame_ptr, |
injae | d698fa9 | 2017-06-23 19:39:30 | [diff] [blame] | 33 | const base::android::JavaRef<jobject>& jcallback, |
| 34 | const std::vector<uint8_t>& thumbnail_data, |
| 35 | const gfx::Size& max_dimen_px)>; |
| 36 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 37 | public: |
dcheng | 361fdb3 | 2015-02-04 02:56:07 | [diff] [blame] | 38 | ~ContextMenuHelper() override; |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 39 | |
amaralp | dbb23e2 | 2016-09-26 22:40:11 | [diff] [blame] | 40 | void ShowContextMenu(content::RenderFrameHost* render_frame_host, |
tedchoc | cd0bf1f | 2015-12-15 21:23:10 | [diff] [blame] | 41 | const content::ContextMenuParams& params); |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 42 | |
shaktisahu | 3a2f73d | 2016-12-06 04:34:31 | [diff] [blame] | 43 | void OnContextMenuClosed(JNIEnv* env, |
| 44 | const base::android::JavaParamRef<jobject>& obj); |
| 45 | |
Torne (Richard Coles) | 0a10875 | 2017-07-25 15:08:41 | [diff] [blame] | 46 | void SetPopulator(const base::android::JavaRef<jobject>& jpopulator); |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 47 | |
| 48 | // Methods called from Java via JNI ------------------------------------------ |
tedchoc | 69a502c | 2017-04-07 18:11:36 | [diff] [blame] | 49 | base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents( |
| 50 | JNIEnv* env, |
| 51 | const base::android::JavaParamRef<jobject>& obj); |
torne | ebcfa226 | 2015-11-25 17:47:24 | [diff] [blame] | 52 | void OnStartDownload(JNIEnv* env, |
| 53 | const base::android::JavaParamRef<jobject>& obj, |
| 54 | jboolean jis_link, |
bauerb | f6d2732 | 2016-03-30 17:02:48 | [diff] [blame] | 55 | jboolean jis_data_reduction_proxy_enabled); |
injae | d698fa9 | 2017-06-23 19:39:30 | [diff] [blame] | 56 | void RetrieveImageForShare( |
| 57 | JNIEnv* env, |
| 58 | const base::android::JavaParamRef<jobject>& obj, |
| 59 | const base::android::JavaParamRef<jobject>& jcallback, |
Daniel Park | 0de6677 | 2017-11-03 21:20:47 | [diff] [blame] | 60 | jint max_width_px, |
| 61 | jint max_height_px); |
injae | d698fa9 | 2017-06-23 19:39:30 | [diff] [blame] | 62 | void RetrieveImageForContextMenu( |
| 63 | JNIEnv* env, |
| 64 | const base::android::JavaParamRef<jobject>& obj, |
| 65 | const base::android::JavaParamRef<jobject>& jcallback, |
Daniel Park | 0de6677 | 2017-11-03 21:20:47 | [diff] [blame] | 66 | jint max_width_px, |
| 67 | jint max_height_px); |
injae | d698fa9 | 2017-06-23 19:39:30 | [diff] [blame] | 68 | void RetrieveImageInternal( |
| 69 | JNIEnv* env, |
| 70 | const ImageRetrieveCallback& retrieve_callback, |
| 71 | const base::android::JavaParamRef<jobject>& jcallback, |
Daniel Park | 0de6677 | 2017-11-03 21:20:47 | [diff] [blame] | 72 | jint max_width_px, |
| 73 | jint max_height_px); |
torne | ebcfa226 | 2015-11-25 17:47:24 | [diff] [blame] | 74 | void SearchForImage(JNIEnv* env, |
| 75 | const base::android::JavaParamRef<jobject>& obj); |
jwanda | 8817202 | 2017-03-31 22:28:34 | [diff] [blame] | 76 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 77 | private: |
| 78 | explicit ContextMenuHelper(content::WebContents* web_contents); |
| 79 | friend class content::WebContentsUserData<ContextMenuHelper>; |
| 80 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 81 | base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
| 82 | content::WebContents* web_contents_; |
| 83 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 84 | content::ContextMenuParams context_menu_params_; |
tedchoc | cd0bf1f | 2015-12-15 21:23:10 | [diff] [blame] | 85 | int render_frame_id_; |
| 86 | int render_process_id_; |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 87 | |
François Doray | 4f51d5d | 2018-12-03 22:26:24 | [diff] [blame] | 88 | WEB_CONTENTS_USER_DATA_KEY_DECL(); |
| 89 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 90 | DISALLOW_COPY_AND_ASSIGN(ContextMenuHelper); |
| 91 | }; |
| 92 | |
[email protected] | e9622687 | 2013-12-06 00:02:37 | [diff] [blame] | 93 | #endif // CHROME_BROWSER_UI_ANDROID_CONTEXT_MENU_HELPER_H_ |