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;
}
}
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;
*image_html = image_Prefix;
*image_html += file_contents;
*image_html += kDataURIImageSuffix;
+ *filename_extension = image_type;
return true;
}
// 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
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) {