Add gif support for image share and copy on Android

This CL add gif support for image share and copy on Android. Android
Context Menu Can request original image data from renderer if image is
PNG, JPEG or GIF, and then share to other apps or save to the system's
clipboard.

Bug: 1057006
Change-Id: I624eeb10d3377857c0867fb73b4b6402b24ef476
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2101933
Commit-Queue: Gang Wu <[email protected]>
Reviewed-by: Mustafa Emre Acer <[email protected]>
Reviewed-by: Theresa  <[email protected]>
Reviewed-by: Philip Rogers <[email protected]>
Reviewed-by: Khushal <[email protected]>
Reviewed-by: Sinan Sahin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#755704}
diff --git a/chrome/browser/ui/android/context_menu_helper.h b/chrome/browser/ui/android/context_menu_helper.h
index 71d645b..a9c86d52 100644
--- a/chrome/browser/ui/android/context_menu_helper.h
+++ b/chrome/browser/ui/android/context_menu_helper.h
@@ -24,6 +24,13 @@
 class WebContents;
 }
 
+// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.contextmenu
+enum ContextMenuImageFormat {
+  JPEG = 0,
+  PNG = 1,
+  ORIGINAL = 2,
+};
+
 class ContextMenuHelper
     : public content::WebContentsUserData<ContextMenuHelper> {
  protected:
@@ -32,7 +39,8 @@
           chrome_render_frame_ptr,
       const base::android::JavaRef<jobject>& jcallback,
       const std::vector<uint8_t>& thumbnail_data,
-      const gfx::Size& max_dimen_px)>;
+      const gfx::Size& max_dimen_px,
+      const std::string& image_extension)>;
 
  public:
   ~ContextMenuHelper() override;
@@ -53,30 +61,36 @@
                        const base::android::JavaParamRef<jobject>& obj,
                        jboolean jis_link,
                        jboolean jis_data_reduction_proxy_enabled);
+  void SearchForImage(JNIEnv* env,
+                      const base::android::JavaParamRef<jobject>& obj);
   void RetrieveImageForShare(
       JNIEnv* env,
       const base::android::JavaParamRef<jobject>& obj,
       const base::android::JavaParamRef<jobject>& jcallback,
       jint max_width_px,
-      jint max_height_px);
+      jint max_height_px,
+      jint j_image_type);
   void RetrieveImageForContextMenu(
       JNIEnv* env,
       const base::android::JavaParamRef<jobject>& obj,
       const base::android::JavaParamRef<jobject>& jcallback,
       jint max_width_px,
       jint max_height_px);
+
+ private:
+  explicit ContextMenuHelper(content::WebContents* web_contents);
+  friend class content::WebContentsUserData<ContextMenuHelper>;
+
   void RetrieveImageInternal(
       JNIEnv* env,
       const ImageRetrieveCallback& retrieve_callback,
       const base::android::JavaParamRef<jobject>& jcallback,
       jint max_width_px,
-      jint max_height_px);
-  void SearchForImage(JNIEnv* env,
-                      const base::android::JavaParamRef<jobject>& obj);
+      jint max_height_px,
+      chrome::mojom::ImageFormat image_format);
 
- private:
-  explicit ContextMenuHelper(content::WebContents* web_contents);
-  friend class content::WebContentsUserData<ContextMenuHelper>;
+  mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame>
+  GetChromeRenderFrame() const;
 
   base::android::ScopedJavaGlobalRef<jobject> java_obj_;
   content::WebContents* web_contents_;