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

Side by Side Diff: content/renderer/renderer_glue.cc

Issue 8591030: Move clipboard-related webkit_glue embedder functions into a ClipboardClient interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file provides the embedder's side of random webkit glue functions. 5 // This file provides the embedder's side of random webkit glue functions.
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN)
10 #include <windows.h>
11 #endif
12
13 #include <vector> 9 #include <vector>
14 10
15 #include "base/command_line.h" 11 #include "base/string16.h"
16 #include "base/memory/ref_counted.h" 12 #include "base/string_piece.h"
17 #include "base/shared_memory.h"
18 #include "base/string_util.h"
19 #include "content/common/clipboard_messages.h"
20 #include "content/common/npobject_util.h"
21 #include "content/common/socket_stream_dispatcher.h" 13 #include "content/common/socket_stream_dispatcher.h"
22 #include "content/common/view_messages.h" 14 #include "content/common/view_messages.h"
23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
25 #include "content/public/renderer/content_renderer_client.h" 16 #include "content/public/renderer/content_renderer_client.h"
26 #include "content/renderer/render_thread_impl.h" 17 #include "content/renderer/render_thread_impl.h"
27 #include "googleurl/src/url_util.h" 18 #include "googleurl/src/url_util.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitPlatformSupport .h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
31 #include "third_party/skia/include/core/SkBitmap.h"
32 #include "ui/base/clipboard/clipboard.h"
33 #include "ui/base/ui_base_switches.h"
34 #include "webkit/glue/scoped_clipboard_writer_glue.h"
35 #include "webkit/glue/webkit_glue.h" 19 #include "webkit/glue/webkit_glue.h"
36 #include "webkit/glue/websocketstreamhandle_bridge.h" 20 #include "webkit/glue/websocketstreamhandle_bridge.h"
37 21
38 // This definition of WriteBitmapFromPixels uses shared memory to communicate
39 // across processes.
40 void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels,
41 const gfx::Size& size) {
42 // Do not try to write a bitmap more than once
43 if (shared_buf_)
44 return;
45
46 uint32 buf_size = 4 * size.width() * size.height();
47
48 // Allocate a shared memory buffer to hold the bitmap bits.
49 shared_buf_ = ChildThread::current()->AllocateSharedMemory(buf_size);
50 if (!shared_buf_)
51 return;
52
53 // Copy the bits into shared memory
54 DCHECK(shared_buf_->memory());
55 memcpy(shared_buf_->memory(), pixels, buf_size);
56 shared_buf_->Unmap();
57
58 ui::Clipboard::ObjectMapParam size_param;
59 const char* size_data = reinterpret_cast<const char*>(&size);
60 for (size_t i = 0; i < sizeof(gfx::Size); ++i)
61 size_param.push_back(size_data[i]);
62
63 ui::Clipboard::ObjectMapParams params;
64
65 // The first parameter is replaced on the receiving end with a pointer to
66 // a shared memory object containing the bitmap. We reserve space for it here.
67 ui::Clipboard::ObjectMapParam place_holder_param;
68 params.push_back(place_holder_param);
69 params.push_back(size_param);
70 objects_[ui::Clipboard::CBF_SMBITMAP] = params;
71 }
72
73 // Define a destructor that makes IPCs to flush the contents to the
74 // system clipboard.
75 ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
76 if (objects_.empty())
77 return;
78
79 if (shared_buf_) {
80 RenderThreadImpl::current()->Send(
81 new ClipboardHostMsg_WriteObjectsSync(objects_,
82 shared_buf_->handle()));
83 delete shared_buf_;
84 return;
85 }
86
87 RenderThreadImpl::current()->Send(
88 new ClipboardHostMsg_WriteObjectsAsync(objects_));
89 }
90
91 namespace webkit_glue { 22 namespace webkit_glue {
92 23
93 // Clipboard glue
94
95 ui::Clipboard* ClipboardGetClipboard() {
96 return NULL;
97 }
98
99 uint64 ClipboardGetSequenceNumber(ui::Clipboard::Buffer buffer) {
100 uint64 sequence_number = 0;
101 RenderThreadImpl::current()->Send(
102 new ClipboardHostMsg_GetSequenceNumber(buffer,
103 &sequence_number));
104 return sequence_number;
105 }
106
107 bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format,
108 ui::Clipboard::Buffer buffer) {
109 bool result;
110 RenderThreadImpl::current()->Send(
111 new ClipboardHostMsg_IsFormatAvailable(format, buffer, &result));
112 return result;
113 }
114
115 void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer,
116 std::vector<string16>* types,
117 bool* contains_filenames) {
118 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadAvailableTypes(
119 buffer, types, contains_filenames));
120 }
121
122 void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result) {
123 RenderThreadImpl::current()->Send(
124 new ClipboardHostMsg_ReadText(buffer, result));
125 }
126
127 void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result) {
128 RenderThreadImpl::current()->Send(
129 new ClipboardHostMsg_ReadAsciiText(buffer, result));
130 }
131
132 void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
133 GURL* url, uint32* fragment_start,
134 uint32* fragment_end) {
135 RenderThreadImpl::current()->Send(
136 new ClipboardHostMsg_ReadHTML(buffer, markup, url, fragment_start,
137 fragment_end));
138 }
139
140 void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) {
141 base::SharedMemoryHandle image_handle;
142 uint32 image_size;
143 RenderThreadImpl::current()->Send(
144 new ClipboardHostMsg_ReadImage(buffer, &image_handle, &image_size));
145 if (base::SharedMemory::IsHandleValid(image_handle)) {
146 base::SharedMemory buffer(image_handle, true);
147 buffer.Map(image_size);
148 data->append(static_cast<char*>(buffer.memory()), image_size);
149 }
150 }
151
152 void GetPlugins(bool refresh, 24 void GetPlugins(bool refresh,
153 std::vector<webkit::WebPluginInfo>* plugins) { 25 std::vector<webkit::WebPluginInfo>* plugins) {
154 if (!RenderThreadImpl::current()->plugin_refresh_allowed()) 26 if (!RenderThreadImpl::current()->plugin_refresh_allowed())
155 refresh = false; 27 refresh = false;
156 RenderThreadImpl::current()->Send( 28 RenderThreadImpl::current()->Send(
157 new ViewHostMsg_GetPlugins(refresh, plugins)); 29 new ViewHostMsg_GetPlugins(refresh, plugins));
158 } 30 }
159 31
160 bool IsProtocolSupportedForMedia(const GURL& url) { 32 bool IsProtocolSupportedForMedia(const GURL& url) {
161 // If new protocol is to be added here, we need to make sure the response is 33 // If new protocol is to be added here, we need to make sure the response is
(...skipping 25 matching lines...) Expand all
187 59
188 string16 GetLocalizedString(int message_id) { 60 string16 GetLocalizedString(int message_id) {
189 return content::GetContentClient()->GetLocalizedString(message_id); 61 return content::GetContentClient()->GetLocalizedString(message_id);
190 } 62 }
191 63
192 base::StringPiece GetDataResource(int resource_id) { 64 base::StringPiece GetDataResource(int resource_id) {
193 return content::GetContentClient()->GetDataResource(resource_id); 65 return content::GetContentClient()->GetDataResource(resource_id);
194 } 66 }
195 67
196 } // namespace webkit_glue 68 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « content/renderer/renderer_clipboard_client.cc ('k') | content/renderer/renderer_webkitplatformsupport_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698