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 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/process/process.h" | 18 #include "base/process/process.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/version.h" | 22 #include "base/version.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "cc/resources/shared_bitmap.h" | 24 #include "cc/resources/shared_bitmap.h" |
25 #include "content/child/child_process.h" | 25 #include "content/child/child_process.h" |
26 #include "content/child/child_shared_bitmap_manager.h" | 26 #include "content/child/child_shared_bitmap_manager.h" |
27 #include "content/child/npapi/npobject_proxy.h" | |
28 #include "content/child/npapi/npobject_stub.h" | |
29 #include "content/child/npapi/npobject_util.h" | |
30 #include "content/child/npapi/webplugin_resource_client.h" | 27 #include "content/child/npapi/webplugin_resource_client.h" |
31 #include "content/child/plugin_messages.h" | 28 #include "content/child/plugin_messages.h" |
32 #include "content/common/content_constants_internal.h" | 29 #include "content/common/content_constants_internal.h" |
33 #include "content/common/cursors/webcursor.h" | 30 #include "content/common/cursors/webcursor.h" |
34 #include "content/common/frame_messages.h" | 31 #include "content/common/frame_messages.h" |
35 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
36 #include "content/public/renderer/content_renderer_client.h" | 33 #include "content/public/renderer/content_renderer_client.h" |
37 #include "content/renderer/npapi/plugin_channel_host.h" | 34 #include "content/renderer/npapi/plugin_channel_host.h" |
38 #include "content/renderer/npapi/webplugin_impl.h" | 35 #include "content/renderer/npapi/webplugin_impl.h" |
39 #include "content/renderer/render_thread_impl.h" | 36 #include "content/renderer/render_thread_impl.h" |
40 #include "content/renderer/render_view_impl.h" | 37 #include "content/renderer/render_view_impl.h" |
41 #include "content/renderer/sad_plugin.h" | 38 #include "content/renderer/sad_plugin.h" |
42 #include "ipc/ipc_channel_handle.h" | 39 #include "ipc/ipc_channel_handle.h" |
43 #include "net/base/mime_util.h" | 40 #include "net/base/mime_util.h" |
44 #include "skia/ext/platform_canvas.h" | 41 #include "skia/ext/platform_canvas.h" |
45 #include "third_party/WebKit/public/platform/WebDragData.h" | 42 #include "third_party/WebKit/public/platform/WebDragData.h" |
46 #include "third_party/WebKit/public/platform/WebString.h" | 43 #include "third_party/WebKit/public/platform/WebString.h" |
47 #include "third_party/WebKit/public/web/WebBindings.h" | |
48 #include "third_party/WebKit/public/web/WebDocument.h" | 44 #include "third_party/WebKit/public/web/WebDocument.h" |
49 #include "third_party/WebKit/public/web/WebFrame.h" | 45 #include "third_party/WebKit/public/web/WebFrame.h" |
50 #include "third_party/WebKit/public/web/WebView.h" | 46 #include "third_party/WebKit/public/web/WebView.h" |
51 #include "ui/gfx/blit.h" | 47 #include "ui/gfx/blit.h" |
52 #include "ui/gfx/canvas.h" | 48 #include "ui/gfx/canvas.h" |
53 #include "ui/gfx/geometry/size.h" | 49 #include "ui/gfx/geometry/size.h" |
54 #include "ui/gfx/native_widget_types.h" | 50 #include "ui/gfx/native_widget_types.h" |
55 #include "ui/gfx/skia_util.h" | 51 #include "ui/gfx/skia_util.h" |
56 | 52 |
57 #if defined(OS_POSIX) | 53 #if defined(OS_POSIX) |
58 #include "ipc/ipc_channel_posix.h" | 54 #include "ipc/ipc_channel_posix.h" |
59 #endif | 55 #endif |
60 | 56 |
61 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
62 #include "base/win/scoped_handle.h" | 58 #include "base/win/scoped_handle.h" |
63 #include "content/public/common/sandbox_init.h" | 59 #include "content/public/common/sandbox_init.h" |
64 #endif | 60 #endif |
65 | 61 |
66 using blink::WebBindings; | |
67 using blink::WebCursorInfo; | 62 using blink::WebCursorInfo; |
68 using blink::WebDragData; | 63 using blink::WebDragData; |
69 using blink::WebInputEvent; | 64 using blink::WebInputEvent; |
70 using blink::WebString; | 65 using blink::WebString; |
71 using blink::WebView; | 66 using blink::WebView; |
72 | 67 |
73 namespace content { | 68 namespace content { |
74 | 69 |
75 namespace { | 70 namespace { |
76 | 71 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 plugin_(plugin), | 176 plugin_(plugin), |
182 uses_shared_bitmaps_(false), | 177 uses_shared_bitmaps_(false), |
183 #if defined(OS_MACOSX) | 178 #if defined(OS_MACOSX) |
184 uses_compositor_(false), | 179 uses_compositor_(false), |
185 #elif defined(OS_WIN) | 180 #elif defined(OS_WIN) |
186 dummy_activation_window_(NULL), | 181 dummy_activation_window_(NULL), |
187 #endif | 182 #endif |
188 window_(gfx::kNullPluginWindow), | 183 window_(gfx::kNullPluginWindow), |
189 mime_type_(mime_type), | 184 mime_type_(mime_type), |
190 instance_id_(MSG_ROUTING_NONE), | 185 instance_id_(MSG_ROUTING_NONE), |
191 npobject_(NULL), | |
192 npp_(new NPP_t), | |
193 sad_plugin_(NULL), | 186 sad_plugin_(NULL), |
194 invalidate_pending_(false), | 187 invalidate_pending_(false), |
195 transparent_(false), | 188 transparent_(false), |
196 front_buffer_index_(0), | 189 front_buffer_index_(0), |
197 page_url_(render_view_->webview()->mainFrame()->document().url()) { | 190 page_url_(render_view_->webview()->mainFrame()->document().url()) { |
198 } | 191 } |
199 | 192 |
200 WebPluginDelegateProxy::~WebPluginDelegateProxy() { | 193 WebPluginDelegateProxy::~WebPluginDelegateProxy() { |
201 if (npobject_) | |
202 WebBindings::releaseObject(npobject_); | |
203 } | 194 } |
204 | 195 |
205 WebPluginDelegateProxy::SharedBitmap::SharedBitmap() {} | 196 WebPluginDelegateProxy::SharedBitmap::SharedBitmap() {} |
206 | 197 |
207 WebPluginDelegateProxy::SharedBitmap::~SharedBitmap() {} | 198 WebPluginDelegateProxy::SharedBitmap::~SharedBitmap() {} |
208 | 199 |
209 void WebPluginDelegateProxy::PluginDestroyed() { | 200 void WebPluginDelegateProxy::PluginDestroyed() { |
210 #if defined(OS_MACOSX) || defined(OS_WIN) | 201 #if defined(OS_MACOSX) || defined(OS_WIN) |
211 // Ensure that the renderer doesn't think the plugin still has focus. | 202 // Ensure that the renderer doesn't think the plugin still has focus. |
212 if (render_view_) | 203 if (render_view_) |
(...skipping 15 matching lines...) Expand all Loading... |
228 render_view_->UnregisterPluginDelegate(this); | 219 render_view_->UnregisterPluginDelegate(this); |
229 | 220 |
230 if (channel_host_.get()) { | 221 if (channel_host_.get()) { |
231 Send(new PluginMsg_DestroyInstance(instance_id_)); | 222 Send(new PluginMsg_DestroyInstance(instance_id_)); |
232 | 223 |
233 // Must remove the route after sending the destroy message, rather than | 224 // Must remove the route after sending the destroy message, rather than |
234 // before, since RemoveRoute can lead to all the outstanding NPObjects | 225 // before, since RemoveRoute can lead to all the outstanding NPObjects |
235 // being told the channel went away if this was the last instance. | 226 // being told the channel went away if this was the last instance. |
236 channel_host_->RemoveRoute(instance_id_); | 227 channel_host_->RemoveRoute(instance_id_); |
237 | 228 |
238 // Remove the mapping between our instance-Id and NPP identifiers, used by | |
239 // the channel to track object ownership, before releasing it. | |
240 channel_host_->RemoveMappingForNPObjectOwner(instance_id_); | |
241 | |
242 // Release the channel host now. If we are is the last reference to the | 229 // Release the channel host now. If we are is the last reference to the |
243 // channel, this avoids a race where this renderer asks a new connection to | 230 // channel, this avoids a race where this renderer asks a new connection to |
244 // the same plugin between now and the time 'this' is actually deleted. | 231 // the same plugin between now and the time 'this' is actually deleted. |
245 // Destroying the channel host is what releases the channel name -> FD | 232 // Destroying the channel host is what releases the channel name -> FD |
246 // association on POSIX, and if we ask for a new connection before it is | 233 // association on POSIX, and if we ask for a new connection before it is |
247 // released, the plugin will give us a new FD, and we'll assert when trying | 234 // released, the plugin will give us a new FD, and we'll assert when trying |
248 // to associate it with the channel name. | 235 // to associate it with the channel name. |
249 channel_host_ = NULL; | 236 channel_host_ = NULL; |
250 } | 237 } |
251 | 238 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 311 } |
325 } | 312 } |
326 | 313 |
327 // Failed too often, give up. | 314 // Failed too often, give up. |
328 if (!result) | 315 if (!result) |
329 return false; | 316 return false; |
330 | 317 |
331 channel_host_ = channel_host; | 318 channel_host_ = channel_host; |
332 instance_id_ = instance_id; | 319 instance_id_ = instance_id; |
333 | 320 |
334 channel_host_->AddRoute(instance_id_, this, NULL); | 321 channel_host_->AddRoute(instance_id_, this); |
335 | |
336 // Inform the channel of the mapping between our instance-Id and dummy NPP | |
337 // identifier, for use in object ownership tracking. | |
338 channel_host_->AddMappingForNPObjectOwner(instance_id_, GetPluginNPP()); | |
339 | 322 |
340 // Now tell the PluginInstance in the plugin process to initialize. | 323 // Now tell the PluginInstance in the plugin process to initialize. |
341 PluginMsg_Init_Params params; | 324 PluginMsg_Init_Params params; |
342 params.url = url; | 325 params.url = url; |
343 params.page_url = page_url_; | 326 params.page_url = page_url_; |
344 params.arg_names = arg_names; | 327 params.arg_names = arg_names; |
345 params.arg_values = arg_values; | 328 params.arg_values = arg_values; |
346 params.host_render_view_routing_id = render_view_->routing_id(); | 329 params.host_render_view_routing_id = render_view_->routing_id(); |
347 params.load_manually = load_manually; | 330 params.load_manually = load_manually; |
348 | 331 |
(...skipping 19 matching lines...) Expand all Loading... |
368 } | 351 } |
369 | 352 |
370 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { | 353 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { |
371 GetContentClient()->SetActiveURL(page_url_); | 354 GetContentClient()->SetActiveURL(page_url_); |
372 | 355 |
373 bool handled = true; | 356 bool handled = true; |
374 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) | 357 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) |
375 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) | 358 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) |
376 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) | 359 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) |
377 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) | 360 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) |
378 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, | |
379 OnGetWindowScriptNPObject) | |
380 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) | |
381 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) | 361 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) |
382 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) | 362 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) |
383 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) | 363 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) |
384 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) | 364 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) |
385 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) | 365 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) |
386 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) | 366 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) |
387 IPC_MESSAGE_HANDLER(PluginHostMsg_DeferResourceLoading, | 367 IPC_MESSAGE_HANDLER(PluginHostMsg_DeferResourceLoading, |
388 OnDeferResourceLoading) | 368 OnDeferResourceLoading) |
389 IPC_MESSAGE_HANDLER(PluginHostMsg_URLRedirectResponse, | 369 IPC_MESSAGE_HANDLER(PluginHostMsg_URLRedirectResponse, |
390 OnURLRedirectResponse) | 370 OnURLRedirectResponse) |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 | 624 |
645 if (invalidate_pending_) { | 625 if (invalidate_pending_) { |
646 // Only send the PaintAck message if this paint is in response to an | 626 // Only send the PaintAck message if this paint is in response to an |
647 // invalidate from the plugin, since this message acts as an access token | 627 // invalidate from the plugin, since this message acts as an access token |
648 // to ensure only one process is using the shared bitmap at a time. | 628 // to ensure only one process is using the shared bitmap at a time. |
649 invalidate_pending_ = false; | 629 invalidate_pending_ = false; |
650 Send(new PluginMsg_DidPaint(instance_id_)); | 630 Send(new PluginMsg_DidPaint(instance_id_)); |
651 } | 631 } |
652 } | 632 } |
653 | 633 |
654 NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { | |
655 if (npobject_) | |
656 return WebBindings::retainObject(npobject_); | |
657 | |
658 if (!channel_host_.get()) | |
659 return NULL; | |
660 | |
661 int route_id = MSG_ROUTING_NONE; | |
662 Send(new PluginMsg_GetPluginScriptableObject(instance_id_, &route_id)); | |
663 if (route_id == MSG_ROUTING_NONE) | |
664 return NULL; | |
665 | |
666 if (!channel_host_.get()) | |
667 return nullptr; | |
668 | |
669 npobject_ = NPObjectProxy::Create( | |
670 channel_host_.get(), route_id, 0, page_url_, GetPluginNPP()); | |
671 | |
672 return WebBindings::retainObject(npobject_); | |
673 } | |
674 | |
675 NPP WebPluginDelegateProxy::GetPluginNPP() { | |
676 // Return a dummy NPP for WebKit to use to identify this plugin. | |
677 return npp_.get(); | |
678 } | |
679 | |
680 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { | 634 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { |
681 bool success = false; | 635 bool success = false; |
682 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); | 636 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); |
683 return success; | 637 return success; |
684 } | 638 } |
685 | 639 |
686 void WebPluginDelegateProxy::SetFocus(bool focused) { | 640 void WebPluginDelegateProxy::SetFocus(bool focused) { |
687 Send(new PluginMsg_SetFocus(instance_id_, focused)); | 641 Send(new PluginMsg_SetFocus(instance_id_, focused)); |
688 #if defined(OS_WIN) | 642 #if defined(OS_WIN) |
689 if (render_view_) | 643 if (render_view_) |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); | 831 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); |
878 | 832 |
879 invalidate_pending_ = true; | 833 invalidate_pending_ = true; |
880 // The plugin is blocked on the renderer because the invalidate message it has | 834 // The plugin is blocked on the renderer because the invalidate message it has |
881 // sent us is synchronous, so we can use buffer flipping here if the caller | 835 // sent us is synchronous, so we can use buffer flipping here if the caller |
882 // allows it. | 836 // allows it. |
883 UpdateFrontBuffer(clipped_rect, true); | 837 UpdateFrontBuffer(clipped_rect, true); |
884 plugin_->InvalidateRect(clipped_rect); | 838 plugin_->InvalidateRect(clipped_rect); |
885 } | 839 } |
886 | 840 |
887 void WebPluginDelegateProxy::OnGetWindowScriptNPObject( | |
888 int route_id, bool* success) { | |
889 *success = false; | |
890 NPObject* npobject = NULL; | |
891 if (plugin_) | |
892 npobject = plugin_->GetWindowScriptNPObject(); | |
893 | |
894 if (!npobject) | |
895 return; | |
896 | |
897 // The stub will delete itself when the proxy tells it that it's released, or | |
898 // otherwise when the channel is closed. | |
899 new NPObjectStub(npobject, channel_host_.get(), route_id, 0, page_url_); | |
900 *success = true; | |
901 } | |
902 | |
903 void WebPluginDelegateProxy::OnResolveProxy(const GURL& url, | 841 void WebPluginDelegateProxy::OnResolveProxy(const GURL& url, |
904 bool* result, | 842 bool* result, |
905 std::string* proxy_list) { | 843 std::string* proxy_list) { |
906 *result = RenderThreadImpl::current()->ResolveProxy(url, proxy_list); | 844 *result = RenderThreadImpl::current()->ResolveProxy(url, proxy_list); |
907 } | 845 } |
908 | 846 |
909 void WebPluginDelegateProxy::OnGetPluginElement(int route_id, bool* success) { | |
910 *success = false; | |
911 NPObject* npobject = NULL; | |
912 if (plugin_) | |
913 npobject = plugin_->GetPluginElement(); | |
914 if (!npobject) | |
915 return; | |
916 | |
917 // The stub will delete itself when the proxy tells it that it's released, or | |
918 // otherwise when the channel is closed. | |
919 new NPObjectStub( | |
920 npobject, channel_host_.get(), route_id, 0, page_url_); | |
921 *success = true; | |
922 } | |
923 | |
924 void WebPluginDelegateProxy::OnSetCookie(const GURL& url, | 847 void WebPluginDelegateProxy::OnSetCookie(const GURL& url, |
925 const GURL& first_party_for_cookies, | 848 const GURL& first_party_for_cookies, |
926 const std::string& cookie) { | 849 const std::string& cookie) { |
927 if (plugin_) | 850 if (plugin_) |
928 plugin_->SetCookie(url, first_party_for_cookies, cookie); | 851 plugin_->SetCookie(url, first_party_for_cookies, cookie); |
929 } | 852 } |
930 | 853 |
931 void WebPluginDelegateProxy::OnGetCookies(const GURL& url, | 854 void WebPluginDelegateProxy::OnGetCookies(const GURL& url, |
932 const GURL& first_party_for_cookies, | 855 const GURL& first_party_for_cookies, |
933 std::string* cookies) { | 856 std::string* cookies) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1009 |
1087 plugin_->URLRedirectResponse(allow, resource_id); | 1010 plugin_->URLRedirectResponse(allow, resource_id); |
1088 } | 1011 } |
1089 | 1012 |
1090 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, | 1013 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, |
1091 bool* result) { | 1014 bool* result) { |
1092 *result = plugin_->CheckIfRunInsecureContent(url); | 1015 *result = plugin_->CheckIfRunInsecureContent(url); |
1093 } | 1016 } |
1094 | 1017 |
1095 } // namespace content | 1018 } // namespace content |
OLD | NEW |