| 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_WillSendRequest, OnWillSendRequest) | 82 IPC_MESSAGE_HANDLER(PluginMsg_WillSendRequest, OnWillSendRequest) |
| 97 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse) | 83 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse) |
| 98 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData) | 84 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData) |
| 99 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoading, OnDidFinishLoading) | 85 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoading, OnDidFinishLoading) |
| 100 IPC_MESSAGE_HANDLER(PluginMsg_DidFail, OnDidFail) | 86 IPC_MESSAGE_HANDLER(PluginMsg_DidFail, OnDidFail) |
| 101 IPC_MESSAGE_HANDLER(PluginMsg_SetFocus, OnSetFocus) | 87 IPC_MESSAGE_HANDLER(PluginMsg_SetFocus, OnSetFocus) |
| 102 IPC_MESSAGE_HANDLER(PluginMsg_HandleInputEvent, OnHandleInputEvent) | 88 IPC_MESSAGE_HANDLER(PluginMsg_HandleInputEvent, OnHandleInputEvent) |
| 103 IPC_MESSAGE_HANDLER(PluginMsg_Paint, OnPaint) | 89 IPC_MESSAGE_HANDLER(PluginMsg_Paint, OnPaint) |
| 104 IPC_MESSAGE_HANDLER(PluginMsg_DidPaint, OnDidPaint) | 90 IPC_MESSAGE_HANDLER(PluginMsg_DidPaint, OnDidPaint) |
| 105 IPC_MESSAGE_HANDLER(PluginMsg_GetPluginScriptableObject, | |
| 106 OnGetPluginScriptableObject) | |
| 107 IPC_MESSAGE_HANDLER(PluginMsg_GetFormValue, OnGetFormValue) | 91 IPC_MESSAGE_HANDLER(PluginMsg_GetFormValue, OnGetFormValue) |
| 108 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometry, OnUpdateGeometry) | 92 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometry, OnUpdateGeometry) |
| 109 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometrySync, OnUpdateGeometry) | 93 IPC_MESSAGE_HANDLER(PluginMsg_UpdateGeometrySync, OnUpdateGeometry) |
| 110 IPC_MESSAGE_HANDLER(PluginMsg_SetContentAreaFocus, OnSetContentAreaFocus) | 94 IPC_MESSAGE_HANDLER(PluginMsg_SetContentAreaFocus, OnSetContentAreaFocus) |
| 111 #if defined(OS_WIN) && !defined(USE_AURA) | 95 #if defined(OS_WIN) && !defined(USE_AURA) |
| 112 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionUpdated, | 96 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionUpdated, |
| 113 OnImeCompositionUpdated) | 97 OnImeCompositionUpdated) |
| 114 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionCompleted, | 98 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionCompleted, |
| 115 OnImeCompositionCompleted) | 99 OnImeCompositionCompleted) |
| 116 #endif | 100 #endif |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 if (delegate_) { | 146 if (delegate_) { |
| 163 if (delegate_->GetQuirks() & | 147 if (delegate_->GetQuirks() & |
| 164 WebPluginDelegateImpl::PLUGIN_QUIRK_DIE_AFTER_UNLOAD) { | 148 WebPluginDelegateImpl::PLUGIN_QUIRK_DIE_AFTER_UNLOAD) { |
| 165 PluginThread::current()->SetForcefullyTerminatePluginProcess(); | 149 PluginThread::current()->SetForcefullyTerminatePluginProcess(); |
| 166 } | 150 } |
| 167 | 151 |
| 168 webplugin_->set_delegate(delegate_); | 152 webplugin_->set_delegate(delegate_); |
| 169 std::vector<std::string> arg_names = params.arg_names; | 153 std::vector<std::string> arg_names = params.arg_names; |
| 170 std::vector<std::string> arg_values = params.arg_values; | 154 std::vector<std::string> arg_values = params.arg_values; |
| 171 | 155 |
| 172 // Add an NPObject owner mapping for this instance, to support ownership | |
| 173 // tracking in the renderer. | |
| 174 channel_->AddMappingForNPObjectOwner(instance_id_, | |
| 175 delegate_->GetPluginNPP()); | |
| 176 | |
| 177 *result = delegate_->Initialize(params.url, | 156 *result = delegate_->Initialize(params.url, |
| 178 arg_names, | 157 arg_names, |
| 179 arg_values, | 158 arg_values, |
| 180 params.load_manually); | 159 params.load_manually); |
| 181 *transparent = delegate_->instance()->transparent(); | 160 *transparent = delegate_->instance()->transparent(); |
| 182 } | 161 } |
| 183 } | 162 } |
| 184 | 163 |
| 185 void WebPluginDelegateStub::OnWillSendRequest(int id, const GURL& url, | 164 void WebPluginDelegateStub::OnWillSendRequest(int id, const GURL& url, |
| 186 int http_status_code) { | 165 int http_status_code) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 236 } |
| 258 | 237 |
| 259 void WebPluginDelegateStub::OnUpdateGeometry( | 238 void WebPluginDelegateStub::OnUpdateGeometry( |
| 260 const PluginMsg_UpdateGeometry_Param& param) { | 239 const PluginMsg_UpdateGeometry_Param& param) { |
| 261 webplugin_->UpdateGeometry( | 240 webplugin_->UpdateGeometry( |
| 262 param.window_rect, param.clip_rect, | 241 param.window_rect, param.clip_rect, |
| 263 param.windowless_buffer0, param.windowless_buffer1, | 242 param.windowless_buffer0, param.windowless_buffer1, |
| 264 param.windowless_buffer_index); | 243 param.windowless_buffer_index); |
| 265 } | 244 } |
| 266 | 245 |
| 267 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) { | |
| 268 NPObject* object = delegate_->GetPluginScriptableObject(); | |
| 269 if (!object) { | |
| 270 *route_id = MSG_ROUTING_NONE; | |
| 271 return; | |
| 272 } | |
| 273 | |
| 274 *route_id = channel_->GenerateRouteID(); | |
| 275 // We will delete the stub immediately before calling PluginDestroyed on the | |
| 276 // delegate. It will delete itself sooner if the proxy tells it that it has | |
| 277 // been released, or if the channel to the proxy is closed. | |
| 278 NPObjectStub* scriptable_stub = new NPObjectStub( | |
| 279 object, channel_.get(), *route_id, | |
| 280 webplugin_->host_render_view_routing_id(), page_url_); | |
| 281 plugin_scriptable_object_ = scriptable_stub->AsWeakPtr(); | |
| 282 | |
| 283 // Release ref added by GetPluginScriptableObject (our stub holds its own). | |
| 284 WebBindings::releaseObject(object); | |
| 285 } | |
| 286 | |
| 287 void WebPluginDelegateStub::OnGetFormValue(base::string16* value, | 246 void WebPluginDelegateStub::OnGetFormValue(base::string16* value, |
| 288 bool* success) { | 247 bool* success) { |
| 289 *success = false; | 248 *success = false; |
| 290 if (!delegate_) | 249 if (!delegate_) |
| 291 return; | 250 return; |
| 292 *success = delegate_->GetFormValue(value); | 251 *success = delegate_->GetFormValue(value); |
| 293 } | 252 } |
| 294 | 253 |
| 295 void WebPluginDelegateStub::OnSetContentAreaFocus(bool has_focus) { | 254 void WebPluginDelegateStub::OnSetContentAreaFocus(bool has_focus) { |
| 296 if (delegate_) | 255 if (delegate_) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 302 } |
| 344 | 303 |
| 345 void WebPluginDelegateStub::OnImeCompositionCompleted( | 304 void WebPluginDelegateStub::OnImeCompositionCompleted( |
| 346 const base::string16& text) { | 305 const base::string16& text) { |
| 347 if (delegate_) | 306 if (delegate_) |
| 348 delegate_->ImeCompositionCompleted(text); | 307 delegate_->ImeCompositionCompleted(text); |
| 349 } | 308 } |
| 350 #endif // OS_MACOSX | 309 #endif // OS_MACOSX |
| 351 | 310 |
| 352 } // namespace content | 311 } // namespace content |
| OLD | NEW |