| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/plugin/webplugin_proxy.h" | 5 #include "content/plugin/webplugin_proxy.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "content/child/npapi/npobject_proxy.h" | 11 #include "content/child/npapi/npobject_proxy.h" |
| 12 #include "content/child/npapi/npobject_util.h" | 12 #include "content/child/npapi/npobject_util.h" |
| 13 #include "content/child/npapi/webplugin_delegate_impl.h" | 13 #include "content/child/npapi/webplugin_delegate_impl.h" |
| 14 #include "content/child/npapi/webplugin_resource_client.h" | |
| 15 #include "content/child/plugin_messages.h" | 14 #include "content/child/plugin_messages.h" |
| 16 #include "content/plugin/plugin_channel.h" | 15 #include "content/plugin/plugin_channel.h" |
| 17 #include "content/plugin/plugin_thread.h" | 16 #include "content/plugin/plugin_thread.h" |
| 18 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 19 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
| 20 #include "third_party/WebKit/public/web/WebBindings.h" | 19 #include "third_party/WebKit/public/web/WebBindings.h" |
| 21 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 22 #include "url/url_constants.h" | 21 #include "url/url_constants.h" |
| 23 | 22 |
| 24 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 HANDLE pump_messages_event_for_renderer = NULL; | 100 HANDLE pump_messages_event_for_renderer = NULL; |
| 102 BrokerDuplicateHandle(pump_messages_event, channel_->peer_pid(), | 101 BrokerDuplicateHandle(pump_messages_event, channel_->peer_pid(), |
| 103 &pump_messages_event_for_renderer, | 102 &pump_messages_event_for_renderer, |
| 104 SYNCHRONIZE | EVENT_MODIFY_STATE, 0); | 103 SYNCHRONIZE | EVENT_MODIFY_STATE, 0); |
| 105 DCHECK(pump_messages_event_for_renderer); | 104 DCHECK(pump_messages_event_for_renderer); |
| 106 Send(new PluginHostMsg_SetWindowlessData( | 105 Send(new PluginHostMsg_SetWindowlessData( |
| 107 route_id_, pump_messages_event_for_renderer, dummy_activation_window)); | 106 route_id_, pump_messages_event_for_renderer, dummy_activation_window)); |
| 108 } | 107 } |
| 109 #endif | 108 #endif |
| 110 | 109 |
| 111 void WebPluginProxy::CancelResource(unsigned long id) { | |
| 112 Send(new PluginHostMsg_CancelResource(route_id_, id)); | |
| 113 resource_clients_.erase(id); | |
| 114 } | |
| 115 | |
| 116 void WebPluginProxy::Invalidate() { | 110 void WebPluginProxy::Invalidate() { |
| 117 gfx::Rect rect(0, 0, | 111 gfx::Rect rect(0, 0, |
| 118 delegate_->GetRect().width(), | 112 delegate_->GetRect().width(), |
| 119 delegate_->GetRect().height()); | 113 delegate_->GetRect().height()); |
| 120 InvalidateRect(rect); | 114 InvalidateRect(rect); |
| 121 } | 115 } |
| 122 | 116 |
| 123 void WebPluginProxy::InvalidateRect(const gfx::Rect& rect) { | 117 void WebPluginProxy::InvalidateRect(const gfx::Rect& rect) { |
| 124 #if defined(OS_MACOSX) | 118 #if defined(OS_MACOSX) |
| 125 // If this is a Core Animation plugin, all we need to do is inform the | 119 // If this is a Core Animation plugin, all we need to do is inform the |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 224 |
| 231 std::string WebPluginProxy::GetCookies(const GURL& url, | 225 std::string WebPluginProxy::GetCookies(const GURL& url, |
| 232 const GURL& first_party_for_cookies) { | 226 const GURL& first_party_for_cookies) { |
| 233 std::string cookies; | 227 std::string cookies; |
| 234 Send(new PluginHostMsg_GetCookies(route_id_, url, | 228 Send(new PluginHostMsg_GetCookies(route_id_, url, |
| 235 first_party_for_cookies, &cookies)); | 229 first_party_for_cookies, &cookies)); |
| 236 | 230 |
| 237 return cookies; | 231 return cookies; |
| 238 } | 232 } |
| 239 | 233 |
| 240 WebPluginResourceClient* WebPluginProxy::GetResourceClient(int id) { | |
| 241 ResourceClientMap::iterator iterator = resource_clients_.find(id); | |
| 242 // The IPC messages which deal with streams are now asynchronous. It is | |
| 243 // now possible to receive stream messages from the renderer for streams | |
| 244 // which may have been cancelled by the plugin. | |
| 245 if (iterator == resource_clients_.end()) { | |
| 246 return NULL; | |
| 247 } | |
| 248 | |
| 249 return iterator->second; | |
| 250 } | |
| 251 | |
| 252 int WebPluginProxy::GetRendererId() { | 234 int WebPluginProxy::GetRendererId() { |
| 253 if (channel_.get()) | 235 if (channel_.get()) |
| 254 return channel_->renderer_id(); | 236 return channel_->renderer_id(); |
| 255 return -1; | 237 return -1; |
| 256 } | 238 } |
| 257 | 239 |
| 258 void WebPluginProxy::DidPaint() { | 240 void WebPluginProxy::DidPaint() { |
| 259 // If we have an accumulated damaged rect, then check to see if we need to | 241 // If we have an accumulated damaged rect, then check to see if we need to |
| 260 // send out another InvalidateRect message. | 242 // send out another InvalidateRect message. |
| 261 waiting_for_paint_ = false; | 243 waiting_for_paint_ = false; |
| 262 if (!damaged_rect_.IsEmpty()) | 244 if (!damaged_rect_.IsEmpty()) |
| 263 InvalidateRect(damaged_rect_); | 245 InvalidateRect(damaged_rect_); |
| 264 } | 246 } |
| 265 | 247 |
| 266 void WebPluginProxy::OnResourceCreated(int resource_id, | |
| 267 WebPluginResourceClient* client) { | |
| 268 DCHECK(resource_clients_.find(resource_id) == resource_clients_.end()); | |
| 269 resource_clients_[resource_id] = client; | |
| 270 } | |
| 271 | |
| 272 void WebPluginProxy::Paint(const gfx::Rect& rect) { | 248 void WebPluginProxy::Paint(const gfx::Rect& rect) { |
| 273 #if defined(OS_MACOSX) | 249 #if defined(OS_MACOSX) |
| 274 if (!windowless_context()) | 250 if (!windowless_context()) |
| 275 return; | 251 return; |
| 276 #else | 252 #else |
| 277 if (!windowless_canvas() || !windowless_canvas()->getDevice()) | 253 if (!windowless_canvas() || !windowless_canvas()->getDevice()) |
| 278 return; | 254 return; |
| 279 #endif | 255 #endif |
| 280 | 256 |
| 281 // Clear the damaged area so that if the plugin doesn't paint there we won't | 257 // Clear the damaged area so that if the plugin doesn't paint there we won't |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 437 } |
| 462 | 438 |
| 463 void WebPluginProxy::DidStartLoading() { | 439 void WebPluginProxy::DidStartLoading() { |
| 464 Send(new PluginHostMsg_DidStartLoading(route_id_)); | 440 Send(new PluginHostMsg_DidStartLoading(route_id_)); |
| 465 } | 441 } |
| 466 | 442 |
| 467 void WebPluginProxy::DidStopLoading() { | 443 void WebPluginProxy::DidStopLoading() { |
| 468 Send(new PluginHostMsg_DidStopLoading(route_id_)); | 444 Send(new PluginHostMsg_DidStopLoading(route_id_)); |
| 469 } | 445 } |
| 470 | 446 |
| 471 void WebPluginProxy::SetDeferResourceLoading(unsigned long resource_id, | |
| 472 bool defer) { | |
| 473 Send(new PluginHostMsg_DeferResourceLoading(route_id_, resource_id, defer)); | |
| 474 } | |
| 475 | |
| 476 #if defined(OS_MACOSX) | 447 #if defined(OS_MACOSX) |
| 477 void WebPluginProxy::FocusChanged(bool focused) { | 448 void WebPluginProxy::FocusChanged(bool focused) { |
| 478 IPC::Message* msg = new PluginHostMsg_FocusChanged(route_id_, focused); | 449 IPC::Message* msg = new PluginHostMsg_FocusChanged(route_id_, focused); |
| 479 Send(msg); | 450 Send(msg); |
| 480 } | 451 } |
| 481 | 452 |
| 482 void WebPluginProxy::StartIme() { | 453 void WebPluginProxy::StartIme() { |
| 483 IPC::Message* msg = new PluginHostMsg_StartIme(route_id_); | 454 IPC::Message* msg = new PluginHostMsg_StartIme(route_id_); |
| 484 // This message can be sent during event-handling, and needs to be delivered | 455 // This message can be sent during event-handling, and needs to be delivered |
| 485 // within that context. | 456 // within that context. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 516 GetContentClient()->SetActiveURL(page_url_); | 487 GetContentClient()->SetActiveURL(page_url_); |
| 517 | 488 |
| 518 Paint(damaged_rect); | 489 Paint(damaged_rect); |
| 519 Send(new PluginHostMsg_InvalidateRect(route_id_, damaged_rect)); | 490 Send(new PluginHostMsg_InvalidateRect(route_id_, damaged_rect)); |
| 520 } | 491 } |
| 521 | 492 |
| 522 bool WebPluginProxy::IsOffTheRecord() { | 493 bool WebPluginProxy::IsOffTheRecord() { |
| 523 return channel_->incognito(); | 494 return channel_->incognito(); |
| 524 } | 495 } |
| 525 | 496 |
| 526 void WebPluginProxy::ResourceClientDeleted( | |
| 527 WebPluginResourceClient* resource_client) { | |
| 528 // resource_client->ResourceId() is 0 at this point, so can't use it as an | |
| 529 // index into the map. | |
| 530 ResourceClientMap::iterator index = resource_clients_.begin(); | |
| 531 while (index != resource_clients_.end()) { | |
| 532 WebPluginResourceClient* client = (*index).second; | |
| 533 if (client == resource_client) { | |
| 534 resource_clients_.erase(index); | |
| 535 return; | |
| 536 } else { | |
| 537 index++; | |
| 538 } | |
| 539 } | |
| 540 } | |
| 541 | |
| 542 void WebPluginProxy::URLRedirectResponse(bool allow, int resource_id) { | |
| 543 Send(new PluginHostMsg_URLRedirectResponse(route_id_, allow, resource_id)); | |
| 544 } | |
| 545 | |
| 546 #if defined(OS_WIN) && !defined(USE_AURA) | 497 #if defined(OS_WIN) && !defined(USE_AURA) |
| 547 void WebPluginProxy::UpdateIMEStatus() { | 498 void WebPluginProxy::UpdateIMEStatus() { |
| 548 // Retrieve the IME status from a plugin and send it to a renderer process | 499 // Retrieve the IME status from a plugin and send it to a renderer process |
| 549 // when the plugin has updated it. | 500 // when the plugin has updated it. |
| 550 int input_type; | 501 int input_type; |
| 551 gfx::Rect caret_rect; | 502 gfx::Rect caret_rect; |
| 552 if (!delegate_->GetIMEStatus(&input_type, &caret_rect)) | 503 if (!delegate_->GetIMEStatus(&input_type, &caret_rect)) |
| 553 return; | 504 return; |
| 554 | 505 |
| 555 Send(new PluginHostMsg_NotifyIMEStatus(route_id_, input_type, caret_rect)); | 506 Send(new PluginHostMsg_NotifyIMEStatus(route_id_, input_type, caret_rect)); |
| 556 } | 507 } |
| 557 #endif | 508 #endif |
| 558 | 509 |
| 559 } // namespace content | 510 } // namespace content |
| OLD | NEW |