Roll src/third_party/skia ff271c2:b679ca8
[chromium-blink-merge.git] / content / renderer / drop_data_builder.cc
blob395c2b55f378a95134fc7c166197931a84b3d298
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 (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) {
30 result.text = base::NullableString16(item.stringData, false);
31 break;
33 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) {
34 result.url = GURL(item.stringData);
35 result.url_title = item.title;
36 break;
38 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeDownloadURL)) {
39 result.download_metadata = item.stringData;
40 break;
42 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) {
43 result.html = base::NullableString16(item.stringData, false);
44 result.html_base_url = item.baseURL;
45 break;
47 result.custom_data.insert(
48 std::make_pair(item.stringType, item.stringData));
49 break;
51 case WebDragData::Item::StorageTypeBinaryData:
52 result.file_contents.assign(item.binaryData.data(),
53 item.binaryData.size());
54 result.file_description_filename = item.title;
55 break;
56 case WebDragData::Item::StorageTypeFilename:
57 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk.
58 result.filenames.push_back(ui::FileInfo(
59 base::FilePath::FromUTF16Unsafe(item.filenameData),
60 base::FilePath::FromUTF16Unsafe(item.displayNameData)));
61 break;
62 case WebDragData::Item::StorageTypeFileSystemFile: {
63 DropData::FileSystemFileInfo info;
64 info.url = item.fileSystemURL;
65 info.size = item.fileSystemFileSize;
66 result.file_system_files.push_back(info);
67 break;
72 return result;
75 } // namespace content