| 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 #if defined (OS_WIN) | 9 #if defined (OS_WIN) |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 11 #endif | 11 #endif |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "content/common/browser_plugin_messages.h" | 13 #include "content/common/browser_plugin_messages.h" |
| 14 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
| 15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
| 16 #include "content/public/renderer/content_renderer_client.h" | 16 #include "content/public/renderer/content_renderer_client.h" |
| 17 #include "content/renderer/gpu/compositor_thread.h" |
| 17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
| 18 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 19 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 20 #include "content/renderer/browser_plugin/browser_plugin_texture_provider.h" |
| 19 #include "content/renderer/render_process_impl.h" | 21 #include "content/renderer/render_process_impl.h" |
| 20 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 21 #include "skia/ext/platform_canvas.h" | 23 #include "skia/ext/platform_canvas.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 sad_guest_(NULL), | 91 sad_guest_(NULL), |
| 90 guest_crashed_(false), | 92 guest_crashed_(false), |
| 91 resize_pending_(false), | 93 resize_pending_(false), |
| 92 navigate_src_sent_(false), | 94 navigate_src_sent_(false), |
| 93 process_id_(-1), | 95 process_id_(-1), |
| 94 persist_storage_(false), | 96 persist_storage_(false), |
| 95 content_window_routing_id_(MSG_ROUTING_NONE), | 97 content_window_routing_id_(MSG_ROUTING_NONE), |
| 96 focused_(false), | 98 focused_(false), |
| 97 visible_(true), | 99 visible_(true), |
| 98 current_nav_entry_index_(0), | 100 current_nav_entry_index_(0), |
| 99 nav_entry_count_(0) { | 101 nav_entry_count_(0), |
| 102 provider_(0), |
| 103 compositingPossible_(false), |
| 104 compositingEnabled_(false) { |
| 100 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 105 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
| 101 bindings_.reset(new BrowserPluginBindings(this)); | 106 bindings_.reset(new BrowserPluginBindings(this)); |
| 102 | 107 |
| 103 InitializeEvents(); | 108 InitializeEvents(); |
| 104 | 109 |
| 105 ParseAttributes(params); | 110 ParseAttributes(params); |
| 106 } | 111 } |
| 107 | 112 |
| 108 BrowserPlugin::~BrowserPlugin() { | 113 BrowserPlugin::~BrowserPlugin() { |
| 109 if (damage_buffer_) | 114 if (damage_buffer_) |
| 110 FreeDamageBuffer(); | 115 FreeDamageBuffer(); |
| 111 RemoveEventListeners(); | 116 RemoveEventListeners(); |
| 112 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); | 117 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); |
| 113 BrowserPluginManager::Get()->Send( | 118 BrowserPluginManager::Get()->Send( |
| 114 new BrowserPluginHostMsg_PluginDestroyed( | 119 new BrowserPluginHostMsg_PluginDestroyed( |
| 115 render_view_routing_id_, | 120 render_view_routing_id_, |
| 116 instance_id_)); | 121 instance_id_)); |
| 122 |
| 123 if (provider_) |
| 124 provider_->Destroy(); |
| 117 } | 125 } |
| 118 | 126 |
| 119 void BrowserPlugin::Cleanup() { | 127 void BrowserPlugin::Cleanup() { |
| 120 if (damage_buffer_) | 128 if (damage_buffer_) |
| 121 FreeDamageBuffer(); | 129 FreeDamageBuffer(); |
| 122 } | 130 } |
| 123 | 131 |
| 124 std::string BrowserPlugin::GetSrcAttribute() const { | 132 std::string BrowserPlugin::GetSrcAttribute() const { |
| 125 return src_; | 133 return src_; |
| 126 } | 134 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 140 storage_partition_id_, | 148 storage_partition_id_, |
| 141 persist_storage_, | 149 persist_storage_, |
| 142 focused_, | 150 focused_, |
| 143 visible_)); | 151 visible_)); |
| 144 } | 152 } |
| 145 | 153 |
| 146 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params( | 154 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params( |
| 147 GetPendingResizeParams()); | 155 GetPendingResizeParams()); |
| 148 DCHECK(!params->resize_pending); | 156 DCHECK(!params->resize_pending); |
| 149 | 157 |
| 158 WebKit::WebView* web_view = render_view_->webview(); |
| 159 DCHECK(web_view); |
| 160 WebGraphicsContext3DCommandBufferImpl* context = NULL; |
| 161 if (compositingPossible_) { |
| 162 context = static_cast<WebGraphicsContext3DCommandBufferImpl*>( |
| 163 web_view->sharedGraphicsContext3D()); |
| 164 } |
| 165 ProvideHWCompositingInfo(params.get(), context); |
| 166 |
| 150 BrowserPluginManager::Get()->Send( | 167 BrowserPluginManager::Get()->Send( |
| 151 new BrowserPluginHostMsg_NavigateGuest( | 168 new BrowserPluginHostMsg_NavigateGuest( |
| 152 render_view_routing_id_, | 169 render_view_routing_id_, |
| 153 instance_id_, | 170 instance_id_, |
| 154 src, | 171 src, |
| 155 *params)); | 172 *params)); |
| 156 // Record that we sent a NavigateGuest message to embedder. | 173 // Record that we sent a NavigateGuest message to embedder. |
| 157 // Once this instance has navigated, the storage partition cannot be changed, | 174 // Once this instance has navigated, the storage partition cannot be changed, |
| 158 // so this value is used for enforcing this. | 175 // so this value is used for enforcing this. |
| 159 navigate_src_sent_ = true; | 176 navigate_src_sent_ = true; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 265 |
| 249 void BrowserPlugin::InitializeEvents() { | 266 void BrowserPlugin::InitializeEvents() { |
| 250 event_listener_map_[kExitEventName] = EventListeners(); | 267 event_listener_map_[kExitEventName] = EventListeners(); |
| 251 event_listener_map_[kLoadAbortEventName] = EventListeners(); | 268 event_listener_map_[kLoadAbortEventName] = EventListeners(); |
| 252 event_listener_map_[kLoadCommitEventName] = EventListeners(); | 269 event_listener_map_[kLoadCommitEventName] = EventListeners(); |
| 253 event_listener_map_[kLoadRedirectEventName] = EventListeners(); | 270 event_listener_map_[kLoadRedirectEventName] = EventListeners(); |
| 254 event_listener_map_[kLoadStartEventName] = EventListeners(); | 271 event_listener_map_[kLoadStartEventName] = EventListeners(); |
| 255 event_listener_map_[kLoadStopEventName] = EventListeners(); | 272 event_listener_map_[kLoadStopEventName] = EventListeners(); |
| 256 } | 273 } |
| 257 | 274 |
| 275 void BrowserPlugin::InitializeTextureProvider() { |
| 276 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 277 CompositorThread* compositor_thread = render_thread_impl->compositor_thread(); |
| 278 compositingPossible_ = !!compositor_thread; |
| 279 |
| 280 if (compositingPossible_) { |
| 281 MessageLoop* compositor_thread_loop = compositor_thread->message_loop(); |
| 282 provider_ = new BrowserPluginTextureProvider( |
| 283 instance_id_, |
| 284 render_view_->GetRoutingID(), |
| 285 RenderThreadImpl::Get()->GetChannel(), |
| 286 compositor_thread_loop->message_loop_proxy()); |
| 287 provider_->Initialize(); |
| 288 } |
| 289 } |
| 290 |
| 291 void BrowserPlugin::ProvideHWCompositingInfo( |
| 292 BrowserPluginHostMsg_ResizeGuest_Params* params, |
| 293 WebGraphicsContext3DCommandBufferImpl* context) { |
| 294 if (context) { |
| 295 params->gpu_process_id = context->GetGPUProcessID(); |
| 296 params->client_id = context->GetChannelID(); |
| 297 params->context_id = context->GetContextID(); |
| 298 params->texture_id_0 = context->createTexture(); |
| 299 params->texture_id_1 = context->createTexture(); |
| 300 params->sync_point = context->insertSyncPoint(); |
| 301 } else { |
| 302 // Zero textures signal a lack of compositing |
| 303 params->gpu_process_id = 0; |
| 304 params->client_id = 0; |
| 305 params->context_id = 0; |
| 306 params->texture_id_0 = 0; |
| 307 params->texture_id_1 = 0; |
| 308 params->sync_point = 0; |
| 309 } |
| 310 } |
| 311 |
| 258 void BrowserPlugin::RemoveEventListeners() { | 312 void BrowserPlugin::RemoveEventListeners() { |
| 259 EventListenerMap::iterator event_listener_map_iter = | 313 EventListenerMap::iterator event_listener_map_iter = |
| 260 event_listener_map_.begin(); | 314 event_listener_map_.begin(); |
| 261 for (; event_listener_map_iter != event_listener_map_.end(); | 315 for (; event_listener_map_iter != event_listener_map_.end(); |
| 262 ++event_listener_map_iter) { | 316 ++event_listener_map_iter) { |
| 263 EventListeners& listeners = | 317 EventListeners& listeners = |
| 264 event_listener_map_[event_listener_map_iter->first]; | 318 event_listener_map_[event_listener_map_iter->first]; |
| 265 EventListeners::iterator it = listeners.begin(); | 319 EventListeners::iterator it = listeners.begin(); |
| 266 for (; it != listeners.end(); ++it) { | 320 for (; it != listeners.end(); ++it) { |
| 267 it->Dispose(); | 321 it->Dispose(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 for (unsigned i = 0; i < params.copy_rects.size(); i++) { | 448 for (unsigned i = 0; i < params.copy_rects.size(); i++) { |
| 395 backing_store_->PaintToBackingStore(params.bitmap_rect, | 449 backing_store_->PaintToBackingStore(params.bitmap_rect, |
| 396 params.copy_rects, | 450 params.copy_rects, |
| 397 damage_buffer_); | 451 damage_buffer_); |
| 398 } | 452 } |
| 399 // Invalidate the container. | 453 // Invalidate the container. |
| 400 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 454 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 401 // NULL so we shouldn't attempt to access it. | 455 // NULL so we shouldn't attempt to access it. |
| 402 if (container_) | 456 if (container_) |
| 403 container_->invalidate(); | 457 container_->invalidate(); |
| 458 |
| 404 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 459 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 405 render_view_routing_id_, | 460 render_view_routing_id_, |
| 406 instance_id_, | 461 instance_id_, |
| 407 message_id, | 462 message_id, |
| 408 gfx::Size())); | 463 gfx::Size())); |
| 409 } | 464 } |
| 410 | 465 |
| 411 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { | 466 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { |
| 412 // We fire the event listeners before painting the sad graphic to give the | 467 // We fire the event listeners before painting the sad graphic to give the |
| 413 // developer an opportunity to display an alternative overlay image on crash. | 468 // developer an opportunity to display an alternative overlay image on crash. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 669 |
| 615 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 670 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
| 616 return container_; | 671 return container_; |
| 617 } | 672 } |
| 618 | 673 |
| 619 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 674 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 620 container_ = container; | 675 container_ = container; |
| 621 return true; | 676 return true; |
| 622 } | 677 } |
| 623 | 678 |
| 679 void BrowserPlugin::EnableCompositing() { |
| 680 if (!compositingPossible_) { |
| 681 LOG(WARNING) << "BrowserPlugin compositing requires an impl thread, " |
| 682 << "try running with --enable-threaded-compositing"; |
| 683 return; |
| 684 } |
| 685 if (!compositingEnabled_) |
| 686 container_->setBackingTextureProvider(provider_); |
| 687 |
| 688 compositingEnabled_ = true; |
| 689 } |
| 690 |
| 624 void BrowserPlugin::destroy() { | 691 void BrowserPlugin::destroy() { |
| 625 // The BrowserPlugin's WebPluginContainer is deleted immediately after this | 692 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
| 626 // call returns, so let's not keep a reference to it around. | 693 // call returns, so let's not keep a reference to it around. |
| 627 container_ = NULL; | 694 container_ = NULL; |
| 628 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 695 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 629 } | 696 } |
| 630 | 697 |
| 631 NPObject* BrowserPlugin::scriptableObject() { | 698 NPObject* BrowserPlugin::scriptableObject() { |
| 632 NPObject* browser_plugin_np_object(bindings_->np_object()); | 699 NPObject* browser_plugin_np_object(bindings_->np_object()); |
| 633 // The object is expected to be retained before it is returned. | 700 // The object is expected to be retained before it is returned. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 float inverse_scale_factor = 1.0f / backing_store_->GetScaleFactor(); | 745 float inverse_scale_factor = 1.0f / backing_store_->GetScaleFactor(); |
| 679 canvas->scale(inverse_scale_factor, inverse_scale_factor); | 746 canvas->scale(inverse_scale_factor, inverse_scale_factor); |
| 680 canvas->drawBitmap(backing_store_->GetBitmap(), 0, 0); | 747 canvas->drawBitmap(backing_store_->GetBitmap(), 0, 0); |
| 681 } | 748 } |
| 682 | 749 |
| 683 void BrowserPlugin::updateGeometry( | 750 void BrowserPlugin::updateGeometry( |
| 684 const WebRect& window_rect, | 751 const WebRect& window_rect, |
| 685 const WebRect& clip_rect, | 752 const WebRect& clip_rect, |
| 686 const WebVector<WebRect>& cut_outs_rects, | 753 const WebVector<WebRect>& cut_outs_rects, |
| 687 bool is_visible) { | 754 bool is_visible) { |
| 755 |
| 688 int old_width = width(); | 756 int old_width = width(); |
| 689 int old_height = height(); | 757 int old_height = height(); |
| 690 plugin_rect_ = window_rect; | 758 plugin_rect_ = window_rect; |
| 691 if (old_width == window_rect.width && | 759 if (old_width == window_rect.width && |
| 692 old_height == window_rect.height) { | 760 old_height == window_rect.height) { |
| 693 return; | 761 return; |
| 694 } | 762 } |
| 695 | 763 |
| 696 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width); | 764 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width); |
| 697 // Make sure the size of the damage buffer is at least four bytes so that we | 765 // Make sure the size of the damage buffer is at least four bytes so that we |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 } else { | 832 } else { |
| 765 BrowserPluginHostMsg_ResizeGuest_Params* params = | 833 BrowserPluginHostMsg_ResizeGuest_Params* params = |
| 766 new BrowserPluginHostMsg_ResizeGuest_Params; | 834 new BrowserPluginHostMsg_ResizeGuest_Params; |
| 767 | 835 |
| 768 // We don't have a pending resize to send, so we send an invalid transport | 836 // We don't have a pending resize to send, so we send an invalid transport |
| 769 // dib Id. | 837 // dib Id. |
| 770 params->damage_buffer_id = TransportDIB::Id(); | 838 params->damage_buffer_id = TransportDIB::Id(); |
| 771 params->width = width(); | 839 params->width = width(); |
| 772 params->height = height(); | 840 params->height = height(); |
| 773 params->resize_pending = false; | 841 params->resize_pending = false; |
| 842 // Reset HW compositing info. |
| 843 ProvideHWCompositingInfo(params, NULL); |
| 774 return params; | 844 return params; |
| 775 } | 845 } |
| 776 } | 846 } |
| 777 | 847 |
| 778 TransportDIB* BrowserPlugin::CreateTransportDIB(const size_t size) { | 848 TransportDIB* BrowserPlugin::CreateTransportDIB(const size_t size) { |
| 779 #if defined(OS_MACOSX) | 849 #if defined(OS_MACOSX) |
| 780 TransportDIB::Handle handle; | 850 TransportDIB::Handle handle; |
| 781 // On OSX we don't let the browser manage the transport dib. We manage the | 851 // On OSX we don't let the browser manage the transport dib. We manage the |
| 782 // deletion of the dib in FreeDamageBuffer(). | 852 // deletion of the dib in FreeDamageBuffer(). |
| 783 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB( | 853 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 void* notify_data) { | 960 void* notify_data) { |
| 891 } | 961 } |
| 892 | 962 |
| 893 void BrowserPlugin::didFailLoadingFrameRequest( | 963 void BrowserPlugin::didFailLoadingFrameRequest( |
| 894 const WebKit::WebURL& url, | 964 const WebKit::WebURL& url, |
| 895 void* notify_data, | 965 void* notify_data, |
| 896 const WebKit::WebURLError& error) { | 966 const WebKit::WebURLError& error) { |
| 897 } | 967 } |
| 898 | 968 |
| 899 } // namespace content | 969 } // namespace content |
| OLD | NEW |