• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/renderer/drop_data_builder.h"
6 
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"
13 
14 using blink::WebDragData;
15 using blink::WebVector;
16 
17 namespace content {
18 
19 //static
Build(const WebDragData & drag_data)20 DropData DropDataBuilder::Build(const WebDragData& drag_data) {
21   DropData result;
22   result.referrer_policy = blink::WebReferrerPolicyDefault;
23 
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;
32         }
33         if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) {
34           result.url = GURL(item.stringData);
35           result.url_title = item.title;
36           break;
37         }
38         if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeDownloadURL)) {
39           result.download_metadata = item.stringData;
40           break;
41         }
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;
46         }
47         result.custom_data.insert(
48             std::make_pair(item.stringType, item.stringData));
49         break;
50       }
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;
68       }
69     }
70   }
71 
72   return result;
73 }
74 
75 }  // namespace content
76