From c6562f4b883b37a288205a206bdadf9a37978bf3 Mon Sep 17 00:00:00 2001 From: "dcheng@chromium.org" Date: Sun, 4 Dec 2011 06:19:37 +0000 Subject: Add glue for supporting custom MIME types in DataTransfer. BUG=31037 TEST=none in this patch, will be landed in WebKit as layout tests. Review URL: http://codereview.chromium.org/8775025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112927 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/clipboard_client.h | 5 +++++ webkit/glue/webclipboard_impl.cc | 11 +++++++++++ webkit/glue/webclipboard_impl.h | 2 ++ webkit/glue/webdropdata.cc | 17 ++++++++++++++++- webkit/glue/webdropdata.h | 3 +++ 5 files changed, 37 insertions(+), 1 deletion(-) (limited to 'webkit/glue') diff --git a/webkit/glue/clipboard_client.h b/webkit/glue/clipboard_client.h index 92e8c88..7fe395d 100644 --- a/webkit/glue/clipboard_client.h +++ b/webkit/glue/clipboard_client.h @@ -59,6 +59,11 @@ class ClipboardClient { // Reads and image from the clipboard, if available. virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data) = 0; + // Reads a custom data type from the clipboard, if available. + virtual void ReadCustomData(ui::Clipboard::Buffer buffer, + const string16& type, + string16* data) = 0; + // Creates a context to write clipboard data. May return NULL. virtual WriteContext* CreateWriteContext() = 0; }; diff --git a/webkit/glue/webclipboard_impl.cc b/webkit/glue/webclipboard_impl.cc index 1f2019b..4f2dd99 100644 --- a/webkit/glue/webclipboard_impl.cc +++ b/webkit/glue/webclipboard_impl.cc @@ -173,6 +173,17 @@ WebData WebClipboardImpl::readImage(Buffer buffer) { return WebData(png_data); } +WebString WebClipboardImpl::readCustomData(Buffer buffer, + const WebString& type) { + ui::Clipboard::Buffer buffer_type; + if (!ConvertBufferType(buffer, &buffer_type)) + return WebString(); + + string16 data; + client_->ReadCustomData(buffer_type, type, &data); + return data; +} + void WebClipboardImpl::writeHTML( const WebString& html_text, const WebURL& source_url, const WebString& plain_text, bool write_smart_paste) { diff --git a/webkit/glue/webclipboard_impl.h b/webkit/glue/webclipboard_impl.h index c3ba604..df72609 100644 --- a/webkit/glue/webclipboard_impl.h +++ b/webkit/glue/webclipboard_impl.h @@ -40,6 +40,8 @@ class WEBKIT_GLUE_EXPORT WebClipboardImpl : unsigned* fragment_start, unsigned* fragment_end); virtual WebKit::WebData readImage(Buffer buffer); + virtual WebKit::WebString readCustomData( + Buffer buffer, const WebKit::WebString& type); virtual void writeHTML( const WebKit::WebString& html_text, const WebKit::WebURL& source_url, diff --git a/webkit/glue/webdropdata.cc b/webkit/glue/webdropdata.cc index dc68365..be45487 100644 --- a/webkit/glue/webdropdata.cc +++ b/webkit/glue/webdropdata.cc @@ -1,9 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "webkit/glue/webdropdata.h" +#include + #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" @@ -33,6 +35,11 @@ WebDropData::WebDropData(const WebDragData& drag_data) WebData contents = drag_data.fileContent(); if (!contents.isEmpty()) file_contents.assign(contents.data(), contents.size()); + WebVector custom_data_copy = drag_data.customData(); + for (size_t i = 0; i < custom_data_copy.size(); ++i) { + custom_data.insert(std::make_pair(custom_data_copy[i].type, + custom_data_copy[i].data)); + } } WebDropData::WebDropData() { @@ -53,5 +60,13 @@ WebDragData WebDropData::ToDragData() const { result.setHTMLBaseURL(html_base_url); result.setFileContentFilename(file_description_filename); result.setFileContent(WebData(file_contents.data(), file_contents.size())); + WebVector custom_data_vector(custom_data.size()); + size_t i = 0; + for (std::map::const_iterator it = custom_data.begin(); + it != custom_data.end(); + ++it, ++i) { + WebDragData::CustomData data = {it->first, it->second}; + custom_data_vector[i] = data; + } return result; } diff --git a/webkit/glue/webdropdata.h b/webkit/glue/webdropdata.h index 8b79a78..82d08f2 100644 --- a/webkit/glue/webdropdata.h +++ b/webkit/glue/webdropdata.h @@ -9,6 +9,7 @@ #ifndef WEBKIT_GLUE_WEBDROPDATA_H_ #define WEBKIT_GLUE_WEBDROPDATA_H_ +#include #include #include @@ -56,6 +57,8 @@ struct WEBKIT_GLUE_EXPORT WebDropData { string16 file_description_filename; std::string file_contents; + std::map custom_data; + // Convert to a WebDragData object. WebKit::WebDragData ToDragData() const; -- cgit v1.1