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

Side by Side Diff: webkit/plugins/ppapi/ppapi_webplugin_impl.cc

Issue 9403039: PPAPI: Really force-free NPObjects on Instance destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix instance object reference leak, add testing. Created 8 years, 10 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 | « webkit/plugins/ppapi/ppapi_webplugin_impl.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 "webkit/plugins/ppapi/ppapi_webplugin_impl.h" 5 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "ppapi/c/pp_var.h" 11 #include "ppapi/shared_impl/ppapi_globals.h"
12 #include "ppapi/shared_impl/var_tracker.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
21 #include "webkit/plugins/ppapi/message_channel.h" 22 #include "webkit/plugins/ppapi/message_channel.h"
(...skipping 22 matching lines...) Expand all
44 std::vector<std::string> arg_names; 45 std::vector<std::string> arg_names;
45 std::vector<std::string> arg_values; 46 std::vector<std::string> arg_values;
46 GURL url; 47 GURL url;
47 }; 48 };
48 49
49 WebPluginImpl::WebPluginImpl( 50 WebPluginImpl::WebPluginImpl(
50 PluginModule* plugin_module, 51 PluginModule* plugin_module,
51 const WebPluginParams& params, 52 const WebPluginParams& params,
52 const base::WeakPtr<PluginDelegate>& plugin_delegate) 53 const base::WeakPtr<PluginDelegate>& plugin_delegate)
53 : init_data_(new InitData()), 54 : init_data_(new InitData()),
54 full_frame_(params.loadManually) { 55 full_frame_(params.loadManually),
56 instance_object_(PP_MakeUndefined()) {
55 DCHECK(plugin_module); 57 DCHECK(plugin_module);
56 init_data_->module = plugin_module; 58 init_data_->module = plugin_module;
57 init_data_->delegate = plugin_delegate; 59 init_data_->delegate = plugin_delegate;
58 for (size_t i = 0; i < params.attributeNames.size(); ++i) { 60 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
59 init_data_->arg_names.push_back(params.attributeNames[i].utf8()); 61 init_data_->arg_names.push_back(params.attributeNames[i].utf8());
60 init_data_->arg_values.push_back(params.attributeValues[i].utf8()); 62 init_data_->arg_values.push_back(params.attributeValues[i].utf8());
61 } 63 }
62 init_data_->url = params.url; 64 init_data_->url = params.url;
63 } 65 }
64 66
(...skipping 19 matching lines...) Expand all
84 instance_ = NULL; 86 instance_ = NULL;
85 return false; 87 return false;
86 } 88 }
87 89
88 init_data_.reset(); 90 init_data_.reset();
89 return true; 91 return true;
90 } 92 }
91 93
92 void WebPluginImpl::destroy() { 94 void WebPluginImpl::destroy() {
93 if (instance_) { 95 if (instance_) {
96 ::ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(instance_object_);
brettw 2012/02/28 00:18:27 Can you also clear the instance_object_ var here?
94 instance_->Delete(); 97 instance_->Delete();
95 instance_ = NULL; 98 instance_ = NULL;
96 } 99 }
97 100
98 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 101 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
99 } 102 }
100 103
101 NPObject* WebPluginImpl::scriptableObject() { 104 NPObject* WebPluginImpl::scriptableObject() {
102 // Call through the plugin to get its instance object. Note that we "leak" a 105 // Call through the plugin to get its instance object. The plugin should pass
103 // reference here. But we want to keep the instance object alive so long as 106 // us a reference which we release in destroy().
104 // the instance is alive, so it's okay. It will get cleaned up when all 107 if (instance_object_.type == PP_VARTYPE_UNDEFINED)
105 // NPObjectVars are "force freed" at instance shutdown. 108 instance_object_ = instance_->GetInstanceObject();
106 scoped_refptr<NPObjectVar> object(
107 NPObjectVar::FromPPVar(instance_->GetInstanceObject()));
108 // GetInstanceObject talked to the plugin which may have removed the instance 109 // GetInstanceObject talked to the plugin which may have removed the instance
109 // from the DOM, in which case instance_ would be NULL now. 110 // from the DOM, in which case instance_ would be NULL now.
110 if (!instance_) 111 if (!instance_)
111 return NULL; 112 return NULL;
112 113
114 scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(instance_object_));
113 // If there's an InstanceObject, tell the Instance's MessageChannel to pass 115 // If there's an InstanceObject, tell the Instance's MessageChannel to pass
114 // any non-postMessage calls to it. 116 // any non-postMessage calls to it.
115 if (object) { 117 if (object) {
116 instance_->message_channel().SetPassthroughObject(object->np_object()); 118 instance_->message_channel().SetPassthroughObject(object->np_object());
117 } 119 }
118 NPObject* message_channel_np_object(instance_->message_channel().np_object()); 120 NPObject* message_channel_np_object(instance_->message_channel().np_object());
119 // The object is expected to be retained before it is returned. 121 // The object is expected to be retained before it is returned.
120 WebKit::WebBindings::retainObject(message_channel_np_object); 122 WebKit::WebBindings::retainObject(message_channel_np_object);
121 return message_channel_np_object; 123 return message_channel_np_object;
122 } 124 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 bool WebPluginImpl::canRotateView() { 265 bool WebPluginImpl::canRotateView() {
264 return instance_->CanRotateView(); 266 return instance_->CanRotateView();
265 } 267 }
266 268
267 void WebPluginImpl::rotateView(RotationType type) { 269 void WebPluginImpl::rotateView(RotationType type) {
268 instance_->RotateView(type); 270 instance_->RotateView(type);
269 } 271 }
270 272
271 } // namespace ppapi 273 } // namespace ppapi
272 } // namespace webkit 274 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_webplugin_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698