Chromium Code Reviews| 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 DCHECK(context); | |
| 107 BrowserPluginHostMsg_Surface_Params params; | |
| 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(); | |
| 94 BrowserPluginManager::Get()->Send( | 114 BrowserPluginManager::Get()->Send( |
| 95 new BrowserPluginHostMsg_NavigateOrCreateGuest( | 115 new BrowserPluginHostMsg_NavigateOrCreateGuest( |
| 96 render_view_->GetRoutingID(), | 116 render_view_->GetRoutingID(), |
| 97 instance_id_, | 117 instance_id_, |
| 98 parent_frame_, | 118 parent_frame_, |
| 99 src)); | 119 src, |
| 120 params)); | |
| 100 } | 121 } |
| 101 src_ = src; | 122 src_ = src; |
| 102 guest_crashed_ = false; | 123 guest_crashed_ = false; |
| 103 } | 124 } |
| 104 | 125 |
| 105 bool BrowserPlugin::ParseSrcAttribute( | 126 bool BrowserPlugin::ParseSrcAttribute( |
| 106 const WebKit::WebPluginParams& params, | 127 const WebKit::WebPluginParams& params, |
| 107 std::string* src) { | 128 std::string* src) { |
| 108 // Get the src attribute from the attributes vector | 129 // Get the src attribute from the attributes vector |
| 109 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { | 130 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 133 for (; it != listeners.end(); ++it) { | 154 for (; it != listeners.end(); ++it) { |
| 134 it->Dispose(); | 155 it->Dispose(); |
| 135 } | 156 } |
| 136 } | 157 } |
| 137 event_listener_map_.clear(); | 158 event_listener_map_.clear(); |
| 138 } | 159 } |
| 139 | 160 |
| 140 void BrowserPlugin::UpdateRect( | 161 void BrowserPlugin::UpdateRect( |
| 141 int message_id, | 162 int message_id, |
| 142 const BrowserPluginMsg_UpdateRect_Params& params) { | 163 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 143 if (width() != params.view_size.width() || | 164 if ((width() != params.view_size.width() || |
| 144 height() != params.view_size.height()) { | 165 height() != params.view_size.height()) && params.needs_ack) { |
| 145 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 166 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 146 render_view_->GetRoutingID(), | 167 render_view_->GetRoutingID(), |
| 147 instance_id_, | 168 instance_id_, |
| 148 message_id, | 169 message_id, |
| 149 gfx::Size(width(), height()))); | 170 gfx::Size(width(), height()))); |
| 150 return; | 171 return; |
| 151 } | 172 } |
| 152 | 173 |
| 153 float backing_store_scale_factor = | 174 float backing_store_scale_factor = |
| 154 backing_store_.get() ? backing_store_->GetScaleFactor() : 1.0f; | 175 backing_store_.get() ? backing_store_->GetScaleFactor() : 1.0f; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 168 params.scroll_rect, | 189 params.scroll_rect, |
| 169 params.view_size); | 190 params.view_size); |
| 170 } | 191 } |
| 171 for (unsigned i = 0; i < params.copy_rects.size(); i++) { | 192 for (unsigned i = 0; i < params.copy_rects.size(); i++) { |
| 172 backing_store_->PaintToBackingStore(params.bitmap_rect, | 193 backing_store_->PaintToBackingStore(params.bitmap_rect, |
| 173 params.copy_rects, | 194 params.copy_rects, |
| 174 damage_buffer_); | 195 damage_buffer_); |
| 175 } | 196 } |
| 176 // Invalidate the container. | 197 // Invalidate the container. |
| 177 container_->invalidate(); | 198 container_->invalidate(); |
| 178 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 199 if (params.needs_ack) |
| 179 render_view_->GetRoutingID(), | 200 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 180 instance_id_, | 201 render_view_->GetRoutingID(), |
| 181 message_id, | 202 instance_id_, |
| 182 gfx::Size())); | 203 message_id, |
| 204 gfx::Size())); | |
| 183 } | 205 } |
| 184 | 206 |
| 185 void BrowserPlugin::GuestCrashed() { | 207 void BrowserPlugin::GuestCrashed() { |
| 186 guest_crashed_ = true; | 208 guest_crashed_ = true; |
| 187 container_->invalidate(); | 209 container_->invalidate(); |
| 188 | 210 |
| 189 if (!HasListeners(kCrashEventName)) | 211 if (!HasListeners(kCrashEventName)) |
| 190 return; | 212 return; |
| 191 | 213 |
| 192 EventListeners& listeners = event_listener_map_[kCrashEventName]; | 214 EventListeners& listeners = event_listener_map_[kCrashEventName]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 void BrowserPlugin::AdvanceFocus(bool reverse) { | 247 void BrowserPlugin::AdvanceFocus(bool reverse) { |
| 226 // We do not have a RenderView when we are testing. | 248 // We do not have a RenderView when we are testing. |
| 227 if (render_view_) | 249 if (render_view_) |
| 228 render_view_->GetWebView()->advanceFocus(reverse); | 250 render_view_->GetWebView()->advanceFocus(reverse); |
| 229 } | 251 } |
| 230 | 252 |
| 231 bool BrowserPlugin::HasListeners(const std::string& event_name) { | 253 bool BrowserPlugin::HasListeners(const std::string& event_name) { |
| 232 return event_listener_map_.find(event_name) != event_listener_map_.end(); | 254 return event_listener_map_.find(event_name) != event_listener_map_.end(); |
| 233 } | 255 } |
| 234 | 256 |
| 257 void BrowserPlugin::SurfaceResize(const gfx::Size& size) { | |
| 258 if (!provider_) { | |
| 259 provider_ = new BrowserPluginTextureProvider(instance_id_, render_view_); | |
| 260 provider_->Resize(gfx::Size(width(), height())); | |
| 261 } | |
| 262 | |
| 263 provider_->SurfaceResize(size); | |
| 264 } | |
| 265 | |
| 266 void BrowserPlugin::BuffersSwapped( | |
| 267 uint64 surface_handle, | |
| 268 const BrowserPlugin_SwapInfo& info) { | |
| 269 DCHECK(!ignore_input_); | |
| 270 DCHECK(surface_handle); | |
| 271 DCHECK(container_); | |
| 272 DCHECK(provider_); | |
| 273 | |
| 274 provider_->SetDelayedSwap(surface_handle, info); | |
| 275 | |
| 276 container_->setBackingTextureProvider(provider_); | |
| 277 container_->commitBackingTexture(); | |
| 278 | |
| 279 ignore_input_ = true; | |
|
scshunt
2012/08/12 01:42:45
ignore_input should probably be commented, explain
| |
| 280 } | |
| 281 | |
| 282 void BrowserPlugin::TextureProviderIsReady() { | |
| 283 ignore_input_ = false; | |
| 284 } | |
| 285 | |
| 235 bool BrowserPlugin::AddEventListener(const std::string& event_name, | 286 bool BrowserPlugin::AddEventListener(const std::string& event_name, |
| 236 v8::Local<v8::Function> function) { | 287 v8::Local<v8::Function> function) { |
| 237 EventListeners& listeners = event_listener_map_[event_name]; | 288 EventListeners& listeners = event_listener_map_[event_name]; |
| 238 for (unsigned int i = 0; i < listeners.size(); ++i) { | 289 for (unsigned int i = 0; i < listeners.size(); ++i) { |
| 239 if (listeners[i] == function) | 290 if (listeners[i] == function) |
| 240 return false; | 291 return false; |
| 241 } | 292 } |
| 242 v8::Persistent<v8::Function> persistent_function = | 293 v8::Persistent<v8::Function> persistent_function = |
| 243 v8::Persistent<v8::Function>::New(function); | 294 v8::Persistent<v8::Function>::New(function); |
| 244 listeners.push_back(persistent_function); | 295 listeners.push_back(persistent_function); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 render_view_->GetRoutingID(), | 403 render_view_->GetRoutingID(), |
| 353 instance_id_, | 404 instance_id_, |
| 354 params)); | 405 params)); |
| 355 resize_pending_ = true; | 406 resize_pending_ = true; |
| 356 | 407 |
| 357 if (damage_buffer_) { | 408 if (damage_buffer_) { |
| 358 RenderProcess::current()->FreeTransportDIB(damage_buffer_); | 409 RenderProcess::current()->FreeTransportDIB(damage_buffer_); |
| 359 damage_buffer_ = NULL; | 410 damage_buffer_ = NULL; |
| 360 } | 411 } |
| 361 damage_buffer_ = new_damage_buffer; | 412 damage_buffer_ = new_damage_buffer; |
| 413 | |
| 414 if (provider_) | |
| 415 provider_->Resize(gfx::Size(window_rect.width, window_rect.height)); | |
| 362 } | 416 } |
| 363 | 417 |
| 364 void BrowserPlugin::updateFocus(bool focused) { | 418 void BrowserPlugin::updateFocus(bool focused) { |
| 365 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus( | 419 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus( |
| 366 render_view_->GetRoutingID(), | 420 render_view_->GetRoutingID(), |
| 367 instance_id_, | 421 instance_id_, |
| 368 focused)); | 422 focused)); |
| 369 } | 423 } |
| 370 | 424 |
| 371 void BrowserPlugin::updateVisibility(bool visible) { | 425 void BrowserPlugin::updateVisibility(bool visible) { |
| 372 } | 426 } |
| 373 | 427 |
| 374 bool BrowserPlugin::acceptsInputEvents() { | 428 bool BrowserPlugin::acceptsInputEvents() { |
| 375 return true; | 429 return true; |
| 376 } | 430 } |
| 377 | 431 |
| 378 bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, | 432 bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, |
| 379 WebKit::WebCursorInfo& cursor_info) { | 433 WebKit::WebCursorInfo& cursor_info) { |
| 380 if (guest_crashed_ || src_.empty()) | 434 if (guest_crashed_ || src_.empty() || !container_ || ignore_input_) |
| 381 return false; | 435 return false; |
| 382 bool handled = false; | 436 bool handled = false; |
| 383 WebCursor cursor; | 437 WebCursor cursor; |
| 384 IPC::Message* message = | 438 IPC::Message* message = |
| 385 new BrowserPluginHostMsg_HandleInputEvent( | 439 new BrowserPluginHostMsg_HandleInputEvent( |
| 386 render_view_->GetRoutingID(), | 440 render_view_->GetRoutingID(), |
| 387 &handled, | 441 &handled, |
| 388 &cursor); | 442 &cursor); |
| 389 message->WriteInt(instance_id_); | 443 message->WriteInt(instance_id_); |
| 390 message->WriteData(reinterpret_cast<const char*>(&plugin_rect_), | 444 message->WriteData(reinterpret_cast<const char*>(&plugin_rect_), |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 412 void* notify_data) { | 466 void* notify_data) { |
| 413 } | 467 } |
| 414 | 468 |
| 415 void BrowserPlugin::didFailLoadingFrameRequest( | 469 void BrowserPlugin::didFailLoadingFrameRequest( |
| 416 const WebKit::WebURL& url, | 470 const WebKit::WebURL& url, |
| 417 void* notify_data, | 471 void* notify_data, |
| 418 const WebKit::WebURLError& error) { | 472 const WebKit::WebURLError& error) { |
| 419 } | 473 } |
| 420 | 474 |
| 421 } // namespace content | 475 } // namespace content |
| OLD | NEW |