[email protected] | dc293a7 | 2013-07-01 11:11:22 | [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 | #include "content/renderer/drop_data_builder.h" | ||||
6 | |||||
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 7 | #include <stddef.h> |
8 | |||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 9 | #include "base/strings/string_util.h" |
10 | #include "content/public/common/drop_data.h" | ||||
kinuko | b473f00 | 2016-02-22 05:23:19 | [diff] [blame] | 11 | #include "third_party/WebKit/public/platform/FilePathConversion.h" |
brettw | dfbcc3b | 2016-01-20 01:49:17 | [diff] [blame] | 12 | #include "third_party/WebKit/public/platform/URLConversion.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 13 | #include "third_party/WebKit/public/platform/WebDragData.h" |
14 | #include "third_party/WebKit/public/platform/WebString.h" | ||||
15 | #include "third_party/WebKit/public/platform/WebVector.h" | ||||
16 | #include "ui/base/clipboard/clipboard.h" | ||||
17 | |||||
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 18 | using blink::WebDragData; |
kinuko | 365b58f | 2017-01-26 03:15:36 | [diff] [blame] | 19 | using blink::WebString; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 20 | using blink::WebVector; |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 21 | |
22 | namespace content { | ||||
23 | |||||
ajose | 1e515a6 | 2015-07-28 23:42:27 | [diff] [blame] | 24 | // static |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 25 | DropData DropDataBuilder::Build(const WebDragData& drag_data) { |
26 | DropData result; | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 27 | result.key_modifiers = drag_data.ModifierKeyState(); |
28 | result.referrer_policy = blink::kWebReferrerPolicyDefault; | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 29 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 30 | const WebVector<WebDragData::Item>& item_list = drag_data.Items(); |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 31 | for (size_t i = 0; i < item_list.size(); ++i) { |
32 | const WebDragData::Item& item = item_list[i]; | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 33 | switch (item.storage_type) { |
34 | case WebDragData::Item::kStorageTypeString: { | ||||
35 | base::string16 str_type(item.string_type.Utf16()); | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 36 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 37 | result.text = WebString::ToNullableString16(item.string_data); |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 38 | break; |
39 | } | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 40 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeURIList)) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 41 | result.url = blink::WebStringToGURL(item.string_data); |
42 | result.url_title = item.title.Utf16(); | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 43 | break; |
44 | } | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 45 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeDownloadURL)) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 46 | result.download_metadata = item.string_data.Utf16(); |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 47 | break; |
48 | } | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 49 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeHTML)) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 50 | result.html = WebString::ToNullableString16(item.string_data); |
51 | result.html_base_url = item.base_url; | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 52 | break; |
53 | } | ||||
54 | result.custom_data.insert( | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 55 | std::make_pair(item.string_type.Utf16(), item.string_data.Utf16())); |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 56 | break; |
57 | } | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 58 | case WebDragData::Item::kStorageTypeBinaryData: |
59 | result.file_contents.assign(item.binary_data.Data(), | ||||
60 | item.binary_data.size()); | ||||
61 | result.file_contents_source_url = item.binary_data_source_url; | ||||
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 62 | #if defined(OS_WIN) |
63 | result.file_contents_filename_extension = | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 64 | item.binary_data_filename_extension.Utf16(); |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 65 | #else |
66 | result.file_contents_filename_extension = | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 67 | item.binary_data_filename_extension.Utf8(); |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 68 | #endif |
69 | result.file_contents_content_disposition = | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 70 | item.binary_data_content_disposition.Utf8(); |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 71 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 72 | case WebDragData::Item::kStorageTypeFilename: |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 73 | // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 74 | result.filenames.push_back( |
75 | ui::FileInfo(blink::WebStringToFilePath(item.filename_data), | ||||
76 | blink::WebStringToFilePath(item.display_name_data))); | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 77 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 78 | case WebDragData::Item::kStorageTypeFileSystemFile: { |
[email protected] | 60ed95f | 2014-04-23 12:19:48 | [diff] [blame] | 79 | DropData::FileSystemFileInfo info; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 80 | info.url = item.file_system_url; |
81 | info.size = item.file_system_file_size; | ||||
82 | info.filesystem_id = item.file_system_id.Ascii(); | ||||
[email protected] | 60ed95f | 2014-04-23 12:19:48 | [diff] [blame] | 83 | result.file_system_files.push_back(info); |
84 | break; | ||||
85 | } | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 86 | } |
87 | } | ||||
88 | |||||
89 | return result; | ||||
90 | } | ||||
91 | |||||
92 | } // namespace content |