Further cleanup of some assets
[chromium-blink-merge.git] / content / renderer / drop_data_builder.cc
blob37b723130fc1b00bdb2eb0c47c09458de54e84fe
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 base::string16 str_type(item.stringType);
30 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) {
31 result.text = base::NullableString16(item.stringData, false);
32 break;
34 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeURIList)) {
35 result.url = GURL(item.stringData);
36 result.url_title = item.title;
37 break;
39 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeDownloadURL)) {
40 result.download_metadata = item.stringData;
41 break;
43 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeHTML)) {
44 result.html = base::NullableString16(item.stringData, false);
45 result.html_base_url = item.baseURL;
46 break;
48 result.custom_data.insert(
49 std::make_pair(item.stringType, item.stringData));
50 break;
52 case WebDragData::Item::StorageTypeBinaryData:
53 result.file_contents.assign(item.binaryData.data(),
54 item.binaryData.size());
55 result.file_description_filename = item.title;
56 break;
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)));
62 break;
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);
68 break;
73 return result;
76 } // namespace content