blob: beb98b6dec2c20976ec126df03a6d89024dac9cd [file] [log] [blame]
[email protected]dc293a72013-07-01 11:11:221// 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
avi1023d012015-12-25 02:39:147#include <stddef.h>
8
[email protected]dc293a72013-07-01 11:11:229#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]180ef242013-11-07 06:50:4616using blink::WebDragData;
17using blink::WebVector;
[email protected]dc293a72013-07-01 11:11:2218
19namespace content {
20
ajose1e515a62015-07-28 23:42:2721// static
[email protected]dc293a72013-07-01 11:11:2222DropData DropDataBuilder::Build(const WebDragData& drag_data) {
23 DropData result;
[email protected]180ef242013-11-07 06:50:4624 result.referrer_policy = blink::WebReferrerPolicyDefault;
[email protected]dc293a72013-07-01 11:11:2225
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: {
brettw85111672015-07-23 21:56:3531 base::string16 str_type(item.stringType);
32 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) {
[email protected]dc293a72013-07-01 11:11:2233 result.text = base::NullableString16(item.stringData, false);
34 break;
35 }
brettw85111672015-07-23 21:56:3536 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeURIList)) {
[email protected]dc293a72013-07-01 11:11:2237 result.url = GURL(item.stringData);
38 result.url_title = item.title;
39 break;
40 }
brettw85111672015-07-23 21:56:3541 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeDownloadURL)) {
[email protected]dc293a72013-07-01 11:11:2242 result.download_metadata = item.stringData;
43 break;
44 }
brettw85111672015-07-23 21:56:3545 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeHTML)) {
[email protected]dc293a72013-07-01 11:11:2246 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]17ea0ae22014-03-28 21:54:4661 result.filenames.push_back(ui::FileInfo(
62 base::FilePath::FromUTF16Unsafe(item.filenameData),
63 base::FilePath::FromUTF16Unsafe(item.displayNameData)));
[email protected]dc293a72013-07-01 11:11:2264 break;
[email protected]60ed95f2014-04-23 12:19:4865 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]dc293a72013-07-01 11:11:2272 }
73 }
74
75 return result;
76}
77
78} // namespace content