summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-04 06:19:37 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-04 06:19:37 +0000
commitc6562f4b883b37a288205a206bdadf9a37978bf3 (patch)
tree1a576398bcb2cd32e972449068bc1b66324df84f
parent5d2cded762eacf51f77021b3de61de430f50a9d8 (diff)
downloadchromium_src-c6562f4b883b37a288205a206bdadf9a37978bf3.zip
chromium_src-c6562f4b883b37a288205a206bdadf9a37978bf3.tar.gz
chromium_src-c6562f4b883b37a288205a206bdadf9a37978bf3.tar.bz2
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
-rw-r--r--content/browser/renderer_host/clipboard_message_filter.cc6
-rw-r--r--content/browser/renderer_host/clipboard_message_filter.h3
-rw-r--r--content/common/clipboard_messages.h4
-rw-r--r--content/renderer/renderer_clipboard_client.cc7
-rw-r--r--content/renderer/renderer_clipboard_client.h3
-rw-r--r--ui/base/clipboard/clipboard.h4
-rw-r--r--ui/base/clipboard/clipboard_aurax11.cc7
-rw-r--r--ui/base/clipboard/clipboard_gtk.cc7
-rw-r--r--ui/base/clipboard/clipboard_mac.mm7
-rw-r--r--ui/base/clipboard/clipboard_win.cc7
-rw-r--r--webkit/glue/clipboard_client.h5
-rw-r--r--webkit/glue/webclipboard_impl.cc11
-rw-r--r--webkit/glue/webclipboard_impl.h2
-rw-r--r--webkit/glue/webdropdata.cc17
-rw-r--r--webkit/glue/webdropdata.h3
-rw-r--r--webkit/tools/test_shell/mock_webclipboard_impl.cc24
-rw-r--r--webkit/tools/test_shell/mock_webclipboard_impl.h6
-rw-r--r--webkit/tools/test_shell/simple_clipboard_impl.cc7
-rw-r--r--webkit/tools/test_shell/simple_clipboard_impl.h3
19 files changed, 130 insertions, 3 deletions
diff --git a/content/browser/renderer_host/clipboard_message_filter.cc b/content/browser/renderer_host/clipboard_message_filter.cc
index cd4b6df..1825b34 100644
--- a/content/browser/renderer_host/clipboard_message_filter.cc
+++ b/content/browser/renderer_host/clipboard_message_filter.cc
@@ -62,6 +62,7 @@ bool ClipboardMessageFilter::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadAsciiText, OnReadAsciiText)
IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadHTML, OnReadHTML)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ClipboardHostMsg_ReadImage, OnReadImage)
+ IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadCustomData, OnReadCustomData)
#if defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(ClipboardHostMsg_FindPboardWriteStringAsync,
OnFindPboardWriteString)
@@ -195,6 +196,11 @@ void ClipboardMessageFilter::OnReadImageReply(
Send(reply_msg);
}
+void ClipboardMessageFilter::OnReadCustomData(
+ ui::Clipboard::Buffer buffer, const string16& type, string16* result) {
+ GetClipboard()->ReadCustomData(buffer, type, result);
+}
+
// static
ui::Clipboard* ClipboardMessageFilter::GetClipboard() {
// We have a static instance of the clipboard service for use by all message
diff --git a/content/browser/renderer_host/clipboard_message_filter.h b/content/browser/renderer_host/clipboard_message_filter.h
index b4f24bb..72169e0 100644
--- a/content/browser/renderer_host/clipboard_message_filter.h
+++ b/content/browser/renderer_host/clipboard_message_filter.h
@@ -44,6 +44,9 @@ class ClipboardMessageFilter : public BrowserMessageFilter {
uint32* fragment_start, uint32* fragment_end);
void OnReadImage(ui::Clipboard::Buffer buffer, IPC::Message* reply_msg);
void OnReadImageReply(const SkBitmap& bitmap, IPC::Message* reply_msg);
+ void OnReadCustomData(ui::Clipboard::Buffer buffer,
+ const string16& type,
+ string16* result);
#if defined(OS_MACOSX)
void OnFindPboardWriteString(const string16& text);
#endif
diff --git a/content/common/clipboard_messages.h b/content/common/clipboard_messages.h
index 93e26fe..00497dc 100644
--- a/content/common/clipboard_messages.h
+++ b/content/common/clipboard_messages.h
@@ -55,6 +55,10 @@ IPC_SYNC_MESSAGE_CONTROL1_2(ClipboardHostMsg_ReadImage,
ui::Clipboard::Buffer /* buffer */,
base::SharedMemoryHandle /* PNG-encoded image */,
uint32 /* image size */)
+IPC_SYNC_MESSAGE_CONTROL2_1(ClipboardHostMsg_ReadCustomData,
+ ui::Clipboard::Buffer /* buffer */,
+ string16 /* type */,
+ string16 /* result */)
#if defined(OS_MACOSX)
IPC_MESSAGE_CONTROL1(ClipboardHostMsg_FindPboardWriteStringAsync,
diff --git a/content/renderer/renderer_clipboard_client.cc b/content/renderer/renderer_clipboard_client.cc
index d87d527..87e8b60 100644
--- a/content/renderer/renderer_clipboard_client.cc
+++ b/content/renderer/renderer_clipboard_client.cc
@@ -169,6 +169,13 @@ void RendererClipboardClient::ReadImage(ui::Clipboard::Buffer buffer,
}
}
+void RendererClipboardClient::ReadCustomData(ui::Clipboard::Buffer buffer,
+ const string16& type,
+ string16* data) {
+ RenderThreadImpl::current()->Send(
+ new ClipboardHostMsg_ReadCustomData(buffer, type, data));
+}
+
webkit_glue::ClipboardClient::WriteContext*
RendererClipboardClient::CreateWriteContext() {
return new RendererClipboardWriteContext;
diff --git a/content/renderer/renderer_clipboard_client.h b/content/renderer/renderer_clipboard_client.h
index df0ab07..bf1de96 100644
--- a/content/renderer/renderer_clipboard_client.h
+++ b/content/renderer/renderer_clipboard_client.h
@@ -30,6 +30,9 @@ class RendererClipboardClient : public webkit_glue::ClipboardClient {
uint32* fragment_end) OVERRIDE;
virtual void ReadImage(ui::Clipboard::Buffer buffer,
std::string* data) OVERRIDE;
+ virtual void ReadCustomData(ui::Clipboard::Buffer buffer,
+ const string16& type,
+ string16* data) OVERRIDE;
virtual WriteContext* CreateWriteContext() OVERRIDE;
};
diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h
index 9c010e4..a3e9181 100644
--- a/ui/base/clipboard/clipboard.h
+++ b/ui/base/clipboard/clipboard.h
@@ -156,6 +156,10 @@ class UI_EXPORT Clipboard {
// Reads an image from the clipboard, if available.
SkBitmap ReadImage(Buffer buffer) const;
+ void ReadCustomData(Buffer buffer,
+ const string16& type,
+ string16* result) const;
+
// Reads a bookmark from the clipboard, if available.
void ReadBookmark(string16* title, std::string* url) const;
diff --git a/ui/base/clipboard/clipboard_aurax11.cc b/ui/base/clipboard/clipboard_aurax11.cc
index 793c996..c6fa094 100644
--- a/ui/base/clipboard/clipboard_aurax11.cc
+++ b/ui/base/clipboard/clipboard_aurax11.cc
@@ -240,6 +240,13 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
return image;
}
+void Clipboard::ReadCustomData(Buffer buffer,
+ const string16& type,
+ string16* result) const {
+ // TODO(dcheng): Implement this.
+ NOTIMPLEMENTED();
+}
+
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
*title = UTF8ToUTF16(GetClipboardData()->bookmark_title());
*url = GetClipboardData()->bookmark_url();
diff --git a/ui/base/clipboard/clipboard_gtk.cc b/ui/base/clipboard/clipboard_gtk.cc
index e9af2f3..83f232c 100644
--- a/ui/base/clipboard/clipboard_gtk.cc
+++ b/ui/base/clipboard/clipboard_gtk.cc
@@ -488,6 +488,13 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
return canvas.ExtractBitmap();
}
+void Clipboard::ReadCustomData(Buffer buffer,
+ const string16& type,
+ string16* result) const {
+ // TODO(dcheng): Implement this.
+ NOTIMPLEMENTED();
+}
+
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
// TODO(estade): implement this.
NOTIMPLEMENTED();
diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm
index e97cd81..ebeb907 100644
--- a/ui/base/clipboard/clipboard_mac.mm
+++ b/ui/base/clipboard/clipboard_mac.mm
@@ -284,6 +284,13 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
return canvas.ExtractBitmap();
}
+void Clipboard::ReadCustomData(Buffer buffer,
+ const string16& type,
+ string16* result) const {
+ // TODO(dcheng): Implement this.
+ NOTIMPLEMENTED();
+}
+
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
NSPasteboard* pb = GetPasteboard();
diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc
index a543fe6..a3f050e 100644
--- a/ui/base/clipboard/clipboard_win.cc
+++ b/ui/base/clipboard/clipboard_win.cc
@@ -544,6 +544,13 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
return canvas.ExtractBitmap();
}
+void Clipboard::ReadCustomData(Buffer buffer,
+ const string16& type,
+ string16* result) const {
+ // TODO(dcheng): Implement this.
+ NOTIMPLEMENTED();
+}
+
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
if (title)
title->clear();
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 <utility>
+
#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<WebDragData::CustomData> 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<WebDragData::CustomData> custom_data_vector(custom_data.size());
+ size_t i = 0;
+ 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;
+ }
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 <map>
#include <string>
#include <vector>
@@ -56,6 +57,8 @@ struct WEBKIT_GLUE_EXPORT WebDropData {
string16 file_description_filename;
std::string file_contents;
+ std::map<string16, string16> custom_data;
+
// Convert to a WebDragData object.
WebKit::WebDragData ToDragData() const;
diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.cc b/webkit/tools/test_shell/mock_webclipboard_impl.cc
index d5a00b6..934ebac 100644
--- a/webkit/tools/test_shell/mock_webclipboard_impl.cc
+++ b/webkit/tools/test_shell/mock_webclipboard_impl.cc
@@ -4,6 +4,8 @@
#include "webkit/tools/test_shell/mock_webclipboard_impl.h"
+#include <algorithm>
+
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/string_util.h"
@@ -21,6 +23,7 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
+using WebKit::WebDragData;
using WebKit::WebString;
using WebKit::WebURL;
using WebKit::WebVector;
@@ -75,6 +78,11 @@ WebVector<WebString> MockWebClipboardImpl::readAvailableTypes(
if (!m_image.isNull()) {
results.push_back(WebString("image/png"));
}
+ for (size_t i = 0; i < m_customData.size(); ++i) {
+ CHECK(std::find(results.begin(), results.end(), m_customData[i].type) ==
+ results.end());
+ results.push_back(m_customData[i].type);
+ }
return results;
}
@@ -124,12 +132,24 @@ WebKit::WebData MockWebClipboardImpl::readImage(
return data;
}
+WebKit::WebString MockWebClipboardImpl::readCustomData(
+ WebKit::WebClipboard::Buffer buffer,
+ const WebKit::WebString& type) {
+ for (size_t i = 0; i < m_customData.size(); ++i) {
+ if (m_customData[i].type == type) {
+ return m_customData[i].data;
+ }
+ }
+ return WebKit::WebString();
+}
+
void MockWebClipboardImpl::writeHTML(
const WebKit::WebString& htmlText, const WebKit::WebURL& url,
const WebKit::WebString& plainText, bool writeSmartPaste) {
m_htmlText = htmlText;
m_plainText = plainText;
m_image.reset();
+ m_customData = WebVector<WebDragData::CustomData>();
m_writeSmartPaste = writeSmartPaste;
}
@@ -137,6 +157,7 @@ void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) {
m_htmlText = WebKit::WebString();
m_plainText = plain_text;
m_image.reset();
+ m_customData = WebVector<WebDragData::CustomData>();
m_writeSmartPaste = false;
}
@@ -146,6 +167,7 @@ void MockWebClipboardImpl::writeURL(
webkit_glue::WebClipboardImpl::URLToMarkup(url, title));
m_plainText = url.spec().utf16();
m_image.reset();
+ m_customData = WebVector<WebDragData::CustomData>();
m_writeSmartPaste = false;
}
@@ -156,6 +178,7 @@ void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image,
webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title));
m_plainText = m_htmlText;
m_image = image;
+ m_customData = WebVector<WebDragData::CustomData>();
m_writeSmartPaste = false;
}
}
@@ -164,5 +187,6 @@ void MockWebClipboardImpl::writeDataObject(const WebKit::WebDragData& data) {
m_htmlText = data.htmlText();
m_plainText = data.plainText();
m_image.reset();
+ m_customData = data.customData();
m_writeSmartPaste = false;
}
diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.h b/webkit/tools/test_shell/mock_webclipboard_impl.h
index c80175b..8133089 100644
--- a/webkit/tools/test_shell/mock_webclipboard_impl.h
+++ b/webkit/tools/test_shell/mock_webclipboard_impl.h
@@ -11,6 +11,7 @@
#define WEBKIT_TOOLS_TEST_SHELL_MOCK_WEBCLIPBOARD_IMPL_H_
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebClipboard.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
class MockWebClipboardImpl : public WebKit::WebClipboard {
@@ -28,7 +29,9 @@ class MockWebClipboardImpl : public WebKit::WebClipboard {
WebKit::WebURL* url,
unsigned* fragmentStart,
unsigned* fragmentEnd);
- virtual WebKit::WebData readImage(WebKit::WebClipboard::Buffer);
+ virtual WebKit::WebData readImage(WebKit::WebClipboard::Buffer buffer);
+ virtual WebKit::WebString readCustomData(WebKit::WebClipboard::Buffer buffer,
+ const WebKit::WebString& type);
virtual void writePlainText(const WebKit::WebString& plain_text);
virtual void writeHTML(
@@ -45,6 +48,7 @@ class MockWebClipboardImpl : public WebKit::WebClipboard {
WebKit::WebString m_plainText;
WebKit::WebString m_htmlText;
WebKit::WebImage m_image;
+ WebKit::WebVector<WebKit::WebDragData::CustomData> m_customData;
bool m_writeSmartPaste;
};
diff --git a/webkit/tools/test_shell/simple_clipboard_impl.cc b/webkit/tools/test_shell/simple_clipboard_impl.cc
index 0b137f1c..c7bb959 100644
--- a/webkit/tools/test_shell/simple_clipboard_impl.cc
+++ b/webkit/tools/test_shell/simple_clipboard_impl.cc
@@ -94,8 +94,13 @@ void SimpleClipboardClient::ReadImage(ui::Clipboard::Buffer buffer,
}
}
+void SimpleClipboardClient::ReadCustomData(ui::Clipboard::Buffer buffer,
+ const string16& type,
+ string16* data) {
+ GetClipboard()->ReadCustomData(buffer, type, data);
+}
+
webkit_glue::ClipboardClient::WriteContext*
SimpleClipboardClient::CreateWriteContext() {
return NULL;
}
-
diff --git a/webkit/tools/test_shell/simple_clipboard_impl.h b/webkit/tools/test_shell/simple_clipboard_impl.h
index f572eb3..873adc6 100644
--- a/webkit/tools/test_shell/simple_clipboard_impl.h
+++ b/webkit/tools/test_shell/simple_clipboard_impl.h
@@ -29,6 +29,9 @@ class SimpleClipboardClient : public webkit_glue::ClipboardClient {
uint32* fragment_end) OVERRIDE;
virtual void ReadImage(ui::Clipboard::Buffer buffer,
std::string* data) OVERRIDE;
+ virtual void ReadCustomData(ui::Clipboard::Buffer buffer,
+ const string16& type,
+ string16* data) OVERRIDE;
virtual WriteContext* CreateWriteContext() OVERRIDE;
};