| 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> |
| 11 | 11 |
| 12 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/process/process.h" | 19 #include "base/process/process.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/version.h" | 23 #include "base/version.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "cc/resources/shared_bitmap.h" | 25 #include "cc/resources/shared_bitmap.h" |
| 26 #include "content/child/child_process.h" | 26 #include "content/child/child_process.h" |
| 27 #include "content/child/child_shared_bitmap_manager.h" | 27 #include "content/child/child_shared_bitmap_manager.h" |
| 28 #include "content/child/npapi/npobject_proxy.h" | |
| 29 #include "content/child/npapi/npobject_stub.h" | |
| 30 #include "content/child/npapi/npobject_util.h" | |
| 31 #include "content/child/npapi/webplugin_resource_client.h" | 28 #include "content/child/npapi/webplugin_resource_client.h" |
| 32 #include "content/child/plugin_messages.h" | 29 #include "content/child/plugin_messages.h" |
| 33 #include "content/common/content_constants_internal.h" | 30 #include "content/common/content_constants_internal.h" |
| 34 #include "content/common/cursors/webcursor.h" | 31 #include "content/common/cursors/webcursor.h" |
| 35 #include "content/common/frame_messages.h" | 32 #include "content/common/frame_messages.h" |
| 36 #include "content/common/view_messages.h" | 33 #include "content/common/view_messages.h" |
| 37 #include "content/public/renderer/content_renderer_client.h" | 34 #include "content/public/renderer/content_renderer_client.h" |
| 38 #include "content/renderer/npapi/plugin_channel_host.h" | 35 #include "content/renderer/npapi/plugin_channel_host.h" |
| 39 #include "content/renderer/npapi/webplugin_impl.h" | 36 #include "content/renderer/npapi/webplugin_impl.h" |
| 40 #include "content/renderer/render_thread_impl.h" | 37 #include "content/renderer/render_thread_impl.h" |
| 41 #include "content/renderer/render_view_impl.h" | 38 #include "content/renderer/render_view_impl.h" |
| 42 #include "content/renderer/sad_plugin.h" | 39 #include "content/renderer/sad_plugin.h" |
| 43 #include "ipc/ipc_channel_handle.h" | 40 #include "ipc/ipc_channel_handle.h" |
| 44 #include "net/base/mime_util.h" | 41 #include "net/base/mime_util.h" |
| 45 #include "skia/ext/platform_canvas.h" | 42 #include "skia/ext/platform_canvas.h" |
| 46 #include "third_party/WebKit/public/platform/WebDragData.h" | 43 #include "third_party/WebKit/public/platform/WebDragData.h" |
| 47 #include "third_party/WebKit/public/platform/WebString.h" | 44 #include "third_party/WebKit/public/platform/WebString.h" |
| 48 #include "third_party/WebKit/public/web/WebBindings.h" | |
| 49 #include "third_party/WebKit/public/web/WebDocument.h" | 45 #include "third_party/WebKit/public/web/WebDocument.h" |
| 50 #include "third_party/WebKit/public/web/WebFrame.h" | 46 #include "third_party/WebKit/public/web/WebFrame.h" |
| 51 #include "third_party/WebKit/public/web/WebView.h" | 47 #include "third_party/WebKit/public/web/WebView.h" |
| 52 #include "ui/gfx/blit.h" | 48 #include "ui/gfx/blit.h" |
| 53 #include "ui/gfx/canvas.h" | 49 #include "ui/gfx/canvas.h" |
| 54 #include "ui/gfx/geometry/size.h" | 50 #include "ui/gfx/geometry/size.h" |
| 55 #include "ui/gfx/native_widget_types.h" | 51 #include "ui/gfx/native_widget_types.h" |
| 56 #include "ui/gfx/skia_util.h" | 52 #include "ui/gfx/skia_util.h" |
| 57 | 53 |
| 58 #if defined(OS_POSIX) | 54 #if defined(OS_POSIX) |
| 59 #include "ipc/ipc_channel_posix.h" | 55 #include "ipc/ipc_channel_posix.h" |
| 60 #endif | 56 #endif |
| 61 | 57 |
| 62 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 63 #include "base/win/scoped_handle.h" | 59 #include "base/win/scoped_handle.h" |
| 64 #include "content/public/common/sandbox_init.h" | 60 #include "content/public/common/sandbox_init.h" |
| 65 #endif | 61 #endif |
| 66 | 62 |
| 67 using blink::WebBindings; | |
| 68 using blink::WebCursorInfo; | 63 using blink::WebCursorInfo; |
| 69 using blink::WebDragData; | 64 using blink::WebDragData; |
| 70 using blink::WebInputEvent; | 65 using blink::WebInputEvent; |
| 71 using blink::WebString; | 66 using blink::WebString; |
| 72 using blink::WebView; | 67 using blink::WebView; |
| 73 | 68 |
| 74 namespace content { | 69 namespace content { |
| 75 | 70 |
| 76 namespace { | 71 namespace { |
| 77 | 72 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 106 render_frame_(render_frame), | 101 render_frame_(render_frame), |
| 107 plugin_(plugin), | 102 plugin_(plugin), |
| 108 uses_shared_bitmaps_(true), | 103 uses_shared_bitmaps_(true), |
| 109 #if defined(OS_MACOSX) | 104 #if defined(OS_MACOSX) |
| 110 uses_compositor_(false), | 105 uses_compositor_(false), |
| 111 #elif defined(OS_WIN) | 106 #elif defined(OS_WIN) |
| 112 dummy_activation_window_(NULL), | 107 dummy_activation_window_(NULL), |
| 113 #endif | 108 #endif |
| 114 mime_type_(mime_type), | 109 mime_type_(mime_type), |
| 115 instance_id_(MSG_ROUTING_NONE), | 110 instance_id_(MSG_ROUTING_NONE), |
| 116 npobject_(NULL), | |
| 117 npp_(new NPP_t), | |
| 118 sad_plugin_(NULL), | 111 sad_plugin_(NULL), |
| 119 invalidate_pending_(false), | 112 invalidate_pending_(false), |
| 120 transparent_(false), | 113 transparent_(false), |
| 121 front_buffer_index_(0), | 114 front_buffer_index_(0), |
| 122 page_url_(render_view_->webview()->mainFrame()->document().url()) { | 115 page_url_(render_view_->webview()->mainFrame()->document().url()) { |
| 123 } | 116 } |
| 124 | 117 |
| 125 WebPluginDelegateProxy::~WebPluginDelegateProxy() { | 118 WebPluginDelegateProxy::~WebPluginDelegateProxy() { |
| 126 if (npobject_) | |
| 127 WebBindings::releaseObject(npobject_); | |
| 128 } | 119 } |
| 129 | 120 |
| 130 WebPluginDelegateProxy::SharedBitmap::SharedBitmap() {} | 121 WebPluginDelegateProxy::SharedBitmap::SharedBitmap() {} |
| 131 | 122 |
| 132 WebPluginDelegateProxy::SharedBitmap::~SharedBitmap() {} | 123 WebPluginDelegateProxy::SharedBitmap::~SharedBitmap() {} |
| 133 | 124 |
| 134 void WebPluginDelegateProxy::PluginDestroyed() { | 125 void WebPluginDelegateProxy::PluginDestroyed() { |
| 135 #if defined(OS_MACOSX) || defined(OS_WIN) | 126 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 136 // Ensure that the renderer doesn't think the plugin still has focus. | 127 // Ensure that the renderer doesn't think the plugin still has focus. |
| 137 if (render_view_) | 128 if (render_view_) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 render_view_->UnregisterPluginDelegate(this); | 141 render_view_->UnregisterPluginDelegate(this); |
| 151 | 142 |
| 152 if (channel_host_.get()) { | 143 if (channel_host_.get()) { |
| 153 Send(new PluginMsg_DestroyInstance(instance_id_)); | 144 Send(new PluginMsg_DestroyInstance(instance_id_)); |
| 154 | 145 |
| 155 // Must remove the route after sending the destroy message, rather than | 146 // Must remove the route after sending the destroy message, rather than |
| 156 // before, since RemoveRoute can lead to all the outstanding NPObjects | 147 // before, since RemoveRoute can lead to all the outstanding NPObjects |
| 157 // being told the channel went away if this was the last instance. | 148 // being told the channel went away if this was the last instance. |
| 158 channel_host_->RemoveRoute(instance_id_); | 149 channel_host_->RemoveRoute(instance_id_); |
| 159 | 150 |
| 160 // Remove the mapping between our instance-Id and NPP identifiers, used by | |
| 161 // the channel to track object ownership, before releasing it. | |
| 162 channel_host_->RemoveMappingForNPObjectOwner(instance_id_); | |
| 163 | |
| 164 // Release the channel host now. If we are is the last reference to the | 151 // Release the channel host now. If we are is the last reference to the |
| 165 // channel, this avoids a race where this renderer asks a new connection to | 152 // channel, this avoids a race where this renderer asks a new connection to |
| 166 // the same plugin between now and the time 'this' is actually deleted. | 153 // the same plugin between now and the time 'this' is actually deleted. |
| 167 // Destroying the channel host is what releases the channel name -> FD | 154 // Destroying the channel host is what releases the channel name -> FD |
| 168 // association on POSIX, and if we ask for a new connection before it is | 155 // association on POSIX, and if we ask for a new connection before it is |
| 169 // released, the plugin will give us a new FD, and we'll assert when trying | 156 // released, the plugin will give us a new FD, and we'll assert when trying |
| 170 // to associate it with the channel name. | 157 // to associate it with the channel name. |
| 171 channel_host_ = NULL; | 158 channel_host_ = NULL; |
| 172 } | 159 } |
| 173 | 160 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 233 } |
| 247 } | 234 } |
| 248 | 235 |
| 249 // Failed too often, give up. | 236 // Failed too often, give up. |
| 250 if (!result) | 237 if (!result) |
| 251 return false; | 238 return false; |
| 252 | 239 |
| 253 channel_host_ = channel_host; | 240 channel_host_ = channel_host; |
| 254 instance_id_ = instance_id; | 241 instance_id_ = instance_id; |
| 255 | 242 |
| 256 channel_host_->AddRoute(instance_id_, this, NULL); | 243 channel_host_->AddRoute(instance_id_, this); |
| 257 | |
| 258 // Inform the channel of the mapping between our instance-Id and dummy NPP | |
| 259 // identifier, for use in object ownership tracking. | |
| 260 channel_host_->AddMappingForNPObjectOwner(instance_id_, GetPluginNPP()); | |
| 261 | 244 |
| 262 // Now tell the PluginInstance in the plugin process to initialize. | 245 // Now tell the PluginInstance in the plugin process to initialize. |
| 263 PluginMsg_Init_Params params; | 246 PluginMsg_Init_Params params; |
| 264 params.url = url; | 247 params.url = url; |
| 265 params.page_url = page_url_; | 248 params.page_url = page_url_; |
| 266 params.arg_names = arg_names; | 249 params.arg_names = arg_names; |
| 267 params.arg_values = arg_values; | 250 params.arg_values = arg_values; |
| 268 params.host_render_view_routing_id = render_view_->GetRoutingID(); | 251 params.host_render_view_routing_id = render_view_->GetRoutingID(); |
| 269 params.load_manually = load_manually; | 252 params.load_manually = load_manually; |
| 270 | 253 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 288 | 271 |
| 289 return channel_host_->Send(msg); | 272 return channel_host_->Send(msg); |
| 290 } | 273 } |
| 291 | 274 |
| 292 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { | 275 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { |
| 293 GetContentClient()->SetActiveURL(page_url_); | 276 GetContentClient()->SetActiveURL(page_url_); |
| 294 | 277 |
| 295 bool handled = true; | 278 bool handled = true; |
| 296 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) | 279 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) |
| 297 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) | 280 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) |
| 298 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, | |
| 299 OnGetWindowScriptNPObject) | |
| 300 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) | |
| 301 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) | 281 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) |
| 302 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) | 282 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) |
| 303 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) | 283 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) |
| 304 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) | 284 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) |
| 305 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) | 285 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) |
| 306 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) | 286 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) |
| 307 #if defined(OS_WIN) | 287 #if defined(OS_WIN) |
| 308 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) | 288 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) |
| 309 IPC_MESSAGE_HANDLER(PluginHostMsg_NotifyIMEStatus, OnNotifyIMEStatus) | 289 IPC_MESSAGE_HANDLER(PluginHostMsg_NotifyIMEStatus, OnNotifyIMEStatus) |
| 310 #endif | 290 #endif |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 530 |
| 551 if (invalidate_pending_) { | 531 if (invalidate_pending_) { |
| 552 // Only send the PaintAck message if this paint is in response to an | 532 // Only send the PaintAck message if this paint is in response to an |
| 553 // invalidate from the plugin, since this message acts as an access token | 533 // invalidate from the plugin, since this message acts as an access token |
| 554 // to ensure only one process is using the shared bitmap at a time. | 534 // to ensure only one process is using the shared bitmap at a time. |
| 555 invalidate_pending_ = false; | 535 invalidate_pending_ = false; |
| 556 Send(new PluginMsg_DidPaint(instance_id_)); | 536 Send(new PluginMsg_DidPaint(instance_id_)); |
| 557 } | 537 } |
| 558 } | 538 } |
| 559 | 539 |
| 560 NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { | |
| 561 if (npobject_) | |
| 562 return WebBindings::retainObject(npobject_); | |
| 563 | |
| 564 if (!channel_host_.get()) | |
| 565 return NULL; | |
| 566 | |
| 567 int route_id = MSG_ROUTING_NONE; | |
| 568 Send(new PluginMsg_GetPluginScriptableObject(instance_id_, &route_id)); | |
| 569 if (route_id == MSG_ROUTING_NONE) | |
| 570 return NULL; | |
| 571 | |
| 572 if (!channel_host_.get()) | |
| 573 return nullptr; | |
| 574 | |
| 575 npobject_ = NPObjectProxy::Create( | |
| 576 channel_host_.get(), route_id, 0, page_url_, GetPluginNPP()); | |
| 577 | |
| 578 return WebBindings::retainObject(npobject_); | |
| 579 } | |
| 580 | |
| 581 NPP WebPluginDelegateProxy::GetPluginNPP() { | |
| 582 // Return a dummy NPP for WebKit to use to identify this plugin. | |
| 583 return npp_.get(); | |
| 584 } | |
| 585 | |
| 586 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { | 540 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { |
| 587 bool success = false; | 541 bool success = false; |
| 588 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); | 542 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); |
| 589 return success; | 543 return success; |
| 590 } | 544 } |
| 591 | 545 |
| 592 void WebPluginDelegateProxy::SetFocus(bool focused) { | 546 void WebPluginDelegateProxy::SetFocus(bool focused) { |
| 593 Send(new PluginMsg_SetFocus(instance_id_, focused)); | 547 Send(new PluginMsg_SetFocus(instance_id_, focused)); |
| 594 #if defined(OS_WIN) | 548 #if defined(OS_WIN) |
| 595 if (render_view_) | 549 if (render_view_) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); | 714 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); |
| 761 | 715 |
| 762 invalidate_pending_ = true; | 716 invalidate_pending_ = true; |
| 763 // The plugin is blocked on the renderer because the invalidate message it has | 717 // The plugin is blocked on the renderer because the invalidate message it has |
| 764 // sent us is synchronous, so we can use buffer flipping here if the caller | 718 // sent us is synchronous, so we can use buffer flipping here if the caller |
| 765 // allows it. | 719 // allows it. |
| 766 UpdateFrontBuffer(clipped_rect, true); | 720 UpdateFrontBuffer(clipped_rect, true); |
| 767 plugin_->InvalidateRect(clipped_rect); | 721 plugin_->InvalidateRect(clipped_rect); |
| 768 } | 722 } |
| 769 | 723 |
| 770 void WebPluginDelegateProxy::OnGetWindowScriptNPObject( | |
| 771 int route_id, bool* success) { | |
| 772 *success = false; | |
| 773 NPObject* npobject = NULL; | |
| 774 if (plugin_) | |
| 775 npobject = plugin_->GetWindowScriptNPObject(); | |
| 776 | |
| 777 if (!npobject) | |
| 778 return; | |
| 779 | |
| 780 // The stub will delete itself when the proxy tells it that it's released, or | |
| 781 // otherwise when the channel is closed. | |
| 782 new NPObjectStub(npobject, channel_host_.get(), route_id, 0, page_url_); | |
| 783 *success = true; | |
| 784 } | |
| 785 | |
| 786 void WebPluginDelegateProxy::OnResolveProxy(const GURL& url, | 724 void WebPluginDelegateProxy::OnResolveProxy(const GURL& url, |
| 787 bool* result, | 725 bool* result, |
| 788 std::string* proxy_list) { | 726 std::string* proxy_list) { |
| 789 *result = RenderThreadImpl::current()->ResolveProxy(url, proxy_list); | 727 *result = RenderThreadImpl::current()->ResolveProxy(url, proxy_list); |
| 790 } | 728 } |
| 791 | 729 |
| 792 void WebPluginDelegateProxy::OnGetPluginElement(int route_id, bool* success) { | |
| 793 *success = false; | |
| 794 NPObject* npobject = NULL; | |
| 795 if (plugin_) | |
| 796 npobject = plugin_->GetPluginElement(); | |
| 797 if (!npobject) | |
| 798 return; | |
| 799 | |
| 800 // The stub will delete itself when the proxy tells it that it's released, or | |
| 801 // otherwise when the channel is closed. | |
| 802 new NPObjectStub( | |
| 803 npobject, channel_host_.get(), route_id, 0, page_url_); | |
| 804 *success = true; | |
| 805 } | |
| 806 | |
| 807 void WebPluginDelegateProxy::OnSetCookie(const GURL& url, | 730 void WebPluginDelegateProxy::OnSetCookie(const GURL& url, |
| 808 const GURL& first_party_for_cookies, | 731 const GURL& first_party_for_cookies, |
| 809 const std::string& cookie) { | 732 const std::string& cookie) { |
| 810 if (plugin_) | 733 if (plugin_) |
| 811 plugin_->SetCookie(url, first_party_for_cookies, cookie); | 734 plugin_->SetCookie(url, first_party_for_cookies, cookie); |
| 812 } | 735 } |
| 813 | 736 |
| 814 void WebPluginDelegateProxy::OnGetCookies(const GURL& url, | 737 void WebPluginDelegateProxy::OnGetCookies(const GURL& url, |
| 815 const GURL& first_party_for_cookies, | 738 const GURL& first_party_for_cookies, |
| 816 std::string* cookies) { | 739 std::string* cookies) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 index->mime_type == "application/x-vnd.movenetworks.qm" || | 863 index->mime_type == "application/x-vnd.movenetworks.qm" || |
| 941 index->mime_type == "application/x-vnd.mnplayer.qm") { | 864 index->mime_type == "application/x-vnd.mnplayer.qm") { |
| 942 return true; | 865 return true; |
| 943 } | 866 } |
| 944 } | 867 } |
| 945 return false; | 868 return false; |
| 946 } | 869 } |
| 947 #endif | 870 #endif |
| 948 | 871 |
| 949 } // namespace content | 872 } // namespace content |
| OLD | NEW |