| 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_MACOSX) | 90 #if defined(OS_MACOSX) |
| 107 IPC_MESSAGE_HANDLER(PluginMsg_SetWindowFocus, OnSetWindowFocus) | 91 IPC_MESSAGE_HANDLER(PluginMsg_SetWindowFocus, OnSetWindowFocus) |
| 108 IPC_MESSAGE_HANDLER(PluginMsg_ContainerHidden, OnContainerHidden) | 92 IPC_MESSAGE_HANDLER(PluginMsg_ContainerHidden, OnContainerHidden) |
| 109 IPC_MESSAGE_HANDLER(PluginMsg_ContainerShown, OnContainerShown) | 93 IPC_MESSAGE_HANDLER(PluginMsg_ContainerShown, OnContainerShown) |
| 110 IPC_MESSAGE_HANDLER(PluginMsg_WindowFrameChanged, OnWindowFrameChanged) | 94 IPC_MESSAGE_HANDLER(PluginMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 111 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionCompleted, | 95 IPC_MESSAGE_HANDLER(PluginMsg_ImeCompositionCompleted, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (delegate_) { | 135 if (delegate_) { |
| 152 if (delegate_->GetQuirks() & | 136 if (delegate_->GetQuirks() & |
| 153 WebPluginDelegateImpl::PLUGIN_QUIRK_DIE_AFTER_UNLOAD) { | 137 WebPluginDelegateImpl::PLUGIN_QUIRK_DIE_AFTER_UNLOAD) { |
| 154 PluginThread::current()->SetForcefullyTerminatePluginProcess(); | 138 PluginThread::current()->SetForcefullyTerminatePluginProcess(); |
| 155 } | 139 } |
| 156 | 140 |
| 157 webplugin_->set_delegate(delegate_); | 141 webplugin_->set_delegate(delegate_); |
| 158 std::vector<std::string> arg_names = params.arg_names; | 142 std::vector<std::string> arg_names = params.arg_names; |
| 159 std::vector<std::string> arg_values = params.arg_values; | 143 std::vector<std::string> arg_values = params.arg_values; |
| 160 | 144 |
| 161 // Add an NPObject owner mapping for this instance, to support ownership | |
| 162 // tracking in the renderer. | |
| 163 channel_->AddMappingForNPObjectOwner(instance_id_, | |
| 164 delegate_->GetPluginNPP()); | |
| 165 | |
| 166 *result = delegate_->Initialize(params.url, | 145 *result = delegate_->Initialize(params.url, |
| 167 arg_names, | 146 arg_names, |
| 168 arg_values, | 147 arg_values, |
| 169 params.load_manually); | 148 params.load_manually); |
| 170 *transparent = delegate_->instance()->transparent(); | 149 *transparent = delegate_->instance()->transparent(); |
| 171 } | 150 } |
| 172 } | 151 } |
| 173 | 152 |
| 174 void WebPluginDelegateStub::OnSetFocus(bool focused) { | 153 void WebPluginDelegateStub::OnSetFocus(bool focused) { |
| 175 delegate_->SetFocus(focused); | 154 delegate_->SetFocus(focused); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 193 } | 172 } |
| 194 | 173 |
| 195 void WebPluginDelegateStub::OnUpdateGeometry( | 174 void WebPluginDelegateStub::OnUpdateGeometry( |
| 196 const PluginMsg_UpdateGeometry_Param& param) { | 175 const PluginMsg_UpdateGeometry_Param& param) { |
| 197 webplugin_->UpdateGeometry( | 176 webplugin_->UpdateGeometry( |
| 198 param.window_rect, param.clip_rect, | 177 param.window_rect, param.clip_rect, |
| 199 param.windowless_buffer0, param.windowless_buffer1, | 178 param.windowless_buffer0, param.windowless_buffer1, |
| 200 param.windowless_buffer_index); | 179 param.windowless_buffer_index); |
| 201 } | 180 } |
| 202 | 181 |
| 203 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) { | |
| 204 NPObject* object = delegate_->GetPluginScriptableObject(); | |
| 205 if (!object) { | |
| 206 *route_id = MSG_ROUTING_NONE; | |
| 207 return; | |
| 208 } | |
| 209 | |
| 210 *route_id = channel_->GenerateRouteID(); | |
| 211 // We will delete the stub immediately before calling PluginDestroyed on the | |
| 212 // delegate. It will delete itself sooner if the proxy tells it that it has | |
| 213 // been released, or if the channel to the proxy is closed. | |
| 214 NPObjectStub* scriptable_stub = new NPObjectStub( | |
| 215 object, channel_.get(), *route_id, | |
| 216 webplugin_->host_render_view_routing_id(), page_url_); | |
| 217 plugin_scriptable_object_ = scriptable_stub->AsWeakPtr(); | |
| 218 | |
| 219 // Release ref added by GetPluginScriptableObject (our stub holds its own). | |
| 220 WebBindings::releaseObject(object); | |
| 221 } | |
| 222 | |
| 223 void WebPluginDelegateStub::OnGetFormValue(base::string16* value, | 182 void WebPluginDelegateStub::OnGetFormValue(base::string16* value, |
| 224 bool* success) { | 183 bool* success) { |
| 225 *success = false; | 184 *success = false; |
| 226 if (!delegate_) | 185 if (!delegate_) |
| 227 return; | 186 return; |
| 228 *success = delegate_->GetFormValue(value); | 187 *success = delegate_->GetFormValue(value); |
| 229 } | 188 } |
| 230 | 189 |
| 231 void WebPluginDelegateStub::OnSetContentAreaFocus(bool has_focus) { | 190 void WebPluginDelegateStub::OnSetContentAreaFocus(bool has_focus) { |
| 232 if (delegate_) | 191 if (delegate_) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 261 } | 220 } |
| 262 | 221 |
| 263 void WebPluginDelegateStub::OnImeCompositionCompleted( | 222 void WebPluginDelegateStub::OnImeCompositionCompleted( |
| 264 const base::string16& text) { | 223 const base::string16& text) { |
| 265 if (delegate_) | 224 if (delegate_) |
| 266 delegate_->ImeCompositionCompleted(text); | 225 delegate_->ImeCompositionCompleted(text); |
| 267 } | 226 } |
| 268 #endif // OS_MACOSX | 227 #endif // OS_MACOSX |
| 269 | 228 |
| 270 } // namespace content | 229 } // namespace content |
| OLD | NEW |