OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) 2007, 2008, 2009 Google, Inc. All rights reserved. | 3 * Copyright (C) 2007, 2008, 2009 Google, Inc. All rights reserved. |
4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. | 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 v8::HandleScope handleScope(isolate); | 94 v8::HandleScope handleScope(isolate); |
95 v8::Handle<v8::Context> context = toV8Context(object->rootObject->frame(), D
OMWrapperWorld::mainWorld()); | 95 v8::Handle<v8::Context> context = toV8Context(object->rootObject->frame(), D
OMWrapperWorld::mainWorld()); |
96 return ScriptState::from(context); | 96 return ScriptState::from(context); |
97 } | 97 } |
98 | 98 |
99 static PassOwnPtr<v8::Handle<v8::Value>[]> createValueListFromVariantArgs(const
NPVariant* arguments, uint32_t argumentCount, NPObject* owner, v8::Isolate* isol
ate) | 99 static PassOwnPtr<v8::Handle<v8::Value>[]> createValueListFromVariantArgs(const
NPVariant* arguments, uint32_t argumentCount, NPObject* owner, v8::Isolate* isol
ate) |
100 { | 100 { |
101 OwnPtr<v8::Handle<v8::Value>[]> argv = adoptArrayPtr(new v8::Handle<v8::Valu
e>[argumentCount]); | 101 OwnPtr<v8::Handle<v8::Value>[]> argv = adoptArrayPtr(new v8::Handle<v8::Valu
e>[argumentCount]); |
102 for (uint32_t index = 0; index < argumentCount; index++) { | 102 for (uint32_t index = 0; index < argumentCount; index++) { |
103 const NPVariant* arg = &arguments[index]; | 103 const NPVariant* arg = &arguments[index]; |
104 argv[index] = convertNPVariantToV8Object(arg, owner, isolate); | 104 argv[index] = convertNPVariantToV8Object(isolate, arg, owner); |
105 } | 105 } |
106 return argv.release(); | 106 return argv.release(); |
107 } | 107 } |
108 | 108 |
109 // Create an identifier (null terminated utf8 char*) from the NPIdentifier. | 109 // Create an identifier (null terminated utf8 char*) from the NPIdentifier. |
110 static v8::Local<v8::String> npIdentifierToV8Identifier(NPIdentifier name, v8::I
solate* isolate) | 110 static v8::Local<v8::String> npIdentifierToV8Identifier(v8::Isolate* isolate, NP
Identifier name) |
111 { | 111 { |
112 PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(name); | 112 PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(name); |
113 if (identifier->isString) | 113 if (identifier->isString) |
114 return v8AtomicString(isolate, static_cast<const char*>(identifier->valu
e.string)); | 114 return v8AtomicString(isolate, static_cast<const char*>(identifier->valu
e.string)); |
115 | 115 |
116 char buffer[32]; | 116 char buffer[32]; |
117 snprintf(buffer, sizeof(buffer), "%d", identifier->value.number); | 117 snprintf(buffer, sizeof(buffer), "%d", identifier->value.number); |
118 return v8AtomicString(isolate, buffer); | 118 return v8AtomicString(isolate, buffer); |
119 } | 119 } |
120 | 120 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // Call the function object. | 275 // Call the function object. |
276 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(functionO
bject); | 276 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(functionO
bject); |
277 OwnPtr<v8::Handle<v8::Value>[]> argv = createValueListFromVariantArgs(argume
nts, argumentCount, npObject, isolate); | 277 OwnPtr<v8::Handle<v8::Value>[]> argv = createValueListFromVariantArgs(argume
nts, argumentCount, npObject, isolate); |
278 v8::Local<v8::Value> resultObject = frame->script().callFunction(function, v
8Object, argumentCount, argv.get()); | 278 v8::Local<v8::Value> resultObject = frame->script().callFunction(function, v
8Object, argumentCount, argv.get()); |
279 | 279 |
280 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was | 280 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was |
281 // successfully invoked". If we get an error return value, was that success
fully invoked? | 281 // successfully invoked". If we get an error return value, was that success
fully invoked? |
282 if (resultObject.IsEmpty()) | 282 if (resultObject.IsEmpty()) |
283 return false; | 283 return false; |
284 | 284 |
285 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate); | 285 convertV8ObjectToNPVariant(isolate, resultObject, npObject, result); |
286 return true; | 286 return true; |
287 } | 287 } |
288 | 288 |
289 // FIXME: Fix it same as _NPN_Invoke (HandleScope and such). | 289 // FIXME: Fix it same as _NPN_Invoke (HandleScope and such). |
290 bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments,
uint32_t argumentCount, NPVariant* result) | 290 bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments,
uint32_t argumentCount, NPVariant* result) |
291 { | 291 { |
292 if (!npObject) | 292 if (!npObject) |
293 return false; | 293 return false; |
294 | 294 |
295 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 295 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
(...skipping 28 matching lines...) Expand all Loading... |
324 ASSERT(frame); | 324 ASSERT(frame); |
325 | 325 |
326 OwnPtr<v8::Handle<v8::Value>[]> argv = createValueListFromVariantArgs(ar
guments, argumentCount, npObject, isolate); | 326 OwnPtr<v8::Handle<v8::Value>[]> argv = createValueListFromVariantArgs(ar
guments, argumentCount, npObject, isolate); |
327 resultObject = frame->script().callFunction(function, functionObject, ar
gumentCount, argv.get()); | 327 resultObject = frame->script().callFunction(function, functionObject, ar
gumentCount, argv.get()); |
328 } | 328 } |
329 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was | 329 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was |
330 // successfully invoked". If we get an error return value, was that success
fully invoked? | 330 // successfully invoked". If we get an error return value, was that success
fully invoked? |
331 if (resultObject.IsEmpty()) | 331 if (resultObject.IsEmpty()) |
332 return false; | 332 return false; |
333 | 333 |
334 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate); | 334 convertV8ObjectToNPVariant(isolate, resultObject, npObject, result); |
335 return true; | 335 return true; |
336 } | 336 } |
337 | 337 |
338 bool _NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* r
esult) | 338 bool _NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* r
esult) |
339 { | 339 { |
340 // FIXME: Give the embedder a way to control this. | 340 // FIXME: Give the embedder a way to control this. |
341 bool popupsAllowed = false; | 341 bool popupsAllowed = false; |
342 return _NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result); | 342 return _NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result); |
343 } | 343 } |
344 | 344 |
(...skipping 25 matching lines...) Expand all Loading... |
370 | 370 |
371 String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Len
gth); | 371 String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Len
gth); |
372 | 372 |
373 UserGestureIndicator gestureIndicator(popupsAllowed ? DefinitelyProcessingNe
wUserGesture : PossiblyProcessingUserGesture); | 373 UserGestureIndicator gestureIndicator(popupsAllowed ? DefinitelyProcessingNe
wUserGesture : PossiblyProcessingUserGesture); |
374 v8::Local<v8::Value> v8result = frame->script().executeScriptAndReturnValue(
scriptState->context(), ScriptSourceCode(script, KURL(ParsedURLString, filename)
)); | 374 v8::Local<v8::Value> v8result = frame->script().executeScriptAndReturnValue(
scriptState->context(), ScriptSourceCode(script, KURL(ParsedURLString, filename)
)); |
375 | 375 |
376 if (v8result.IsEmpty()) | 376 if (v8result.IsEmpty()) |
377 return false; | 377 return false; |
378 | 378 |
379 if (_NPN_IsAlive(npObject)) | 379 if (_NPN_IsAlive(npObject)) |
380 convertV8ObjectToNPVariant(v8result, npObject, result, isolate); | 380 convertV8ObjectToNPVariant(isolate, v8result, npObject, result); |
381 return true; | 381 return true; |
382 } | 382 } |
383 | 383 |
384 bool _NPN_GetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, NP
Variant* result) | 384 bool _NPN_GetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, NP
Variant* result) |
385 { | 385 { |
386 if (!npObject) | 386 if (!npObject) |
387 return false; | 387 return false; |
388 | 388 |
389 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { | 389 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { |
390 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 390 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
391 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); | 391 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); |
392 if (!scriptState) | 392 if (!scriptState) |
393 return false; | 393 return false; |
394 | 394 |
395 ScriptState::Scope scope(scriptState); | 395 ScriptState::Scope scope(scriptState); |
396 ExceptionCatcher exceptionCatcher; | 396 ExceptionCatcher exceptionCatcher; |
397 | 397 |
398 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); | 398 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); |
399 v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(prop
ertyName, isolate)); | 399 v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(isol
ate, propertyName)); |
400 | 400 |
401 if (v8result.IsEmpty()) | 401 if (v8result.IsEmpty()) |
402 return false; | 402 return false; |
403 | 403 |
404 convertV8ObjectToNPVariant(v8result, npObject, result, isolate); | 404 convertV8ObjectToNPVariant(isolate, v8result, npObject, result); |
405 return true; | 405 return true; |
406 } | 406 } |
407 | 407 |
408 if (npObject->_class->hasProperty && npObject->_class->getProperty) { | 408 if (npObject->_class->hasProperty && npObject->_class->getProperty) { |
409 if (npObject->_class->hasProperty(npObject, propertyName)) | 409 if (npObject->_class->hasProperty(npObject, propertyName)) |
410 return npObject->_class->getProperty(npObject, propertyName, result)
; | 410 return npObject->_class->getProperty(npObject, propertyName, result)
; |
411 } | 411 } |
412 | 412 |
413 VOID_TO_NPVARIANT(*result); | 413 VOID_TO_NPVARIANT(*result); |
414 return false; | 414 return false; |
415 } | 415 } |
416 | 416 |
417 bool _NPN_SetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, co
nst NPVariant* value) | 417 bool _NPN_SetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, co
nst NPVariant* value) |
418 { | 418 { |
419 if (!npObject) | 419 if (!npObject) |
420 return false; | 420 return false; |
421 | 421 |
422 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { | 422 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { |
423 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 423 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
424 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); | 424 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); |
425 if (!scriptState) | 425 if (!scriptState) |
426 return false; | 426 return false; |
427 | 427 |
428 ScriptState::Scope scope(scriptState); | 428 ScriptState::Scope scope(scriptState); |
429 ExceptionCatcher exceptionCatcher; | 429 ExceptionCatcher exceptionCatcher; |
430 | 430 |
431 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); | 431 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); |
432 obj->Set(npIdentifierToV8Identifier(propertyName, isolate), convertNPVar
iantToV8Object(value, object->rootObject->frame()->script().windowScriptNPObject
(), isolate)); | 432 obj->Set(npIdentifierToV8Identifier(isolate, propertyName), convertNPVar
iantToV8Object(isolate, value, object->rootObject->frame()->script().windowScrip
tNPObject())); |
433 return true; | 433 return true; |
434 } | 434 } |
435 | 435 |
436 if (npObject->_class->setProperty) | 436 if (npObject->_class->setProperty) |
437 return npObject->_class->setProperty(npObject, propertyName, value); | 437 return npObject->_class->setProperty(npObject, propertyName, value); |
438 | 438 |
439 return false; | 439 return false; |
440 } | 440 } |
441 | 441 |
442 bool _NPN_RemoveProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) | 442 bool _NPN_RemoveProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) |
443 { | 443 { |
444 if (!npObject) | 444 if (!npObject) |
445 return false; | 445 return false; |
446 | 446 |
447 V8NPObject* object = npObjectToV8NPObject(npObject); | 447 V8NPObject* object = npObjectToV8NPObject(npObject); |
448 if (!object) | 448 if (!object) |
449 return false; | 449 return false; |
450 | 450 |
451 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 451 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
452 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); | 452 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); |
453 if (!scriptState) | 453 if (!scriptState) |
454 return false; | 454 return false; |
455 ScriptState::Scope scope(scriptState); | 455 ScriptState::Scope scope(scriptState); |
456 ExceptionCatcher exceptionCatcher; | 456 ExceptionCatcher exceptionCatcher; |
457 | 457 |
458 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object->v8O
bject); | 458 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object->v8O
bject); |
459 // FIXME: Verify that setting to undefined is right. | 459 // FIXME: Verify that setting to undefined is right. |
460 obj->Set(npIdentifierToV8Identifier(propertyName, isolate), v8::Undefined(is
olate)); | 460 obj->Set(npIdentifierToV8Identifier(isolate, propertyName), v8::Undefined(is
olate)); |
461 return true; | 461 return true; |
462 } | 462 } |
463 | 463 |
464 bool _NPN_HasProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) | 464 bool _NPN_HasProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) |
465 { | 465 { |
466 if (!npObject) | 466 if (!npObject) |
467 return false; | 467 return false; |
468 | 468 |
469 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { | 469 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { |
470 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 470 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
471 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); | 471 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); |
472 if (!scriptState) | 472 if (!scriptState) |
473 return false; | 473 return false; |
474 ScriptState::Scope scope(scriptState); | 474 ScriptState::Scope scope(scriptState); |
475 ExceptionCatcher exceptionCatcher; | 475 ExceptionCatcher exceptionCatcher; |
476 | 476 |
477 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); | 477 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); |
478 return obj->Has(npIdentifierToV8Identifier(propertyName, isolate)); | 478 return obj->Has(npIdentifierToV8Identifier(isolate, propertyName)); |
479 } | 479 } |
480 | 480 |
481 if (npObject->_class->hasProperty) | 481 if (npObject->_class->hasProperty) |
482 return npObject->_class->hasProperty(npObject, propertyName); | 482 return npObject->_class->hasProperty(npObject, propertyName); |
483 return false; | 483 return false; |
484 } | 484 } |
485 | 485 |
486 bool _NPN_HasMethod(NPP npp, NPObject* npObject, NPIdentifier methodName) | 486 bool _NPN_HasMethod(NPP npp, NPObject* npObject, NPIdentifier methodName) |
487 { | 487 { |
488 if (!npObject) | 488 if (!npObject) |
489 return false; | 489 return false; |
490 | 490 |
491 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { | 491 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { |
492 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 492 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
493 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); | 493 ScriptState* scriptState = mainWorldScriptState(isolate, npp, npObject); |
494 if (!scriptState) | 494 if (!scriptState) |
495 return false; | 495 return false; |
496 ScriptState::Scope scope(scriptState); | 496 ScriptState::Scope scope(scriptState); |
497 ExceptionCatcher exceptionCatcher; | 497 ExceptionCatcher exceptionCatcher; |
498 | 498 |
499 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); | 499 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); |
500 v8::Handle<v8::Value> prop = obj->Get(npIdentifierToV8Identifier(methodN
ame, isolate)); | 500 v8::Handle<v8::Value> prop = obj->Get(npIdentifierToV8Identifier(isolate
, methodName)); |
501 return prop->IsFunction(); | 501 return prop->IsFunction(); |
502 } | 502 } |
503 | 503 |
504 if (npObject->_class->hasMethod) | 504 if (npObject->_class->hasMethod) |
505 return npObject->_class->hasMethod(npObject, methodName); | 505 return npObject->_class->hasMethod(npObject, methodName); |
506 return false; | 506 return false; |
507 } | 507 } |
508 | 508 |
509 void _NPN_SetException(NPObject* npObject, const NPUTF8 *message) | 509 void _NPN_SetException(NPObject* npObject, const NPUTF8 *message) |
510 { | 510 { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 if (!ctor->IsNull()) { | 605 if (!ctor->IsNull()) { |
606 LocalFrame* frame = object->rootObject->frame(); | 606 LocalFrame* frame = object->rootObject->frame(); |
607 ASSERT(frame); | 607 ASSERT(frame); |
608 OwnPtr<v8::Handle<v8::Value>[]> argv = createValueListFromVariantArg
s(arguments, argumentCount, npObject, isolate); | 608 OwnPtr<v8::Handle<v8::Value>[]> argv = createValueListFromVariantArg
s(arguments, argumentCount, npObject, isolate); |
609 resultObject = V8ObjectConstructor::newInstanceInDocument(isolate, c
tor, argumentCount, argv.get(), frame ? frame->document() : 0); | 609 resultObject = V8ObjectConstructor::newInstanceInDocument(isolate, c
tor, argumentCount, argv.get(), frame ? frame->document() : 0); |
610 } | 610 } |
611 | 611 |
612 if (resultObject.IsEmpty()) | 612 if (resultObject.IsEmpty()) |
613 return false; | 613 return false; |
614 | 614 |
615 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate); | 615 convertV8ObjectToNPVariant(isolate, resultObject, npObject, result); |
616 return true; | 616 return true; |
617 } | 617 } |
618 | 618 |
619 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->
construct) | 619 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->
construct) |
620 return npObject->_class->construct(npObject, arguments, argumentCount, r
esult); | 620 return npObject->_class->construct(npObject, arguments, argumentCount, r
esult); |
621 | 621 |
622 return false; | 622 return false; |
623 } | 623 } |
OLD | NEW |