| 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/renderer/webplugin_delegate_proxy.h" | 5 #include "chrome/renderer/webplugin_delegate_proxy.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" |
| 8 |
| 9 #if defined(OS_WIN) |
| 7 #include <atlbase.h> | 10 #include <atlbase.h> |
| 11 #endif |
| 8 | 12 |
| 9 #include "base/logging.h" | 13 #include "base/logging.h" |
| 10 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 11 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 12 #include "base/gfx/size.h" | 16 #include "base/gfx/size.h" |
| 13 #include "base/gfx/native_widget_types.h" | 17 #include "base/gfx/native_widget_types.h" |
| 14 #include "chrome/app/chrome_dll_resource.h" | 18 #include "chrome/app/chrome_dll_resource.h" |
| 15 #include "chrome/common/gfx/chrome_canvas.h" | 19 #include "chrome/common/gfx/chrome_canvas.h" |
| 16 #include "chrome/common/gfx/emf.h" | |
| 17 #include "chrome/common/l10n_util.h" | 20 #include "chrome/common/l10n_util.h" |
| 18 #include "chrome/common/plugin_messages.h" | 21 #include "chrome/common/plugin_messages.h" |
| 19 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| 20 #include "chrome/common/resource_bundle.h" | 23 #include "chrome/common/resource_bundle.h" |
| 21 #include "chrome/common/win_util.h" | |
| 22 #include "chrome/plugin/npobject_proxy.h" | 24 #include "chrome/plugin/npobject_proxy.h" |
| 23 #include "chrome/plugin/npobject_stub.h" | 25 #include "chrome/plugin/npobject_stub.h" |
| 24 #include "chrome/renderer/render_thread.h" | 26 #include "chrome/renderer/render_thread.h" |
| 25 #include "chrome/renderer/render_view.h" | 27 #include "chrome/renderer/render_view.h" |
| 26 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
| 27 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 28 #include "net/base/mime_util.h" | 30 #include "net/base/mime_util.h" |
| 29 #include "webkit/glue/webframe.h" | 31 #include "webkit/glue/webframe.h" |
| 30 #include "webkit/glue/webkit_glue.h" | 32 #include "webkit/glue/webkit_glue.h" |
| 31 #include "webkit/glue/webplugin.h" | 33 #include "webkit/glue/webplugin.h" |
| 32 #include "webkit/glue/webview.h" | 34 #include "webkit/glue/webview.h" |
| 33 | 35 |
| 36 #if defined(OS_WIN) |
| 37 #include "chrome/common/gfx/emf.h" |
| 38 #include "chrome/common/win_util.h" |
| 39 #endif |
| 40 |
| 34 // Proxy for WebPluginResourceClient. The object owns itself after creation, | 41 // Proxy for WebPluginResourceClient. The object owns itself after creation, |
| 35 // deleting itself after its callback has been called. | 42 // deleting itself after its callback has been called. |
| 36 class ResourceClientProxy : public WebPluginResourceClient { | 43 class ResourceClientProxy : public WebPluginResourceClient { |
| 37 public: | 44 public: |
| 38 ResourceClientProxy(PluginChannelHost* channel, int instance_id) | 45 ResourceClientProxy(PluginChannelHost* channel, int instance_id) |
| 39 : channel_(channel), instance_id_(instance_id), resource_id_(0), | 46 : channel_(channel), instance_id_(instance_id), resource_id_(0), |
| 40 notify_needed_(false), notify_data_(NULL), | 47 notify_needed_(false), notify_data_(NULL), |
| 41 multibyte_response_expected_(false) { | 48 multibyte_response_expected_(false) { |
| 42 } | 49 } |
| 43 | 50 |
| 44 ~ResourceClientProxy() { | 51 ~ResourceClientProxy() { |
| 45 } | 52 } |
| 46 | 53 |
| 47 void Initialize(int resource_id, const std::string &url, bool notify_needed, | 54 void Initialize(int resource_id, const std::string &url, bool notify_needed, |
| 48 intptr_t notify_data, intptr_t existing_stream) { | 55 intptr_t notify_data, intptr_t existing_stream) { |
| 49 resource_id_ = resource_id; | 56 resource_id_ = resource_id; |
| 50 url_ = url; | 57 url_ = url; |
| 51 notify_needed_ = notify_needed; | 58 notify_needed_ = notify_needed; |
| 52 notify_data_ = notify_data; | 59 notify_data_ = notify_data; |
| 53 | 60 |
| 54 PluginMsg_URLRequestReply_Params params; | 61 PluginMsg_URLRequestReply_Params params; |
| 55 params.resource_id = resource_id; | 62 params.resource_id = resource_id; |
| 56 params.url = url_; | 63 params.url = url_; |
| 57 params.notify_needed = notify_needed_; | 64 params.notify_needed = notify_needed_; |
| 58 params.notify_data = notify_data_; | 65 params.notify_data = notify_data_; |
| 59 params.stream = existing_stream; | 66 params.stream = existing_stream; |
| 60 | 67 |
| 61 multibyte_response_expected_ = (existing_stream != NULL); | 68 multibyte_response_expected_ = (existing_stream != 0); |
| 62 | 69 |
| 63 channel_->Send(new PluginMsg_HandleURLRequestReply(instance_id_, params)); | 70 channel_->Send(new PluginMsg_HandleURLRequestReply(instance_id_, params)); |
| 64 } | 71 } |
| 65 | 72 |
| 66 // PluginResourceClient implementation: | 73 // PluginResourceClient implementation: |
| 67 void WillSendRequest(const GURL& url) { | 74 void WillSendRequest(const GURL& url) { |
| 68 DCHECK(channel_ != NULL); | 75 DCHECK(channel_ != NULL); |
| 69 channel_->Send(new PluginMsg_WillSendRequest(instance_id_, resource_id_, | 76 channel_->Send(new PluginMsg_WillSendRequest(instance_id_, resource_id_, |
| 70 url)); | 77 url)); |
| 71 } | 78 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 DCHECK(channel_ != NULL); | 122 DCHECK(channel_ != NULL); |
| 116 channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_)); | 123 channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_)); |
| 117 channel_ = NULL; | 124 channel_ = NULL; |
| 118 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 125 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 119 } | 126 } |
| 120 | 127 |
| 121 bool IsMultiByteResponseExpected() { | 128 bool IsMultiByteResponseExpected() { |
| 122 return multibyte_response_expected_; | 129 return multibyte_response_expected_; |
| 123 } | 130 } |
| 124 | 131 |
| 125 private: | 132 private: |
| 133 scoped_refptr<PluginChannelHost> channel_; |
| 134 int instance_id_; |
| 126 int resource_id_; | 135 int resource_id_; |
| 127 int instance_id_; | |
| 128 scoped_refptr<PluginChannelHost> channel_; | |
| 129 std::string url_; | 136 std::string url_; |
| 130 bool notify_needed_; | 137 bool notify_needed_; |
| 131 intptr_t notify_data_; | 138 intptr_t notify_data_; |
| 132 // Set to true if the response expected is a multibyte response. | 139 // Set to true if the response expected is a multibyte response. |
| 133 // For e.g. response for a HTTP byte range request. | 140 // For e.g. response for a HTTP byte range request. |
| 134 bool multibyte_response_expected_; | 141 bool multibyte_response_expected_; |
| 135 }; | 142 }; |
| 136 | 143 |
| 137 WebPluginDelegateProxy* WebPluginDelegateProxy::Create( | 144 WebPluginDelegateProxy* WebPluginDelegateProxy::Create( |
| 138 const GURL& url, | 145 const GURL& url, |
| 139 const std::string& mime_type, | 146 const std::string& mime_type, |
| 140 const std::string& clsid, | 147 const std::string& clsid, |
| 141 RenderView* render_view) { | 148 RenderView* render_view) { |
| 142 return new WebPluginDelegateProxy(mime_type, clsid, render_view); | 149 return new WebPluginDelegateProxy(mime_type, clsid, render_view); |
| 143 } | 150 } |
| 144 | 151 |
| 145 WebPluginDelegateProxy::WebPluginDelegateProxy(const std::string& mime_type, | 152 WebPluginDelegateProxy::WebPluginDelegateProxy(const std::string& mime_type, |
| 146 const std::string& clsid, | 153 const std::string& clsid, |
| 147 RenderView* render_view) | 154 RenderView* render_view) |
| 148 : render_view_(render_view), | 155 : render_view_(render_view), |
| 156 plugin_(NULL), |
| 157 windowless_(false), |
| 149 mime_type_(mime_type), | 158 mime_type_(mime_type), |
| 150 clsid_(clsid), | 159 clsid_(clsid), |
| 151 plugin_(NULL), | 160 send_deferred_update_geometry_(false), |
| 152 windowless_(false), | |
| 153 npobject_(NULL), | 161 npobject_(NULL), |
| 154 send_deferred_update_geometry_(false), | 162 window_script_object_(NULL), |
| 155 sad_plugin_(NULL), | 163 sad_plugin_(NULL), |
| 156 window_script_object_(NULL), | 164 invalidate_pending_(false), |
| 157 transparent_(false), | 165 transparent_(false) { |
| 158 invalidate_pending_(false) { | |
| 159 } | 166 } |
| 160 | 167 |
| 161 WebPluginDelegateProxy::~WebPluginDelegateProxy() { | 168 WebPluginDelegateProxy::~WebPluginDelegateProxy() { |
| 162 } | 169 } |
| 163 | 170 |
| 164 void WebPluginDelegateProxy::PluginDestroyed() { | 171 void WebPluginDelegateProxy::PluginDestroyed() { |
| 165 plugin_ = NULL; | 172 plugin_ = NULL; |
| 166 | 173 |
| 167 if (npobject_) { | 174 if (npobject_) { |
| 168 // When we destroy the plugin instance, the NPObjectStub NULLs out its | 175 // When we destroy the plugin instance, the NPObjectStub NULLs out its |
| (...skipping 19 matching lines...) Expand all Loading... |
| 188 render_view_->PluginDestroyed(this); | 195 render_view_->PluginDestroyed(this); |
| 189 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 196 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 190 } | 197 } |
| 191 | 198 |
| 192 void WebPluginDelegateProxy::FlushGeometryUpdates() { | 199 void WebPluginDelegateProxy::FlushGeometryUpdates() { |
| 193 if (send_deferred_update_geometry_) { | 200 if (send_deferred_update_geometry_) { |
| 194 send_deferred_update_geometry_ = false; | 201 send_deferred_update_geometry_ = false; |
| 195 Send(new PluginMsg_UpdateGeometry(instance_id_, | 202 Send(new PluginMsg_UpdateGeometry(instance_id_, |
| 196 plugin_rect_, | 203 plugin_rect_, |
| 197 deferred_clip_rect_, | 204 deferred_clip_rect_, |
| 198 NULL, | 205 TransportDIB::Id(), |
| 199 NULL)); | 206 TransportDIB::Id())); |
| 200 } | 207 } |
| 201 } | 208 } |
| 202 | 209 |
| 203 bool WebPluginDelegateProxy::Initialize(const GURL& url, char** argn, | 210 bool WebPluginDelegateProxy::Initialize(const GURL& url, char** argn, |
| 204 char** argv, int argc, | 211 char** argv, int argc, |
| 205 WebPlugin* plugin, | 212 WebPlugin* plugin, |
| 206 bool load_manually) { | 213 bool load_manually) { |
| 207 std::wstring channel_name; | 214 std::wstring channel_name; |
| 208 FilePath plugin_path; | 215 FilePath plugin_path; |
| 209 if (!RenderThread::current()->Send(new ViewHostMsg_OpenChannelToPlugin( | 216 if (!RenderThread::current()->Send(new ViewHostMsg_OpenChannelToPlugin( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 return plugin_path_; | 319 return plugin_path_; |
| 313 } | 320 } |
| 314 | 321 |
| 315 void WebPluginDelegateProxy::InstallMissingPlugin() { | 322 void WebPluginDelegateProxy::InstallMissingPlugin() { |
| 316 Send(new PluginMsg_InstallMissingPlugin(instance_id_)); | 323 Send(new PluginMsg_InstallMissingPlugin(instance_id_)); |
| 317 } | 324 } |
| 318 | 325 |
| 319 void WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { | 326 void WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { |
| 320 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) | 327 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) |
| 321 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) | 328 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) |
| 329 #if defined(OS_WIN) |
| 322 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessPumpEvent, | 330 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessPumpEvent, |
| 323 OnSetWindowlessPumpEvent) | 331 OnSetWindowlessPumpEvent) |
| 332 #endif |
| 324 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) | 333 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) |
| 325 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) | 334 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) |
| 326 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, | 335 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, |
| 327 OnGetWindowScriptNPObject) | 336 OnGetWindowScriptNPObject) |
| 328 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, | 337 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, |
| 329 OnGetPluginElement) | 338 OnGetPluginElement) |
| 330 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) | 339 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) |
| 331 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) | 340 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) |
| 332 IPC_MESSAGE_HANDLER(PluginHostMsg_ShowModalHTMLDialog, | 341 IPC_MESSAGE_HANDLER(PluginHostMsg_ShowModalHTMLDialog, |
| 333 OnShowModalHTMLDialog) | 342 OnShowModalHTMLDialog) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 352 void WebPluginDelegateProxy::UpdateGeometry( | 361 void WebPluginDelegateProxy::UpdateGeometry( |
| 353 const gfx::Rect& window_rect, | 362 const gfx::Rect& window_rect, |
| 354 const gfx::Rect& clip_rect) { | 363 const gfx::Rect& clip_rect) { |
| 355 plugin_rect_ = window_rect; | 364 plugin_rect_ = window_rect; |
| 356 if (!windowless_) { | 365 if (!windowless_) { |
| 357 deferred_clip_rect_ = clip_rect; | 366 deferred_clip_rect_ = clip_rect; |
| 358 send_deferred_update_geometry_ = true; | 367 send_deferred_update_geometry_ = true; |
| 359 return; | 368 return; |
| 360 } | 369 } |
| 361 | 370 |
| 362 HANDLE transport_store_handle = NULL; | 371 // Be careful to explicitly call the default constructors for these ids, |
| 363 HANDLE background_store_handle = NULL; | 372 // as they can be POD on some platforms and we want them initialized. |
| 373 TransportDIB::Id transport_store_id = TransportDIB::Id(); |
| 374 TransportDIB::Id background_store_id = TransportDIB::Id(); |
| 375 |
| 376 #if defined(OS_WIN) |
| 377 // TODO(port): use TransportDIB instead of allocating these directly. |
| 364 if (!backing_store_canvas_.get() || | 378 if (!backing_store_canvas_.get() || |
| 365 (window_rect.width() != backing_store_canvas_->getDevice()->width() || | 379 (window_rect.width() != backing_store_canvas_->getDevice()->width() || |
| 366 window_rect.height() != backing_store_canvas_->getDevice()->height())) { | 380 window_rect.height() != backing_store_canvas_->getDevice()->height())) { |
| 367 // Create a shared memory section that the plugin paints into | 381 // Create a shared memory section that the plugin paints into |
| 368 // asynchronously. | 382 // asynchronously. |
| 369 ResetWindowlessBitmaps(); | 383 ResetWindowlessBitmaps(); |
| 370 if (!window_rect.IsEmpty()) { | 384 if (!window_rect.IsEmpty()) { |
| 371 if (!CreateBitmap(&backing_store_, &backing_store_canvas_) || | 385 if (!CreateBitmap(&backing_store_, &backing_store_canvas_) || |
| 372 !CreateBitmap(&transport_store_, &transport_store_canvas_) || | 386 !CreateBitmap(&transport_store_, &transport_store_canvas_) || |
| 373 (transparent_ && | 387 (transparent_ && |
| 374 !CreateBitmap(&background_store_, &background_store_canvas_))) { | 388 !CreateBitmap(&background_store_, &background_store_canvas_))) { |
| 375 DCHECK(false); | 389 DCHECK(false); |
| 376 ResetWindowlessBitmaps(); | 390 ResetWindowlessBitmaps(); |
| 377 return; | 391 return; |
| 378 } | 392 } |
| 379 | 393 |
| 380 transport_store_handle = transport_store_->handle(); | 394 // TODO(port): once we use TransportDIB we will properly fill in these |
| 395 // ids; for now we just fill in the HANDLE field. |
| 396 transport_store_id.handle = transport_store_->handle(); |
| 381 if (background_store_.get()) | 397 if (background_store_.get()) |
| 382 background_store_handle = background_store_->handle(); | 398 background_store_id.handle = background_store_->handle(); |
| 383 } | 399 } |
| 384 } | 400 } |
| 401 #else |
| 402 // TODO(port): refactor our allocation of backing stores. |
| 403 NOTIMPLEMENTED(); |
| 404 #endif |
| 385 | 405 |
| 386 IPC::Message* msg = new PluginMsg_UpdateGeometry( | 406 IPC::Message* msg = new PluginMsg_UpdateGeometry( |
| 387 instance_id_, window_rect, clip_rect, | 407 instance_id_, window_rect, clip_rect, |
| 388 transport_store_handle, background_store_handle); | 408 transport_store_id, background_store_id); |
| 389 msg->set_unblock(true); | 409 msg->set_unblock(true); |
| 390 Send(msg); | 410 Send(msg); |
| 391 } | 411 } |
| 392 | 412 |
| 413 #if defined(OS_WIN) |
| 393 // Copied from render_widget.cc | 414 // Copied from render_widget.cc |
| 394 static size_t GetPaintBufSize(const gfx::Rect& rect) { | 415 static size_t GetPaintBufSize(const gfx::Rect& rect) { |
| 395 // TODO(darin): protect against overflow | 416 // TODO(darin): protect against overflow |
| 396 return 4 * rect.width() * rect.height(); | 417 return 4 * rect.width() * rect.height(); |
| 397 } | 418 } |
| 419 #endif |
| 398 | 420 |
| 399 void WebPluginDelegateProxy::ResetWindowlessBitmaps() { | 421 void WebPluginDelegateProxy::ResetWindowlessBitmaps() { |
| 400 backing_store_.reset(); | 422 backing_store_.reset(); |
| 401 transport_store_.reset(); | 423 transport_store_.reset(); |
| 402 backing_store_canvas_.reset(); | 424 backing_store_canvas_.reset(); |
| 403 transport_store_canvas_.reset(); | 425 transport_store_canvas_.reset(); |
| 404 background_store_.reset(); | 426 background_store_.reset(); |
| 405 background_store_canvas_.release(); | 427 background_store_canvas_.release(); |
| 406 backing_store_painted_ = gfx::Rect(); | 428 backing_store_painted_ = gfx::Rect(); |
| 407 } | 429 } |
| 408 | 430 |
| 409 bool WebPluginDelegateProxy::CreateBitmap( | 431 bool WebPluginDelegateProxy::CreateBitmap( |
| 410 scoped_ptr<base::SharedMemory>* memory, | 432 scoped_ptr<base::SharedMemory>* memory, |
| 411 scoped_ptr<skia::PlatformCanvasWin>* canvas) { | 433 scoped_ptr<skia::PlatformCanvas>* canvas) { |
| 434 #if defined(OS_WIN) |
| 412 size_t size = GetPaintBufSize(plugin_rect_); | 435 size_t size = GetPaintBufSize(plugin_rect_); |
| 413 scoped_ptr<base::SharedMemory> new_shared_memory(new base::SharedMemory()); | 436 scoped_ptr<base::SharedMemory> new_shared_memory(new base::SharedMemory()); |
| 414 if (!new_shared_memory->Create(L"", false, true, size)) | 437 if (!new_shared_memory->Create(L"", false, true, size)) |
| 415 return false; | 438 return false; |
| 416 | 439 |
| 417 scoped_ptr<skia::PlatformCanvasWin> new_canvas(new skia::PlatformCanvasWin); | 440 scoped_ptr<skia::PlatformCanvasWin> new_canvas(new skia::PlatformCanvasWin); |
| 418 if (!new_canvas->initialize(plugin_rect_.width(), plugin_rect_.height(), | 441 if (!new_canvas->initialize(plugin_rect_.width(), plugin_rect_.height(), |
| 419 true, new_shared_memory->handle())) { | 442 true, new_shared_memory->handle())) { |
| 420 return false; | 443 return false; |
| 421 } | 444 } |
| 422 | 445 |
| 423 memory->swap(new_shared_memory); | 446 memory->swap(new_shared_memory); |
| 424 canvas->swap(new_canvas); | 447 canvas->swap(new_canvas); |
| 425 return true; | 448 return true; |
| 449 #else |
| 450 // TODO(port): use TransportDIB properly. |
| 451 NOTIMPLEMENTED(); |
| 452 return false; |
| 453 #endif |
| 426 } | 454 } |
| 427 | 455 |
| 428 void WebPluginDelegateProxy::Paint(HDC hdc, const gfx::Rect& damaged_rect) { | 456 void WebPluginDelegateProxy::Paint(gfx::NativeDrawingContext context, |
| 457 const gfx::Rect& damaged_rect) { |
| 429 // If the plugin is no longer connected (channel crashed) draw a crashed | 458 // If the plugin is no longer connected (channel crashed) draw a crashed |
| 430 // plugin bitmap | 459 // plugin bitmap |
| 431 if (!channel_host_->channel_valid()) { | 460 if (!channel_host_->channel_valid()) { |
| 432 PaintSadPlugin(hdc, damaged_rect); | 461 PaintSadPlugin(context, damaged_rect); |
| 433 return; | 462 return; |
| 434 } | 463 } |
| 435 | 464 |
| 436 // No paint events for windowed plugins. | 465 // No paint events for windowed plugins. |
| 437 if (!windowless_) | 466 if (!windowless_) |
| 438 return; | 467 return; |
| 439 | 468 |
| 469 // TODO(port): side-stepping some windowless plugin code for now. |
| 470 #if defined(OS_WIN) |
| 440 // We got a paint before the plugin's coordinates, so there's no buffer to | 471 // We got a paint before the plugin's coordinates, so there's no buffer to |
| 441 // copy from. | 472 // copy from. |
| 442 if (!backing_store_canvas_.get()) | 473 if (!backing_store_canvas_.get()) |
| 443 return; | 474 return; |
| 444 | 475 |
| 445 // Limit the damaged rectangle to whatever is contained inside the plugin | 476 // Limit the damaged rectangle to whatever is contained inside the plugin |
| 446 // rectangle, as that's the rectangle that we'll bitblt to the hdc. | 477 // rectangle, as that's the rectangle that we'll bitblt to the hdc. |
| 447 gfx::Rect rect = damaged_rect.Intersect(plugin_rect_); | 478 gfx::Rect rect = damaged_rect.Intersect(plugin_rect_); |
| 448 | 479 |
| 449 bool background_changed = false; | 480 bool background_changed = false; |
| 450 if (background_store_canvas_.get() && BackgroundChanged(hdc, rect)) { | 481 if (background_store_canvas_.get() && BackgroundChanged(context, rect)) { |
| 451 background_changed = true; | 482 background_changed = true; |
| 452 HDC background_hdc = | 483 HDC background_hdc = |
| 453 background_store_canvas_->getTopPlatformDevice().getBitmapDC(); | 484 background_store_canvas_->getTopPlatformDevice().getBitmapDC(); |
| 454 BitBlt(background_hdc, rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(), | 485 BitBlt(background_hdc, rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(), |
| 455 rect.width(), rect.height(), hdc, rect.x(), rect.y(), SRCCOPY); | 486 rect.width(), rect.height(), context, rect.x(), rect.y(), SRCCOPY); |
| 456 } | 487 } |
| 457 | 488 |
| 458 gfx::Rect offset_rect = rect; | 489 gfx::Rect offset_rect = rect; |
| 459 offset_rect.Offset(-plugin_rect_.x(), -plugin_rect_.y()); | 490 offset_rect.Offset(-plugin_rect_.x(), -plugin_rect_.y()); |
| 460 if (background_changed || !backing_store_painted_.Contains(offset_rect)) { | 491 if (background_changed || !backing_store_painted_.Contains(offset_rect)) { |
| 461 Send(new PluginMsg_Paint(instance_id_, offset_rect)); | 492 Send(new PluginMsg_Paint(instance_id_, offset_rect)); |
| 462 CopyFromTransportToBacking(offset_rect); | 493 CopyFromTransportToBacking(offset_rect); |
| 463 } | 494 } |
| 464 | 495 |
| 465 HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); | 496 HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); |
| 466 BitBlt(hdc, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc, | 497 BitBlt(context, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc, |
| 467 rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(), SRCCOPY); | 498 rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(), SRCCOPY); |
| 468 | 499 |
| 469 if (invalidate_pending_) { | 500 if (invalidate_pending_) { |
| 470 // Only send the PaintAck message if this paint is in response to an | 501 // Only send the PaintAck message if this paint is in response to an |
| 471 // invalidate from the plugin, since this message acts as an access token | 502 // invalidate from the plugin, since this message acts as an access token |
| 472 // to ensure only one process is using the transport dib at a time. | 503 // to ensure only one process is using the transport dib at a time. |
| 473 invalidate_pending_ = false; | 504 invalidate_pending_ = false; |
| 474 Send(new PluginMsg_DidPaint(instance_id_)); | 505 Send(new PluginMsg_DidPaint(instance_id_)); |
| 475 } | 506 } |
| 507 #else |
| 508 // TODO(port): windowless plugin paint handling goes here. |
| 509 NOTIMPLEMENTED(); |
| 510 #endif |
| 476 } | 511 } |
| 477 | 512 |
| 513 #if defined(OS_WIN) |
| 514 // TODO(port): this should be portable; just avoiding windowless plugins for |
| 515 // now. |
| 478 bool WebPluginDelegateProxy::BackgroundChanged( | 516 bool WebPluginDelegateProxy::BackgroundChanged( |
| 479 HDC hdc, | 517 HDC hdc, |
| 480 const gfx::Rect& rect) { | 518 const gfx::Rect& rect) { |
| 481 HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); | 519 HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); |
| 482 if (hbitmap == NULL) { | 520 if (hbitmap == NULL) { |
| 483 NOTREACHED(); | 521 NOTREACHED(); |
| 484 return true; | 522 return true; |
| 485 } | 523 } |
| 486 | 524 |
| 487 BITMAP bitmap = { 0 }; | 525 BITMAP bitmap = { 0 }; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 512 // the plugin origin from the coordinates. | 550 // the plugin origin from the coordinates. |
| 513 uint32_t* canvas_row_start = | 551 uint32_t* canvas_row_start = |
| 514 background_store_canvas_->getDevice()->accessBitmap(true).getAddr32( | 552 background_store_canvas_->getDevice()->accessBitmap(true).getAddr32( |
| 515 check_rect.x() - plugin_rect_.x(), y - plugin_rect_.y()); | 553 check_rect.x() - plugin_rect_.x(), y - plugin_rect_.y()); |
| 516 if (memcmp(hdc_row_start, canvas_row_start, row_byte_size) != 0) | 554 if (memcmp(hdc_row_start, canvas_row_start, row_byte_size) != 0) |
| 517 return true; | 555 return true; |
| 518 } | 556 } |
| 519 | 557 |
| 520 return false; | 558 return false; |
| 521 } | 559 } |
| 560 #endif |
| 522 | 561 |
| 523 void WebPluginDelegateProxy::Print(HDC hdc) { | 562 void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) { |
| 524 base::SharedMemoryHandle shared_memory; | 563 base::SharedMemoryHandle shared_memory; |
| 525 size_t size; | 564 size_t size; |
| 526 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size))) | 565 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size))) |
| 527 return; | 566 return; |
| 528 | 567 |
| 529 base::SharedMemory memory(shared_memory, true); | 568 base::SharedMemory memory(shared_memory, true); |
| 530 if (!memory.Map(size)) { | 569 if (!memory.Map(size)) { |
| 531 NOTREACHED(); | 570 NOTREACHED(); |
| 532 return; | 571 return; |
| 533 } | 572 } |
| 534 | 573 |
| 574 #if defined(OS_WIN) |
| 535 gfx::Emf emf; | 575 gfx::Emf emf; |
| 536 if (!emf.CreateFromData(memory.memory(), size)) { | 576 if (!emf.CreateFromData(memory.memory(), size)) { |
| 537 NOTREACHED(); | 577 NOTREACHED(); |
| 538 return; | 578 return; |
| 539 } | 579 } |
| 540 // Playback the buffer. | 580 // Playback the buffer. |
| 541 emf.Playback(hdc, NULL); | 581 emf.Playback(context, NULL); |
| 582 #else |
| 583 // TODO(port): plugin printing. |
| 584 NOTIMPLEMENTED(); |
| 585 #endif |
| 542 } | 586 } |
| 543 | 587 |
| 544 NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { | 588 NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { |
| 545 if (npobject_) | 589 if (npobject_) |
| 546 return NPN_RetainObject(npobject_); | 590 return NPN_RetainObject(npobject_); |
| 547 | 591 |
| 548 int route_id = MSG_ROUTING_NONE; | 592 int route_id = MSG_ROUTING_NONE; |
| 549 intptr_t npobject_ptr; | 593 intptr_t npobject_ptr; |
| 550 Send(new PluginMsg_GetPluginScriptableObject( | 594 Send(new PluginMsg_GetPluginScriptableObject( |
| 551 instance_id_, &route_id, &npobject_ptr)); | 595 instance_id_, &route_id, &npobject_ptr)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 int route_id, bool* success, intptr_t* npobject_ptr) { | 685 int route_id, bool* success, intptr_t* npobject_ptr) { |
| 642 *success = false; | 686 *success = false; |
| 643 NPObject* npobject = NULL; | 687 NPObject* npobject = NULL; |
| 644 if (plugin_) | 688 if (plugin_) |
| 645 npobject = plugin_->GetPluginElement(); | 689 npobject = plugin_->GetPluginElement(); |
| 646 if (!npobject) | 690 if (!npobject) |
| 647 return; | 691 return; |
| 648 | 692 |
| 649 // The stub will delete itself when the proxy tells it that it's released, or | 693 // The stub will delete itself when the proxy tells it that it's released, or |
| 650 // otherwise when the channel is closed. | 694 // otherwise when the channel is closed. |
| 651 NPObjectStub* stub = new NPObjectStub( | 695 new NPObjectStub( |
| 652 npobject, channel_host_.get(), route_id, | 696 npobject, channel_host_.get(), route_id, |
| 653 render_view_->modal_dialog_event()); | 697 render_view_->modal_dialog_event()); |
| 654 *success = true; | 698 *success = true; |
| 655 *npobject_ptr = reinterpret_cast<intptr_t>(npobject); | 699 *npobject_ptr = reinterpret_cast<intptr_t>(npobject); |
| 656 } | 700 } |
| 657 | 701 |
| 658 void WebPluginDelegateProxy::OnSetCookie(const GURL& url, | 702 void WebPluginDelegateProxy::OnSetCookie(const GURL& url, |
| 659 const GURL& policy_url, | 703 const GURL& policy_url, |
| 660 const std::string& cookie) { | 704 const std::string& cookie) { |
| 661 if (plugin_) | 705 if (plugin_) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 681 | 725 |
| 682 void WebPluginDelegateProxy::OnMissingPluginStatus(int status) { | 726 void WebPluginDelegateProxy::OnMissingPluginStatus(int status) { |
| 683 if (render_view_) | 727 if (render_view_) |
| 684 render_view_->OnMissingPluginStatus(this, status); | 728 render_view_->OnMissingPluginStatus(this, status); |
| 685 } | 729 } |
| 686 | 730 |
| 687 void WebPluginDelegateProxy::OnGetCPBrowsingContext(uint32* context) { | 731 void WebPluginDelegateProxy::OnGetCPBrowsingContext(uint32* context) { |
| 688 *context = render_view_ ? render_view_->GetCPBrowsingContext() : 0; | 732 *context = render_view_ ? render_view_->GetCPBrowsingContext() : 0; |
| 689 } | 733 } |
| 690 | 734 |
| 691 void WebPluginDelegateProxy::PaintSadPlugin(HDC hdc, const gfx::Rect& rect) { | 735 void WebPluginDelegateProxy::PaintSadPlugin(gfx::NativeDrawingContext hdc, |
| 736 const gfx::Rect& rect) { |
| 737 #if defined(OS_WIN) |
| 692 const int width = plugin_rect_.width(); | 738 const int width = plugin_rect_.width(); |
| 693 const int height = plugin_rect_.height(); | 739 const int height = plugin_rect_.height(); |
| 694 | 740 |
| 695 ChromeCanvas canvas(width, height, false); | 741 ChromeCanvas canvas(width, height, false); |
| 696 SkPaint paint; | 742 SkPaint paint; |
| 697 | 743 |
| 698 paint.setStyle(SkPaint::kFill_Style); | 744 paint.setStyle(SkPaint::kFill_Style); |
| 699 paint.setColor(SK_ColorBLACK); | 745 paint.setColor(SK_ColorBLACK); |
| 700 canvas.drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), | 746 canvas.drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), |
| 701 paint); | 747 paint); |
| 702 | 748 |
| 703 if (!sad_plugin_) { | 749 if (!sad_plugin_) { |
| 704 sad_plugin_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 750 sad_plugin_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 705 IDR_SAD_PLUGIN); | 751 IDR_SAD_PLUGIN); |
| 706 } | 752 } |
| 707 | 753 |
| 708 if (sad_plugin_) { | 754 if (sad_plugin_) { |
| 709 canvas.DrawBitmapInt(*sad_plugin_, | 755 canvas.DrawBitmapInt(*sad_plugin_, |
| 710 std::max(0, (width - sad_plugin_->width())/2), | 756 std::max(0, (width - sad_plugin_->width())/2), |
| 711 std::max(0, (height - sad_plugin_->height())/2)); | 757 std::max(0, (height - sad_plugin_->height())/2)); |
| 712 } | 758 } |
| 713 | 759 |
| 714 canvas.getTopPlatformDevice().drawToHDC( | 760 canvas.getTopPlatformDevice().drawToHDC( |
| 715 hdc, plugin_rect_.x(), plugin_rect_.y(), NULL); | 761 hdc, plugin_rect_.x(), plugin_rect_.y(), NULL); |
| 716 return; | 762 #else |
| 763 // TODO(port): it ought to be possible to refactor this to be shared between |
| 764 // platforms. It's just the final drawToHDC that kills us. |
| 765 NOTIMPLEMENTED(); |
| 766 #endif |
| 717 } | 767 } |
| 718 | 768 |
| 719 void WebPluginDelegateProxy::CopyFromTransportToBacking(const gfx::Rect& rect) { | 769 void WebPluginDelegateProxy::CopyFromTransportToBacking(const gfx::Rect& rect) { |
| 720 if (!backing_store_canvas_.get()) | 770 if (!backing_store_canvas_.get()) |
| 721 return; | 771 return; |
| 722 | 772 |
| 773 #if defined(OS_WIN) |
| 723 // Copy the damaged rect from the transport bitmap to the backing store. | 774 // Copy the damaged rect from the transport bitmap to the backing store. |
| 724 HDC backing = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); | 775 HDC backing = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); |
| 725 HDC transport = transport_store_canvas_->getTopPlatformDevice().getBitmapDC(); | 776 HDC transport = transport_store_canvas_->getTopPlatformDevice().getBitmapDC(); |
| 726 BitBlt(backing, rect.x(), rect.y(), rect.width(), rect.height(), | 777 BitBlt(backing, rect.x(), rect.y(), rect.width(), rect.height(), |
| 727 transport, rect.x(), rect.y(), SRCCOPY); | 778 transport, rect.x(), rect.y(), SRCCOPY); |
| 728 backing_store_painted_ = backing_store_painted_.Union(rect); | 779 backing_store_painted_ = backing_store_painted_.Union(rect); |
| 780 #else |
| 781 // TODO(port): probably some new code in TransportDIB should go here. |
| 782 NOTIMPLEMENTED(); |
| 783 #endif |
| 729 } | 784 } |
| 730 | 785 |
| 731 void WebPluginDelegateProxy::OnHandleURLRequest( | 786 void WebPluginDelegateProxy::OnHandleURLRequest( |
| 732 const PluginHostMsg_URLRequest_Params& params) { | 787 const PluginHostMsg_URLRequest_Params& params) { |
| 733 const char* data = NULL; | 788 const char* data = NULL; |
| 734 if (params.buffer.size()) | 789 if (params.buffer.size()) |
| 735 data = ¶ms.buffer[0]; | 790 data = ¶ms.buffer[0]; |
| 736 | 791 |
| 737 const char* target = NULL; | 792 const char* target = NULL; |
| 738 if (params.target.length()) | 793 if (params.target.length()) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 766 plugin_->CancelDocumentLoad(); | 821 plugin_->CancelDocumentLoad(); |
| 767 } | 822 } |
| 768 | 823 |
| 769 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( | 824 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( |
| 770 const std::string& url, const std::string& range_info, | 825 const std::string& url, const std::string& range_info, |
| 771 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { | 826 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { |
| 772 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), | 827 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), |
| 773 existing_stream, notify_needed, | 828 existing_stream, notify_needed, |
| 774 notify_data); | 829 notify_data); |
| 775 } | 830 } |
| OLD | NEW |