[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" | ||||
11 | #include "third_party/WebKit/public/platform/WebDragData.h" | ||||
12 | #include "third_party/WebKit/public/platform/WebString.h" | ||||
13 | #include "third_party/WebKit/public/platform/WebVector.h" | ||||
14 | #include "ui/base/clipboard/clipboard.h" | ||||
15 | |||||
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 16 | using blink::WebDragData; |
17 | using blink::WebVector; | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 18 | |
19 | namespace content { | ||||
20 | |||||
ajose | 1e515a6 | 2015-07-28 23:42:27 | [diff] [blame] | 21 | // static |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 22 | DropData DropDataBuilder::Build(const WebDragData& drag_data) { |
23 | DropData result; | ||||
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 24 | result.referrer_policy = blink::WebReferrerPolicyDefault; |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 25 | |
26 | const WebVector<WebDragData::Item>& item_list = drag_data.items(); | ||||
27 | for (size_t i = 0; i < item_list.size(); ++i) { | ||||
28 | const WebDragData::Item& item = item_list[i]; | ||||
29 | switch (item.storageType) { | ||||
30 | case WebDragData::Item::StorageTypeString: { | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 31 | base::string16 str_type(item.stringType); |
32 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) { | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 33 | result.text = base::NullableString16(item.stringData, false); |
34 | break; | ||||
35 | } | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 36 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeURIList)) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 37 | result.url = GURL(item.stringData); |
38 | result.url_title = item.title; | ||||
39 | break; | ||||
40 | } | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 41 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeDownloadURL)) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 42 | result.download_metadata = item.stringData; |
43 | break; | ||||
44 | } | ||||
brettw | 8511167 | 2015-07-23 21:56:35 | [diff] [blame] | 45 | if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeHTML)) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 46 | result.html = base::NullableString16(item.stringData, false); |
47 | result.html_base_url = item.baseURL; | ||||
48 | break; | ||||
49 | } | ||||
50 | result.custom_data.insert( | ||||
51 | std::make_pair(item.stringType, item.stringData)); | ||||
52 | break; | ||||
53 | } | ||||
54 | case WebDragData::Item::StorageTypeBinaryData: | ||||
55 | result.file_contents.assign(item.binaryData.data(), | ||||
56 | item.binaryData.size()); | ||||
57 | result.file_description_filename = item.title; | ||||
58 | break; | ||||
59 | case WebDragData::Item::StorageTypeFilename: | ||||
60 | // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. | ||||
[email protected] | 17ea0ae2 | 2014-03-28 21:54:46 | [diff] [blame] | 61 | result.filenames.push_back(ui::FileInfo( |
62 | base::FilePath::FromUTF16Unsafe(item.filenameData), | ||||
63 | base::FilePath::FromUTF16Unsafe(item.displayNameData))); | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 64 | break; |
[email protected] | 60ed95f | 2014-04-23 12:19:48 | [diff] [blame] | 65 | case WebDragData::Item::StorageTypeFileSystemFile: { |
66 | DropData::FileSystemFileInfo info; | ||||
67 | info.url = item.fileSystemURL; | ||||
68 | info.size = item.fileSystemFileSize; | ||||
69 | result.file_system_files.push_back(info); | ||||
70 | break; | ||||
71 | } | ||||
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 72 | } |
73 | } | ||||
74 | |||||
75 | return result; | ||||
76 | } | ||||
77 | |||||
78 | } // namespace content |