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/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "content/common/npobject_stub.h" | |
13 #include "content/common/plugin_messages.h" | 12 #include "content/common/plugin_messages.h" |
14 #include "content/plugin/plugin_channel.h" | 13 #include "content/plugin/plugin_channel.h" |
15 #include "content/plugin/plugin_thread.h" | 14 #include "content/plugin/plugin_thread.h" |
16 #include "content/plugin/webplugin_proxy.h" | 15 #include "content/plugin/webplugin_proxy.h" |
17 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
18 #include "content/public/common/content_constants.h" | 17 #include "content/public/common/content_constants.h" |
19 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
20 #include "third_party/npapi/bindings/npapi.h" | 19 #include "third_party/npapi/bindings/npapi.h" |
21 #include "third_party/npapi/bindings/npruntime.h" | 20 #include "third_party/npapi/bindings/npruntime.h" |
22 #include "skia/ext/platform_device.h" | 21 #include "skia/ext/platform_device.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
25 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | 24 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
26 #include "webkit/glue/webcursor.h" | 25 #include "webkit/glue/webcursor.h" |
27 | 26 |
28 using WebKit::WebBindings; | 27 using WebKit::WebBindings; |
29 using WebKit::WebCursorInfo; | 28 using WebKit::WebCursorInfo; |
30 using webkit::npapi::WebPlugin; | 29 using webkit::npapi::WebPlugin; |
31 using webkit::npapi::WebPluginResourceClient; | 30 using webkit::npapi::WebPluginResourceClient; |
32 | 31 |
33 static void DestroyWebPluginAndDelegate( | 32 static void DestroyWebPluginAndDelegate( |
34 webkit::npapi::WebPluginDelegateImpl* delegate, WebPlugin* webplugin) { | 33 base::WeakPtr<NPObjectStub> scriptable_object, |
| 34 webkit::npapi::WebPluginDelegateImpl* delegate, |
| 35 WebPlugin* webplugin) { |
| 36 // The plugin may not expect us to try to release the scriptable object |
| 37 // after calling NPP_Destroy on the instance, so delete the stub now. |
| 38 if (scriptable_object.get()) |
| 39 scriptable_object->DeleteSoon(); |
35 // WebPlugin must outlive WebPluginDelegate. | 40 // WebPlugin must outlive WebPluginDelegate. |
36 if (delegate) | 41 if (delegate) |
37 delegate->PluginDestroyed(); | 42 delegate->PluginDestroyed(); |
38 | 43 |
39 delete webplugin; | 44 delete webplugin; |
40 } | 45 } |
41 | 46 |
42 WebPluginDelegateStub::WebPluginDelegateStub( | 47 WebPluginDelegateStub::WebPluginDelegateStub( |
43 const std::string& mime_type, int instance_id, PluginChannel* channel) : | 48 const std::string& mime_type, int instance_id, PluginChannel* channel) : |
44 mime_type_(mime_type), | 49 mime_type_(mime_type), |
45 instance_id_(instance_id), | 50 instance_id_(instance_id), |
46 channel_(channel), | 51 channel_(channel), |
47 delegate_(NULL), | 52 delegate_(NULL), |
48 webplugin_(NULL), | 53 webplugin_(NULL), |
49 in_destructor_(false) { | 54 in_destructor_(false) { |
50 DCHECK(channel); | 55 DCHECK(channel); |
51 } | 56 } |
52 | 57 |
53 WebPluginDelegateStub::~WebPluginDelegateStub() { | 58 WebPluginDelegateStub::~WebPluginDelegateStub() { |
54 in_destructor_ = true; | 59 in_destructor_ = true; |
55 content::GetContentClient()->SetActiveURL(page_url_); | 60 content::GetContentClient()->SetActiveURL(page_url_); |
56 | 61 |
57 if (channel_->in_send()) { | 62 if (channel_->in_send()) { |
58 // The delegate or an npobject is in the callstack, so don't delete it | 63 // The delegate or an npobject is in the callstack, so don't delete it |
59 // right away. | 64 // right away. |
60 MessageLoop::current()->PostNonNestableTask(FROM_HERE, | 65 MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
61 base::Bind(&DestroyWebPluginAndDelegate, delegate_, webplugin_)); | 66 base::Bind(&DestroyWebPluginAndDelegate, plugin_scriptable_object_, |
| 67 delegate_, webplugin_)); |
62 } else { | 68 } else { |
63 // Safe to delete right away. | 69 // Safe to delete right away. |
64 DestroyWebPluginAndDelegate(delegate_, webplugin_); | 70 DestroyWebPluginAndDelegate( |
| 71 plugin_scriptable_object_, delegate_, webplugin_); |
65 } | 72 } |
66 } | 73 } |
67 | 74 |
68 bool WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { | 75 bool WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { |
69 content::GetContentClient()->SetActiveURL(page_url_); | 76 content::GetContentClient()->SetActiveURL(page_url_); |
70 | 77 |
71 // A plugin can execute a script to delete itself in any of its NPP methods. | 78 // A plugin can execute a script to delete itself in any of its NPP methods. |
72 // Hold an extra reference to ourself so that if this does occur and we're | 79 // Hold an extra reference to ourself so that if this does occur and we're |
73 // handling a sync message, we don't crash when attempting to send a reply. | 80 // handling a sync message, we don't crash when attempting to send a reply. |
74 // The exception to this is when we're already in the destructor. | 81 // The exception to this is when we're already in the destructor. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 282 } |
276 | 283 |
277 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) { | 284 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) { |
278 NPObject* object = delegate_->GetPluginScriptableObject(); | 285 NPObject* object = delegate_->GetPluginScriptableObject(); |
279 if (!object) { | 286 if (!object) { |
280 *route_id = MSG_ROUTING_NONE; | 287 *route_id = MSG_ROUTING_NONE; |
281 return; | 288 return; |
282 } | 289 } |
283 | 290 |
284 *route_id = channel_->GenerateRouteID(); | 291 *route_id = channel_->GenerateRouteID(); |
285 // The stub will delete itself when the proxy tells it that it's released, or | 292 // We will delete the stub immediately before calling PluginDestroyed on the |
286 // otherwise when the channel is closed. | 293 // delegate. It will delete itself sooner if the proxy tells it that it has |
287 new NPObjectStub( | 294 // been released, or if the channel to the proxy is closed. |
| 295 NPObjectStub* scriptable_stub = new NPObjectStub( |
288 object, channel_.get(), *route_id, webplugin_->containing_window(), | 296 object, channel_.get(), *route_id, webplugin_->containing_window(), |
289 page_url_); | 297 page_url_); |
| 298 plugin_scriptable_object_ = scriptable_stub->AsWeakPtr(); |
290 | 299 |
291 // Release ref added by GetPluginScriptableObject (our stub holds its own). | 300 // Release ref added by GetPluginScriptableObject (our stub holds its own). |
292 WebBindings::releaseObject(object); | 301 WebBindings::releaseObject(object); |
293 } | 302 } |
294 | 303 |
295 void WebPluginDelegateStub::OnGetFormValue(string16* value, bool* success) { | 304 void WebPluginDelegateStub::OnGetFormValue(string16* value, bool* success) { |
296 *success = false; | 305 *success = false; |
297 if (!delegate_) | 306 if (!delegate_) |
298 return; | 307 return; |
299 *success = delegate_->GetFormValue(value); | 308 *success = delegate_->GetFormValue(value); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 delegate_->CreateSeekableResourceClient(resource_id, range_request_id); | 407 delegate_->CreateSeekableResourceClient(resource_id, range_request_id); |
399 webplugin_->OnResourceCreated(resource_id, resource_client); | 408 webplugin_->OnResourceCreated(resource_id, resource_client); |
400 } | 409 } |
401 | 410 |
402 #if defined(OS_MACOSX) | 411 #if defined(OS_MACOSX) |
403 void WebPluginDelegateStub::OnSetFakeAcceleratedSurfaceWindowHandle( | 412 void WebPluginDelegateStub::OnSetFakeAcceleratedSurfaceWindowHandle( |
404 gfx::PluginWindowHandle window) { | 413 gfx::PluginWindowHandle window) { |
405 delegate_->set_windowed_handle(window); | 414 delegate_->set_windowed_handle(window); |
406 } | 415 } |
407 #endif | 416 #endif |
OLD | NEW |