[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; | ||||
wjmaclean | 0562edf | 2016-05-17 17:40:42 | [diff] [blame] | 27 | result.key_modifiers = drag_data.modifierKeyState(); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 28 | result.referrer_policy = blink::WebReferrerPolicyDefault; |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 29 | |
30 | const WebVector<WebDragData::Item>& item_list = drag_data.items(); | ||||
31 | for (size_t i = 0; i < item_list.size(); ++i) { | ||||
32 | const WebDragData::Item& item = item_list[i]; | ||||
33 | switch (item.storageType) { | ||||
34 | case WebDragData::Item::StorageTypeString: { | ||||
kinuko | 365b58f | 2017-01-26 03:15:36 | [diff] [blame] | 35 | base::string16 str_type(item.stringType.utf16()); |
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 36 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) { |
kinuko | 365b58f | 2017-01-26 03:15:36 | [diff] [blame] | 37 | result.text = WebString::toNullableString16(item.stringData); |
[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)) { |
brettw | dfbcc3b | 2016-01-20 01:49:17 | [diff] [blame] | 41 | result.url = blink::WebStringToGURL(item.stringData); |
kinuko | 365b58f | 2017-01-26 03:15:36 | [diff] [blame] | 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)) { |
kinuko | 365b58f | 2017-01-26 03:15:36 | [diff] [blame] | 46 | result.download_metadata = item.stringData.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)) { |
kinuko | 365b58f | 2017-01-26 03:15:36 | [diff] [blame] | 50 | result.html = WebString::toNullableString16(item.stringData); |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 51 | result.html_base_url = item.baseURL; |
52 | break; | ||||
53 | } | ||||
54 | result.custom_data.insert( | ||||
kinuko | 365b58f | 2017-01-26 03:15:36 | [diff] [blame] | 55 | std::make_pair(item.stringType.utf16(), item.stringData.utf16())); |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 56 | break; |
57 | } | ||||
58 | case WebDragData::Item::StorageTypeBinaryData: | ||||
59 | result.file_contents.assign(item.binaryData.data(), | ||||
60 | item.binaryData.size()); | ||||
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame^] | 61 | result.file_contents_source_url = item.binaryDataSourceURL; |
62 | #if defined(OS_WIN) | ||||
63 | result.file_contents_filename_extension = | ||||
64 | item.binaryDataFilenameExtension.utf16(); | ||||
65 | #else | ||||
66 | result.file_contents_filename_extension = | ||||
67 | item.binaryDataFilenameExtension.utf8(); | ||||
68 | #endif | ||||
69 | result.file_contents_content_disposition = | ||||
70 | item.binaryDataContentDisposition.utf8(); | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 71 | break; |
72 | case WebDragData::Item::StorageTypeFilename: | ||||
73 | // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. | ||||
[email protected] | 17ea0ae2 | 2014-03-28 21:54:46 | [diff] [blame] | 74 | result.filenames.push_back(ui::FileInfo( |
kinuko | b473f00 | 2016-02-22 05:23:19 | [diff] [blame] | 75 | blink::WebStringToFilePath(item.filenameData), |
76 | blink::WebStringToFilePath(item.displayNameData))); | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 77 | break; |
[email protected] | 60ed95f | 2014-04-23 12:19:48 | [diff] [blame] | 78 | case WebDragData::Item::StorageTypeFileSystemFile: { |
79 | DropData::FileSystemFileInfo info; | ||||
80 | info.url = item.fileSystemURL; | ||||
81 | info.size = item.fileSystemFileSize; | ||||
hirono | da08349d | 2016-12-14 07:36:16 | [diff] [blame] | 82 | info.filesystem_id = item.fileSystemId.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 |