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.
5 #include "content/renderer/drop_data_builder.h"
7 #include "base/strings/string_util.h"
8 #include "content/public/common/drop_data.h"
9 #include "third_party/WebKit/public/platform/WebDragData.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/platform/WebVector.h"
12 #include "ui/base/clipboard/clipboard.h"
14 using blink::WebDragData
;
15 using blink::WebVector
;
20 DropData
DropDataBuilder::Build(const WebDragData
& drag_data
) {
22 result
.referrer_policy
= blink::WebReferrerPolicyDefault
;
24 const WebVector
<WebDragData::Item
>& item_list
= drag_data
.items();
25 for (size_t i
= 0; i
< item_list
.size(); ++i
) {
26 const WebDragData::Item
& item
= item_list
[i
];
27 switch (item
.storageType
) {
28 case WebDragData::Item::StorageTypeString
: {
29 base::string16
str_type(item
.stringType
);
30 if (base::EqualsASCII(str_type
, ui::Clipboard::kMimeTypeText
)) {
31 result
.text
= base::NullableString16(item
.stringData
, false);
34 if (base::EqualsASCII(str_type
, ui::Clipboard::kMimeTypeURIList
)) {
35 result
.url
= GURL(item
.stringData
);
36 result
.url_title
= item
.title
;
39 if (base::EqualsASCII(str_type
, ui::Clipboard::kMimeTypeDownloadURL
)) {
40 result
.download_metadata
= item
.stringData
;
43 if (base::EqualsASCII(str_type
, ui::Clipboard::kMimeTypeHTML
)) {
44 result
.html
= base::NullableString16(item
.stringData
, false);
45 result
.html_base_url
= item
.baseURL
;
48 result
.custom_data
.insert(
49 std::make_pair(item
.stringType
, item
.stringData
));
52 case WebDragData::Item::StorageTypeBinaryData
:
53 result
.file_contents
.assign(item
.binaryData
.data(),
54 item
.binaryData
.size());
55 result
.file_description_filename
= item
.title
;
57 case WebDragData::Item::StorageTypeFilename
:
58 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk.
59 result
.filenames
.push_back(ui::FileInfo(
60 base::FilePath::FromUTF16Unsafe(item
.filenameData
),
61 base::FilePath::FromUTF16Unsafe(item
.displayNameData
)));
63 case WebDragData::Item::StorageTypeFileSystemFile
: {
64 DropData::FileSystemFileInfo info
;
65 info
.url
= item
.fileSystemURL
;
66 info
.size
= item
.fileSystemFileSize
;
67 result
.file_system_files
.push_back(info
);
76 } // namespace content