OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/glue/webdropdata.h" | 5 #include "webkit/glue/webdropdata.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
12 | 14 |
13 using WebKit::WebData; | 15 using WebKit::WebData; |
14 using WebKit::WebDragData; | 16 using WebKit::WebDragData; |
15 using WebKit::WebString; | 17 using WebKit::WebString; |
16 using WebKit::WebVector; | 18 using WebKit::WebVector; |
17 | 19 |
18 WebDropData::WebDropData(const WebDragData& drag_data) | 20 WebDropData::WebDropData(const WebDragData& drag_data) |
19 : url(drag_data.url()), | 21 : url(drag_data.url()), |
20 url_title(drag_data.urlTitle()), | 22 url_title(drag_data.urlTitle()), |
21 download_metadata(drag_data.downloadMetadata()), | 23 download_metadata(drag_data.downloadMetadata()), |
22 file_extension(drag_data.fileExtension()), | 24 file_extension(drag_data.fileExtension()), |
23 plain_text(drag_data.plainText()), | 25 plain_text(drag_data.plainText()), |
24 text_html(drag_data.htmlText()), | 26 text_html(drag_data.htmlText()), |
25 html_base_url(drag_data.htmlBaseURL()), | 27 html_base_url(drag_data.htmlBaseURL()), |
26 file_description_filename(drag_data.fileContentFilename()) { | 28 file_description_filename(drag_data.fileContentFilename()) { |
27 if (drag_data.containsFilenames()) { | 29 if (drag_data.containsFilenames()) { |
28 WebVector<WebString> filenames_copy; | 30 WebVector<WebString> filenames_copy; |
29 drag_data.filenames(filenames_copy); | 31 drag_data.filenames(filenames_copy); |
30 for (size_t i = 0; i < filenames_copy.size(); ++i) | 32 for (size_t i = 0; i < filenames_copy.size(); ++i) |
31 filenames.push_back(filenames_copy[i]); | 33 filenames.push_back(filenames_copy[i]); |
32 } | 34 } |
33 WebData contents = drag_data.fileContent(); | 35 WebData contents = drag_data.fileContent(); |
34 if (!contents.isEmpty()) | 36 if (!contents.isEmpty()) |
35 file_contents.assign(contents.data(), contents.size()); | 37 file_contents.assign(contents.data(), contents.size()); |
| 38 WebVector<WebDragData::CustomData> custom_data_copy = drag_data.customData(); |
| 39 for (size_t i = 0; i < custom_data_copy.size(); ++i) { |
| 40 custom_data.insert(std::make_pair(custom_data_copy[i].m_type, |
| 41 custom_data_copy[i].m_data)); |
| 42 } |
36 } | 43 } |
37 | 44 |
38 WebDropData::WebDropData() { | 45 WebDropData::WebDropData() { |
39 } | 46 } |
40 | 47 |
41 WebDropData::~WebDropData() { | 48 WebDropData::~WebDropData() { |
42 } | 49 } |
43 | 50 |
44 WebDragData WebDropData::ToDragData() const { | 51 WebDragData WebDropData::ToDragData() const { |
45 WebDragData result; | 52 WebDragData result; |
46 result.initialize(); | 53 result.initialize(); |
47 result.setURL(url); | 54 result.setURL(url); |
48 result.setURLTitle(url_title); | 55 result.setURLTitle(url_title); |
49 result.setFileExtension(file_extension); | 56 result.setFileExtension(file_extension); |
50 result.setFilenames(filenames); | 57 result.setFilenames(filenames); |
51 result.setPlainText(plain_text); | 58 result.setPlainText(plain_text); |
52 result.setHTMLText(text_html); | 59 result.setHTMLText(text_html); |
53 result.setHTMLBaseURL(html_base_url); | 60 result.setHTMLBaseURL(html_base_url); |
54 result.setFileContentFilename(file_description_filename); | 61 result.setFileContentFilename(file_description_filename); |
55 result.setFileContent(WebData(file_contents.data(), file_contents.size())); | 62 result.setFileContent(WebData(file_contents.data(), file_contents.size())); |
| 63 WebVector<WebDragData::CustomData> custom_data_vector(custom_data.size()); |
| 64 size_t i = 0; |
| 65 for (std::map<string16, string16>::const_iterator it = custom_data.begin(); |
| 66 it != custom_data.end(); |
| 67 ++it, ++i) { |
| 68 WebDragData::CustomData data = {it->first, it->second}; |
| 69 custom_data_vector[i] = data; |
| 70 } |
56 return result; | 71 return result; |
57 } | 72 } |
OLD | NEW |