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

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

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