Commit c6562f4b authored by dcheng@chromium.org's avatar dcheng@chromium.org

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
parent 5d2cded7
......@@ -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
......
......@@ -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
......
......@@ -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,
......
......@@ -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;
......
......@@ -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;
};
......
......@@ -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;
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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;
};
......
......@@ -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) {
......
......@@ -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,
......
// 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;
}
......@@ -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;
......
......@@ -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;
}
......@@ -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;
};
......
......@@ -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;
}
......@@ -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;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment