Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(922)

Unified Diff: webkit/glue/webdropdata.cc

Issue 9318003: Update WebClipboard/WebDropData glue to use new getter/setter for WebDragData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/glue/webdropdata.cc
diff --git a/webkit/glue/webdropdata.cc b/webkit/glue/webdropdata.cc
index bb898fa1c8c793017acbd1fe14703ba3071e0afb..88b02decb70fedbcd776d55e72ab8180abd09a58 100644
--- a/webkit/glue/webdropdata.cc
+++ b/webkit/glue/webdropdata.cc
@@ -6,39 +6,57 @@
#include <utility>
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
+#include "ui/base/clipboard/clipboard.h"
using WebKit::WebData;
using WebKit::WebDragData;
using WebKit::WebString;
using WebKit::WebVector;
-WebDropData::WebDropData(const WebDragData& drag_data)
- : url(drag_data.url()),
- url_title(drag_data.urlTitle()),
- download_metadata(drag_data.downloadMetadata()),
- plain_text(drag_data.plainText()),
- text_html(drag_data.htmlText()),
- html_base_url(drag_data.htmlBaseURL()),
- file_description_filename(drag_data.fileContentFilename()) {
- if (drag_data.containsFilenames()) {
- WebVector<WebString> filenames_copy;
- drag_data.filenames(filenames_copy);
- for (size_t i = 0; i < filenames_copy.size(); ++i)
- filenames.push_back(filenames_copy[i]);
- }
- WebData contents = drag_data.fileContent();
- if (!contents.isEmpty())
- file_contents.assign(contents.data(), contents.size());
- const WebVector<WebDragData::CustomData>& custom_data_alias =
- drag_data.customData();
- for (size_t i = 0; i < custom_data_alias.size(); ++i) {
- custom_data.insert(std::make_pair(custom_data_alias[i].type,
- custom_data_alias[i].data));
+WebDropData::WebDropData(const WebDragData& drag_data) {
+ const WebVector<WebDragData::Item>& item_list = drag_data.itemList();
+ for (size_t i = 0; i < item_list.size(); ++i) {
+ const WebDragData::Item& item = item_list[i];
+ switch (item.storageType) {
+ case WebDragData::Item::STRING: {
+ std::string type = UTF16ToUTF8(item.stringType);
+ 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
+ plain_text = item.stringData;
+ 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.
+ }
+ if (type == ui::Clipboard::kMimeTypeURIList) {
+ url = GURL(item.stringData);
+ url_title = item.title;
+ continue;
+ }
+ if (type == ui::Clipboard::kMimeTypeDownloadURL) {
+ download_metadata = item.stringData;
+ continue;
+ }
+ if (type == ui::Clipboard::kMimeTypeHTML) {
+ text_html = item.stringData;
+ html_base_url = item.baseURL;
+ continue;
+ }
+ custom_data.insert(std::make_pair(item.stringType, item.stringData));
+ continue;
+ }
tony 2012/02/03 20:35:01 bad indent?
dcheng 2012/02/03 21:37:59 Done.
+ case WebDragData::Item::SHARED_BUFFER:
+ file_contents.assign(item.sharedBufferData.data(),
+ item.sharedBufferData.size());
+ file_description_filename = item.title;
+ continue;
+ case WebDragData::Item::FILENAME:
+ // We don't currently use this.
+ NOTREACHED();
+ };
}
}
@@ -49,24 +67,61 @@ WebDropData::~WebDropData() {
}
WebDragData WebDropData::ToDragData() const {
- WebDragData result;
- result.initialize();
- result.setURL(url);
- result.setURLTitle(url_title);
- result.setFilenames(filenames);
- result.setPlainText(plain_text);
- result.setHTMLText(text_html);
- result.setHTMLBaseURL(html_base_url);
- result.setFileContentFilename(file_description_filename);
- result.setFileContent(WebData(file_contents.data(), file_contents.size()));
- WebVector<WebDragData::CustomData> custom_data_vector(custom_data.size());
- size_t i = 0;
+ std::vector<WebDragData::Item> item_list;
+
+ // These fields are currently unused when dragging into WebKit.
+ DCHECK(download_metadata.empty());
+ DCHECK(file_contents.empty());
+ DCHECK(file_description_filename.empty());
+
+ // TODO(dcheng): We need a way to distinguish between null and empty strings.
+ if (!plain_text.empty()) {
+ WebDragData::Item item;
+ item.storageType = WebDragData::Item::STRING;
+ item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
+ item.stringData = plain_text;
+ item_list.push_back(item);
+ }
+
+ if (!url.is_empty()) {
+ WebDragData::Item item;
+ item.storageType = WebDragData::Item::STRING;
+ item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
+ item.stringData = WebString::fromUTF8(url.spec());
+ item.title = url_title;
+ item_list.push_back(item);
+ }
+
+ if (!text_html.empty()) {
+ WebDragData::Item item;
+ item.storageType = WebDragData::Item::STRING;
+ item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
+ item.stringData = text_html;
+ item.baseURL = html_base_url;
+ item_list.push_back(item);
+ }
+
+ for (std::vector<string16>::const_iterator it = filenames.begin();
+ it != filenames.end();
+ ++it) {
+ WebDragData::Item item;
+ item.storageType = WebDragData::Item::FILENAME;
+ item.filenameData = *it;
+ item_list.push_back(item);
+ }
+
for (std::map<string16, string16>::const_iterator it = custom_data.begin();
it != custom_data.end();
- ++it, ++i) {
- WebDragData::CustomData data = {it->first, it->second};
- custom_data_vector[i] = data;
+ ++it) {
+ WebDragData::Item item;
+ item.storageType = WebDragData::Item::STRING;
+ item.stringType = it->first;
+ item.stringData = it->second;
+ item_list.push_back(item);
}
- result.setCustomData(custom_data_vector);
+
+ WebDragData result;
+ result.initialize();
+ result.setItemList(item_list);
return result;
}

Powered by Google App Engine
This is Rietveld 408576698