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

Side by Side Diff: content/renderer/pepper/ppb_var_deprecated_impl.cc

Issue 225903006: PPAPI: Run clang_format.py on content/renderer/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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/renderer/pepper/ppb_var_deprecated_impl.h" 5 #include "content/renderer/pepper/ppb_var_deprecated_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "content/renderer/pepper/common.h" 9 #include "content/renderer/pepper/common.h"
10 #include "content/renderer/pepper/host_globals.h" 10 #include "content/renderer/pepper/host_globals.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // 102 //
103 // This will automatically retrieve the ObjectVar from the object and throw 103 // This will automatically retrieve the ObjectVar from the object and throw
104 // an exception if it's invalid. At the end of construction, if there is no 104 // an exception if it's invalid. At the end of construction, if there is no
105 // exception, you know that there is no previously set exception, that the 105 // exception, you know that there is no previously set exception, that the
106 // object passed in is valid and ready to use (via the object() getter), and 106 // object passed in is valid and ready to use (via the object() getter), and
107 // that the TryCatch's pp_module() getter is also set up properly and ready to 107 // that the TryCatch's pp_module() getter is also set up properly and ready to
108 // use. 108 // use.
109 class ObjectAccessorTryCatch : public TryCatch { 109 class ObjectAccessorTryCatch : public TryCatch {
110 public: 110 public:
111 ObjectAccessorTryCatch(PP_Var object, PP_Var* exception) 111 ObjectAccessorTryCatch(PP_Var object, PP_Var* exception)
112 : TryCatch(exception), 112 : TryCatch(exception), object_(NPObjectVar::FromPPVar(object)) {
113 object_(NPObjectVar::FromPPVar(object)) {
114 if (!object_.get()) { 113 if (!object_.get()) {
115 SetException(kInvalidObjectException); 114 SetException(kInvalidObjectException);
116 } 115 }
117 } 116 }
118 117
119 NPObjectVar* object() { return object_.get(); } 118 NPObjectVar* object() { return object_.get(); }
120 119
121 PepperPluginInstanceImpl* GetPluginInstance() { 120 PepperPluginInstanceImpl* GetPluginInstance() {
122 return HostGlobals::Get()->GetInstance(object()->pp_instance()); 121 return HostGlobals::Get()->GetInstance(object()->pp_instance());
123 } 122 }
(...skipping 14 matching lines...) Expand all
138 // At the end of construction, if there is no exception, you know that there is 137 // At the end of construction, if there is no exception, you know that there is
139 // no previously set exception, that the object passed in is valid and ready to 138 // no previously set exception, that the object passed in is valid and ready to
140 // use (via the object() getter), that the identifier is valid and ready to 139 // use (via the object() getter), that the identifier is valid and ready to
141 // use (via the identifier() getter), and that the TryCatch's pp_module() getter 140 // use (via the identifier() getter), and that the TryCatch's pp_module() getter
142 // is also set up properly and ready to use. 141 // is also set up properly and ready to use.
143 class ObjectAccessorWithIdentifierTryCatch : public ObjectAccessorTryCatch { 142 class ObjectAccessorWithIdentifierTryCatch : public ObjectAccessorTryCatch {
144 public: 143 public:
145 ObjectAccessorWithIdentifierTryCatch(PP_Var object, 144 ObjectAccessorWithIdentifierTryCatch(PP_Var object,
146 PP_Var identifier, 145 PP_Var identifier,
147 PP_Var* exception) 146 PP_Var* exception)
148 : ObjectAccessorTryCatch(object, exception), 147 : ObjectAccessorTryCatch(object, exception), identifier_(0) {
149 identifier_(0) {
150 if (!has_exception()) { 148 if (!has_exception()) {
151 identifier_ = PPVarToNPIdentifier(identifier); 149 identifier_ = PPVarToNPIdentifier(identifier);
152 if (!identifier_) 150 if (!identifier_)
153 SetException(kInvalidPropertyException); 151 SetException(kInvalidPropertyException);
154 } 152 }
155 } 153 }
156 154
157 NPIdentifier identifier() const { return identifier_; } 155 NPIdentifier identifier() const { return identifier_; }
158 156
159 private: 157 private:
160 NPIdentifier identifier_; 158 NPIdentifier identifier_;
161 159
162 DISALLOW_COPY_AND_ASSIGN(ObjectAccessorWithIdentifierTryCatch); 160 DISALLOW_COPY_AND_ASSIGN(ObjectAccessorWithIdentifierTryCatch);
163 }; 161 };
164 162
165 PP_Bool HasProperty(PP_Var var, 163 PP_Bool HasProperty(PP_Var var, PP_Var name, PP_Var* exception) {
166 PP_Var name,
167 PP_Var* exception) {
168 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 164 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
169 if (accessor.has_exception()) 165 if (accessor.has_exception())
170 return PP_FALSE; 166 return PP_FALSE;
171 return BoolToPPBool(WebBindings::hasProperty(NULL, 167 return BoolToPPBool(WebBindings::hasProperty(
172 accessor.object()->np_object(), 168 NULL, accessor.object()->np_object(), accessor.identifier()));
173 accessor.identifier()));
174 } 169 }
175 170
176 bool HasPropertyDeprecated(PP_Var var, 171 bool HasPropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) {
177 PP_Var name,
178 PP_Var* exception) {
179 return PPBoolToBool(HasProperty(var, name, exception)); 172 return PPBoolToBool(HasProperty(var, name, exception));
180 } 173 }
181 174
182 bool HasMethodDeprecated(PP_Var var, 175 bool HasMethodDeprecated(PP_Var var, PP_Var name, PP_Var* exception) {
183 PP_Var name,
184 PP_Var* exception) {
185 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 176 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
186 if (accessor.has_exception()) 177 if (accessor.has_exception())
187 return false; 178 return false;
188 return WebBindings::hasMethod(NULL, accessor.object()->np_object(), 179 return WebBindings::hasMethod(
189 accessor.identifier()); 180 NULL, accessor.object()->np_object(), accessor.identifier());
190 } 181 }
191 182
192 PP_Var GetProperty(PP_Var var, 183 PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) {
193 PP_Var name,
194 PP_Var* exception) {
195 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 184 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
196 if (accessor.has_exception()) 185 if (accessor.has_exception())
197 return PP_MakeUndefined(); 186 return PP_MakeUndefined();
198 187
199 NPVariant result; 188 NPVariant result;
200 if (!WebBindings::getProperty(NULL, accessor.object()->np_object(), 189 if (!WebBindings::getProperty(NULL,
201 accessor.identifier(), &result)) { 190 accessor.object()->np_object(),
191 accessor.identifier(),
192 &result)) {
202 // An exception may have been raised. 193 // An exception may have been raised.
203 accessor.SetException(kUnableToGetPropertyException); 194 accessor.SetException(kUnableToGetPropertyException);
204 return PP_MakeUndefined(); 195 return PP_MakeUndefined();
205 } 196 }
206 197
207 PP_Var ret = NPVariantToPPVar(accessor.GetPluginInstance(), &result); 198 PP_Var ret = NPVariantToPPVar(accessor.GetPluginInstance(), &result);
208 WebBindings::releaseVariantValue(&result); 199 WebBindings::releaseVariantValue(&result);
209 return ret; 200 return ret;
210 } 201 }
211 202
212 void EnumerateProperties(PP_Var var, 203 void EnumerateProperties(PP_Var var,
213 uint32_t* property_count, 204 uint32_t* property_count,
214 PP_Var** properties, 205 PP_Var** properties,
215 PP_Var* exception) { 206 PP_Var* exception) {
216 *properties = NULL; 207 *properties = NULL;
217 *property_count = 0; 208 *property_count = 0;
218 209
219 ObjectAccessorTryCatch accessor(var, exception); 210 ObjectAccessorTryCatch accessor(var, exception);
220 if (accessor.has_exception()) 211 if (accessor.has_exception())
221 return; 212 return;
222 213
223 NPIdentifier* identifiers = NULL; 214 NPIdentifier* identifiers = NULL;
224 uint32_t count = 0; 215 uint32_t count = 0;
225 if (!WebBindings::enumerate(NULL, accessor.object()->np_object(), 216 if (!WebBindings::enumerate(
226 &identifiers, &count)) { 217 NULL, accessor.object()->np_object(), &identifiers, &count)) {
227 accessor.SetException(kUnableToGetAllPropertiesException); 218 accessor.SetException(kUnableToGetAllPropertiesException);
228 return; 219 return;
229 } 220 }
230 221
231 if (count == 0) 222 if (count == 0)
232 return; 223 return;
233 224
234 *property_count = count; 225 *property_count = count;
235 *properties = static_cast<PP_Var*>(malloc(sizeof(PP_Var) * count)); 226 *properties = static_cast<PP_Var*>(malloc(sizeof(PP_Var) * count));
236 for (uint32_t i = 0; i < count; ++i) { 227 for (uint32_t i = 0; i < count; ++i) {
237 (*properties)[i] = NPIdentifierToPPVar(identifiers[i]); 228 (*properties)[i] = NPIdentifierToPPVar(identifiers[i]);
238 } 229 }
239 free(identifiers); 230 free(identifiers);
240 } 231 }
241 232
242 void SetPropertyDeprecated(PP_Var var, 233 void SetPropertyDeprecated(PP_Var var,
243 PP_Var name, 234 PP_Var name,
244 PP_Var value, 235 PP_Var value,
245 PP_Var* exception) { 236 PP_Var* exception) {
246 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 237 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
247 if (accessor.has_exception()) 238 if (accessor.has_exception())
248 return; 239 return;
249 240
250 NPVariant variant; 241 NPVariant variant;
251 if (!PPVarToNPVariantNoCopy(value, &variant)) { 242 if (!PPVarToNPVariantNoCopy(value, &variant)) {
252 accessor.SetException(kInvalidValueException); 243 accessor.SetException(kInvalidValueException);
253 return; 244 return;
254 } 245 }
255 if (!WebBindings::setProperty(NULL, accessor.object()->np_object(), 246 if (!WebBindings::setProperty(NULL,
256 accessor.identifier(), &variant)) 247 accessor.object()->np_object(),
248 accessor.identifier(),
249 &variant))
257 accessor.SetException(kUnableToSetPropertyException); 250 accessor.SetException(kUnableToSetPropertyException);
258 } 251 }
259 252
260 void DeletePropertyDeprecated(PP_Var var, 253 void DeletePropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) {
261 PP_Var name,
262 PP_Var* exception) {
263 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 254 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
264 if (accessor.has_exception()) 255 if (accessor.has_exception())
265 return; 256 return;
266 257
267 if (!WebBindings::removeProperty(NULL, accessor.object()->np_object(), 258 if (!WebBindings::removeProperty(
268 accessor.identifier())) 259 NULL, accessor.object()->np_object(), accessor.identifier()))
269 accessor.SetException(kUnableToRemovePropertyException); 260 accessor.SetException(kUnableToRemovePropertyException);
270 } 261 }
271 262
272 PP_Var InternalCallDeprecated(ObjectAccessorTryCatch* accessor, 263 PP_Var InternalCallDeprecated(ObjectAccessorTryCatch* accessor,
273 PP_Var method_name, 264 PP_Var method_name,
274 uint32_t argc, 265 uint32_t argc,
275 PP_Var* argv, 266 PP_Var* argv,
276 PP_Var* exception) { 267 PP_Var* exception) {
277 NPIdentifier identifier; 268 NPIdentifier identifier;
278 if (method_name.type == PP_VARTYPE_UNDEFINED) { 269 if (method_name.type == PP_VARTYPE_UNDEFINED) {
(...skipping 19 matching lines...) Expand all
298 accessor->SetException(kInvalidValueException); 289 accessor->SetException(kInvalidValueException);
299 return PP_MakeUndefined(); 290 return PP_MakeUndefined();
300 } 291 }
301 } 292 }
302 } 293 }
303 294
304 bool ok; 295 bool ok;
305 296
306 NPVariant result; 297 NPVariant result;
307 if (identifier) { 298 if (identifier) {
308 ok = WebBindings::invoke(NULL, accessor->object()->np_object(), 299 ok = WebBindings::invoke(NULL,
309 identifier, args.get(), argc, &result); 300 accessor->object()->np_object(),
301 identifier,
302 args.get(),
303 argc,
304 &result);
310 } else { 305 } else {
311 ok = WebBindings::invokeDefault(NULL, accessor->object()->np_object(), 306 ok = WebBindings::invokeDefault(
312 args.get(), argc, &result); 307 NULL, accessor->object()->np_object(), args.get(), argc, &result);
313 } 308 }
314 309
315 if (!ok) { 310 if (!ok) {
316 // An exception may have been raised. 311 // An exception may have been raised.
317 accessor->SetException(kUnableToCallMethodException); 312 accessor->SetException(kUnableToCallMethodException);
318 return PP_MakeUndefined(); 313 return PP_MakeUndefined();
319 } 314 }
320 315
321 PP_Var ret = NPVariantToPPVar(accessor->GetPluginInstance(), &result); 316 PP_Var ret = NPVariantToPPVar(accessor->GetPluginInstance(), &result);
322 WebBindings::releaseVariantValue(&result); 317 WebBindings::releaseVariantValue(&result);
323 return ret; 318 return ret;
324 } 319 }
325 320
326 PP_Var CallDeprecated(PP_Var var, 321 PP_Var CallDeprecated(PP_Var var,
327 PP_Var method_name, 322 PP_Var method_name,
328 uint32_t argc, 323 uint32_t argc,
329 PP_Var* argv, 324 PP_Var* argv,
330 PP_Var* exception) { 325 PP_Var* exception) {
331 ObjectAccessorTryCatch accessor(var, exception); 326 ObjectAccessorTryCatch accessor(var, exception);
332 if (accessor.has_exception()) 327 if (accessor.has_exception())
333 return PP_MakeUndefined(); 328 return PP_MakeUndefined();
334 PepperPluginInstanceImpl* plugin = accessor.GetPluginInstance(); 329 PepperPluginInstanceImpl* plugin = accessor.GetPluginInstance();
335 if (plugin && plugin->IsProcessingUserGesture()) { 330 if (plugin && plugin->IsProcessingUserGesture()) {
336 blink::WebScopedUserGesture user_gesture( 331 blink::WebScopedUserGesture user_gesture(plugin->CurrentUserGestureToken());
337 plugin->CurrentUserGestureToken()); 332 return InternalCallDeprecated(
338 return InternalCallDeprecated(&accessor, method_name, argc, argv, 333 &accessor, method_name, argc, argv, exception);
339 exception);
340 } 334 }
341 return InternalCallDeprecated(&accessor, method_name, argc, argv, exception); 335 return InternalCallDeprecated(&accessor, method_name, argc, argv, exception);
342 } 336 }
343 337
344 PP_Var Construct(PP_Var var, 338 PP_Var Construct(PP_Var var, uint32_t argc, PP_Var* argv, PP_Var* exception) {
345 uint32_t argc,
346 PP_Var* argv,
347 PP_Var* exception) {
348 ObjectAccessorTryCatch accessor(var, exception); 339 ObjectAccessorTryCatch accessor(var, exception);
349 if (accessor.has_exception()) 340 if (accessor.has_exception())
350 return PP_MakeUndefined(); 341 return PP_MakeUndefined();
351 342
352 scoped_ptr<NPVariant[]> args; 343 scoped_ptr<NPVariant[]> args;
353 if (argc) { 344 if (argc) {
354 args.reset(new NPVariant[argc]); 345 args.reset(new NPVariant[argc]);
355 for (uint32_t i = 0; i < argc; ++i) { 346 for (uint32_t i = 0; i < argc; ++i) {
356 if (!PPVarToNPVariantNoCopy(argv[i], &args[i])) { 347 if (!PPVarToNPVariantNoCopy(argv[i], &args[i])) {
357 // This argument was invalid, throw an exception & give up. 348 // This argument was invalid, throw an exception & give up.
358 accessor.SetException(kInvalidValueException); 349 accessor.SetException(kInvalidValueException);
359 return PP_MakeUndefined(); 350 return PP_MakeUndefined();
360 } 351 }
361 } 352 }
362 } 353 }
363 354
364 NPVariant result; 355 NPVariant result;
365 if (!WebBindings::construct(NULL, accessor.object()->np_object(), 356 if (!WebBindings::construct(
366 args.get(), argc, &result)) { 357 NULL, accessor.object()->np_object(), args.get(), argc, &result)) {
367 // An exception may have been raised. 358 // An exception may have been raised.
368 accessor.SetException(kUnableToConstructException); 359 accessor.SetException(kUnableToConstructException);
369 return PP_MakeUndefined(); 360 return PP_MakeUndefined();
370 } 361 }
371 362
372 PP_Var ret = NPVariantToPPVar(accessor.GetPluginInstance(), &result); 363 PP_Var ret = NPVariantToPPVar(accessor.GetPluginInstance(), &result);
373 WebBindings::releaseVariantValue(&result); 364 WebBindings::releaseVariantValue(&result);
374 return ret; 365 return ret;
375 } 366 }
376 367
377 bool IsInstanceOfDeprecated(PP_Var var, 368 bool IsInstanceOfDeprecated(PP_Var var,
378 const PPP_Class_Deprecated* ppp_class, 369 const PPP_Class_Deprecated* ppp_class,
379 void** ppp_class_data) { 370 void** ppp_class_data) {
380 scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var)); 371 scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var));
381 if (!object.get()) 372 if (!object.get())
382 return false; // Not an object at all. 373 return false; // Not an object at all.
383 374
384 return PluginObject::IsInstanceOf(object->np_object(), 375 return PluginObject::IsInstanceOf(
385 ppp_class, ppp_class_data); 376 object->np_object(), ppp_class, ppp_class_data);
386 } 377 }
387 378
388 PP_Var CreateObjectDeprecated(PP_Instance pp_instance, 379 PP_Var CreateObjectDeprecated(PP_Instance pp_instance,
389 const PPP_Class_Deprecated* ppp_class, 380 const PPP_Class_Deprecated* ppp_class,
390 void* ppp_class_data) { 381 void* ppp_class_data) {
391 PepperPluginInstanceImpl* instance = 382 PepperPluginInstanceImpl* instance =
392 HostGlobals::Get()->GetInstance(pp_instance); 383 HostGlobals::Get()->GetInstance(pp_instance);
393 if (!instance) { 384 if (!instance) {
394 DLOG(ERROR) << "Create object passed an invalid instance."; 385 DLOG(ERROR) << "Create object passed an invalid instance.";
395 return PP_MakeNull(); 386 return PP_MakeNull();
396 } 387 }
397 return PluginObject::Create(instance, ppp_class, ppp_class_data); 388 return PluginObject::Create(instance, ppp_class, ppp_class_data);
398 } 389 }
399 390
400 PP_Var CreateObjectWithModuleDeprecated(PP_Module pp_module, 391 PP_Var CreateObjectWithModuleDeprecated(PP_Module pp_module,
401 const PPP_Class_Deprecated* ppp_class, 392 const PPP_Class_Deprecated* ppp_class,
402 void* ppp_class_data) { 393 void* ppp_class_data) {
403 PluginModule* module = HostGlobals::Get()->GetModule(pp_module); 394 PluginModule* module = HostGlobals::Get()->GetModule(pp_module);
404 if (!module) 395 if (!module)
405 return PP_MakeNull(); 396 return PP_MakeNull();
406 return PluginObject::Create(module->GetSomeInstance(), 397 return PluginObject::Create(
407 ppp_class, ppp_class_data); 398 module->GetSomeInstance(), ppp_class, ppp_class_data);
408 } 399 }
409 400
410 } // namespace 401 } // namespace
411 402
412 // static 403 // static
413 const PPB_Var_Deprecated* PPB_Var_Deprecated_Impl::GetVarDeprecatedInterface() { 404 const PPB_Var_Deprecated* PPB_Var_Deprecated_Impl::GetVarDeprecatedInterface() {
414 static const PPB_Var_Deprecated var_deprecated_interface = { 405 static const PPB_Var_Deprecated var_deprecated_interface = {
415 ppapi::PPB_Var_Shared::GetVarInterface1_0()->AddRef, 406 ppapi::PPB_Var_Shared::GetVarInterface1_0()->AddRef,
416 ppapi::PPB_Var_Shared::GetVarInterface1_0()->Release, 407 ppapi::PPB_Var_Shared::GetVarInterface1_0()->Release,
417 ppapi::PPB_Var_Shared::GetVarInterface1_0()->VarFromUtf8, 408 ppapi::PPB_Var_Shared::GetVarInterface1_0()->VarFromUtf8,
418 ppapi::PPB_Var_Shared::GetVarInterface1_0()->VarToUtf8, 409 ppapi::PPB_Var_Shared::GetVarInterface1_0()->VarToUtf8,
419 &HasPropertyDeprecated, 410 &HasPropertyDeprecated,
420 &HasMethodDeprecated, 411 &HasMethodDeprecated,
421 &GetProperty, 412 &GetProperty,
422 &EnumerateProperties, 413 &EnumerateProperties,
423 &SetPropertyDeprecated, 414 &SetPropertyDeprecated,
424 &DeletePropertyDeprecated, 415 &DeletePropertyDeprecated,
425 &CallDeprecated, 416 &CallDeprecated,
426 &Construct, 417 &Construct,
427 &IsInstanceOfDeprecated, 418 &IsInstanceOfDeprecated,
428 &CreateObjectDeprecated, 419 &CreateObjectDeprecated,
429 &CreateObjectWithModuleDeprecated, 420 &CreateObjectWithModuleDeprecated, };
bbudge 2014/04/07 17:02:17 I guess initializers don't end with the closing br
430 };
431 421
432 return &var_deprecated_interface; 422 return &var_deprecated_interface;
433 } 423 }
434 424
435 } // namespace content 425 } // namespace content
436
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698