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

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

Issue 7578001: Unify var tracking between webkit and the proxy. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | « ppapi/tests/test_var_deprecated.cc ('k') | webkit/plugins/ppapi/npobject_var.h » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/npapi_glue.h" 5 #include "webkit/plugins/ppapi/npapi_glue.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "webkit/plugins/ppapi/npobject_var.h" 10 #include "webkit/plugins/ppapi/npobject_var.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 success_(false), 152 success_(false),
153 checked_exception_(false) { 153 checked_exception_(false) {
154 } 154 }
155 155
156 PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() { 156 PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() {
157 // The user should have called SetResult or CheckExceptionForNoResult 157 // The user should have called SetResult or CheckExceptionForNoResult
158 // before letting this class go out of scope, or the exception will have 158 // before letting this class go out of scope, or the exception will have
159 // been lost. 159 // been lost.
160 DCHECK(checked_exception_); 160 DCHECK(checked_exception_);
161 161
162 NPObjectVar::PluginReleasePPVar(exception_); 162 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(exception_);
163 } 163 }
164 164
165 // Call this with the return value of the PPAPI function. It will convert 165 // Call this with the return value of the PPAPI function. It will convert
166 // the result to the NPVariant output parameter and pass any exception on to 166 // the result to the NPVariant output parameter and pass any exception on to
167 // the JS engine. It will update the success flag and return it. 167 // the JS engine. It will update the success flag and return it.
168 bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) { 168 bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) {
169 DCHECK(!checked_exception_); // Don't call more than once. 169 DCHECK(!checked_exception_); // Don't call more than once.
170 DCHECK(np_result_); // Should be expecting a result. 170 DCHECK(np_result_); // Should be expecting a result.
171 171
172 checked_exception_ = true; 172 checked_exception_ = true;
173 173
174 if (has_exception()) { 174 if (has_exception()) {
175 ThrowException(); 175 ThrowException();
176 success_ = false; 176 success_ = false;
177 } else if (!PPVarToNPVariant(result, np_result_)) { 177 } else if (!PPVarToNPVariant(result, np_result_)) {
178 WebBindings::setException(object_var_, kInvalidPluginValue); 178 WebBindings::setException(object_var_, kInvalidPluginValue);
179 success_ = false; 179 success_ = false;
180 } else { 180 } else {
181 success_ = true; 181 success_ = true;
182 } 182 }
183 183
184 // No matter what happened, we need to release the reference to the 184 // No matter what happened, we need to release the reference to the
185 // value passed in. On success, a reference to this value will be in 185 // value passed in. On success, a reference to this value will be in
186 // the np_result_. 186 // the np_result_.
187 ::ppapi::Var::PluginReleasePPVar(result); 187 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(result);
188 return success_; 188 return success_;
189 } 189 }
190 190
191 // Call this after calling a PPAPI function that could have set the 191 // Call this after calling a PPAPI function that could have set the
192 // exception. It will pass the exception on to the JS engine and update 192 // exception. It will pass the exception on to the JS engine and update
193 // the success flag. 193 // the success flag.
194 // 194 //
195 // The success flag will be returned. 195 // The success flag will be returned.
196 bool PPResultAndExceptionToNPResult::CheckExceptionForNoResult() { 196 bool PPResultAndExceptionToNPResult::CheckExceptionForNoResult() {
197 DCHECK(!checked_exception_); // Don't call more than once. 197 DCHECK(!checked_exception_); // Don't call more than once.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 const NPVariant* variants) 230 const NPVariant* variants)
231 : size_(size) { 231 : size_(size) {
232 if (size_ > 0) { 232 if (size_ > 0) {
233 array_.reset(new PP_Var[size_]); 233 array_.reset(new PP_Var[size_]);
234 for (size_t i = 0; i < size_; i++) 234 for (size_t i = 0; i < size_; i++)
235 array_[i] = NPVariantToPPVar(instance, &variants[i]); 235 array_[i] = NPVariantToPPVar(instance, &variants[i]);
236 } 236 }
237 } 237 }
238 238
239 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() { 239 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() {
240 ::ppapi::VarTracker* var_tracker = ResourceTracker::Get()->GetVarTracker();
240 for (size_t i = 0; i < size_; i++) 241 for (size_t i = 0; i < size_; i++)
241 ::ppapi::Var::PluginReleasePPVar(array_[i]); 242 var_tracker->ReleaseVar(array_[i]);
242 } 243 }
243 244
244 // PPVarFromNPObject ----------------------------------------------------------- 245 // PPVarFromNPObject -----------------------------------------------------------
245 246
246 PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object) 247 PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object)
247 : var_(NPObjectToPPVar(instance, object)) { 248 : var_(NPObjectToPPVar(instance, object)) {
248 } 249 }
249 250
250 PPVarFromNPObject::~PPVarFromNPObject() { 251 PPVarFromNPObject::~PPVarFromNPObject() {
251 ::ppapi::Var::PluginReleasePPVar(var_); 252 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(var_);
252 } 253 }
253 254
254 // NPObjectAccessorWithIdentifier ---------------------------------------------- 255 // NPObjectAccessorWithIdentifier ----------------------------------------------
255 256
256 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( 257 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier(
257 NPObject* object, 258 NPObject* object,
258 NPIdentifier identifier, 259 NPIdentifier identifier,
259 bool allow_integer_identifier) 260 bool allow_integer_identifier)
260 : object_(PluginObject::FromNPObject(object)), 261 : object_(PluginObject::FromNPObject(object)),
261 identifier_(PP_MakeUndefined()) { 262 identifier_(PP_MakeUndefined()) {
262 if (object_) { 263 if (object_) {
263 identifier_ = NPIdentifierToPPVar( 264 identifier_ = NPIdentifierToPPVar(
264 object_->instance()->module()->pp_module(), identifier); 265 object_->instance()->module()->pp_module(), identifier);
265 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier) 266 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier)
266 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid. 267 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid.
267 } 268 }
268 } 269 }
269 270
270 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() { 271 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() {
271 ::ppapi::Var::PluginReleasePPVar(identifier_); 272 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(identifier_);
272 } 273 }
273 274
274 // TryCatch -------------------------------------------------------------------- 275 // TryCatch --------------------------------------------------------------------
275 276
276 TryCatch::TryCatch(PP_Module module, PP_Var* exception) 277 TryCatch::TryCatch(PP_Module module, PP_Var* exception)
277 : pp_module_(module), 278 : pp_module_(module),
278 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED), 279 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED),
279 exception_(exception) { 280 exception_(exception) {
280 WebBindings::pushExceptionHandler(&TryCatch::Catch, this); 281 WebBindings::pushExceptionHandler(&TryCatch::Catch, this);
281 } 282 }
(...skipping 28 matching lines...) Expand all
310 } 311 }
311 } 312 }
312 313
313 // static 314 // static
314 void TryCatch::Catch(void* self, const char* message) { 315 void TryCatch::Catch(void* self, const char* message) {
315 static_cast<TryCatch*>(self)->SetException(message); 316 static_cast<TryCatch*>(self)->SetException(message);
316 } 317 }
317 318
318 } // namespace ppapi 319 } // namespace ppapi
319 } // namespace webkit 320 } // namespace webkit
OLDNEW
« no previous file with comments | « ppapi/tests/test_var_deprecated.cc ('k') | webkit/plugins/ppapi/npobject_var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698