| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/plugin/webplugin_delegate_stub.h" | 5 #include "chrome/plugin/webplugin_delegate_stub.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/gfx/bitmap_header.h" | |
| 10 #include "base/gfx/platform_device_win.h" | 9 #include "base/gfx/platform_device_win.h" |
| 11 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/gfx/emf.h" | 11 #include "chrome/common/gfx/emf.h" |
| 13 #include "chrome/common/plugin_messages.h" | 12 #include "chrome/common/plugin_messages.h" |
| 14 #include "chrome/common/win_util.h" | 13 #include "chrome/common/win_util.h" |
| 15 #include "chrome/plugin/npobject_stub.h" | 14 #include "chrome/plugin/npobject_stub.h" |
| 16 #include "chrome/plugin/plugin_channel.h" | 15 #include "chrome/plugin/plugin_channel.h" |
| 17 #include "chrome/plugin/plugin_thread.h" | 16 #include "chrome/plugin/plugin_thread.h" |
| 18 #include "chrome/plugin/webplugin_proxy.h" | 17 #include "chrome/plugin/webplugin_proxy.h" |
| 19 #include "third_party/npapi/bindings/npapi.h" | 18 #include "third_party/npapi/bindings/npapi.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit) | 73 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit) |
| 75 IPC_MESSAGE_HANDLER(PluginMsg_WillSendRequest, OnWillSendRequest) | 74 IPC_MESSAGE_HANDLER(PluginMsg_WillSendRequest, OnWillSendRequest) |
| 76 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse) | 75 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse) |
| 77 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData) | 76 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData) |
| 78 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoading, OnDidFinishLoading) | 77 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoading, OnDidFinishLoading) |
| 79 IPC_MESSAGE_HANDLER(PluginMsg_DidFail, OnDidFail) | 78 IPC_MESSAGE_HANDLER(PluginMsg_DidFail, OnDidFail) |
| 80 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoadWithReason, | 79 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoadWithReason, |
| 81 OnDidFinishLoadWithReason) | 80 OnDidFinishLoadWithReason) |
| 82 IPC_MESSAGE_HANDLER(PluginMsg_SetFocus, OnSetFocus) | 81 IPC_MESSAGE_HANDLER(PluginMsg_SetFocus, OnSetFocus) |
| 83 IPC_MESSAGE_HANDLER(PluginMsg_HandleEvent, OnHandleEvent) | 82 IPC_MESSAGE_HANDLER(PluginMsg_HandleEvent, OnHandleEvent) |
| 84 IPC_MESSAGE_HANDLER(PluginMsg_Paint, OnPaint) | |
| 85 IPC_MESSAGE_HANDLER(PluginMsg_Print, OnPrint) | 83 IPC_MESSAGE_HANDLER(PluginMsg_Print, OnPrint) |
| 86 IPC_MESSAGE_HANDLER(PluginMsg_PaintIntoSharedMemory, | |
| 87 OnPaintIntoSharedMemory) | |
| 88 IPC_MESSAGE_HANDLER(PluginMsg_GetPluginScriptableObject, | 84 IPC_MESSAGE_HANDLER(PluginMsg_GetPluginScriptableObject, |
| 89 OnGetPluginScriptableObject) | 85 OnGetPluginScriptableObject) |
| 90 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometry, OnUpdateGeometry) | 86 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometry, OnUpdateGeometry) |
| 91 IPC_MESSAGE_HANDLER(PluginMsg_SendJavaScriptStream, | 87 IPC_MESSAGE_HANDLER(PluginMsg_SendJavaScriptStream, |
| 92 OnSendJavaScriptStream) | 88 OnSendJavaScriptStream) |
| 93 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveManualResponse, | 89 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveManualResponse, |
| 94 OnDidReceiveManualResponse) | 90 OnDidReceiveManualResponse) |
| 95 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveManualData, OnDidReceiveManualData) | 91 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveManualData, OnDidReceiveManualData) |
| 96 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishManualLoading, | 92 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishManualLoading, |
| 97 OnDidFinishManualLoading) | 93 OnDidFinishManualLoading) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 void WebPluginDelegateStub::OnSetFocus() { | 190 void WebPluginDelegateStub::OnSetFocus() { |
| 195 delegate_->SetFocus(); | 191 delegate_->SetFocus(); |
| 196 } | 192 } |
| 197 | 193 |
| 198 void WebPluginDelegateStub::OnHandleEvent(const NPEvent& event, | 194 void WebPluginDelegateStub::OnHandleEvent(const NPEvent& event, |
| 199 bool* handled, | 195 bool* handled, |
| 200 WebCursor* cursor) { | 196 WebCursor* cursor) { |
| 201 *handled = delegate_->HandleEvent(const_cast<NPEvent*>(&event), cursor); | 197 *handled = delegate_->HandleEvent(const_cast<NPEvent*>(&event), cursor); |
| 202 } | 198 } |
| 203 | 199 |
| 204 void WebPluginDelegateStub::OnPaint(const PluginMsg_Paint_Params& params) { | |
| 205 // Convert the shared memory handle to a handle that works in our process, | |
| 206 // and then use that to create an HDC. | |
| 207 win_util::ScopedHandle shared_section(win_util::GetSectionFromProcess( | |
| 208 params.shared_memory, channel_->renderer_handle(), false)); | |
| 209 | |
| 210 if (shared_section == NULL) { | |
| 211 NOTREACHED(); | |
| 212 return; | |
| 213 } | |
| 214 | |
| 215 void* data = NULL; | |
| 216 HDC screen_dc = GetDC(NULL); | |
| 217 BITMAPINFOHEADER bitmap_header; | |
| 218 gfx::CreateBitmapHeader(params.size.width(), params.size.height(), | |
| 219 &bitmap_header); | |
| 220 win_util::ScopedBitmap hbitmap(CreateDIBSection( | |
| 221 screen_dc, reinterpret_cast<const BITMAPINFO*>(&bitmap_header), | |
| 222 DIB_RGB_COLORS, &data, | |
| 223 shared_section, 0)); | |
| 224 ReleaseDC(NULL, screen_dc); | |
| 225 if (hbitmap == NULL) { | |
| 226 NOTREACHED(); | |
| 227 return; | |
| 228 } | |
| 229 | |
| 230 win_util::ScopedHDC hdc(CreateCompatibleDC(NULL)); | |
| 231 if (hdc == NULL) { | |
| 232 NOTREACHED(); | |
| 233 return; | |
| 234 } | |
| 235 gfx::PlatformDeviceWin::InitializeDC(hdc); | |
| 236 SelectObject(hdc, hbitmap); | |
| 237 SetWorldTransform(hdc, ¶ms.xf); | |
| 238 | |
| 239 win_util::ScopedHRGN hrgn(CreateRectRgnIndirect(¶ms.clip_rect.ToRECT())); | |
| 240 SelectClipRgn(hdc, hrgn); | |
| 241 webplugin_->WillPaint(); | |
| 242 delegate_->Paint(hdc, params.damaged_rect); | |
| 243 } | |
| 244 | |
| 245 void WebPluginDelegateStub::OnPrint(PluginMsg_PrintResponse_Params* params) { | 200 void WebPluginDelegateStub::OnPrint(PluginMsg_PrintResponse_Params* params) { |
| 246 gfx::Emf emf; | 201 gfx::Emf emf; |
| 247 if (!emf.CreateDc(NULL, NULL)) { | 202 if (!emf.CreateDc(NULL, NULL)) { |
| 248 NOTREACHED(); | 203 NOTREACHED(); |
| 249 return; | 204 return; |
| 250 } | 205 } |
| 251 HDC hdc = emf.hdc(); | 206 HDC hdc = emf.hdc(); |
| 252 gfx::PlatformDeviceWin::InitializeDC(hdc); | 207 gfx::PlatformDeviceWin::InitializeDC(hdc); |
| 253 delegate_->Print(hdc); | 208 delegate_->Print(hdc); |
| 254 if (!emf.CloseDc()) { | 209 if (!emf.CloseDc()) { |
| 255 NOTREACHED(); | 210 NOTREACHED(); |
| 256 return; | 211 return; |
| 257 } | 212 } |
| 258 | 213 |
| 259 size_t size = emf.GetDataSize(); | 214 size_t size = emf.GetDataSize(); |
| 260 DCHECK(size); | 215 DCHECK(size); |
| 261 params->size = size; | 216 params->size = size; |
| 262 SharedMemory shared_buf; | 217 SharedMemory shared_buf; |
| 263 CreateSharedBuffer(size, &shared_buf, ¶ms->shared_memory); | 218 CreateSharedBuffer(size, &shared_buf, ¶ms->shared_memory); |
| 264 | 219 |
| 265 // Retrieve a copy of the data. | 220 // Retrieve a copy of the data. |
| 266 bool success = emf.GetData(shared_buf.memory(), size); | 221 bool success = emf.GetData(shared_buf.memory(), size); |
| 267 DCHECK(success); | 222 DCHECK(success); |
| 268 } | 223 } |
| 269 | 224 |
| 270 void WebPluginDelegateStub::OnPaintIntoSharedMemory( | 225 void WebPluginDelegateStub::OnUpdateGeometry( |
| 271 const PluginMsg_Paint_Params& params, | 226 const gfx::Rect& window_rect, |
| 272 SharedMemoryHandle* emf_buffer, | 227 const gfx::Rect& clip_rect, |
| 273 size_t* bytes) { | 228 bool visible, |
| 274 *emf_buffer = NULL; | 229 const SharedMemoryHandle& windowless_buffer, |
| 275 *bytes = 0; | 230 const SharedMemoryLock& lock) { |
| 276 | 231 webplugin_->UpdateGeometry( |
| 277 gfx::Emf emf; | 232 window_rect, clip_rect, visible, windowless_buffer, lock); |
| 278 if (!emf.CreateDc(NULL, NULL)) { | |
| 279 NOTREACHED(); | |
| 280 return; | |
| 281 } | |
| 282 HDC hdc = emf.hdc(); | |
| 283 gfx::PlatformDeviceWin::InitializeDC(hdc); | |
| 284 | |
| 285 if (delegate_->windowless()) { | |
| 286 WindowlessPaint(hdc, params); | |
| 287 } else { | |
| 288 WindowedPaint(hdc, params.damaged_rect); | |
| 289 } | |
| 290 | |
| 291 // Need to send back the data as shared memory. | |
| 292 if (!emf.CloseDc()) { | |
| 293 NOTREACHED(); | |
| 294 return; | |
| 295 } | |
| 296 | |
| 297 size_t size = emf.GetDataSize(); | |
| 298 DCHECK(size); | |
| 299 *bytes = size; | |
| 300 SharedMemory shared_buf; | |
| 301 CreateSharedBuffer(size, &shared_buf, emf_buffer); | |
| 302 | |
| 303 // Retrieve a copy of the data. | |
| 304 bool success = emf.GetData(shared_buf.memory(), size); | |
| 305 DCHECK(success); | |
| 306 } | |
| 307 | |
| 308 void WebPluginDelegateStub::WindowedPaint(HDC hdc, | |
| 309 const gfx::Rect& window_rect) { | |
| 310 // Use the NPAPI print() function to render the plugin. | |
| 311 delegate_->Print(hdc); | |
| 312 } | |
| 313 | |
| 314 void WebPluginDelegateStub::WindowlessPaint( | |
| 315 HDC hdc, | |
| 316 const PluginMsg_Paint_Params& params) { | |
| 317 void* data = NULL; | |
| 318 HDC screen_dc = GetDC(NULL); | |
| 319 BITMAPINFOHEADER bitmap_header; | |
| 320 gfx::CreateBitmapHeader(params.size.width(), params.size.height(), | |
| 321 &bitmap_header); | |
| 322 win_util::ScopedBitmap hbitmap(CreateDIBSection( | |
| 323 screen_dc, reinterpret_cast<const BITMAPINFO*>(&bitmap_header), | |
| 324 DIB_RGB_COLORS, &data, NULL, 0)); | |
| 325 ReleaseDC(NULL, screen_dc); | |
| 326 if (hbitmap == NULL) { | |
| 327 NOTREACHED(); | |
| 328 return; | |
| 329 } | |
| 330 SelectObject(hdc, hbitmap); | |
| 331 | |
| 332 // Apply transform and clipping. | |
| 333 SetWorldTransform(hdc, ¶ms.xf); | |
| 334 win_util::ScopedHRGN hrgn(CreateRectRgnIndirect(¶ms.clip_rect.ToRECT())); | |
| 335 SelectClipRgn(hdc, hrgn); | |
| 336 webplugin_->WillPaint(); | |
| 337 delegate_->Paint(hdc, params.damaged_rect); | |
| 338 } | |
| 339 | |
| 340 void WebPluginDelegateStub::OnUpdateGeometry(const gfx::Rect& window_rect, | |
| 341 const gfx::Rect& clip_rect, | |
| 342 bool visible) { | |
| 343 delegate_->UpdateGeometry(window_rect, clip_rect, visible); | |
| 344 } | 233 } |
| 345 | 234 |
| 346 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, | 235 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, |
| 347 void** npobject_ptr) { | 236 void** npobject_ptr) { |
| 348 NPObject* object = delegate_->GetPluginScriptableObject(); | 237 NPObject* object = delegate_->GetPluginScriptableObject(); |
| 349 if (!object) { | 238 if (!object) { |
| 350 *route_id = MSG_ROUTING_NONE; | 239 *route_id = MSG_ROUTING_NONE; |
| 351 return; | 240 return; |
| 352 } | 241 } |
| 353 | 242 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 params.notify_data); | 318 params.notify_data); |
| 430 webplugin_->OnResourceCreated(params.resource_id, resource_client); | 319 webplugin_->OnResourceCreated(params.resource_id, resource_client); |
| 431 } | 320 } |
| 432 | 321 |
| 433 void WebPluginDelegateStub::OnURLRequestRouted(const std::string& url, | 322 void WebPluginDelegateStub::OnURLRequestRouted(const std::string& url, |
| 434 bool notify_needed, | 323 bool notify_needed, |
| 435 HANDLE notify_data) { | 324 HANDLE notify_data) { |
| 436 delegate_->URLRequestRouted(url, notify_needed, notify_data); | 325 delegate_->URLRequestRouted(url, notify_needed, notify_data); |
| 437 } | 326 } |
| 438 | 327 |
| OLD | NEW |