| 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/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "content/common/browser_plugin_messages.h" | 9 #include "content/common/browser_plugin_messages.h" |
| 10 #include "content/public/common/content_client.h" | 10 #include "content/public/common/content_client.h" |
| 11 #include "content/public/renderer/content_renderer_client.h" | 11 #include "content/public/renderer/content_renderer_client.h" |
| 12 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 12 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
| 13 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 13 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 14 #include "content/renderer/browser_plugin/browser_plugin_texture_provider.h" |
| 14 #include "content/renderer/render_process_impl.h" | 15 #include "content/renderer/render_process_impl.h" |
| 15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
| 16 #include "skia/ext/platform_canvas.h" | 17 #include "skia/ext/platform_canvas.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 25 #include "webkit/plugins/sad_plugin.h" | 27 #include "webkit/plugins/sad_plugin.h" |
| 26 | 28 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 47 RenderViewImpl* render_view, | 49 RenderViewImpl* render_view, |
| 48 WebKit::WebFrame* frame, | 50 WebKit::WebFrame* frame, |
| 49 const WebPluginParams& params) | 51 const WebPluginParams& params) |
| 50 : instance_id_(instance_id), | 52 : instance_id_(instance_id), |
| 51 render_view_(render_view), | 53 render_view_(render_view), |
| 52 container_(NULL), | 54 container_(NULL), |
| 53 damage_buffer_(NULL), | 55 damage_buffer_(NULL), |
| 54 sad_guest_(NULL), | 56 sad_guest_(NULL), |
| 55 guest_crashed_(false), | 57 guest_crashed_(false), |
| 56 resize_pending_(false), | 58 resize_pending_(false), |
| 57 parent_frame_(frame->identifier()) { | 59 parent_frame_(frame->identifier()), |
| 60 provider_(0), |
| 61 ignore_input_(false) { |
| 58 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 62 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
| 59 bindings_.reset(new BrowserPluginBindings(this)); | 63 bindings_.reset(new BrowserPluginBindings(this)); |
| 60 | 64 |
| 61 std::string src; | 65 std::string src; |
| 62 if (ParseSrcAttribute(params, &src)) | 66 if (ParseSrcAttribute(params, &src)) |
| 63 SetSrcAttribute(src); | 67 SetSrcAttribute(src); |
| 64 } | 68 } |
| 65 | 69 |
| 66 BrowserPlugin::~BrowserPlugin() { | 70 BrowserPlugin::~BrowserPlugin() { |
| 67 if (damage_buffer_) { | 71 if (damage_buffer_) { |
| 68 RenderProcess::current()->FreeTransportDIB(damage_buffer_); | 72 RenderProcess::current()->FreeTransportDIB(damage_buffer_); |
| 69 damage_buffer_ = NULL; | 73 damage_buffer_ = NULL; |
| 70 } | 74 } |
| 71 RemoveEventListeners(); | 75 RemoveEventListeners(); |
| 72 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); | 76 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); |
| 73 BrowserPluginManager::Get()->Send( | 77 BrowserPluginManager::Get()->Send( |
| 74 new BrowserPluginHostMsg_PluginDestroyed( | 78 new BrowserPluginHostMsg_PluginDestroyed( |
| 75 render_view_->GetRoutingID(), | 79 render_view_->GetRoutingID(), |
| 76 instance_id_)); | 80 instance_id_)); |
| 81 |
| 82 if (provider_) |
| 83 provider_->Destroy(); |
| 77 } | 84 } |
| 78 | 85 |
| 79 void BrowserPlugin::Cleanup() { | 86 void BrowserPlugin::Cleanup() { |
| 80 if (damage_buffer_) { | 87 if (damage_buffer_) { |
| 81 RenderProcess::current()->FreeTransportDIB(damage_buffer_); | 88 RenderProcess::current()->FreeTransportDIB(damage_buffer_); |
| 82 damage_buffer_ = NULL; | 89 damage_buffer_ = NULL; |
| 83 } | 90 } |
| 84 } | 91 } |
| 85 | 92 |
| 86 std::string BrowserPlugin::GetSrcAttribute() const { | 93 std::string BrowserPlugin::GetSrcAttribute() const { |
| 87 return src_; | 94 return src_; |
| 88 } | 95 } |
| 89 | 96 |
| 90 void BrowserPlugin::SetSrcAttribute(const std::string& src) { | 97 void BrowserPlugin::SetSrcAttribute(const std::string& src) { |
| 91 if (src == src_ && !guest_crashed_) | 98 if (src == src_ && !guest_crashed_) |
| 92 return; | 99 return; |
| 93 if (!src.empty()) { | 100 if (!src.empty()) { |
| 101 WebKit::WebView* web_view = render_view_->webview(); |
| 102 DCHECK(web_view); |
| 103 WebGraphicsContext3DCommandBufferImpl* context = |
| 104 static_cast<WebGraphicsContext3DCommandBufferImpl*>( |
| 105 web_view->sharedGraphicsContext3D()); |
| 106 BrowserPluginHostMsg_Surface_Params params; |
| 107 if (context) { |
| 108 params.gpu_process_id = context->GetGPUProcessID(); |
| 109 params.client_id = context->GetChannelID(); |
| 110 params.context_id = context->GetContextID(); |
| 111 params.texture_id[0] = context->createTexture(); |
| 112 params.texture_id[1] = context->createTexture(); |
| 113 params.sync_point = context->insertSyncPoint(); |
| 114 } else { |
| 115 // Zero textures signal a lack of compositing |
| 116 params.texture_id[0] = params.texture_id[1] = 0; |
| 117 } |
| 94 BrowserPluginManager::Get()->Send( | 118 BrowserPluginManager::Get()->Send( |
| 95 new BrowserPluginHostMsg_NavigateGuest( | 119 new BrowserPluginHostMsg_NavigateGuest( |
| 96 render_view_->GetRoutingID(), | 120 render_view_->GetRoutingID(), |
| 97 instance_id_, | 121 instance_id_, |
| 98 parent_frame_, | 122 parent_frame_, |
| 99 src, | 123 src, |
| 100 gfx::Size(width(), height()))); | 124 gfx::Size(width(), height()), |
| 125 params)); |
| 101 } | 126 } |
| 102 src_ = src; | 127 src_ = src; |
| 103 guest_crashed_ = false; | 128 guest_crashed_ = false; |
| 104 } | 129 } |
| 105 | 130 |
| 106 bool BrowserPlugin::ParseSrcAttribute( | 131 bool BrowserPlugin::ParseSrcAttribute( |
| 107 const WebKit::WebPluginParams& params, | 132 const WebKit::WebPluginParams& params, |
| 108 std::string* src) { | 133 std::string* src) { |
| 109 // Get the src attribute from the attributes vector | 134 // Get the src attribute from the attributes vector |
| 110 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { | 135 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { |
| 111 std::string attributeName = params.attributeNames[i].utf8(); | 136 std::string attributeName = params.attributeNames[i].utf8(); |
| 112 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { | 137 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { |
| 113 *src = params.attributeValues[i].utf8(); | 138 *src = params.attributeValues[i].utf8(); |
| 114 return true; | 139 return true; |
| 115 } | 140 } |
| 116 } | 141 } |
| 117 return false; | 142 return false; |
| 118 } | 143 } |
| 119 | 144 |
| 120 float BrowserPlugin::GetDeviceScaleFactor() const { | 145 float BrowserPlugin::GetDeviceScaleFactor() const { |
| 121 if (!render_view_) | 146 if (!render_view_) |
| 122 return 1.0f; | 147 return 1.0f; |
| 123 return render_view_->GetWebView()->deviceScaleFactor(); | 148 return render_view_->GetWebView()->deviceScaleFactor(); |
| 124 } | 149 } |
| 125 | 150 |
| 151 BrowserPluginTextureProvider* BrowserPlugin::CreateTextureProvider( |
| 152 int instance_id, |
| 153 int routing_id) const { |
| 154 return new BrowserPluginTextureProvider( |
| 155 instance_id_, |
| 156 render_view_->GetRoutingID(), |
| 157 RenderThreadImpl::Get()->GetChannel()); |
| 158 } |
| 159 |
| 126 void BrowserPlugin::RemoveEventListeners() { | 160 void BrowserPlugin::RemoveEventListeners() { |
| 127 EventListenerMap::iterator event_listener_map_iter = | 161 EventListenerMap::iterator event_listener_map_iter = |
| 128 event_listener_map_.begin(); | 162 event_listener_map_.begin(); |
| 129 for (; event_listener_map_iter != event_listener_map_.end(); | 163 for (; event_listener_map_iter != event_listener_map_.end(); |
| 130 ++event_listener_map_iter) { | 164 ++event_listener_map_iter) { |
| 131 EventListeners& listeners = | 165 EventListeners& listeners = |
| 132 event_listener_map_[event_listener_map_iter->first]; | 166 event_listener_map_[event_listener_map_iter->first]; |
| 133 EventListeners::iterator it = listeners.begin(); | 167 EventListeners::iterator it = listeners.begin(); |
| 134 for (; it != listeners.end(); ++it) { | 168 for (; it != listeners.end(); ++it) { |
| 135 it->Dispose(); | 169 it->Dispose(); |
| 136 } | 170 } |
| 137 } | 171 } |
| 138 event_listener_map_.clear(); | 172 event_listener_map_.clear(); |
| 139 } | 173 } |
| 140 | 174 |
| 141 void BrowserPlugin::UpdateRect( | 175 void BrowserPlugin::UpdateRect( |
| 142 int message_id, | 176 int message_id, |
| 143 const BrowserPluginMsg_UpdateRect_Params& params) { | 177 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 144 if (width() != params.view_size.width() || | 178 if (width() != params.view_size.width() || |
| 145 height() != params.view_size.height()) { | 179 height() != params.view_size.height()) { |
| 146 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 180 if (params.needs_ack) |
| 147 render_view_->GetRoutingID(), | 181 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 148 instance_id_, | 182 render_view_->GetRoutingID(), |
| 149 message_id, | 183 instance_id_, |
| 150 gfx::Size(width(), height()))); | 184 message_id, |
| 185 gfx::Size(width(), height()))); |
| 151 return; | 186 return; |
| 152 } | 187 } |
| 153 | 188 |
| 154 float backing_store_scale_factor = | 189 float backing_store_scale_factor = |
| 155 backing_store_.get() ? backing_store_->GetScaleFactor() : 1.0f; | 190 backing_store_.get() ? backing_store_->GetScaleFactor() : 1.0f; |
| 156 | 191 |
| 157 if (params.is_resize_ack || | 192 if (params.is_resize_ack || |
| 158 backing_store_scale_factor != params.scale_factor) { | 193 backing_store_scale_factor != params.scale_factor) { |
| 159 resize_pending_ = !params.is_resize_ack; | 194 resize_pending_ = !params.is_resize_ack; |
| 160 backing_store_.reset( | 195 backing_store_.reset( |
| 161 new BrowserPluginBackingStore(gfx::Size(width(), height()), | 196 new BrowserPluginBackingStore(gfx::Size(width(), height()), |
| 162 params.scale_factor)); | 197 params.scale_factor)); |
| 163 } | 198 } |
| 164 | 199 |
| 165 // Update the backing store. | 200 // Update the backing store. |
| 166 if (!params.scroll_rect.IsEmpty()) { | 201 if (!params.scroll_rect.IsEmpty()) { |
| 167 backing_store_->ScrollBackingStore(params.dx, | 202 backing_store_->ScrollBackingStore(params.dx, |
| 168 params.dy, | 203 params.dy, |
| 169 params.scroll_rect, | 204 params.scroll_rect, |
| 170 params.view_size); | 205 params.view_size); |
| 171 } | 206 } |
| 172 for (unsigned i = 0; i < params.copy_rects.size(); i++) { | 207 for (unsigned i = 0; i < params.copy_rects.size(); i++) { |
| 173 backing_store_->PaintToBackingStore(params.bitmap_rect, | 208 backing_store_->PaintToBackingStore(params.bitmap_rect, |
| 174 params.copy_rects, | 209 params.copy_rects, |
| 175 damage_buffer_); | 210 damage_buffer_); |
| 176 } | 211 } |
| 177 // Invalidate the container. | 212 // Invalidate the container. |
| 178 container_->invalidate(); | 213 container_->invalidate(); |
| 179 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 214 if (params.needs_ack) |
| 180 render_view_->GetRoutingID(), | 215 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 181 instance_id_, | 216 render_view_->GetRoutingID(), |
| 182 message_id, | 217 instance_id_, |
| 183 gfx::Size())); | 218 message_id, |
| 219 gfx::Size())); |
| 184 } | 220 } |
| 185 | 221 |
| 186 void BrowserPlugin::GuestCrashed() { | 222 void BrowserPlugin::GuestCrashed() { |
| 187 guest_crashed_ = true; | 223 guest_crashed_ = true; |
| 188 container_->invalidate(); | 224 container_->invalidate(); |
| 189 | 225 |
| 190 if (!HasListeners(kCrashEventName)) | 226 if (!HasListeners(kCrashEventName)) |
| 191 return; | 227 return; |
| 192 | 228 |
| 193 EventListeners& listeners = event_listener_map_[kCrashEventName]; | 229 EventListeners& listeners = event_listener_map_[kCrashEventName]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 void BrowserPlugin::AdvanceFocus(bool reverse) { | 262 void BrowserPlugin::AdvanceFocus(bool reverse) { |
| 227 // We do not have a RenderView when we are testing. | 263 // We do not have a RenderView when we are testing. |
| 228 if (render_view_) | 264 if (render_view_) |
| 229 render_view_->GetWebView()->advanceFocus(reverse); | 265 render_view_->GetWebView()->advanceFocus(reverse); |
| 230 } | 266 } |
| 231 | 267 |
| 232 bool BrowserPlugin::HasListeners(const std::string& event_name) { | 268 bool BrowserPlugin::HasListeners(const std::string& event_name) { |
| 233 return event_listener_map_.find(event_name) != event_listener_map_.end(); | 269 return event_listener_map_.find(event_name) != event_listener_map_.end(); |
| 234 } | 270 } |
| 235 | 271 |
| 272 void BrowserPlugin::SurfaceResize(const gfx::Size& size) { |
| 273 if (!provider_) { |
| 274 provider_ = CreateTextureProvider(instance_id_, |
| 275 render_view_->GetRoutingID()); |
| 276 provider_->Resize(gfx::Size(width(), height())); |
| 277 } |
| 278 |
| 279 provider_->SurfaceResize(size); |
| 280 } |
| 281 |
| 282 void BrowserPlugin::BuffersSwapped( |
| 283 uint64 surface_handle, |
| 284 const BrowserPlugin_SwapInfo& info) { |
| 285 DCHECK(!ignore_input_); |
| 286 DCHECK(surface_handle); |
| 287 DCHECK(container_); |
| 288 DCHECK(provider_); |
| 289 |
| 290 provider_->SetDelayedSwap(surface_handle, info); |
| 291 |
| 292 container_->setBackingTextureProvider(provider_); |
| 293 container_->commitBackingTexture(); |
| 294 |
| 295 ignore_input_ = true; |
| 296 } |
| 297 |
| 298 void BrowserPlugin::TextureProviderIsReady() { |
| 299 ignore_input_ = false; |
| 300 } |
| 301 |
| 236 bool BrowserPlugin::AddEventListener(const std::string& event_name, | 302 bool BrowserPlugin::AddEventListener(const std::string& event_name, |
| 237 v8::Local<v8::Function> function) { | 303 v8::Local<v8::Function> function) { |
| 238 EventListeners& listeners = event_listener_map_[event_name]; | 304 EventListeners& listeners = event_listener_map_[event_name]; |
| 239 for (unsigned int i = 0; i < listeners.size(); ++i) { | 305 for (unsigned int i = 0; i < listeners.size(); ++i) { |
| 240 if (listeners[i] == function) | 306 if (listeners[i] == function) |
| 241 return false; | 307 return false; |
| 242 } | 308 } |
| 243 v8::Persistent<v8::Function> persistent_function = | 309 v8::Persistent<v8::Function> persistent_function = |
| 244 v8::Persistent<v8::Function>::New(function); | 310 v8::Persistent<v8::Function>::New(function); |
| 245 listeners.push_back(persistent_function); | 311 listeners.push_back(persistent_function); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_ResizeGuest( | 418 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 353 render_view_->GetRoutingID(), | 419 render_view_->GetRoutingID(), |
| 354 instance_id_, | 420 instance_id_, |
| 355 params)); | 421 params)); |
| 356 resize_pending_ = true; | 422 resize_pending_ = true; |
| 357 if (damage_buffer_) { | 423 if (damage_buffer_) { |
| 358 RenderProcess::current()->FreeTransportDIB(damage_buffer_); | 424 RenderProcess::current()->FreeTransportDIB(damage_buffer_); |
| 359 damage_buffer_ = NULL; | 425 damage_buffer_ = NULL; |
| 360 } | 426 } |
| 361 damage_buffer_ = new_damage_buffer; | 427 damage_buffer_ = new_damage_buffer; |
| 428 |
| 429 if (provider_) |
| 430 provider_->Resize(gfx::Size(window_rect.width, window_rect.height)); |
| 362 } | 431 } |
| 363 | 432 |
| 364 void BrowserPlugin::updateFocus(bool focused) { | 433 void BrowserPlugin::updateFocus(bool focused) { |
| 365 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus( | 434 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus( |
| 366 render_view_->GetRoutingID(), | 435 render_view_->GetRoutingID(), |
| 367 instance_id_, | 436 instance_id_, |
| 368 focused)); | 437 focused)); |
| 369 } | 438 } |
| 370 | 439 |
| 371 void BrowserPlugin::updateVisibility(bool visible) { | 440 void BrowserPlugin::updateVisibility(bool visible) { |
| 372 } | 441 } |
| 373 | 442 |
| 374 bool BrowserPlugin::acceptsInputEvents() { | 443 bool BrowserPlugin::acceptsInputEvents() { |
| 375 return true; | 444 return true; |
| 376 } | 445 } |
| 377 | 446 |
| 378 bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, | 447 bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, |
| 379 WebKit::WebCursorInfo& cursor_info) { | 448 WebKit::WebCursorInfo& cursor_info) { |
| 380 if (guest_crashed_ || src_.empty()) | 449 // In certain circumstances we won't pass input on to the guest. If we are |
| 450 // deliberately ignoring input to a working guest, we should sink the input |
| 451 // event so that we won't have a random stray input event handled by the |
| 452 // surrounding page. |
| 453 if (guest_crashed_ || src_.empty() || !container_) |
| 381 return false; | 454 return false; |
| 455 if (ignore_input_) |
| 456 return true; |
| 457 |
| 382 bool handled = false; | 458 bool handled = false; |
| 383 WebCursor cursor; | 459 WebCursor cursor; |
| 384 IPC::Message* message = | 460 IPC::Message* message = |
| 385 new BrowserPluginHostMsg_HandleInputEvent( | 461 new BrowserPluginHostMsg_HandleInputEvent( |
| 386 render_view_->GetRoutingID(), | 462 render_view_->GetRoutingID(), |
| 387 &handled, | 463 &handled, |
| 388 &cursor); | 464 &cursor); |
| 389 message->WriteInt(instance_id_); | 465 message->WriteInt(instance_id_); |
| 390 message->WriteData(reinterpret_cast<const char*>(&plugin_rect_), | 466 message->WriteData(reinterpret_cast<const char*>(&plugin_rect_), |
| 391 sizeof(gfx::Rect)); | 467 sizeof(gfx::Rect)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 412 void* notify_data) { | 488 void* notify_data) { |
| 413 } | 489 } |
| 414 | 490 |
| 415 void BrowserPlugin::didFailLoadingFrameRequest( | 491 void BrowserPlugin::didFailLoadingFrameRequest( |
| 416 const WebKit::WebURL& url, | 492 const WebKit::WebURL& url, |
| 417 void* notify_data, | 493 void* notify_data, |
| 418 const WebKit::WebURLError& error) { | 494 const WebKit::WebURLError& error) { |
| 419 } | 495 } |
| 420 | 496 |
| 421 } // namespace content | 497 } // namespace content |
| OLD | NEW |