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

Side by Side Diff: content/plugin/webplugin_delegate_stub.cc

Issue 9817023: Make sure the plugin scriptable object is released before NPP_Destroy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « content/plugin/webplugin_delegate_stub.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(delegate_, webplugin_);
65 } 71 }
66 } 72 }
67 73
68 bool WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { 74 bool WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) {
69 content::GetContentClient()->SetActiveURL(page_url_); 75 content::GetContentClient()->SetActiveURL(page_url_);
70 76
71 // A plugin can execute a script to delete itself in any of its NPP methods. 77 // A plugin can execute a script to delete itself in any of its NPP methods.
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 281 }
276 282
277 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) { 283 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) {
278 NPObject* object = delegate_->GetPluginScriptableObject(); 284 NPObject* object = delegate_->GetPluginScriptableObject();
279 if (!object) { 285 if (!object) {
280 *route_id = MSG_ROUTING_NONE; 286 *route_id = MSG_ROUTING_NONE;
281 return; 287 return;
282 } 288 }
283 289
284 *route_id = channel_->GenerateRouteID(); 290 *route_id = channel_->GenerateRouteID();
285 // The stub will delete itself when the proxy tells it that it's released, or 291 // The stub will delete itself when the proxy tells it that it's released, or
cpu_(ooo_6.6-7.5) 2012/03/22 00:09:28 stale comment line 291
Wez 2012/03/22 00:42:20 Done.
286 // otherwise when the channel is closed. 292 // otherwise when the channel is closed.
287 new NPObjectStub( 293 NPObjectStub* scriptable_stub = new NPObjectStub(
288 object, channel_.get(), *route_id, webplugin_->containing_window(), 294 object, channel_.get(), *route_id, webplugin_->containing_window(),
289 page_url_); 295 page_url_);
296 plugin_scriptable_object_ = scriptable_stub->AsWeakPtr();
290 297
291 // Release ref added by GetPluginScriptableObject (our stub holds its own). 298 // Release ref added by GetPluginScriptableObject (our stub holds its own).
292 WebBindings::releaseObject(object); 299 WebBindings::releaseObject(object);
293 } 300 }
294 301
295 void WebPluginDelegateStub::OnGetFormValue(string16* value, bool* success) { 302 void WebPluginDelegateStub::OnGetFormValue(string16* value, bool* success) {
296 *success = false; 303 *success = false;
297 if (!delegate_) 304 if (!delegate_)
298 return; 305 return;
299 *success = delegate_->GetFormValue(value); 306 *success = delegate_->GetFormValue(value);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 delegate_->CreateSeekableResourceClient(resource_id, range_request_id); 405 delegate_->CreateSeekableResourceClient(resource_id, range_request_id);
399 webplugin_->OnResourceCreated(resource_id, resource_client); 406 webplugin_->OnResourceCreated(resource_id, resource_client);
400 } 407 }
401 408
402 #if defined(OS_MACOSX) 409 #if defined(OS_MACOSX)
403 void WebPluginDelegateStub::OnSetFakeAcceleratedSurfaceWindowHandle( 410 void WebPluginDelegateStub::OnSetFakeAcceleratedSurfaceWindowHandle(
404 gfx::PluginWindowHandle window) { 411 gfx::PluginWindowHandle window) {
405 delegate_->set_windowed_handle(window); 412 delegate_->set_windowed_handle(window);
406 } 413 }
407 #endif 414 #endif
OLDNEW
« no previous file with comments | « content/plugin/webplugin_delegate_stub.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698