OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/common/webdropdata.h" | 5 #include "content/renderer/drop_data_builder.h" |
6 | 6 |
7 #include <utility> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 8 #include "content/public/common/drop_data.h" |
12 #include "third_party/WebKit/public/platform/WebData.h" | |
13 #include "third_party/WebKit/public/platform/WebDragData.h" | 9 #include "third_party/WebKit/public/platform/WebDragData.h" |
14 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
15 #include "third_party/WebKit/public/platform/WebURL.h" | |
16 #include "third_party/WebKit/public/platform/WebVector.h" | 11 #include "third_party/WebKit/public/platform/WebVector.h" |
17 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
18 | 13 |
19 using WebKit::WebData; | |
20 using WebKit::WebDragData; | 14 using WebKit::WebDragData; |
21 using WebKit::WebString; | |
22 using WebKit::WebVector; | 15 using WebKit::WebVector; |
23 | 16 |
24 WebDropData::FileInfo::FileInfo() { | 17 namespace content { |
25 } | |
26 | 18 |
27 WebDropData::FileInfo::FileInfo(const base::string16& path, | 19 //static |
28 const base::string16& display_name) | 20 DropData DropDataBuilder::Build(const WebDragData& drag_data) { |
29 : path(path), | 21 DropData result; |
30 display_name(display_name) { | 22 result.referrer_policy = WebKit::WebReferrerPolicyDefault; |
31 } | |
32 | 23 |
33 WebDropData::WebDropData(const WebDragData& drag_data) | |
34 : referrer_policy(WebKit::WebReferrerPolicyDefault) { | |
35 const WebVector<WebDragData::Item>& item_list = drag_data.items(); | 24 const WebVector<WebDragData::Item>& item_list = drag_data.items(); |
36 for (size_t i = 0; i < item_list.size(); ++i) { | 25 for (size_t i = 0; i < item_list.size(); ++i) { |
37 const WebDragData::Item& item = item_list[i]; | 26 const WebDragData::Item& item = item_list[i]; |
38 switch (item.storageType) { | 27 switch (item.storageType) { |
39 case WebDragData::Item::StorageTypeString: { | 28 case WebDragData::Item::StorageTypeString: { |
40 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { | 29 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { |
41 text = base::NullableString16(item.stringData, false); | 30 result.text = base::NullableString16(item.stringData, false); |
42 break; | 31 break; |
43 } | 32 } |
44 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) { | 33 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) { |
45 url = GURL(item.stringData); | 34 result.url = GURL(item.stringData); |
46 url_title = item.title; | 35 result.url_title = item.title; |
47 break; | 36 break; |
48 } | 37 } |
49 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeDownloadURL)) { | 38 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeDownloadURL)) { |
50 download_metadata = item.stringData; | 39 result.download_metadata = item.stringData; |
51 break; | 40 break; |
52 } | 41 } |
53 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { | 42 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { |
54 html = base::NullableString16(item.stringData, false); | 43 result.html = base::NullableString16(item.stringData, false); |
55 html_base_url = item.baseURL; | 44 result.html_base_url = item.baseURL; |
56 break; | 45 break; |
57 } | 46 } |
58 custom_data.insert(std::make_pair(item.stringType, item.stringData)); | 47 result.custom_data.insert( |
| 48 std::make_pair(item.stringType, item.stringData)); |
59 break; | 49 break; |
60 } | 50 } |
61 case WebDragData::Item::StorageTypeBinaryData: | 51 case WebDragData::Item::StorageTypeBinaryData: |
62 file_contents.assign(item.binaryData.data(), | 52 result.file_contents.assign(item.binaryData.data(), |
63 item.binaryData.size()); | 53 item.binaryData.size()); |
64 file_description_filename = item.title; | 54 result.file_description_filename = item.title; |
65 break; | 55 break; |
66 case WebDragData::Item::StorageTypeFilename: | 56 case WebDragData::Item::StorageTypeFilename: |
67 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. | 57 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. |
68 filenames.push_back(FileInfo(item.filenameData, | 58 result.filenames.push_back( |
69 item.displayNameData)); | 59 DropData::FileInfo(item.filenameData, item.displayNameData)); |
70 break; | 60 break; |
71 } | 61 } |
72 } | 62 } |
| 63 |
| 64 return result; |
73 } | 65 } |
74 | 66 |
75 WebDropData::WebDropData() | 67 } // namespace content |
76 : referrer_policy(WebKit::WebReferrerPolicyDefault) { | |
77 } | |
78 | |
79 WebDropData::~WebDropData() { | |
80 } | |
OLD | NEW |