Roll src/third_party/WebKit d10c917:a1123a1 (svn 198729:198730)
[chromium-blink-merge.git] / content / renderer / drop_data_builder.cc
blobbff73f56d902d85823ea2afaf124daf2846b46d1
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;
17 namespace content {
19 //static
20 DropData DropDataBuilder::Build(const WebDragData& drag_data) {
21 DropData result;
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 if (base::EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) {
30 result.text = base::NullableString16(item.stringData, false);
31 break;
33 if (base::EqualsASCII(item.stringType,
34 ui::Clipboard::kMimeTypeURIList)) {
35 result.url = GURL(item.stringData);
36 result.url_title = item.title;
37 break;
39 if (base::EqualsASCII(item.stringType,
40 ui::Clipboard::kMimeTypeDownloadURL)) {
41 result.download_metadata = item.stringData;
42 break;
44 if (base::EqualsASCII(item.stringType,
45 ui::Clipboard::kMimeTypeHTML)) {
46 result.html = base::NullableString16(item.stringData, false);
47 result.html_base_url = item.baseURL;
48 break;
50 result.custom_data.insert(
51 std::make_pair(item.stringType, item.stringData));
52 break;
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.
61 result.filenames.push_back(ui::FileInfo(
62 base::FilePath::FromUTF16Unsafe(item.filenameData),
63 base::FilePath::FromUTF16Unsafe(item.displayNameData)));
64 break;
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;
75 return result;
78 } // namespace content