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

Side by Side Diff: chrome/plugin/npobject_stub.cc

Issue 258026: Fix scripting during NPP_Destroy. Note that if the plugin is making a call t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/plugin/npobject_stub.h" 5 #include "chrome/plugin/npobject_stub.h"
6 6
7 #include "chrome/common/child_process_logging.h" 7 #include "chrome/common/child_process_logging.h"
8 #include "chrome/common/plugin_messages.h" 8 #include "chrome/common/plugin_messages.h"
9 #include "chrome/plugin/npobject_util.h" 9 #include "chrome/plugin/npobject_util.h"
10 #include "chrome/plugin/plugin_channel_base.h" 10 #include "chrome/plugin/plugin_channel_base.h"
11 #include "chrome/plugin/plugin_thread.h" 11 #include "chrome/plugin/plugin_thread.h"
12 #include "chrome/renderer/webplugin_delegate_proxy.h"
13 #include "third_party/npapi/bindings/npapi.h" 12 #include "third_party/npapi/bindings/npapi.h"
14 #include "third_party/npapi/bindings/npruntime.h" 13 #include "third_party/npapi/bindings/npruntime.h"
15 #include "webkit/api/public/WebBindings.h" 14 #include "webkit/api/public/WebBindings.h"
16 #include "webkit/glue/plugins/plugin_constants_win.h" 15 #include "webkit/glue/plugins/plugin_constants_win.h"
17 16
18 using WebKit::WebBindings; 17 using WebKit::WebBindings;
19 18
20 NPObjectStub::NPObjectStub( 19 NPObjectStub::NPObjectStub(
21 NPObject* npobject, 20 NPObject* npobject,
22 PluginChannelBase* channel, 21 PluginChannelBase* channel,
23 int route_id, 22 int route_id,
24 gfx::NativeViewId containing_window, 23 gfx::NativeViewId containing_window,
25 const GURL& page_url) 24 const GURL& page_url)
26 : npobject_(npobject), 25 : npobject_(npobject),
27 channel_(channel), 26 channel_(channel),
28 route_id_(route_id), 27 route_id_(route_id),
29 valid_(true),
30 web_plugin_delegate_proxy_(NULL),
31 containing_window_(containing_window), 28 containing_window_(containing_window),
32 page_url_(page_url) { 29 page_url_(page_url) {
33 channel_->AddRoute(route_id, this, true); 30 channel_->AddRoute(route_id, this, true);
34 31
35 // We retain the object just as PluginHost does if everything was in-process. 32 // We retain the object just as PluginHost does if everything was in-process.
36 WebBindings::retainObject(npobject_); 33 WebBindings::retainObject(npobject_);
37 } 34 }
38 35
39 NPObjectStub::~NPObjectStub() { 36 NPObjectStub::~NPObjectStub() {
40 if (web_plugin_delegate_proxy_)
41 web_plugin_delegate_proxy_->DropWindowScriptObject();
42
43 channel_->RemoveRoute(route_id_); 37 channel_->RemoveRoute(route_id_);
44 if (npobject_ && valid_) 38 if (npobject_)
45 WebBindings::releaseObject(npobject_); 39 WebBindings::releaseObject(npobject_);
46 } 40 }
47 41
48 bool NPObjectStub::Send(IPC::Message* msg) { 42 bool NPObjectStub::Send(IPC::Message* msg) {
49 return channel_->Send(msg); 43 return channel_->Send(msg);
50 } 44 }
51 45
46 void NPObjectStub::OnPluginDestroyed() {
47 // We null out the underlying NPObject pointer since it's not valid anymore (
48 // ScriptController manually deleted the object). As a result,
49 // OnMessageReceived won't dispatch any more messages. Since this includes
50 // OnRelease, this object won't get deleted until OnChannelError which might
51 // not happen for a long time if this renderer process has a long lived
52 // plugin instance to the same process. So we delete this object manually.
53 npobject_ = NULL;
54 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
55 }
56
52 void NPObjectStub::OnMessageReceived(const IPC::Message& msg) { 57 void NPObjectStub::OnMessageReceived(const IPC::Message& msg) {
53 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); 58 child_process_logging::ScopedActiveURLSetter url_setter(page_url_);
54 59
55 if (!valid_) { 60 if (!npobject_) {
56 if (msg.is_sync()) { 61 if (msg.is_sync()) {
57 // The object could be garbage because the frame has gone away, so 62 // The object could be garbage because the frame has gone away, so
58 // just send an error reply to the caller. 63 // just send an error reply to the caller.
59 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); 64 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
60 reply->set_reply_error(); 65 reply->set_reply_error();
61 Send(reply); 66 Send(reply);
62 } 67 }
63 68
64 return; 69 return;
65 } 70 }
66 71
67 IPC_BEGIN_MESSAGE_MAP(NPObjectStub, msg) 72 IPC_BEGIN_MESSAGE_MAP(NPObjectStub, msg)
68 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Release, OnRelease); 73 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Release, OnRelease);
69 IPC_MESSAGE_HANDLER(NPObjectMsg_HasMethod, OnHasMethod); 74 IPC_MESSAGE_HANDLER(NPObjectMsg_HasMethod, OnHasMethod);
70 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Invoke, OnInvoke); 75 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Invoke, OnInvoke);
71 IPC_MESSAGE_HANDLER(NPObjectMsg_HasProperty, OnHasProperty); 76 IPC_MESSAGE_HANDLER(NPObjectMsg_HasProperty, OnHasProperty);
72 IPC_MESSAGE_HANDLER(NPObjectMsg_GetProperty, OnGetProperty); 77 IPC_MESSAGE_HANDLER(NPObjectMsg_GetProperty, OnGetProperty);
73 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_SetProperty, OnSetProperty); 78 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_SetProperty, OnSetProperty);
74 IPC_MESSAGE_HANDLER(NPObjectMsg_RemoveProperty, OnRemoveProperty); 79 IPC_MESSAGE_HANDLER(NPObjectMsg_RemoveProperty, OnRemoveProperty);
75 IPC_MESSAGE_HANDLER(NPObjectMsg_Invalidate, OnInvalidate); 80 IPC_MESSAGE_HANDLER(NPObjectMsg_Invalidate, OnInvalidate);
76 IPC_MESSAGE_HANDLER(NPObjectMsg_Enumeration, OnEnumeration); 81 IPC_MESSAGE_HANDLER(NPObjectMsg_Enumeration, OnEnumeration);
77 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Construct, OnConstruct); 82 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Construct, OnConstruct);
78 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Evaluate, OnEvaluate); 83 IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Evaluate, OnEvaluate);
79 IPC_MESSAGE_HANDLER(NPObjectMsg_SetException, OnSetException); 84 IPC_MESSAGE_HANDLER(NPObjectMsg_SetException, OnSetException);
80 IPC_MESSAGE_UNHANDLED_ERROR() 85 IPC_MESSAGE_UNHANDLED_ERROR()
81 IPC_END_MESSAGE_MAP() 86 IPC_END_MESSAGE_MAP()
82 } 87 }
83 88
84 void NPObjectStub::OnChannelError() { 89 void NPObjectStub::OnChannelError() {
85 // When the plugin process is shutting down, all the NPObjectStubs
86 // destructors are called. However the plugin dll might have already
87 // been released, in which case the NPN_ReleaseObject will cause a crash.
88 npobject_ = NULL;
jam 2009/10/06 07:10:48 note: I tracked this code to http://chrome-corpsvn
89 delete this; 90 delete this;
90 } 91 }
91 92
92 void NPObjectStub::OnRelease(IPC::Message* reply_msg) { 93 void NPObjectStub::OnRelease(IPC::Message* reply_msg) {
93 Send(reply_msg); 94 Send(reply_msg);
94 delete this; 95 delete this;
95 } 96 }
96 97
97 void NPObjectStub::OnHasMethod(const NPIdentifier_Param& name, 98 void NPObjectStub::OnHasMethod(const NPIdentifier_Param& name,
98 bool* result) { 99 bool* result) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 372 }
372 373
373 void NPObjectStub::OnSetException(const std::string& message) { 374 void NPObjectStub::OnSetException(const std::string& message) {
374 if (IsPluginProcess()) { 375 if (IsPluginProcess()) {
375 NOTREACHED() << "Should only be called on NPObjects in the renderer"; 376 NOTREACHED() << "Should only be called on NPObjects in the renderer";
376 return; 377 return;
377 } 378 }
378 379
379 WebBindings::setException(npobject_, message.c_str()); 380 WebBindings::setException(npobject_, message.c_str());
380 } 381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698