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/plugin/webplugin_delegate_stub.h" | 5 #include "content/plugin/webplugin_delegate_stub.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "content/child/npapi/plugin_instance.h" | 12 #include "content/child/npapi/plugin_instance.h" |
13 #include "content/child/npapi/webplugin_delegate_impl.h" | 13 #include "content/child/npapi/webplugin_delegate_impl.h" |
14 #include "content/child/npapi/webplugin_resource_client.h" | 14 #include "content/child/npapi/webplugin_resource_client.h" |
15 #include "content/child/plugin_messages.h" | 15 #include "content/child/plugin_messages.h" |
16 #include "content/common/cursors/webcursor.h" | 16 #include "content/common/cursors/webcursor.h" |
17 #include "content/plugin/plugin_channel.h" | 17 #include "content/plugin/plugin_channel.h" |
18 #include "content/plugin/plugin_thread.h" | 18 #include "content/plugin/plugin_thread.h" |
19 #include "content/plugin/webplugin_proxy.h" | 19 #include "content/plugin/webplugin_proxy.h" |
20 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
21 #include "content/public/common/content_constants.h" | 21 #include "content/public/common/content_constants.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 23 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
24 #include "third_party/WebKit/public/web/WebBindings.h" | |
25 #include "third_party/npapi/bindings/npapi.h" | 24 #include "third_party/npapi/bindings/npapi.h" |
26 #include "third_party/npapi/bindings/npruntime.h" | 25 #include "third_party/npapi/bindings/npruntime.h" |
27 | 26 |
28 using blink::WebBindings; | |
29 using blink::WebCursorInfo; | 27 using blink::WebCursorInfo; |
30 | 28 |
31 namespace content { | 29 namespace content { |
32 | 30 |
33 static void DestroyWebPluginAndDelegate( | 31 static void DestroyWebPluginAndDelegate( |
34 base::WeakPtr<NPObjectStub> scriptable_object, | |
35 WebPluginDelegateImpl* delegate, | 32 WebPluginDelegateImpl* delegate, |
36 WebPlugin* webplugin) { | 33 WebPlugin* webplugin) { |
37 // The plugin may not expect us to try to release the scriptable object | |
38 // after calling NPP_Destroy on the instance, so delete the stub now. | |
39 if (scriptable_object.get()) | |
40 scriptable_object->DeleteSoon(); | |
41 | |
42 if (delegate) | 34 if (delegate) |
43 delegate->PluginDestroyed(); | 35 delegate->PluginDestroyed(); |
44 | 36 |
45 delete webplugin; | 37 delete webplugin; |
46 } | 38 } |
47 | 39 |
48 WebPluginDelegateStub::WebPluginDelegateStub( | 40 WebPluginDelegateStub::WebPluginDelegateStub( |
49 const std::string& mime_type, int instance_id, PluginChannel* channel) : | 41 const std::string& mime_type, int instance_id, PluginChannel* channel) : |
50 mime_type_(mime_type), | 42 mime_type_(mime_type), |
51 instance_id_(instance_id), | 43 instance_id_(instance_id), |
52 channel_(channel), | 44 channel_(channel), |
53 delegate_(NULL), | 45 delegate_(NULL), |
54 webplugin_(NULL), | 46 webplugin_(NULL), |
55 in_destructor_(false) { | 47 in_destructor_(false) { |
56 DCHECK(channel); | 48 DCHECK(channel); |
57 } | 49 } |
58 | 50 |
59 WebPluginDelegateStub::~WebPluginDelegateStub() { | 51 WebPluginDelegateStub::~WebPluginDelegateStub() { |
60 in_destructor_ = true; | 52 in_destructor_ = true; |
61 GetContentClient()->SetActiveURL(page_url_); | 53 GetContentClient()->SetActiveURL(page_url_); |
62 | 54 |
63 if (channel_->in_send()) { | 55 if (channel_->in_send()) { |
64 // The delegate or an npobject is in the callstack, so don't delete it | 56 // The delegate or an npobject is in the callstack, so don't delete it |
65 // right away. | 57 // right away. |
66 base::MessageLoop::current()->PostNonNestableTask( | 58 base::MessageLoop::current()->PostNonNestableTask( |
67 FROM_HERE, | 59 FROM_HERE, |
68 base::Bind(&DestroyWebPluginAndDelegate, | 60 base::Bind(&DestroyWebPluginAndDelegate, |
69 plugin_scriptable_object_, | |
70 delegate_, | 61 delegate_, |
71 webplugin_)); | 62 webplugin_)); |
72 } else { | 63 } else { |
73 // Safe to delete right away. | 64 // Safe to delete right away. |
74 DestroyWebPluginAndDelegate( | 65 DestroyWebPluginAndDelegate(delegate_, webplugin_); |
75 plugin_scriptable_object_, delegate_, webplugin_); | |
76 } | 66 } |
77 | |
78 // Remove the NPObject owner mapping for this instance. | |
79 if (delegate_) | |
80 channel_->RemoveMappingForNPObjectOwner(instance_id_); | |
81 } | 67 } |
82 | 68 |
83 bool WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { | 69 bool WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { |
84 GetContentClient()->SetActiveURL(page_url_); | 70 GetContentClient()->SetActiveURL(page_url_); |
85 | 71 |
86 // A plugin can execute a script to delete itself in any of its NPP methods. | 72 // A plugin can execute a script to delete itself in any of its NPP methods. |
87 // Hold an extra reference to ourself so that if this does occur and we're | 73 // Hold an extra reference to ourself so that if this does occur and we're |
88 // handling a sync message, we don't crash when attempting to send a reply. | 74 // handling a sync message, we don't crash when attempting to send a reply. |
89 // The exception to this is when we're already in the destructor. | 75 // The exception to this is when we're already in the destructor. |
90 if (!in_destructor_) | 76 if (!in_destructor_) |
91 AddRef(); | 77 AddRef(); |
92 | 78 |
93 bool handled = true; | 79 bool handled = true; |
94 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateStub, msg) | 80 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateStub, msg) |
95 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit) | 81 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit) |
96 IPC_MESSAGE_HANDLER(PluginMsg_SetFocus, OnSetFocus) | 82 IPC_MESSAGE_HANDLER(PluginMsg_SetFocus, OnSetFocus) |
97 IPC_MESSAGE_HANDLER(PluginMsg_HandleInputEvent, OnHandleInputEvent) | 83 IPC_MESSAGE_HANDLER(PluginMsg_HandleInputEvent, OnHandleInputEvent) |
98 IPC_MESSAGE_HANDLER(PluginMsg_Paint, OnPaint) | 84 IPC_MESSAGE_HANDLER(PluginMsg_Paint, OnPaint) |
99 IPC_MESSAGE_HANDLER(PluginMsg_DidPaint, OnDidPaint) | 85 IPC_MESSAGE_HANDLER(PluginMsg_DidPaint, OnDidPaint) |
100 IPC_MESSAGE_HANDLER(PluginMsg_GetPluginScriptableObject, | |
101 OnGetPluginScriptableObject) | |
102 IPC_MESSAGE_HANDLER(PluginMsg_GetFormValue, OnGetFormValue) | 86 IPC_MESSAGE_HANDLER(PluginMsg_GetFormValue, OnGetFormValue) |
103 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometry, OnUpdateGeometry) | 87 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometry, OnUpdateGeometry) |
104 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometrySync, OnUpdateGeometry) | 88 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometrySync, OnUpdateGeometry) |
105 IPC_MESSAGE_HANDLER(PluginMsg_SetContentAreaFocus, OnSetContentAreaFocus) | 89 IPC_MESSAGE_HANDLER(PluginMsg_SetContentAreaFocus, OnSetContentAreaFocus) |
106 #if defined(OS_WIN) && !defined(USE_AURA) | 90 #if defined(OS_WIN) && !defined(USE_AURA) |
107 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionUpdated, | 91 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionUpdated, |
108 OnImeCompositionUpdated) | 92 OnImeCompositionUpdated) |
109 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionCompleted, | 93 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionCompleted, |
110 OnImeCompositionCompleted) | 94 OnImeCompositionCompleted) |
111 #endif | 95 #endif |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 if (delegate_) { | 141 if (delegate_) { |
158 if (delegate_->GetQuirks() & | 142 if (delegate_->GetQuirks() & |
159 WebPluginDelegateImpl::PLUGIN_QUIRK_DIE_AFTER_UNLOAD) { | 143 WebPluginDelegateImpl::PLUGIN_QUIRK_DIE_AFTER_UNLOAD) { |
160 PluginThread::current()->SetForcefullyTerminatePluginProcess(); | 144 PluginThread::current()->SetForcefullyTerminatePluginProcess(); |
161 } | 145 } |
162 | 146 |
163 webplugin_->set_delegate(delegate_); | 147 webplugin_->set_delegate(delegate_); |
164 std::vector<std::string> arg_names = params.arg_names; | 148 std::vector<std::string> arg_names = params.arg_names; |
165 std::vector<std::string> arg_values = params.arg_values; | 149 std::vector<std::string> arg_values = params.arg_values; |
166 | 150 |
167 // Add an NPObject owner mapping for this instance, to support ownership | |
168 // tracking in the renderer. | |
169 channel_->AddMappingForNPObjectOwner(instance_id_, | |
170 delegate_->GetPluginNPP()); | |
171 | |
172 *result = delegate_->Initialize(params.url, | 151 *result = delegate_->Initialize(params.url, |
173 arg_names, | 152 arg_names, |
174 arg_values, | 153 arg_values, |
175 params.load_manually); | 154 params.load_manually); |
176 *transparent = delegate_->instance()->transparent(); | 155 *transparent = delegate_->instance()->transparent(); |
177 } | 156 } |
178 } | 157 } |
179 | 158 |
180 void WebPluginDelegateStub::OnSetFocus(bool focused) { | 159 void WebPluginDelegateStub::OnSetFocus(bool focused) { |
181 delegate_->SetFocus(focused); | 160 delegate_->SetFocus(focused); |
(...skipping 21 matching lines...) Expand all Loading... |
203 } | 182 } |
204 | 183 |
205 void WebPluginDelegateStub::OnUpdateGeometry( | 184 void WebPluginDelegateStub::OnUpdateGeometry( |
206 const PluginMsg_UpdateGeometry_Param& param) { | 185 const PluginMsg_UpdateGeometry_Param& param) { |
207 webplugin_->UpdateGeometry( | 186 webplugin_->UpdateGeometry( |
208 param.window_rect, param.clip_rect, | 187 param.window_rect, param.clip_rect, |
209 param.windowless_buffer0, param.windowless_buffer1, | 188 param.windowless_buffer0, param.windowless_buffer1, |
210 param.windowless_buffer_index); | 189 param.windowless_buffer_index); |
211 } | 190 } |
212 | 191 |
213 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) { | |
214 NPObject* object = delegate_->GetPluginScriptableObject(); | |
215 if (!object) { | |
216 *route_id = MSG_ROUTING_NONE; | |
217 return; | |
218 } | |
219 | |
220 *route_id = channel_->GenerateRouteID(); | |
221 // We will delete the stub immediately before calling PluginDestroyed on the | |
222 // delegate. It will delete itself sooner if the proxy tells it that it has | |
223 // been released, or if the channel to the proxy is closed. | |
224 NPObjectStub* scriptable_stub = new NPObjectStub( | |
225 object, channel_.get(), *route_id, | |
226 webplugin_->host_render_view_routing_id(), page_url_); | |
227 plugin_scriptable_object_ = scriptable_stub->AsWeakPtr(); | |
228 | |
229 // Release ref added by GetPluginScriptableObject (our stub holds its own). | |
230 WebBindings::releaseObject(object); | |
231 } | |
232 | |
233 void WebPluginDelegateStub::OnGetFormValue(base::string16* value, | 192 void WebPluginDelegateStub::OnGetFormValue(base::string16* value, |
234 bool* success) { | 193 bool* success) { |
235 *success = false; | 194 *success = false; |
236 if (!delegate_) | 195 if (!delegate_) |
237 return; | 196 return; |
238 *success = delegate_->GetFormValue(value); | 197 *success = delegate_->GetFormValue(value); |
239 } | 198 } |
240 | 199 |
241 void WebPluginDelegateStub::OnSetContentAreaFocus(bool has_focus) { | 200 void WebPluginDelegateStub::OnSetContentAreaFocus(bool has_focus) { |
242 if (delegate_) | 201 if (delegate_) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 248 } |
290 | 249 |
291 void WebPluginDelegateStub::OnImeCompositionCompleted( | 250 void WebPluginDelegateStub::OnImeCompositionCompleted( |
292 const base::string16& text) { | 251 const base::string16& text) { |
293 if (delegate_) | 252 if (delegate_) |
294 delegate_->ImeCompositionCompleted(text); | 253 delegate_->ImeCompositionCompleted(text); |
295 } | 254 } |
296 #endif // OS_MACOSX | 255 #endif // OS_MACOSX |
297 | 256 |
298 } // namespace content | 257 } // namespace content |
OLD | NEW |