Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8318)

Unified Diff: chrome/renderer/renderer_glue.cc

Issue 9154: Rewrote the clipboard API to be more concurrent. Added a helper class to make... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/render_messages_internal.h ('k') | chrome/views/text_field.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/renderer_glue.cc
===================================================================
--- chrome/renderer/renderer_glue.cc (revision 4189)
+++ chrome/renderer/renderer_glue.cc (working copy)
@@ -7,6 +7,8 @@
#include <windows.h>
#include <wininet.h>
+#include "base/clipboard.h"
+#include "base/scoped_clipboard_writer.h"
#include "chrome/renderer/net/render_dns_master.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/plugin/npobject_util.h"
@@ -14,9 +16,12 @@
#include "chrome/renderer/visitedlink_slave.h"
#include "googleurl/src/url_util.h"
#include "net/base/mime_util.h"
+#include "webkit/glue/scoped_clipboard_writer_glue.h"
#include "webkit/glue/webframe.h"
#include "webkit/glue/webkit_glue.h"
+#include <vector>
+
#include "SkBitmap.h"
#include <strsafe.h> // note: per msdn docs, this must *follow* other includes
@@ -66,6 +71,66 @@
size_t cur_capacity_;
};
+#if defined(OS_WIN)
+// This definition of WriteBitmap uses shared memory to communicate across
+// processes.
+void ScopedClipboardWriterGlue::WriteBitmap(const SkBitmap& bitmap) {
+ // do not try to write a bitmap more than once
+ if (shared_buf_)
+ return;
+
+ size_t buf_size = bitmap.getSize();
+ gfx::Size size(bitmap.width(), bitmap.height());
+
+ // Allocate a shared memory buffer to hold the bitmap bits
+ shared_buf_ = RenderProcess::AllocSharedMemory(buf_size);
+ if (!shared_buf_ || !shared_buf_->Map(buf_size)) {
+ NOTREACHED();
+ return;
+ }
+
+ // Copy the bits into shared memory
+ SkAutoLockPixels bitmap_lock(bitmap);
+ memcpy(shared_buf_->memory(), bitmap.getPixels(), buf_size);
+ shared_buf_->Unmap();
+
+ Clipboard::ObjectMapParam param1, param2;
+ SharedMemoryHandle smh = shared_buf_->handle();
+
+ const char* shared_handle = reinterpret_cast<const char*>(&smh);
+ for (size_t i = 0; i < sizeof SharedMemoryHandle; i++)
+ param1.push_back(shared_handle[i]);
+
+ const char* size_data = reinterpret_cast<const char*>(&size);
+ for (size_t i = 0; i < sizeof gfx::Size; i++)
+ param2.push_back(size_data[i]);
+
+ Clipboard::ObjectMapParams params;
+ params.push_back(param1);
+ params.push_back(param2);
+ objects_[Clipboard::CBF_SMBITMAP] = params;
+}
+#endif
+
+// Define a destructor that makes IPCs to flush the contents to the
+// system clipboard.
+ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
+ if (objects_.empty())
+ return;
+
+#if defined(OS_WIN)
+ if (shared_buf_) {
+ RenderThread::current()->Send(
+ new ViewHostMsg_ClipboardWriteObjectsSync(objects_));
+ RenderProcess::FreeSharedMemory(shared_buf_);
+ return;
+ }
+#endif
+
+ RenderThread::current()->Send(
+ new ViewHostMsg_ClipboardWriteObjectsAsync(objects_));
+}
+
namespace webkit_glue {
void PrefetchDns(const std::string& hostname) {
@@ -141,60 +206,10 @@
// Clipboard glue
-void webkit_glue::ClipboardClear() {
- RenderThread::current()->Send(new ViewHostMsg_ClipboardClear());
+Clipboard* webkit_glue::ClipboardGetClipboard(){
+ return NULL;
}
-void webkit_glue::ClipboardWriteText(const std::wstring& text) {
- RenderThread::current()->Send(new ViewHostMsg_ClipboardWriteText(text));
-}
-
-void webkit_glue::ClipboardWriteHTML(const std::wstring& html,
- const GURL& url) {
- RenderThread::current()->Send(new ViewHostMsg_ClipboardWriteHTML(html, url));
-}
-
-void webkit_glue::ClipboardWriteBookmark(const std::wstring& title,
- const GURL& url) {
- RenderThread::current()->Send(
- new ViewHostMsg_ClipboardWriteBookmark(title, url));
-}
-
-// Here we need to do some work to marshal the bitmap through shared memory
-void webkit_glue::ClipboardWriteBitmap(const SkBitmap& bitmap) {
- size_t buf_size = bitmap.getSize();
- gfx::Size size(bitmap.width(), bitmap.height());
-
- // Allocate a shared memory buffer to hold the bitmap bits
- SharedMemory* shared_buf =
- RenderProcess::AllocSharedMemory(buf_size);
- if (!shared_buf) {
- NOTREACHED();
- return;
- }
- if (!shared_buf->Map(buf_size)) {
- NOTREACHED();
- return;
- }
-
- // Copy the bits into shared memory
- SkAutoLockPixels bitmap_lock(bitmap);
- memcpy(shared_buf->memory(), bitmap.getPixels(), buf_size);
- shared_buf->Unmap();
-
- // Send the handle over synchronous IPC
- RenderThread::current()->Send(
- new ViewHostMsg_ClipboardWriteBitmap(shared_buf->handle(), size));
-
- // The browser should be done with the bitmap now. It's our job to free
- // the shared memory.
- RenderProcess::FreeSharedMemory(shared_buf);
-}
-
-void webkit_glue::ClipboardWriteWebSmartPaste() {
- RenderThread::current()->Send(new ViewHostMsg_ClipboardWriteWebSmartPaste());
-}
-
bool webkit_glue::ClipboardIsFormatAvailable(unsigned int format) {
bool result;
RenderThread::current()->Send(
« no previous file with comments | « chrome/common/render_messages_internal.h ('k') | chrome/views/text_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698