| 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/npapi/webplugin_delegate_proxy.h" | 5 #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 WebPluginDelegateProxy::WebPluginDelegateProxy( | 100 WebPluginDelegateProxy::WebPluginDelegateProxy( |
| 101 WebPluginImpl* plugin, | 101 WebPluginImpl* plugin, |
| 102 const std::string& mime_type, | 102 const std::string& mime_type, |
| 103 const base::WeakPtr<RenderViewImpl>& render_view, | 103 const base::WeakPtr<RenderViewImpl>& render_view, |
| 104 RenderFrameImpl* render_frame) | 104 RenderFrameImpl* render_frame) |
| 105 : render_view_(render_view), | 105 : render_view_(render_view), |
| 106 render_frame_(render_frame), | 106 render_frame_(render_frame), |
| 107 plugin_(plugin), | 107 plugin_(plugin), |
| 108 uses_shared_bitmaps_(false), | 108 uses_shared_bitmaps_(true), |
| 109 #if defined(OS_MACOSX) | 109 #if defined(OS_MACOSX) |
| 110 uses_compositor_(false), | 110 uses_compositor_(false), |
| 111 #elif defined(OS_WIN) | 111 #elif defined(OS_WIN) |
| 112 dummy_activation_window_(NULL), | 112 dummy_activation_window_(NULL), |
| 113 #endif | 113 #endif |
| 114 window_(gfx::kNullPluginWindow), | |
| 115 mime_type_(mime_type), | 114 mime_type_(mime_type), |
| 116 instance_id_(MSG_ROUTING_NONE), | 115 instance_id_(MSG_ROUTING_NONE), |
| 117 npobject_(NULL), | 116 npobject_(NULL), |
| 118 npp_(new NPP_t), | 117 npp_(new NPP_t), |
| 119 sad_plugin_(NULL), | 118 sad_plugin_(NULL), |
| 120 invalidate_pending_(false), | 119 invalidate_pending_(false), |
| 121 transparent_(false), | 120 transparent_(false), |
| 122 front_buffer_index_(0), | 121 front_buffer_index_(0), |
| 123 page_url_(render_view_->webview()->mainFrame()->document().url()) { | 122 page_url_(render_view_->webview()->mainFrame()->document().url()) { |
| 124 } | 123 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 140 #endif | 139 #endif |
| 141 | 140 |
| 142 #if defined(OS_WIN) | 141 #if defined(OS_WIN) |
| 143 if (dummy_activation_window_ && render_view_) { | 142 if (dummy_activation_window_ && render_view_) { |
| 144 render_view_->Send(new ViewHostMsg_WindowlessPluginDummyWindowDestroyed( | 143 render_view_->Send(new ViewHostMsg_WindowlessPluginDummyWindowDestroyed( |
| 145 render_view_->GetRoutingID(), dummy_activation_window_)); | 144 render_view_->GetRoutingID(), dummy_activation_window_)); |
| 146 } | 145 } |
| 147 dummy_activation_window_ = NULL; | 146 dummy_activation_window_ = NULL; |
| 148 #endif | 147 #endif |
| 149 | 148 |
| 150 if (window_) | |
| 151 WillDestroyWindow(); | |
| 152 | |
| 153 if (render_view_.get()) | 149 if (render_view_.get()) |
| 154 render_view_->UnregisterPluginDelegate(this); | 150 render_view_->UnregisterPluginDelegate(this); |
| 155 | 151 |
| 156 if (channel_host_.get()) { | 152 if (channel_host_.get()) { |
| 157 Send(new PluginMsg_DestroyInstance(instance_id_)); | 153 Send(new PluginMsg_DestroyInstance(instance_id_)); |
| 158 | 154 |
| 159 // Must remove the route after sending the destroy message, rather than | 155 // Must remove the route after sending the destroy message, rather than |
| 160 // before, since RemoveRoute can lead to all the outstanding NPObjects | 156 // before, since RemoveRoute can lead to all the outstanding NPObjects |
| 161 // being told the channel went away if this was the last instance. | 157 // being told the channel went away if this was the last instance. |
| 162 channel_host_->RemoveRoute(instance_id_); | 158 channel_host_->RemoveRoute(instance_id_); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 287 } |
| 292 | 288 |
| 293 return channel_host_->Send(msg); | 289 return channel_host_->Send(msg); |
| 294 } | 290 } |
| 295 | 291 |
| 296 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { | 292 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { |
| 297 GetContentClient()->SetActiveURL(page_url_); | 293 GetContentClient()->SetActiveURL(page_url_); |
| 298 | 294 |
| 299 bool handled = true; | 295 bool handled = true; |
| 300 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) | 296 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) |
| 301 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) | |
| 302 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) | 297 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) |
| 303 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, | 298 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, |
| 304 OnGetWindowScriptNPObject) | 299 OnGetWindowScriptNPObject) |
| 305 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) | 300 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) |
| 306 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) | 301 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) |
| 307 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) | 302 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) |
| 308 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) | 303 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) |
| 309 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) | 304 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) |
| 310 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) | 305 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) |
| 311 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) | 306 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 326 OnAcceleratedPluginSwappedIOSurface) | 321 OnAcceleratedPluginSwappedIOSurface) |
| 327 #endif | 322 #endif |
| 328 IPC_MESSAGE_UNHANDLED(handled = false) | 323 IPC_MESSAGE_UNHANDLED(handled = false) |
| 329 IPC_END_MESSAGE_MAP() | 324 IPC_END_MESSAGE_MAP() |
| 330 DCHECK(handled); | 325 DCHECK(handled); |
| 331 return handled; | 326 return handled; |
| 332 } | 327 } |
| 333 | 328 |
| 334 void WebPluginDelegateProxy::OnChannelError() { | 329 void WebPluginDelegateProxy::OnChannelError() { |
| 335 if (plugin_) { | 330 if (plugin_) { |
| 336 if (window_) { | |
| 337 // The actual WebPluginDelegate never got a chance to tell the WebPlugin | |
| 338 // its window was going away. Do it on its behalf. | |
| 339 WillDestroyWindow(); | |
| 340 } | |
| 341 plugin_->Invalidate(); | 331 plugin_->Invalidate(); |
| 342 } | 332 } |
| 343 if (channel_host_.get() && !channel_host_->expecting_shutdown()) { | 333 if (channel_host_.get() && !channel_host_->expecting_shutdown()) { |
| 344 render_view_->GetMainRenderFrame()->PluginCrashed( | 334 render_view_->GetMainRenderFrame()->PluginCrashed( |
| 345 info_.path, channel_host_->peer_pid()); | 335 info_.path, channel_host_->peer_pid()); |
| 346 } | 336 } |
| 347 | 337 |
| 348 #if defined(OS_MACOSX) || defined(OS_WIN) | 338 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 349 // Ensure that the renderer doesn't think the plugin still has focus. | 339 // Ensure that the renderer doesn't think the plugin still has focus. |
| 350 if (render_view_) | 340 if (render_view_) |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 return; | 699 return; |
| 710 | 700 |
| 711 IPC::Message* msg = new PluginMsg_ImeCompositionCompleted(instance_id_, | 701 IPC::Message* msg = new PluginMsg_ImeCompositionCompleted(instance_id_, |
| 712 text); | 702 text); |
| 713 // Order relative to other key events is important. | 703 // Order relative to other key events is important. |
| 714 msg->set_unblock(true); | 704 msg->set_unblock(true); |
| 715 Send(msg); | 705 Send(msg); |
| 716 } | 706 } |
| 717 #endif // OS_MACOSX | 707 #endif // OS_MACOSX |
| 718 | 708 |
| 719 void WebPluginDelegateProxy::OnSetWindow(gfx::PluginWindowHandle window) { | |
| 720 #if defined(OS_MACOSX) | |
| 721 uses_shared_bitmaps_ = !window && !uses_compositor_; | |
| 722 #else | |
| 723 uses_shared_bitmaps_ = !window; | |
| 724 #endif | |
| 725 window_ = window; | |
| 726 if (plugin_) | |
| 727 plugin_->SetWindow(window); | |
| 728 } | |
| 729 | |
| 730 void WebPluginDelegateProxy::WillDestroyWindow() { | |
| 731 DCHECK(window_); | |
| 732 plugin_->WillDestroyWindow(window_); | |
| 733 window_ = gfx::kNullPluginWindow; | |
| 734 } | |
| 735 | |
| 736 #if defined(OS_WIN) | 709 #if defined(OS_WIN) |
| 737 void WebPluginDelegateProxy::OnSetWindowlessData( | 710 void WebPluginDelegateProxy::OnSetWindowlessData( |
| 738 HANDLE modal_loop_pump_messages_event_handle, | 711 HANDLE modal_loop_pump_messages_event_handle, |
| 739 gfx::NativeViewId dummy_activation_window) { | 712 gfx::NativeViewId dummy_activation_window) { |
| 740 DCHECK(!modal_loop_pump_messages_event_.get()); | 713 DCHECK(!modal_loop_pump_messages_event_.get()); |
| 741 DCHECK(!dummy_activation_window_); | 714 DCHECK(!dummy_activation_window_); |
| 742 base::win::ScopedHandle modal_loop_pump_messages_event( | 715 base::win::ScopedHandle modal_loop_pump_messages_event( |
| 743 modal_loop_pump_messages_event_handle); | 716 modal_loop_pump_messages_event_handle); |
| 744 | 717 |
| 745 dummy_activation_window_ = dummy_activation_window; | 718 dummy_activation_window_ = dummy_activation_window; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 if (render_view_) | 882 if (render_view_) |
| 910 render_view_->PluginFocusChanged(focused, instance_id_); | 883 render_view_->PluginFocusChanged(focused, instance_id_); |
| 911 } | 884 } |
| 912 | 885 |
| 913 void WebPluginDelegateProxy::OnStartIme() { | 886 void WebPluginDelegateProxy::OnStartIme() { |
| 914 if (render_view_) | 887 if (render_view_) |
| 915 render_view_->StartPluginIme(); | 888 render_view_->StartPluginIme(); |
| 916 } | 889 } |
| 917 #endif | 890 #endif |
| 918 | 891 |
| 919 gfx::PluginWindowHandle WebPluginDelegateProxy::GetPluginWindowHandle() { | |
| 920 return window_; | |
| 921 } | |
| 922 | |
| 923 void WebPluginDelegateProxy::OnCancelDocumentLoad() { | 892 void WebPluginDelegateProxy::OnCancelDocumentLoad() { |
| 924 plugin_->CancelDocumentLoad(); | 893 plugin_->CancelDocumentLoad(); |
| 925 } | 894 } |
| 926 | 895 |
| 927 void WebPluginDelegateProxy::OnDidStartLoading() { | 896 void WebPluginDelegateProxy::OnDidStartLoading() { |
| 928 plugin_->DidStartLoading(); | 897 plugin_->DidStartLoading(); |
| 929 } | 898 } |
| 930 | 899 |
| 931 void WebPluginDelegateProxy::OnDidStopLoading() { | 900 void WebPluginDelegateProxy::OnDidStopLoading() { |
| 932 plugin_->DidStopLoading(); | 901 plugin_->DidStopLoading(); |
| 933 } | 902 } |
| 934 | 903 |
| 935 #if defined(OS_MACOSX) | 904 #if defined(OS_MACOSX) |
| 936 void WebPluginDelegateProxy::OnAcceleratedPluginEnabledRendering() { | 905 void WebPluginDelegateProxy::OnAcceleratedPluginEnabledRendering() { |
| 937 uses_compositor_ = true; | 906 uses_compositor_ = true; |
| 938 OnSetWindow(gfx::kNullPluginWindow); | 907 uses_shared_bitmaps_ = false; |
| 939 } | 908 } |
| 940 | 909 |
| 941 void WebPluginDelegateProxy::OnAcceleratedPluginAllocatedIOSurface( | 910 void WebPluginDelegateProxy::OnAcceleratedPluginAllocatedIOSurface( |
| 942 int32_t width, | 911 int32_t width, |
| 943 int32_t height, | 912 int32_t height, |
| 944 uint32_t surface_id) { | 913 uint32_t surface_id) { |
| 945 if (plugin_) | 914 if (plugin_) |
| 946 plugin_->AcceleratedPluginAllocatedIOSurface(width, height, surface_id); | 915 plugin_->AcceleratedPluginAllocatedIOSurface(width, height, surface_id); |
| 947 } | 916 } |
| 948 | 917 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 971 index->mime_type == "application/x-vnd.movenetworks.qm" || | 940 index->mime_type == "application/x-vnd.movenetworks.qm" || |
| 972 index->mime_type == "application/x-vnd.mnplayer.qm") { | 941 index->mime_type == "application/x-vnd.mnplayer.qm") { |
| 973 return true; | 942 return true; |
| 974 } | 943 } |
| 975 } | 944 } |
| 976 return false; | 945 return false; |
| 977 } | 946 } |
| 978 #endif | 947 #endif |
| 979 | 948 |
| 980 } // namespace content | 949 } // namespace content |
| OLD | NEW |