Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | |
| 10 #include "base/utf_string_conversions.h" | |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData. h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData. h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 16 #include "ui/base/clipboard/clipboard.h" | |
| 14 | 17 |
| 15 using WebKit::WebData; | 18 using WebKit::WebData; |
| 16 using WebKit::WebDragData; | 19 using WebKit::WebDragData; |
| 17 using WebKit::WebString; | 20 using WebKit::WebString; |
| 18 using WebKit::WebVector; | 21 using WebKit::WebVector; |
| 19 | 22 |
| 20 WebDropData::WebDropData(const WebDragData& drag_data) | 23 WebDropData::WebDropData(const WebDragData& drag_data) { |
| 21 : url(drag_data.url()), | 24 const WebVector<WebDragData::Item>& item_list = drag_data.itemList(); |
| 22 url_title(drag_data.urlTitle()), | 25 for (size_t i = 0; i < item_list.size(); ++i) { |
| 23 download_metadata(drag_data.downloadMetadata()), | 26 const WebDragData::Item& item = item_list[i]; |
| 24 plain_text(drag_data.plainText()), | 27 switch (item.storageType) { |
| 25 text_html(drag_data.htmlText()), | 28 case WebDragData::Item::STRING: { |
| 26 html_base_url(drag_data.htmlBaseURL()), | 29 std::string type = UTF16ToUTF8(item.stringType); |
| 27 file_description_filename(drag_data.fileContentFilename()) { | 30 if (type == ui::Clipboard::kMimeTypeText) { |
|
tony
2012/02/03 20:35:01
Should we use EqualsASCII from base/string_util.h?
dcheng
2012/02/03 21:37:59
Done. I updated the mock web clipboard implementat
| |
| 28 if (drag_data.containsFilenames()) { | 31 plain_text = item.stringData; |
| 29 WebVector<WebString> filenames_copy; | 32 continue; |
|
tony
2012/02/03 20:35:01
break seems better to me than continue (here and b
dcheng
2012/02/03 21:37:59
Done.
| |
| 30 drag_data.filenames(filenames_copy); | 33 } |
| 31 for (size_t i = 0; i < filenames_copy.size(); ++i) | 34 if (type == ui::Clipboard::kMimeTypeURIList) { |
| 32 filenames.push_back(filenames_copy[i]); | 35 url = GURL(item.stringData); |
| 33 } | 36 url_title = item.title; |
| 34 WebData contents = drag_data.fileContent(); | 37 continue; |
| 35 if (!contents.isEmpty()) | 38 } |
| 36 file_contents.assign(contents.data(), contents.size()); | 39 if (type == ui::Clipboard::kMimeTypeDownloadURL) { |
| 37 const WebVector<WebDragData::CustomData>& custom_data_alias = | 40 download_metadata = item.stringData; |
| 38 drag_data.customData(); | 41 continue; |
| 39 for (size_t i = 0; i < custom_data_alias.size(); ++i) { | 42 } |
| 40 custom_data.insert(std::make_pair(custom_data_alias[i].type, | 43 if (type == ui::Clipboard::kMimeTypeHTML) { |
| 41 custom_data_alias[i].data)); | 44 text_html = item.stringData; |
| 45 html_base_url = item.baseURL; | |
| 46 continue; | |
| 47 } | |
| 48 custom_data.insert(std::make_pair(item.stringType, item.stringData)); | |
| 49 continue; | |
| 50 } | |
|
tony
2012/02/03 20:35:01
bad indent?
dcheng
2012/02/03 21:37:59
Done.
| |
| 51 case WebDragData::Item::SHARED_BUFFER: | |
| 52 file_contents.assign(item.sharedBufferData.data(), | |
| 53 item.sharedBufferData.size()); | |
| 54 file_description_filename = item.title; | |
| 55 continue; | |
| 56 case WebDragData::Item::FILENAME: | |
| 57 // We don't currently use this. | |
| 58 NOTREACHED(); | |
| 59 }; | |
| 42 } | 60 } |
| 43 } | 61 } |
| 44 | 62 |
| 45 WebDropData::WebDropData() { | 63 WebDropData::WebDropData() { |
| 46 } | 64 } |
| 47 | 65 |
| 48 WebDropData::~WebDropData() { | 66 WebDropData::~WebDropData() { |
| 49 } | 67 } |
| 50 | 68 |
| 51 WebDragData WebDropData::ToDragData() const { | 69 WebDragData WebDropData::ToDragData() const { |
| 70 std::vector<WebDragData::Item> item_list; | |
| 71 | |
| 72 // These fields are currently unused when dragging into WebKit. | |
| 73 DCHECK(download_metadata.empty()); | |
| 74 DCHECK(file_contents.empty()); | |
| 75 DCHECK(file_description_filename.empty()); | |
| 76 | |
| 77 // TODO(dcheng): We need a way to distinguish between null and empty strings. | |
| 78 if (!plain_text.empty()) { | |
| 79 WebDragData::Item item; | |
| 80 item.storageType = WebDragData::Item::STRING; | |
| 81 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); | |
| 82 item.stringData = plain_text; | |
| 83 item_list.push_back(item); | |
| 84 } | |
| 85 | |
| 86 if (!url.is_empty()) { | |
| 87 WebDragData::Item item; | |
| 88 item.storageType = WebDragData::Item::STRING; | |
| 89 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); | |
| 90 item.stringData = WebString::fromUTF8(url.spec()); | |
| 91 item.title = url_title; | |
| 92 item_list.push_back(item); | |
| 93 } | |
| 94 | |
| 95 if (!text_html.empty()) { | |
| 96 WebDragData::Item item; | |
| 97 item.storageType = WebDragData::Item::STRING; | |
| 98 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); | |
| 99 item.stringData = text_html; | |
| 100 item.baseURL = html_base_url; | |
| 101 item_list.push_back(item); | |
| 102 } | |
| 103 | |
| 104 for (std::vector<string16>::const_iterator it = filenames.begin(); | |
| 105 it != filenames.end(); | |
| 106 ++it) { | |
| 107 WebDragData::Item item; | |
| 108 item.storageType = WebDragData::Item::FILENAME; | |
| 109 item.filenameData = *it; | |
| 110 item_list.push_back(item); | |
| 111 } | |
| 112 | |
| 113 for (std::map<string16, string16>::const_iterator it = custom_data.begin(); | |
| 114 it != custom_data.end(); | |
| 115 ++it) { | |
| 116 WebDragData::Item item; | |
| 117 item.storageType = WebDragData::Item::STRING; | |
| 118 item.stringType = it->first; | |
| 119 item.stringData = it->second; | |
| 120 item_list.push_back(item); | |
| 121 } | |
| 122 | |
| 52 WebDragData result; | 123 WebDragData result; |
| 53 result.initialize(); | 124 result.initialize(); |
| 54 result.setURL(url); | 125 result.setItemList(item_list); |
| 55 result.setURLTitle(url_title); | |
| 56 result.setFilenames(filenames); | |
| 57 result.setPlainText(plain_text); | |
| 58 result.setHTMLText(text_html); | |
| 59 result.setHTMLBaseURL(html_base_url); | |
| 60 result.setFileContentFilename(file_description_filename); | |
| 61 result.setFileContent(WebData(file_contents.data(), file_contents.size())); | |
| 62 WebVector<WebDragData::CustomData> custom_data_vector(custom_data.size()); | |
| 63 size_t i = 0; | |
| 64 for (std::map<string16, string16>::const_iterator it = custom_data.begin(); | |
| 65 it != custom_data.end(); | |
| 66 ++it, ++i) { | |
| 67 WebDragData::CustomData data = {it->first, it->second}; | |
| 68 custom_data_vector[i] = data; | |
| 69 } | |
| 70 result.setCustomData(custom_data_vector); | |
| 71 return result; | 126 return result; |
| 72 } | 127 } |
| OLD | NEW |