[MultiControl][VD] Support Drag and Drop image file 48/315948/3
authorchenshurong <shurong.chen@samsung.com>
Mon, 12 Aug 2024 02:47:00 +0000 (10:47 +0800)
committerchen shurong <shurong.chen@samsung.com>
Mon, 12 Aug 2024 08:34:20 +0000 (08:34 +0000)
Add dataTransfer.file property value for drag and drop image file,
as some website(such as naver mail and naver blog) need handled as
file when received the drop event.

Change-Id: I22b23012bc31d0d0012a5350b295c11e3518fd23
Signed-off-by: chenshurong <shurong.chen@samsung.com>
tizen_src/chromium_impl/content/browser/web_contents/web_drag_dest_efl.cc
tizen_src/chromium_impl/content/browser/web_contents/web_drag_dest_efl.h

index cea23806df788c0f0d7d513da3a09849ffb49407..abb3d69ed2675409454d955161c8864f9db0c9fa 100644 (file)
@@ -271,9 +271,29 @@ DropData WebDragDestEfl::ELMDropDataToDropData(Elm_Selection_Data* es_data) {
   if (StartsWithImgTag(data)) {
     if (IsImgFile(data)) {
       std::string img_tag;
-      if (ConvertImgTagToBase64(data, &img_tag)) {
+      std::string filename_extension;
+      std::string file_path;
+
+      if (ConvertImgTagToBase64(data, &img_tag, &filename_extension,
+                                &file_path)) {
         data = img_tag;
         LOG(INFO) << "[DND] convert image file to html: " << data;
+
+        std::vector<ui::FileInfo> filenames;
+        ui::FileInfo imagefile;
+        imagefile.path = base::FilePath(file_path);
+        imagefile.display_name =
+            base::FilePath("DragAndDrop." + filename_extension);
+        filenames.push_back(imagefile);
+        result.filenames = filenames;
+        LOG(INFO) << "[DND] convert image file_path: " << file_path;
+
+        std::vector<std::u16string> file_mime_types;
+        std::u16string file_mime_type =
+            u"image/" + base::UTF8ToUTF16(filename_extension);
+        file_mime_types.push_back(file_mime_type);
+        result.file_mime_types = file_mime_types;
+        LOG(INFO) << "[DND] convert image file mime_types: " << file_mime_type;
       }
     }
 
@@ -374,8 +394,10 @@ std::string WebDragDestEfl::GetImageTypeFromPath(const std::string& path) {
   return image_type;
 }
 
-bool WebDragDestEfl::Base64ImageTagFromImagePath(const std::string& path,
-                                                 std::string* image_html) {
+bool WebDragDestEfl::Base64ImageTagFromImagePath(
+    const std::string& path,
+    std::string* image_html,
+    std::string* filename_extension) {
   std::string file_contents;
   if (!base::ReadFileToString(base::FilePath(path), &file_contents)) {
     LOG(ERROR) << "[DND] couldn't read file: " << path;
@@ -393,6 +415,7 @@ bool WebDragDestEfl::Base64ImageTagFromImagePath(const std::string& path,
   *image_html = image_Prefix;
   *image_html += file_contents;
   *image_html += kDataURIImageSuffix;
+  *filename_extension = image_type;
   return true;
 }
 
@@ -401,7 +424,9 @@ bool WebDragDestEfl::Base64ImageTagFromImagePath(const std::string& path,
 // this for security reasons). To work around this limitation we convert local
 // images to base64 encoded data URI.
 bool WebDragDestEfl::ConvertImgTagToBase64(const std::string& tag,
-                                           std::string* out_tag) {
+                                           std::string* out_tag,
+                                           std::string* filename_extension,
+                                           std::string* file_path) {
   std::string::size_type front_pos = tag.find(kHTMLImageFromClipboardAppFront);
   if (front_pos == std::string::npos) {
     LOG(ERROR) << "[DND] couldn't find " << kHTMLImageFromClipboardAppFront
@@ -421,7 +446,9 @@ bool WebDragDestEfl::ConvertImgTagToBase64(const std::string& tag,
 
   std::string image_path = front_stripped.substr(0, back_pos);
   LOG(INFO) << "[DND] image_path:" << image_path;
-  return Base64ImageTagFromImagePath(image_path, out_tag);
+
+  *file_path = image_path;
+  return Base64ImageTagFromImagePath(image_path, out_tag, filename_extension);
 }
 
 bool WebDragDestEfl::IsImgFile(const std::string& html_str) {
index b1ca64afa447695fff664a44d82ab68924b16ad6..612d90127721a0b851d457cc142750339a98bb28 100644 (file)
@@ -61,9 +61,12 @@ class WebDragDestEfl {
   static std::string GetImageTypeFromPath(const std::string& path);
 
   static bool Base64ImageTagFromImagePath(const std::string& path,
-                                          std::string* image_html);
+                                          std::string* image_html,
+                                          std::string* filename_extension);
   static bool ConvertImgTagToBase64(const std::string& tag,
-                                    std::string* out_tag);
+                                    std::string* out_tag,
+                                    std::string* filename_extension,
+                                    std::string* file_path);
 
  private:
   void SetDragCallbacks();