OLD | NEW |
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) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #endif | 11 #endif |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/shared_memory.h" | 17 #include "base/shared_memory.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "content/common/clipboard_messages.h" | 19 #include "content/common/clipboard_messages.h" |
20 #include "content/common/content_client.h" | 20 #include "content/common/content_client.h" |
21 #include "content/common/content_switches.h" | 21 #include "content/common/content_switches.h" |
22 #include "content/common/npobject_util.h" | 22 #include "content/common/npobject_util.h" |
23 #include "content/common/socket_stream_dispatcher.h" | 23 #include "content/common/socket_stream_dispatcher.h" |
24 #include "content/common/url_constants.h" | 24 #include "content/common/url_constants.h" |
25 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
26 #include "content/public/renderer/content_renderer_client.h" | 26 #include "content/public/renderer/content_renderer_client.h" |
27 #include "content/renderer/render_thread.h" | 27 #include "content/renderer/render_thread_impl.h" |
28 #include "googleurl/src/url_util.h" | 28 #include "googleurl/src/url_util.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitPlatformSupport
.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitPlatformSupport
.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
32 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
33 #include "ui/base/clipboard/clipboard.h" | 33 #include "ui/base/clipboard/clipboard.h" |
34 #include "ui/base/ui_base_switches.h" | 34 #include "ui/base/ui_base_switches.h" |
35 #include "webkit/glue/scoped_clipboard_writer_glue.h" | 35 #include "webkit/glue/scoped_clipboard_writer_glue.h" |
36 #include "webkit/glue/webkit_glue.h" | 36 #include "webkit/glue/webkit_glue.h" |
37 #include "webkit/glue/websocketstreamhandle_bridge.h" | 37 #include "webkit/glue/websocketstreamhandle_bridge.h" |
(...skipping 13 matching lines...) Expand all Loading... |
51 uint32 buf_size = 4 * size.width() * size.height(); | 51 uint32 buf_size = 4 * size.width() * size.height(); |
52 | 52 |
53 // Allocate a shared memory buffer to hold the bitmap bits. | 53 // Allocate a shared memory buffer to hold the bitmap bits. |
54 #if defined(OS_POSIX) | 54 #if defined(OS_POSIX) |
55 // On POSIX, we need to ask the browser to create the shared memory for us, | 55 // On POSIX, we need to ask the browser to create the shared memory for us, |
56 // since this is blocked by the sandbox. | 56 // since this is blocked by the sandbox. |
57 base::SharedMemoryHandle shared_mem_handle; | 57 base::SharedMemoryHandle shared_mem_handle; |
58 ViewHostMsg_AllocateSharedMemoryBuffer *msg = | 58 ViewHostMsg_AllocateSharedMemoryBuffer *msg = |
59 new ViewHostMsg_AllocateSharedMemoryBuffer(buf_size, | 59 new ViewHostMsg_AllocateSharedMemoryBuffer(buf_size, |
60 &shared_mem_handle); | 60 &shared_mem_handle); |
61 if (RenderThread::current()->Send(msg)) { | 61 if (RenderThreadImpl::current()->Send(msg)) { |
62 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { | 62 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { |
63 shared_buf_ = new base::SharedMemory(shared_mem_handle, false); | 63 shared_buf_ = new base::SharedMemory(shared_mem_handle, false); |
64 if (!shared_buf_ || !shared_buf_->Map(buf_size)) { | 64 if (!shared_buf_ || !shared_buf_->Map(buf_size)) { |
65 NOTREACHED() << "Map failed"; | 65 NOTREACHED() << "Map failed"; |
66 return; | 66 return; |
67 } | 67 } |
68 } else { | 68 } else { |
69 NOTREACHED() << "Browser failed to allocate shared memory"; | 69 NOTREACHED() << "Browser failed to allocate shared memory"; |
70 return; | 70 return; |
71 } | 71 } |
(...skipping 28 matching lines...) Expand all Loading... |
100 objects_[ui::Clipboard::CBF_SMBITMAP] = params; | 100 objects_[ui::Clipboard::CBF_SMBITMAP] = params; |
101 } | 101 } |
102 | 102 |
103 // Define a destructor that makes IPCs to flush the contents to the | 103 // Define a destructor that makes IPCs to flush the contents to the |
104 // system clipboard. | 104 // system clipboard. |
105 ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() { | 105 ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() { |
106 if (objects_.empty()) | 106 if (objects_.empty()) |
107 return; | 107 return; |
108 | 108 |
109 if (shared_buf_) { | 109 if (shared_buf_) { |
110 RenderThread::current()->Send( | 110 RenderThreadImpl::current()->Send( |
111 new ClipboardHostMsg_WriteObjectsSync(objects_, | 111 new ClipboardHostMsg_WriteObjectsSync(objects_, |
112 shared_buf_->handle())); | 112 shared_buf_->handle())); |
113 delete shared_buf_; | 113 delete shared_buf_; |
114 return; | 114 return; |
115 } | 115 } |
116 | 116 |
117 RenderThread::current()->Send( | 117 RenderThreadImpl::current()->Send( |
118 new ClipboardHostMsg_WriteObjectsAsync(objects_)); | 118 new ClipboardHostMsg_WriteObjectsAsync(objects_)); |
119 } | 119 } |
120 | 120 |
121 namespace webkit_glue { | 121 namespace webkit_glue { |
122 | 122 |
123 // Clipboard glue | 123 // Clipboard glue |
124 | 124 |
125 ui::Clipboard* ClipboardGetClipboard() { | 125 ui::Clipboard* ClipboardGetClipboard() { |
126 return NULL; | 126 return NULL; |
127 } | 127 } |
128 | 128 |
129 bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format, | 129 bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format, |
130 ui::Clipboard::Buffer buffer) { | 130 ui::Clipboard::Buffer buffer) { |
131 bool result; | 131 bool result; |
132 RenderThread::current()->Send( | 132 RenderThreadImpl::current()->Send( |
133 new ClipboardHostMsg_IsFormatAvailable(format, buffer, &result)); | 133 new ClipboardHostMsg_IsFormatAvailable(format, buffer, &result)); |
134 return result; | 134 return result; |
135 } | 135 } |
136 | 136 |
137 void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer, | 137 void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer, |
138 std::vector<string16>* types, | 138 std::vector<string16>* types, |
139 bool* contains_filenames) { | 139 bool* contains_filenames) { |
140 RenderThread::current()->Send(new ClipboardHostMsg_ReadAvailableTypes( | 140 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadAvailableTypes( |
141 buffer, types, contains_filenames)); | 141 buffer, types, contains_filenames)); |
142 } | 142 } |
143 | 143 |
144 void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result) { | 144 void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result) { |
145 RenderThread::current()->Send(new ClipboardHostMsg_ReadText(buffer, result)); | 145 RenderThreadImpl::current()->Send( |
| 146 new ClipboardHostMsg_ReadText(buffer, result)); |
146 } | 147 } |
147 | 148 |
148 void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result) { | 149 void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result) { |
149 RenderThread::current()->Send( | 150 RenderThreadImpl::current()->Send( |
150 new ClipboardHostMsg_ReadAsciiText(buffer, result)); | 151 new ClipboardHostMsg_ReadAsciiText(buffer, result)); |
151 } | 152 } |
152 | 153 |
153 void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup, | 154 void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup, |
154 GURL* url) { | 155 GURL* url) { |
155 RenderThread::current()->Send( | 156 RenderThreadImpl::current()->Send( |
156 new ClipboardHostMsg_ReadHTML(buffer, markup, url)); | 157 new ClipboardHostMsg_ReadHTML(buffer, markup, url)); |
157 } | 158 } |
158 | 159 |
159 void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) { | 160 void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) { |
160 base::SharedMemoryHandle image_handle; | 161 base::SharedMemoryHandle image_handle; |
161 uint32 image_size; | 162 uint32 image_size; |
162 RenderThread::current()->Send( | 163 RenderThreadImpl::current()->Send( |
163 new ClipboardHostMsg_ReadImage(buffer, &image_handle, &image_size)); | 164 new ClipboardHostMsg_ReadImage(buffer, &image_handle, &image_size)); |
164 if (base::SharedMemory::IsHandleValid(image_handle)) { | 165 if (base::SharedMemory::IsHandleValid(image_handle)) { |
165 base::SharedMemory buffer(image_handle, true); | 166 base::SharedMemory buffer(image_handle, true); |
166 buffer.Map(image_size); | 167 buffer.Map(image_size); |
167 data->append(static_cast<char*>(buffer.memory()), image_size); | 168 data->append(static_cast<char*>(buffer.memory()), image_size); |
168 } | 169 } |
169 } | 170 } |
170 | 171 |
171 bool ClipboardReadData(ui::Clipboard::Buffer buffer, const string16& type, | 172 bool ClipboardReadData(ui::Clipboard::Buffer buffer, const string16& type, |
172 string16* data, string16* metadata) { | 173 string16* data, string16* metadata) { |
173 bool result = false; | 174 bool result = false; |
174 RenderThread::current()->Send(new ClipboardHostMsg_ReadData( | 175 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadData( |
175 buffer, type, &result, data, metadata)); | 176 buffer, type, &result, data, metadata)); |
176 return result; | 177 return result; |
177 } | 178 } |
178 | 179 |
179 bool ClipboardReadFilenames(ui::Clipboard::Buffer buffer, | 180 bool ClipboardReadFilenames(ui::Clipboard::Buffer buffer, |
180 std::vector<string16>* filenames) { | 181 std::vector<string16>* filenames) { |
181 bool result; | 182 bool result; |
182 RenderThread::current()->Send(new ClipboardHostMsg_ReadFilenames( | 183 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadFilenames( |
183 buffer, &result, filenames)); | 184 buffer, &result, filenames)); |
184 return result; | 185 return result; |
185 } | 186 } |
186 | 187 |
187 uint64 ClipboardGetSequenceNumber() { | 188 uint64 ClipboardGetSequenceNumber() { |
188 uint64 seq_num = 0; | 189 uint64 seq_num = 0; |
189 RenderThread::current()->Send( | 190 RenderThreadImpl::current()->Send( |
190 new ClipboardHostMsg_GetSequenceNumber(&seq_num)); | 191 new ClipboardHostMsg_GetSequenceNumber(&seq_num)); |
191 return seq_num; | 192 return seq_num; |
192 } | 193 } |
193 | 194 |
194 void GetPlugins(bool refresh, | 195 void GetPlugins(bool refresh, |
195 std::vector<webkit::WebPluginInfo>* plugins) { | 196 std::vector<webkit::WebPluginInfo>* plugins) { |
196 if (!RenderThread::current()->plugin_refresh_allowed()) | 197 if (!RenderThreadImpl::current()->plugin_refresh_allowed()) |
197 refresh = false; | 198 refresh = false; |
198 RenderThread::current()->Send(new ViewHostMsg_GetPlugins(refresh, plugins)); | 199 RenderThreadImpl::current()->Send( |
| 200 new ViewHostMsg_GetPlugins(refresh, plugins)); |
199 } | 201 } |
200 | 202 |
201 bool IsProtocolSupportedForMedia(const GURL& url) { | 203 bool IsProtocolSupportedForMedia(const GURL& url) { |
202 // If new protocol is to be added here, we need to make sure the response is | 204 // If new protocol is to be added here, we need to make sure the response is |
203 // validated accordingly in the media engine. | 205 // validated accordingly in the media engine. |
204 if (url.SchemeIsFile() || url.SchemeIs(chrome::kHttpScheme) || | 206 if (url.SchemeIsFile() || url.SchemeIs(chrome::kHttpScheme) || |
205 url.SchemeIs(chrome::kHttpsScheme) || | 207 url.SchemeIs(chrome::kHttpsScheme) || |
206 url.SchemeIs(chrome::kDataScheme) || | 208 url.SchemeIs(chrome::kDataScheme) || |
207 url.SchemeIs(chrome::kFileSystemScheme) || | 209 url.SchemeIs(chrome::kFileSystemScheme) || |
208 url.SchemeIs(chrome::kBlobScheme)) | 210 url.SchemeIs(chrome::kBlobScheme)) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 244 |
243 string16 GetLocalizedString(int message_id) { | 245 string16 GetLocalizedString(int message_id) { |
244 return content::GetContentClient()->GetLocalizedString(message_id); | 246 return content::GetContentClient()->GetLocalizedString(message_id); |
245 } | 247 } |
246 | 248 |
247 base::StringPiece GetDataResource(int resource_id) { | 249 base::StringPiece GetDataResource(int resource_id) { |
248 return content::GetContentClient()->GetDataResource(resource_id); | 250 return content::GetContentClient()->GetDataResource(resource_id); |
249 } | 251 } |
250 | 252 |
251 } // namespace webkit_glue | 253 } // namespace webkit_glue |
OLD | NEW |