Commit 0de5d860 authored by piman@chromium.org's avatar piman@chromium.org

Move clipboard-related webkit_glue embedder functions into a ClipboardClient interface.

This moves the functions into a pattern that is component-friendly.

BUG=98755
TEST=Chrome, DRT, test_shell

Review URL: http://codereview.chromium.org/8591030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111097 0039d316-1c4b-4281-b951-d872f2087c98
parent 66d22164
......@@ -142,6 +142,8 @@
'renderer/render_widget_fullscreen_pepper.h',
'renderer/renderer_accessibility.cc',
'renderer/renderer_accessibility.h',
'renderer/renderer_clipboard_client.cc',
'renderer/renderer_clipboard_client.h',
'renderer/renderer_glue.cc',
'renderer/renderer_main.cc',
'renderer/renderer_main_platform_delegate.h',
......
// 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.
// This file provides the embedder's side of random webkit glue functions.
#include "content/renderer/renderer_clipboard_client.h"
#include "build/build_config.h"
#include <string>
#include <vector>
#include "base/shared_memory.h"
#include "base/string16.h"
#include "content/common/clipboard_messages.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/render_thread_impl.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/gfx/size.h"
#include "webkit/glue/scoped_clipboard_writer_glue.h"
namespace {
class RendererClipboardWriteContext :
public webkit_glue::ClipboardClient::WriteContext {
public:
RendererClipboardWriteContext();
virtual ~RendererClipboardWriteContext();
virtual void WriteBitmapFromPixels(ui::Clipboard::ObjectMap* objects,
const void* pixels,
const gfx::Size& size);
virtual void FlushAndDestroy(const ui::Clipboard::ObjectMap& objects);
private:
scoped_ptr<base::SharedMemory> shared_buf_;
DISALLOW_COPY_AND_ASSIGN(RendererClipboardWriteContext);
};
RendererClipboardWriteContext::RendererClipboardWriteContext() {
}
RendererClipboardWriteContext::~RendererClipboardWriteContext() {
}
// This definition of WriteBitmapFromPixels uses shared memory to communicate
// across processes.
void RendererClipboardWriteContext::WriteBitmapFromPixels(
ui::Clipboard::ObjectMap* objects,
const void* pixels,
const gfx::Size& size) {
// Do not try to write a bitmap more than once
if (shared_buf_.get())
return;
uint32 buf_size = 4 * size.width() * size.height();
// Allocate a shared memory buffer to hold the bitmap bits.
shared_buf_.reset(ChildThread::current()->AllocateSharedMemory(buf_size));
if (!shared_buf_.get())
return;
// Copy the bits into shared memory
DCHECK(shared_buf_->memory());
memcpy(shared_buf_->memory(), pixels, buf_size);
shared_buf_->Unmap();
ui::Clipboard::ObjectMapParam size_param;
const char* size_data = reinterpret_cast<const char*>(&size);
for (size_t i = 0; i < sizeof(gfx::Size); ++i)
size_param.push_back(size_data[i]);
ui::Clipboard::ObjectMapParams params;
// The first parameter is replaced on the receiving end with a pointer to
// a shared memory object containing the bitmap. We reserve space for it here.
ui::Clipboard::ObjectMapParam place_holder_param;
params.push_back(place_holder_param);
params.push_back(size_param);
(*objects)[ui::Clipboard::CBF_SMBITMAP] = params;
}
// Define a destructor that makes IPCs to flush the contents to the
// system clipboard.
void RendererClipboardWriteContext::FlushAndDestroy(
const ui::Clipboard::ObjectMap& objects) {
scoped_ptr<RendererClipboardWriteContext> delete_on_return(this);
if (objects.empty())
return;
if (shared_buf_.get()) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_WriteObjectsSync(objects, shared_buf_->handle()));
} else {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_WriteObjectsAsync(objects));
}
}
} // anonymous namespace
RendererClipboardClient::RendererClipboardClient() {
}
RendererClipboardClient::~RendererClipboardClient() {
}
ui::Clipboard* RendererClipboardClient::GetClipboard() {
return NULL;
}
uint64 RendererClipboardClient::GetSequenceNumber(
ui::Clipboard::Buffer buffer) {
uint64 sequence_number = 0;
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_GetSequenceNumber(buffer,
&sequence_number));
return sequence_number;
}
bool RendererClipboardClient::IsFormatAvailable(
const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer) {
bool result;
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_IsFormatAvailable(format, buffer, &result));
return result;
}
void RendererClipboardClient::ReadAvailableTypes(
ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames) {
RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadAvailableTypes(
buffer, types, contains_filenames));
}
void RendererClipboardClient::ReadText(ui::Clipboard::Buffer buffer,
string16* result) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadText(buffer, result));
}
void RendererClipboardClient::ReadAsciiText(ui::Clipboard::Buffer buffer,
std::string* result) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadAsciiText(buffer, result));
}
void RendererClipboardClient::ReadHTML(ui::Clipboard::Buffer buffer,
string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadHTML(buffer, markup, url, fragment_start,
fragment_end));
}
void RendererClipboardClient::ReadImage(ui::Clipboard::Buffer buffer,
std::string* data) {
base::SharedMemoryHandle image_handle;
uint32 image_size;
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadImage(buffer, &image_handle, &image_size));
if (base::SharedMemory::IsHandleValid(image_handle)) {
base::SharedMemory buffer(image_handle, true);
buffer.Map(image_size);
data->append(static_cast<char*>(buffer.memory()), image_size);
}
}
webkit_glue::ClipboardClient::WriteContext*
RendererClipboardClient::CreateWriteContext() {
return new RendererClipboardWriteContext;
}
// 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.
#ifndef CONTENT_RENDERER_RENDERER_CLIPBOARD_CLIENT_H_
#define CONTENT_RENDERER_RENDERER_CLIPBOARD_CLIENT_H_
#include "webkit/glue/clipboard_client.h"
// An implementation of ClipboardClient that gets and sends data over IPC.
class RendererClipboardClient : public webkit_glue::ClipboardClient {
public:
RendererClipboardClient();
virtual ~RendererClipboardClient();
virtual ui::Clipboard* GetClipboard();
virtual uint64 GetSequenceNumber(ui::Clipboard::Buffer buffer);
virtual bool IsFormatAvailable(const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer);
virtual void ReadAvailableTypes(ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames);
virtual void ReadText(ui::Clipboard::Buffer buffer, string16* result);
virtual void ReadAsciiText(ui::Clipboard::Buffer buffer,
std::string* result);
virtual void ReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end);
virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data);
virtual WriteContext* CreateWriteContext();
};
#endif // CONTENT_RENDERER_RENDERER_CLIPBOARD_CLIENT_H_
......@@ -6,149 +6,21 @@
#include "build/build_config.h"
#if defined(OS_WIN)
#include <windows.h>
#endif
#include <vector>
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
#include "content/common/clipboard_messages.h"
#include "content/common/npobject_util.h"
#include "base/string16.h"
#include "base/string_piece.h"
#include "content/common/socket_stream_dispatcher.h"
#include "content/common/view_messages.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/render_thread_impl.h"
#include "googleurl/src/url_util.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKitPlatformSupport.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/ui_base_switches.h"
#include "webkit/glue/scoped_clipboard_writer_glue.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/websocketstreamhandle_bridge.h"
// This definition of WriteBitmapFromPixels uses shared memory to communicate
// across processes.
void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels,
const gfx::Size& size) {
// Do not try to write a bitmap more than once
if (shared_buf_)
return;
uint32 buf_size = 4 * size.width() * size.height();
// Allocate a shared memory buffer to hold the bitmap bits.
shared_buf_ = ChildThread::current()->AllocateSharedMemory(buf_size);
if (!shared_buf_)
return;
// Copy the bits into shared memory
DCHECK(shared_buf_->memory());
memcpy(shared_buf_->memory(), pixels, buf_size);
shared_buf_->Unmap();
ui::Clipboard::ObjectMapParam size_param;
const char* size_data = reinterpret_cast<const char*>(&size);
for (size_t i = 0; i < sizeof(gfx::Size); ++i)
size_param.push_back(size_data[i]);
ui::Clipboard::ObjectMapParams params;
// The first parameter is replaced on the receiving end with a pointer to
// a shared memory object containing the bitmap. We reserve space for it here.
ui::Clipboard::ObjectMapParam place_holder_param;
params.push_back(place_holder_param);
params.push_back(size_param);
objects_[ui::Clipboard::CBF_SMBITMAP] = params;
}
// Define a destructor that makes IPCs to flush the contents to the
// system clipboard.
ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
if (objects_.empty())
return;
if (shared_buf_) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_WriteObjectsSync(objects_,
shared_buf_->handle()));
delete shared_buf_;
return;
}
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_WriteObjectsAsync(objects_));
}
namespace webkit_glue {
// Clipboard glue
ui::Clipboard* ClipboardGetClipboard() {
return NULL;
}
uint64 ClipboardGetSequenceNumber(ui::Clipboard::Buffer buffer) {
uint64 sequence_number = 0;
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_GetSequenceNumber(buffer,
&sequence_number));
return sequence_number;
}
bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer) {
bool result;
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_IsFormatAvailable(format, buffer, &result));
return result;
}
void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames) {
RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadAvailableTypes(
buffer, types, contains_filenames));
}
void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadText(buffer, result));
}
void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadAsciiText(buffer, result));
}
void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end) {
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadHTML(buffer, markup, url, fragment_start,
fragment_end));
}
void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) {
base::SharedMemoryHandle image_handle;
uint32 image_size;
RenderThreadImpl::current()->Send(
new ClipboardHostMsg_ReadImage(buffer, &image_handle, &image_size));
if (base::SharedMemory::IsHandleValid(image_handle)) {
base::SharedMemory buffer(image_handle, true);
buffer.Map(image_size);
data->append(static_cast<char*>(buffer.memory()), image_size);
}
}
void GetPlugins(bool refresh,
std::vector<webkit::WebPluginInfo>* plugins) {
if (!RenderThreadImpl::current()->plugin_refresh_allowed())
......
......@@ -24,6 +24,7 @@
#include "content/renderer/media/audio_device.h"
#include "content/renderer/media/audio_hardware.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/renderer_clipboard_client.h"
#include "content/renderer/renderer_webaudiodevice_impl.h"
#include "content/renderer/renderer_webidbfactory_impl.h"
#include "content/renderer/renderer_webstoragenamespace_impl.h"
......@@ -143,7 +144,8 @@ class RendererWebKitPlatformSupportImpl::SandboxSupport
//------------------------------------------------------------------------------
RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl()
: clipboard_(new webkit_glue::WebClipboardImpl),
: clipboard_client_(new RendererClipboardClient),
clipboard_(new webkit_glue::WebClipboardImpl(clipboard_client_.get())),
mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry),
sandbox_support_(new RendererWebKitPlatformSupportImpl::SandboxSupport),
sudden_termination_disables_(0),
......
......@@ -12,6 +12,7 @@
#include "content/common/content_export.h"
#include "webkit/glue/webkitplatformsupport_impl.h"
class RendererClipboardClient;
class WebSharedWorkerRepositoryImpl;
class WebFileSystemImpl;
......@@ -95,6 +96,7 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
// Helper function to send synchronous message from any thread.
static bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg);
scoped_ptr<RendererClipboardClient> clipboard_client_;
scoped_ptr<webkit_glue::WebClipboardImpl> clipboard_;
class FileUtilities;
......
......@@ -88,7 +88,7 @@ void ScopedClipboardWriter::WriteWebSmartPaste() {
void ScopedClipboardWriter::WriteBitmapFromPixels(const void* pixels,
const gfx::Size& size) {
Clipboard::ObjectMapParam pixels_parameter, size_parameter;
const char* pixels_data = reinterpret_cast<const char*>(pixels);
const char* pixels_data = static_cast<const char*>(pixels);
size_t pixels_length = 4 * size.width() * size.height();
for (size_t i = 0; i < pixels_length; i++)
pixels_parameter.push_back(pixels_data[i]);
......
// 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.
#ifndef WEBKIT_GLUE_CLIPBOARD_CLIENT_H_
#define WEBKIT_GLUE_CLIPBOARD_CLIENT_H_
#include "ui/base/clipboard/clipboard.h"
class GURL;
namespace webkit_glue {
// Interface for the webkit glue embedder to implement to support clipboard.
class ClipboardClient {
public:
class WriteContext {
public:
virtual ~WriteContext() { }
// Writes bitmap data into the context, updating the ObjectMap.
virtual void WriteBitmapFromPixels(ui::Clipboard::ObjectMap* objects,
const void* pixels,
const gfx::Size& size) = 0;
// Flushes all gathered data, and destroys the context.
virtual void FlushAndDestroy(const ui::Clipboard::ObjectMap& objects) = 0;
};
virtual ~ClipboardClient() { }
// Get a clipboard that can be used to construct a ScopedClipboardWriterGlue.
virtual ui::Clipboard* GetClipboard() = 0;
// Get a sequence number which uniquely identifies clipboard state.
virtual uint64 GetSequenceNumber(ui::Clipboard::Buffer buffer) = 0;
// Tests whether the clipboard contains a certain format
virtual bool IsFormatAvailable(const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer) = 0;
// Reads the available types from the clipboard, if available.
virtual void ReadAvailableTypes(ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames) = 0;
// Reads UNICODE text from the clipboard, if available.
virtual void ReadText(ui::Clipboard::Buffer buffer, string16* result) = 0;
// Reads ASCII text from the clipboard, if available.
virtual void ReadAsciiText(ui::Clipboard::Buffer buffer,
std::string* result) = 0;
// Reads HTML from the clipboard, if available.
virtual void ReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end) = 0;
// Reads and image from the clipboard, if available.
virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data) = 0;
// Creates a context to write clipboard data. May return NULL.
virtual WriteContext* CreateWriteContext() = 0;
};
} // namespace webkit_glue
#endif // WEBKIT_GLUE_CLIPBOARD_CLIENT_H_
// 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/scoped_clipboard_writer_glue.h"
ScopedClipboardWriterGlue::ScopedClipboardWriterGlue(
webkit_glue::ClipboardClient* client)
: ui::ScopedClipboardWriter(client->GetClipboard()),
context_(client->CreateWriteContext()) {
}
ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
if (context_)
context_->FlushAndDestroy(objects_);
}
void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels,
const gfx::Size& size) {
if (context_) {
context_->WriteBitmapFromPixels(&objects_, pixels, size);
} else {
ScopedClipboardWriter::WriteBitmapFromPixels(pixels, size);
}
}
......@@ -6,24 +6,18 @@
#define WEBKIT_GLUE_SCOPED_CLIPBOARD_WRITER_GLUE_H_
#include "ui/base/clipboard/scoped_clipboard_writer.h"
namespace base {
class SharedMemory;
}
#include "webkit/glue/clipboard_client.h"
class ScopedClipboardWriterGlue : public ui::ScopedClipboardWriter {
public:
explicit ScopedClipboardWriterGlue(ui::Clipboard* clipboard)
: ui::ScopedClipboardWriter(clipboard),
shared_buf_(NULL) {
}
explicit ScopedClipboardWriterGlue(webkit_glue::ClipboardClient* client);
~ScopedClipboardWriterGlue();
void WriteBitmapFromPixels(const void* pixels, const gfx::Size& size);
private:
base::SharedMemory* shared_buf_;
webkit_glue::ClipboardClient::WriteContext* context_;
DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriterGlue);
};
......
......@@ -62,6 +62,10 @@ std::string WebClipboardImpl::URLToImageMarkup(const WebURL& url,
return markup;
}
WebClipboardImpl::WebClipboardImpl(ClipboardClient* client)
: client_(client) {
}
WebClipboardImpl::~WebClipboardImpl() {
}
......@@ -74,7 +78,7 @@ uint64 WebClipboardImpl::sequenceNumber(Buffer buffer) {
if (!ConvertBufferType(buffer, &buffer_type))
return 0;
return ClipboardGetSequenceNumber(buffer_type);
return client_->GetSequenceNumber(buffer_type);
}
bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) {
......@@ -86,9 +90,9 @@ bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) {
switch (format) {
case FormatPlainText:
return ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
return client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
buffer_type) ||
ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
buffer_type);
case FormatHTML:
format_type = ui::Clipboard::GetHtmlFormatType();
......@@ -106,7 +110,7 @@ bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) {
return false;
}
return ClipboardIsFormatAvailable(format_type, buffer_type);
return client_->IsFormatAvailable(format_type, buffer_type);
}
WebVector<WebString> WebClipboardImpl::readAvailableTypes(
......@@ -114,7 +118,7 @@ WebVector<WebString> WebClipboardImpl::readAvailableTypes(
ui::Clipboard::Buffer buffer_type;
std::vector<string16> types;
if (ConvertBufferType(buffer, &buffer_type)) {
ClipboardReadAvailableTypes(buffer_type, &types, contains_filenames);
client_->ReadAvailableTypes(buffer_type, &types, contains_filenames);
}
return types;
}
......@@ -124,18 +128,18 @@ WebString WebClipboardImpl::readPlainText(Buffer buffer) {
if (!ConvertBufferType(buffer, &buffer_type))
return WebString();
if (ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
buffer_type)) {
string16 text;
ClipboardReadText(buffer_type, &text);
client_->ReadText(buffer_type, &text);
if (!text.empty())
return text;
}
if (ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
buffer_type)) {
std::string text;
ClipboardReadAsciiText(buffer_type, &text);
client_->ReadAsciiText(buffer_type, &text);
if (!text.empty())
return ASCIIToUTF16(text);
}
......@@ -152,7 +156,7 @@ WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url,
string16 html_stdstr;
GURL gurl;
ClipboardReadHTML(buffer_type, &html_stdstr, &gurl,
client_->ReadHTML(buffer_type, &html_stdstr, &gurl,
static_cast<uint32*>(fragment_start),
static_cast<uint32*>(fragment_end));
*source_url = gurl;
......@@ -165,14 +169,14 @@ WebData WebClipboardImpl::readImage(Buffer buffer) {
return WebData();
std::string png_data;
ClipboardReadImage(buffer_type, &png_data);
client_->ReadImage(buffer_type, &png_data);
return WebData(png_data);
}
void WebClipboardImpl::writeHTML(
const WebString& html_text, const WebURL& source_url,
const WebString& plain_text, bool write_smart_paste) {
ScopedClipboardWriterGlue scw(ClipboardGetClipboard());
ScopedClipboardWriterGlue scw(client_);
scw.WriteHTML(html_text, source_url.spec());
scw.WriteText(plain_text);
......@@ -181,12 +185,12 @@ void WebClipboardImpl::writeHTML(
}
void WebClipboardImpl::writePlainText(const WebString& plain_text) {
ScopedClipboardWriterGlue scw(ClipboardGetClipboard());
ScopedClipboardWriterGlue scw(client_);
scw.WriteText(plain_text);
}
void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) {
ScopedClipboardWriterGlue scw(ClipboardGetClipboard());
ScopedClipboardWriterGlue scw(client_);
scw.WriteBookmark(title, url.spec());
scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), "");
......@@ -195,7 +199,7 @@ void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) {
void WebClipboardImpl::writeImage(
const WebImage& image, const WebURL& url, const WebString& title) {
ScopedClipboardWriterGlue scw(ClipboardGetClipboard());
ScopedClipboardWriterGlue scw(client_);
if (!image.isNull()) {
#if WEBKIT_USING_SKIA
......@@ -226,7 +230,7 @@ void WebClipboardImpl::writeDataObject(const WebDragData& data) {
// TODO(dcheng): This actually results in a double clear of the clipboard.
// Once in WebKit, and once here when the clipboard writer goes out of scope.
// The same is true of the other WebClipboard::write* methods.
ScopedClipboardWriterGlue scw(ClipboardGetClipboard());
ScopedClipboardWriterGlue scw(client_);
// TODO(dcheng): Properly support text/uri-list here.
scw.WriteText(data.plainText());
......
......@@ -11,6 +11,7 @@
#include <string>
namespace webkit_glue {
class ClipboardClient;
class WebClipboardImpl : public WebKit::WebClipboard {
public:
......@@ -19,6 +20,8 @@ class WebClipboardImpl : public WebKit::WebClipboard {
static std::string URLToImageMarkup(const WebKit::WebURL& url,
const WebKit::WebString& title);
explicit WebClipboardImpl(ClipboardClient* client);
virtual ~WebClipboardImpl();
// WebClipboard methods:
......@@ -51,6 +54,7 @@ class WebClipboardImpl : public WebKit::WebClipboard {
private:
bool ConvertBufferType(Buffer, ui::Clipboard::Buffer*);
ClipboardClient* client_;
};
} // namespace webkit_glue
......
......@@ -373,6 +373,7 @@
'resource_loader_bridge.h',
'resource_type.cc',
'resource_type.h',
'scoped_clipboard_writer_glue.cc',
'scoped_clipboard_writer_glue.h',
'simple_webmimeregistry_impl.cc',
'simple_webmimeregistry_impl.h',
......
......@@ -19,7 +19,6 @@
#include "base/string16.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h"
#include "ui/base/clipboard/clipboard.h"
class GURL;
class SkBitmap;
......@@ -167,47 +166,10 @@ string16 GetLocalizedString(int message_id);
// specified as BINDATA in the relevant .rc file.
base::StringPiece GetDataResource(int resource_id);
// Glue to access the clipboard.
// Get a clipboard that can be used to construct a ScopedClipboardWriterGlue.
ui::Clipboard* ClipboardGetClipboard();
// Get a sequence number which uniquely identifies clipboard state.
uint64 ClipboardGetSequenceNumber(ui::Clipboard::Buffer buffer);
// Tests whether the clipboard contains a certain format
bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer);
// Reads the available types from the clipboard, if available.
void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames);
// Reads UNICODE text from the clipboard, if available.
void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result);
// Reads ASCII text from the clipboard, if available.
void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result);
// Reads HTML from the clipboard, if available.
void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end);
void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data);
// Embedders implement this function to return the list of plugins to Webkit.
void GetPlugins(bool refresh,
std::vector<webkit::WebPluginInfo>* plugins);
// Returns the locale that this instance of webkit is running as. This is of
// the form language-country (e.g., en-US or pt-BR).
std::string GetWebKitLocale();
// Returns true if the embedder is running in single process mode.
bool IsSingleProcess();
// ---- END FUNCTIONS IMPLEMENTED BY EMBEDDER ---------------------------------
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_clipboard_impl.h"
#include <string>
......@@ -15,62 +15,66 @@
#include "ui/base/clipboard/clipboard.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/size.h"
#include "webkit/glue/scoped_clipboard_writer_glue.h"
#include "webkit/glue/webkit_glue.h"
// Clipboard glue
namespace {
void ScopedClipboardWriterGlue::WriteBitmapFromPixels(
const void* pixels, const gfx::Size& size) {
ScopedClipboardWriter::WriteBitmapFromPixels(pixels, size);
}
base::LazyInstance<ui::Clipboard> clipboard = LAZY_INSTANCE_INITIALIZER;
} // anonymous namespace
ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
SimpleClipboardClient::SimpleClipboardClient() {
}
namespace webkit_glue {
SimpleClipboardClient::~SimpleClipboardClient() {
}
base::LazyInstance<ui::Clipboard> clipboard = LAZY_INSTANCE_INITIALIZER;
ui::Clipboard* ClipboardGetClipboard() {
ui::Clipboard* SimpleClipboardClient::GetClipboard() {
return clipboard.Pointer();
}
uint64 ClipboardGetSequenceNumber(ui::Clipboard::Buffer buffer) {
return ClipboardGetClipboard()->GetSequenceNumber(buffer);
uint64 SimpleClipboardClient::GetSequenceNumber(ui::Clipboard::Buffer buffer) {
return GetClipboard()->GetSequenceNumber(buffer);
}
bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer) {
return ClipboardGetClipboard()->IsFormatAvailable(format, buffer);
bool SimpleClipboardClient::IsFormatAvailable(
const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer) {
return GetClipboard()->IsFormatAvailable(format, buffer);
}
void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames) {
return ClipboardGetClipboard()->ReadAvailableTypes(buffer, types,
void SimpleClipboardClient::ReadAvailableTypes(ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames) {
return GetClipboard()->ReadAvailableTypes(buffer, types,
contains_filenames);
}
void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result) {
ClipboardGetClipboard()->ReadText(buffer, result);
void SimpleClipboardClient::ReadText(ui::Clipboard::Buffer buffer,
string16* result) {
GetClipboard()->ReadText(buffer, result);
}
void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result) {
ClipboardGetClipboard()->ReadAsciiText(buffer, result);
void SimpleClipboardClient::ReadAsciiText(ui::Clipboard::Buffer buffer,
std::string* result) {
GetClipboard()->ReadAsciiText(buffer, result);
}
void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end) {
void SimpleClipboardClient::ReadHTML(ui::Clipboard::Buffer buffer,
string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end) {
std::string url_str;
ClipboardGetClipboard()->ReadHTML(buffer, markup, url ? &url_str : NULL,
fragment_start, fragment_end);
GetClipboard()->ReadHTML(buffer, markup, url ? &url_str : NULL,
fragment_start, fragment_end);
if (url)
*url = GURL(url_str);
}
void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) {
SkBitmap bitmap = ClipboardGetClipboard()->ReadImage(buffer);
void SimpleClipboardClient::ReadImage(ui::Clipboard::Buffer buffer,
std::string* data) {
SkBitmap bitmap = GetClipboard()->ReadImage(buffer);
if (bitmap.isNull())
return;
......@@ -90,4 +94,8 @@ void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) {
}
}
} // namespace webkit_glue
webkit_glue::ClipboardClient::WriteContext*
SimpleClipboardClient::CreateWriteContext() {
return NULL;
}
// 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.
#ifndef WEBKIT_TOOLS_TEST_SHELL_SIMPLE_CLIPBOARD_IMPL_H_
#define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_CLIPBOARD_IMPL_H_
#include "webkit/glue/clipboard_client.h"
class SimpleClipboardClient : public webkit_glue::ClipboardClient {
public:
SimpleClipboardClient();
virtual ~SimpleClipboardClient();
virtual ui::Clipboard* GetClipboard();
virtual uint64 GetSequenceNumber(ui::Clipboard::Buffer buffer);
virtual bool IsFormatAvailable(const ui::Clipboard::FormatType& format,
ui::Clipboard::Buffer buffer);
virtual void ReadAvailableTypes(ui::Clipboard::Buffer buffer,
std::vector<string16>* types,
bool* contains_filenames);
virtual void ReadText(ui::Clipboard::Buffer buffer, string16* result);
virtual void ReadAsciiText(ui::Clipboard::Buffer buffer,
std::string* result);
virtual void ReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
GURL* url, uint32* fragment_start,
uint32* fragment_end);
virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data);
virtual WriteContext* CreateWriteContext();
};
#endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_CLIPBOARD_IMPL_H_
......@@ -21,7 +21,8 @@
#include "webkit/tools/test_shell/test_shell_webthemeengine.h"
#endif
TestShellWebKitInit::TestShellWebKitInit(bool layout_test_mode) {
TestShellWebKitInit::TestShellWebKitInit(bool layout_test_mode)
: real_clipboard_(&clipboard_client_) {
v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
WebKit::initialize(this);
......
......@@ -19,6 +19,7 @@
#include "webkit/support/simple_database_system.h"
#include "webkit/tools/test_shell/mock_webclipboard_impl.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_clipboard_impl.h"
#include "webkit/tools/test_shell/simple_file_system.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/simple_webcookiejar_impl.h"
......@@ -107,6 +108,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitPlatformSupportImpl {
private:
scoped_ptr<webkit_glue::SimpleWebMimeRegistryImpl> mime_registry_;
MockWebClipboardImpl mock_clipboard_;
SimpleClipboardClient clipboard_client_;
webkit_glue::WebClipboardImpl real_clipboard_;
webkit_glue::WebFileUtilitiesImpl file_utilities_;
ScopedTempDir appcache_dir_;
......
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