Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: content/renderer/npapi/webplugin_delegate_proxy.cc

Issue 1483733002: Remove support for NPObjects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26 matching lines...) Expand all
104 RenderFrameImpl* render_frame) 99 RenderFrameImpl* render_frame)
105 : render_view_(render_view), 100 : render_view_(render_view),
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 #endif 106 #endif
112 mime_type_(mime_type), 107 mime_type_(mime_type),
113 instance_id_(MSG_ROUTING_NONE), 108 instance_id_(MSG_ROUTING_NONE),
114 npobject_(NULL),
115 npp_(new NPP_t),
116 sad_plugin_(NULL), 109 sad_plugin_(NULL),
117 invalidate_pending_(false), 110 invalidate_pending_(false),
118 transparent_(false), 111 transparent_(false),
119 front_buffer_index_(0), 112 front_buffer_index_(0),
120 page_url_(render_view_->webview()->mainFrame()->document().url()) { 113 page_url_(render_view_->webview()->mainFrame()->document().url()) {
121 } 114 }
122 115
123 WebPluginDelegateProxy::~WebPluginDelegateProxy() { 116 WebPluginDelegateProxy::~WebPluginDelegateProxy() {
124 if (npobject_)
125 WebBindings::releaseObject(npobject_);
126 } 117 }
127 118
128 WebPluginDelegateProxy::SharedBitmap::SharedBitmap() {} 119 WebPluginDelegateProxy::SharedBitmap::SharedBitmap() {}
129 120
130 WebPluginDelegateProxy::SharedBitmap::~SharedBitmap() {} 121 WebPluginDelegateProxy::SharedBitmap::~SharedBitmap() {}
131 122
132 void WebPluginDelegateProxy::PluginDestroyed() { 123 void WebPluginDelegateProxy::PluginDestroyed() {
133 #if defined(OS_MACOSX) 124 #if defined(OS_MACOSX)
134 // Ensure that the renderer doesn't think the plugin still has focus. 125 // Ensure that the renderer doesn't think the plugin still has focus.
135 if (render_view_) 126 if (render_view_)
136 render_view_->PluginFocusChanged(false, instance_id_); 127 render_view_->PluginFocusChanged(false, instance_id_);
137 #endif 128 #endif
138 129
139 if (render_view_.get()) 130 if (render_view_.get())
140 render_view_->UnregisterPluginDelegate(this); 131 render_view_->UnregisterPluginDelegate(this);
141 132
142 if (channel_host_.get()) { 133 if (channel_host_.get()) {
143 Send(new PluginMsg_DestroyInstance(instance_id_)); 134 Send(new PluginMsg_DestroyInstance(instance_id_));
144 135
145 // Must remove the route after sending the destroy message, rather than 136 // Must remove the route after sending the destroy message, rather than
146 // before, since RemoveRoute can lead to all the outstanding NPObjects 137 // before, since RemoveRoute can lead to all the outstanding NPObjects
147 // being told the channel went away if this was the last instance. 138 // being told the channel went away if this was the last instance.
148 channel_host_->RemoveRoute(instance_id_); 139 channel_host_->RemoveRoute(instance_id_);
149 140
150 // Remove the mapping between our instance-Id and NPP identifiers, used by
151 // the channel to track object ownership, before releasing it.
152 channel_host_->RemoveMappingForNPObjectOwner(instance_id_);
153
154 // Release the channel host now. If we are is the last reference to the 141 // Release the channel host now. If we are is the last reference to the
155 // channel, this avoids a race where this renderer asks a new connection to 142 // channel, this avoids a race where this renderer asks a new connection to
156 // the same plugin between now and the time 'this' is actually deleted. 143 // the same plugin between now and the time 'this' is actually deleted.
157 // Destroying the channel host is what releases the channel name -> FD 144 // Destroying the channel host is what releases the channel name -> FD
158 // association on POSIX, and if we ask for a new connection before it is 145 // association on POSIX, and if we ask for a new connection before it is
159 // released, the plugin will give us a new FD, and we'll assert when trying 146 // released, the plugin will give us a new FD, and we'll assert when trying
160 // to associate it with the channel name. 147 // to associate it with the channel name.
161 channel_host_ = NULL; 148 channel_host_ = NULL;
162 } 149 }
163 150
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 223 }
237 } 224 }
238 225
239 // Failed too often, give up. 226 // Failed too often, give up.
240 if (!result) 227 if (!result)
241 return false; 228 return false;
242 229
243 channel_host_ = channel_host; 230 channel_host_ = channel_host;
244 instance_id_ = instance_id; 231 instance_id_ = instance_id;
245 232
246 channel_host_->AddRoute(instance_id_, this, NULL); 233 channel_host_->AddRoute(instance_id_, this);
247
248 // Inform the channel of the mapping between our instance-Id and dummy NPP
249 // identifier, for use in object ownership tracking.
250 channel_host_->AddMappingForNPObjectOwner(instance_id_, GetPluginNPP());
251 234
252 // Now tell the PluginInstance in the plugin process to initialize. 235 // Now tell the PluginInstance in the plugin process to initialize.
253 PluginMsg_Init_Params params; 236 PluginMsg_Init_Params params;
254 params.url = url; 237 params.url = url;
255 params.page_url = page_url_; 238 params.page_url = page_url_;
256 params.arg_names = arg_names; 239 params.arg_names = arg_names;
257 params.arg_values = arg_values; 240 params.arg_values = arg_values;
258 params.host_render_view_routing_id = render_view_->GetRoutingID(); 241 params.host_render_view_routing_id = render_view_->GetRoutingID();
259 params.load_manually = load_manually; 242 params.load_manually = load_manually;
260 243
(...skipping 17 matching lines...) Expand all
278 261
279 return channel_host_->Send(msg); 262 return channel_host_->Send(msg);
280 } 263 }
281 264
282 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { 265 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) {
283 GetContentClient()->SetActiveURL(page_url_); 266 GetContentClient()->SetActiveURL(page_url_);
284 267
285 bool handled = true; 268 bool handled = true;
286 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) 269 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg)
287 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) 270 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect)
288 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject,
289 OnGetWindowScriptNPObject)
290 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement)
291 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) 271 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy)
292 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) 272 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie)
293 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) 273 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies)
294 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) 274 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad)
295 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) 275 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading)
296 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) 276 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading)
297 #if defined(OS_MACOSX) 277 #if defined(OS_MACOSX)
298 IPC_MESSAGE_HANDLER(PluginHostMsg_FocusChanged, 278 IPC_MESSAGE_HANDLER(PluginHostMsg_FocusChanged,
299 OnFocusChanged); 279 OnFocusChanged);
300 IPC_MESSAGE_HANDLER(PluginHostMsg_StartIme, 280 IPC_MESSAGE_HANDLER(PluginHostMsg_StartIme,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 516
537 if (invalidate_pending_) { 517 if (invalidate_pending_) {
538 // Only send the PaintAck message if this paint is in response to an 518 // Only send the PaintAck message if this paint is in response to an
539 // invalidate from the plugin, since this message acts as an access token 519 // invalidate from the plugin, since this message acts as an access token
540 // to ensure only one process is using the shared bitmap at a time. 520 // to ensure only one process is using the shared bitmap at a time.
541 invalidate_pending_ = false; 521 invalidate_pending_ = false;
542 Send(new PluginMsg_DidPaint(instance_id_)); 522 Send(new PluginMsg_DidPaint(instance_id_));
543 } 523 }
544 } 524 }
545 525
546 NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() {
547 if (npobject_)
548 return WebBindings::retainObject(npobject_);
549
550 if (!channel_host_.get())
551 return NULL;
552
553 int route_id = MSG_ROUTING_NONE;
554 Send(new PluginMsg_GetPluginScriptableObject(instance_id_, &route_id));
555 if (route_id == MSG_ROUTING_NONE)
556 return NULL;
557
558 if (!channel_host_.get())
559 return nullptr;
560
561 npobject_ = NPObjectProxy::Create(
562 channel_host_.get(), route_id, 0, page_url_, GetPluginNPP());
563
564 return WebBindings::retainObject(npobject_);
565 }
566
567 NPP WebPluginDelegateProxy::GetPluginNPP() {
568 // Return a dummy NPP for WebKit to use to identify this plugin.
569 return npp_.get();
570 }
571
572 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { 526 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) {
573 bool success = false; 527 bool success = false;
574 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); 528 Send(new PluginMsg_GetFormValue(instance_id_, value, &success));
575 return success; 529 return success;
576 } 530 }
577 531
578 void WebPluginDelegateProxy::SetFocus(bool focused) { 532 void WebPluginDelegateProxy::SetFocus(bool focused) {
579 Send(new PluginMsg_SetFocus(instance_id_, focused)); 533 Send(new PluginMsg_SetFocus(instance_id_, focused));
580 } 534 }
581 535
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); 616 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size()));
663 617
664 invalidate_pending_ = true; 618 invalidate_pending_ = true;
665 // The plugin is blocked on the renderer because the invalidate message it has 619 // The plugin is blocked on the renderer because the invalidate message it has
666 // sent us is synchronous, so we can use buffer flipping here if the caller 620 // sent us is synchronous, so we can use buffer flipping here if the caller
667 // allows it. 621 // allows it.
668 UpdateFrontBuffer(clipped_rect, true); 622 UpdateFrontBuffer(clipped_rect, true);
669 plugin_->InvalidateRect(clipped_rect); 623 plugin_->InvalidateRect(clipped_rect);
670 } 624 }
671 625
672 void WebPluginDelegateProxy::OnGetWindowScriptNPObject(
673 int route_id, bool* success) {
674 *success = false;
675 NPObject* npobject = NULL;
676 if (plugin_)
677 npobject = plugin_->GetWindowScriptNPObject();
678
679 if (!npobject)
680 return;
681
682 // The stub will delete itself when the proxy tells it that it's released, or
683 // otherwise when the channel is closed.
684 new NPObjectStub(npobject, channel_host_.get(), route_id, 0, page_url_);
685 *success = true;
686 }
687
688 void WebPluginDelegateProxy::OnResolveProxy(const GURL& url, 626 void WebPluginDelegateProxy::OnResolveProxy(const GURL& url,
689 bool* result, 627 bool* result,
690 std::string* proxy_list) { 628 std::string* proxy_list) {
691 *result = RenderThreadImpl::current()->ResolveProxy(url, proxy_list); 629 *result = RenderThreadImpl::current()->ResolveProxy(url, proxy_list);
692 } 630 }
693 631
694 void WebPluginDelegateProxy::OnGetPluginElement(int route_id, bool* success) {
695 *success = false;
696 NPObject* npobject = NULL;
697 if (plugin_)
698 npobject = plugin_->GetPluginElement();
699 if (!npobject)
700 return;
701
702 // The stub will delete itself when the proxy tells it that it's released, or
703 // otherwise when the channel is closed.
704 new NPObjectStub(
705 npobject, channel_host_.get(), route_id, 0, page_url_);
706 *success = true;
707 }
708
709 void WebPluginDelegateProxy::OnSetCookie(const GURL& url, 632 void WebPluginDelegateProxy::OnSetCookie(const GURL& url,
710 const GURL& first_party_for_cookies, 633 const GURL& first_party_for_cookies,
711 const std::string& cookie) { 634 const std::string& cookie) {
712 if (plugin_) 635 if (plugin_)
713 plugin_->SetCookie(url, first_party_for_cookies, cookie); 636 plugin_->SetCookie(url, first_party_for_cookies, cookie);
714 } 637 }
715 638
716 void WebPluginDelegateProxy::OnGetCookies(const GURL& url, 639 void WebPluginDelegateProxy::OnGetCookies(const GURL& url,
717 const GURL& first_party_for_cookies, 640 const GURL& first_party_for_cookies,
718 std::string* cookies) { 641 std::string* cookies) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 index->mime_type == "application/x-vnd.movenetworks.qm" || 765 index->mime_type == "application/x-vnd.movenetworks.qm" ||
843 index->mime_type == "application/x-vnd.mnplayer.qm") { 766 index->mime_type == "application/x-vnd.mnplayer.qm") {
844 return true; 767 return true;
845 } 768 }
846 } 769 }
847 return false; 770 return false;
848 } 771 }
849 #endif 772 #endif
850 773
851 } // namespace content 774 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/npapi/webplugin_delegate_proxy.h ('k') | content/renderer/npapi/webplugin_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698