Index: content/renderer/renderer_clipboard_client.cc |
diff --git a/content/renderer/renderer_clipboard_client.cc b/content/renderer/renderer_clipboard_client.cc |
index 81f5cae07bd6ce73770967d066286cdedd876d83..2acc5d83aa96bb081d0e38be2f352d7502e42ad8 100644 |
--- a/content/renderer/renderer_clipboard_client.cc |
+++ b/content/renderer/renderer_clipboard_client.cc |
@@ -8,105 +8,18 @@ |
#include "base/memory/shared_memory.h" |
#include "base/numerics/safe_math.h" |
-#include "base/strings/string16.h" |
#include "content/common/clipboard_messages.h" |
#include "content/public/renderer/content_renderer_client.h" |
#include "content/renderer/render_thread_impl.h" |
-#include "content/renderer/scoped_clipboard_writer_glue.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/base/clipboard/clipboard.h" |
#include "ui/gfx/size.h" |
namespace content { |
-namespace { |
- |
-class RendererClipboardWriteContext : public ClipboardClient::WriteContext { |
- public: |
- RendererClipboardWriteContext(); |
- virtual ~RendererClipboardWriteContext(); |
- virtual void WriteBitmapFromPixels(ui::Clipboard::ObjectMap* objects, |
- const void* pixels, |
- const gfx::Size& size) OVERRIDE; |
- virtual void Flush(const ui::Clipboard::ObjectMap& objects) OVERRIDE; |
- |
- 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_) |
- return; |
- |
- base::CheckedNumeric<uint32> checked_buf_size = 4; |
- checked_buf_size *= size.width(); |
- checked_buf_size *= size.height(); |
- if (!checked_buf_size.IsValid()) |
- return; |
- |
- uint32 buf_size = checked_buf_size.ValueOrDie(); |
- |
- // Allocate a shared memory buffer to hold the bitmap bits. |
- shared_buf_.reset(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; |
-} |
- |
-// Flushes the objects to the clipboard with an IPC. |
-void RendererClipboardWriteContext::Flush( |
- const ui::Clipboard::ObjectMap& objects) { |
- if (shared_buf_) { |
- 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::ClipboardType type) { |
uint64 sequence_number = 0; |
RenderThreadImpl::current()->Send( |
@@ -173,8 +86,78 @@ void RendererClipboardClient::ReadCustomData(ui::ClipboardType clipboard_type, |
new ClipboardHostMsg_ReadCustomData(clipboard_type, type, data)); |
} |
-ClipboardClient::WriteContext* RendererClipboardClient::CreateWriteContext() { |
- return new RendererClipboardWriteContext; |
+void RendererClipboardClient::WriteText(ui::ClipboardType clipboard_type, |
+ const base::string16& text) { |
+ RenderThreadImpl::current()->Send( |
+ new ClipboardHostMsg_WriteText(clipboard_type, text)); |
+} |
+ |
+void RendererClipboardClient::WriteHTML(ui::ClipboardType clipboard_type, |
+ const base::string16& markup, |
+ const GURL& url) { |
+ RenderThreadImpl::current()->Send( |
+ new ClipboardHostMsg_WriteHTML(clipboard_type, markup, url)); |
+} |
+ |
+void RendererClipboardClient::WriteSmartPasteMarker( |
+ ui::ClipboardType clipboard_type) { |
+ RenderThreadImpl::current()->Send( |
+ new ClipboardHostMsg_WriteSmartPasteMarker(clipboard_type)); |
+} |
+ |
+void RendererClipboardClient::WriteCustomData( |
+ ui::ClipboardType clipboard_type, |
+ const std::map<base::string16, base::string16>& data) { |
+ RenderThreadImpl::current()->Send( |
+ new ClipboardHostMsg_WriteCustomData(clipboard_type, data)); |
+} |
+ |
+void RendererClipboardClient::WriteBookmark(ui::ClipboardType clipboard_type, |
+ const GURL& url, |
+ const base::string16& title) { |
+ RenderThreadImpl::current()->Send( |
+ new ClipboardHostMsg_WriteBookmark(clipboard_type, url, title)); |
+} |
+ |
+bool RendererClipboardClient::WriteImage(ui::ClipboardType clipboard_type, |
+ const SkBitmap& bitmap) { |
+ // Only 32-bit bitmaps are supported. |
+ DCHECK_EQ(bitmap.colorType(), kN32_SkColorType); |
+ |
+ const gfx::Size size(bitmap.width(), bitmap.height()); |
+ scoped_ptr<base::SharedMemory> shared_buf; |
+ { |
+ SkAutoLockPixels locked(bitmap); |
+ void* pixels = bitmap.getPixels(); |
+ // TODO(piman): this should not be NULL, but it is. crbug.com/369621 |
+ if (!pixels) |
+ return false; |
+ |
+ base::CheckedNumeric<uint32> checked_buf_size = 4; |
+ checked_buf_size *= size.width(); |
+ checked_buf_size *= size.height(); |
+ if (!checked_buf_size.IsValid()) |
+ return false; |
+ |
+ // Allocate a shared memory buffer to hold the bitmap bits. |
+ uint32 buf_size = checked_buf_size.ValueOrDie(); |
+ shared_buf.reset(ChildThread::current()->AllocateSharedMemory(buf_size)); |
+ if (!shared_buf) |
+ return false; |
+ // Copy the bits into shared memory |
+ DCHECK(shared_buf->memory()); |
+ memcpy(shared_buf->memory(), pixels, buf_size); |
+ shared_buf->Unmap(); |
+ } |
+ |
+ RenderThreadImpl::current()->Send(new ClipboardHostMsg_WriteImage( |
+ clipboard_type, size, shared_buf->handle())); |
+ return true; |
+} |
+ |
+void RendererClipboardClient::CommitWrite(ui::ClipboardType clipboard_type) { |
+ RenderThreadImpl::current()->Send( |
+ new ClipboardHostMsg_CommitWrite(clipboard_type)); |
} |
} // namespace content |