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-2009 Google, Inc. All rights reserved. | 3 * Copyright (C) 2007-2009 Google, Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "NPV8Object.h" | 34 #include "NPV8Object.h" |
35 #include "ChromiumBridge.h" | 35 #include "ChromiumBridge.h" |
36 #include "Frame.h" | 36 #include "Frame.h" |
37 #include "bindings/npruntime.h" | 37 #include "bindings/npruntime.h" |
38 #include "npruntime_priv.h" | 38 #include "npruntime_priv.h" |
39 #include "PlatformString.h" | 39 #include "PlatformString.h" |
40 #include "ScriptController.h" | 40 #include "ScriptController.h" |
41 #include "V8CustomBinding.h" | 41 #include "V8CustomBinding.h" |
42 #include "V8Helpers.h" | 42 #include "V8Helpers.h" |
43 #include "V8NPUtils.h" | 43 #include "V8NPUtils.h" |
44 #include "v8_proxy.h" | 44 #include "V8Proxy.h" |
45 #include "DOMWindow.h" | 45 #include "DOMWindow.h" |
46 | 46 |
47 using WebCore::toV8Context; | 47 using WebCore::toV8Context; |
48 using WebCore::toV8Proxy; | 48 using WebCore::toV8Proxy; |
49 using WebCore::V8ClassIndex; | 49 using WebCore::V8ClassIndex; |
50 using WebCore::V8Custom; | 50 using WebCore::V8Custom; |
51 using WebCore::V8Proxy; | 51 using WebCore::V8Proxy; |
52 | 52 |
53 // FIXME(mbelshe): comments on why use malloc and free. | 53 // FIXME(mbelshe): comments on why use malloc and free. |
54 static NPObject* AllocV8NPObject(NPP, NPClass*) | 54 static NPObject* AllocV8NPObject(NPP, NPClass*) |
55 { | 55 { |
56 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); | 56 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); |
57 } | 57 } |
58 | 58 |
59 static void FreeV8NPObject(NPObject* npobj) | 59 static void FreeV8NPObject(NPObject* npobj) |
60 { | 60 { |
61 V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj); | 61 V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj); |
62 #ifndef NDEBUG | 62 #ifndef NDEBUG |
63 V8Proxy::UnregisterGlobalHandle(object, object->v8Object); | 63 V8Proxy::unregisterGlobalHandle(object, object->v8Object); |
64 #endif | 64 #endif |
65 object->v8Object.Dispose(); | 65 object->v8Object.Dispose(); |
66 free(object); | 66 free(object); |
67 } | 67 } |
68 | 68 |
69 static v8::Handle<v8::Value>* listFromVariantArgs(const NPVariant* args, | 69 static v8::Handle<v8::Value>* listFromVariantArgs(const NPVariant* args, |
70 uint32_t argCount, | 70 uint32_t argCount, |
71 NPObject *owner) | 71 NPObject *owner) |
72 { | 72 { |
73 v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[argCount]; | 73 v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[argCount]; |
(...skipping 24 matching lines...) Expand all Loading... |
98 // NPAPI's npruntime functions | 98 // NPAPI's npruntime functions |
99 NPClass* npScriptObjectClass = &V8NPObjectClass; | 99 NPClass* npScriptObjectClass = &V8NPObjectClass; |
100 | 100 |
101 NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, WebCore
::DOMWindow* root) | 101 NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, WebCore
::DOMWindow* root) |
102 { | 102 { |
103 // Check to see if this object is already wrapped. | 103 // Check to see if this object is already wrapped. |
104 if (object->InternalFieldCount() == V8Custom::kNPObjectInternalFieldCount && | 104 if (object->InternalFieldCount() == V8Custom::kNPObjectInternalFieldCount && |
105 object->GetInternalField(V8Custom::kDOMWrapperTypeIndex)->IsNumber() && | 105 object->GetInternalField(V8Custom::kDOMWrapperTypeIndex)->IsNumber() && |
106 object->GetInternalField(V8Custom::kDOMWrapperTypeIndex)->Uint32Value()
== V8ClassIndex::NPOBJECT) { | 106 object->GetInternalField(V8Custom::kDOMWrapperTypeIndex)->Uint32Value()
== V8ClassIndex::NPOBJECT) { |
107 | 107 |
108 NPObject* rv = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT,
object); | 108 NPObject* rv = V8Proxy::convertToNativeObject<NPObject>(V8ClassIndex::NP
OBJECT, object); |
109 NPN_RetainObject(rv); | 109 NPN_RetainObject(rv); |
110 return rv; | 110 return rv; |
111 } | 111 } |
112 | 112 |
113 V8NPObject* obj = reinterpret_cast<V8NPObject*>(NPN_CreateObject(npp, &V8NPO
bjectClass)); | 113 V8NPObject* obj = reinterpret_cast<V8NPObject*>(NPN_CreateObject(npp, &V8NPO
bjectClass)); |
114 obj->v8Object = v8::Persistent<v8::Object>::New(object); | 114 obj->v8Object = v8::Persistent<v8::Object>::New(object); |
115 #ifndef NDEBUG | 115 #ifndef NDEBUG |
116 V8Proxy::RegisterGlobalHandle(WebCore::NPOBJECT, obj, obj->v8Object); | 116 V8Proxy::registerGlobalHandle(WebCore::NPOBJECT, obj, obj->v8Object); |
117 #endif | 117 #endif |
118 obj->rootObject = root; | 118 obj->rootObject = root; |
119 return reinterpret_cast<NPObject*>(obj); | 119 return reinterpret_cast<NPObject*>(obj); |
120 } | 120 } |
121 | 121 |
122 bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, | 122 bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, |
123 const NPVariant *args, uint32_t argCount, NPVariant *result) | 123 const NPVariant *args, uint32_t argCount, NPVariant *result) |
124 { | 124 { |
125 if (!npobj) | 125 if (!npobj) |
126 return false; | 126 return false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 V8Proxy* proxy = toV8Proxy(npobj); | 162 V8Proxy* proxy = toV8Proxy(npobj); |
163 ASSERT(proxy); // must not be null | 163 ASSERT(proxy); // must not be null |
164 | 164 |
165 // FIXME: fix variable naming | 165 // FIXME: fix variable naming |
166 // Call the function object | 166 // Call the function object |
167 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(funcObj); | 167 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(funcObj); |
168 // Create list of args to pass to v8 | 168 // Create list of args to pass to v8 |
169 v8::Handle<v8::Value>* argv = listFromVariantArgs(args, argCount, npobj)
; | 169 v8::Handle<v8::Value>* argv = listFromVariantArgs(args, argCount, npobj)
; |
170 v8::Local<v8::Value> resultObj = proxy->CallFunction(func, object->v8Obj
ect, argCount, argv); | 170 v8::Local<v8::Value> resultObj = proxy->callFunction(func, object->v8Obj
ect, argCount, argv); |
171 delete[] argv; | 171 delete[] argv; |
172 | 172 |
173 // If we had an error, return false. The spec is a little unclear here,
but | 173 // If we had an error, return false. The spec is a little unclear here,
but |
174 // says "Returns true if the method was successfully invoked". If we ge
t an | 174 // says "Returns true if the method was successfully invoked". If we ge
t an |
175 // error return value, was that successfully invoked? | 175 // error return value, was that successfully invoked? |
176 if (resultObj.IsEmpty()) | 176 if (resultObj.IsEmpty()) |
177 return false; | 177 return false; |
178 | 178 |
179 // Convert the result back to an NPVariant | 179 // Convert the result back to an NPVariant |
180 convertV8ObjectToNPVariant(resultObj, npobj, result); | 180 convertV8ObjectToNPVariant(resultObj, npobj, result); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 214 |
215 // Call the function object | 215 // Call the function object |
216 v8::Local<v8::Value> resultObj; | 216 v8::Local<v8::Value> resultObj; |
217 v8::Handle<v8::Function> func(v8::Function::Cast(*funcObj)); | 217 v8::Handle<v8::Function> func(v8::Function::Cast(*funcObj)); |
218 if (!func->IsNull()) { | 218 if (!func->IsNull()) { |
219 V8Proxy* proxy = toV8Proxy(npobj); | 219 V8Proxy* proxy = toV8Proxy(npobj); |
220 ASSERT(proxy); | 220 ASSERT(proxy); |
221 | 221 |
222 // Create list of args to pass to v8 | 222 // Create list of args to pass to v8 |
223 v8::Handle<v8::Value>* argv = listFromVariantArgs(args, argCount, np
obj); | 223 v8::Handle<v8::Value>* argv = listFromVariantArgs(args, argCount, np
obj); |
224 resultObj = proxy->CallFunction(func, funcObj, argCount, argv); | 224 resultObj = proxy->callFunction(func, funcObj, argCount, argv); |
225 delete[] argv; | 225 delete[] argv; |
226 } | 226 } |
227 | 227 |
228 // If we had an error, return false. The spec is a little unclear here,
but | 228 // If we had an error, return false. The spec is a little unclear here,
but |
229 // says "Returns true if the method was successfully invoked". If we ge
t an | 229 // says "Returns true if the method was successfully invoked". If we ge
t an |
230 // error return value, was that successfully invoked? | 230 // error return value, was that successfully invoked? |
231 if (resultObj.IsEmpty()) | 231 if (resultObj.IsEmpty()) |
232 return false; | 232 return false; |
233 | 233 |
234 // Convert the result back to an NPVariant. | 234 // Convert the result back to an NPVariant. |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 void NPN_SetException(NPObject *npobj, const NPUTF8 *message) | 413 void NPN_SetException(NPObject *npobj, const NPUTF8 *message) |
414 { | 414 { |
415 if (npobj->_class != npScriptObjectClass) | 415 if (npobj->_class != npScriptObjectClass) |
416 return; | 416 return; |
417 v8::HandleScope handleScope; | 417 v8::HandleScope handleScope; |
418 v8::Handle<v8::Context> context = toV8Context(0, npobj); | 418 v8::Handle<v8::Context> context = toV8Context(0, npobj); |
419 if (context.IsEmpty()) | 419 if (context.IsEmpty()) |
420 return; | 420 return; |
421 | 421 |
422 v8::Context::Scope scope(context); | 422 v8::Context::Scope scope(context); |
423 V8Proxy::ThrowError(V8Proxy::GENERAL_ERROR, message); | 423 V8Proxy::throwError(V8Proxy::GeneralError, message); |
424 } | 424 } |
425 | 425 |
426 bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t
*count) | 426 bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t
*count) |
427 { | 427 { |
428 if (!npobj) | 428 if (!npobj) |
429 return false; | 429 return false; |
430 | 430 |
431 if (npobj->_class == npScriptObjectClass) { | 431 if (npobj->_class == npScriptObjectClass) { |
432 V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj); | 432 V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj); |
433 | 433 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 500 |
501 // Call the constructor. | 501 // Call the constructor. |
502 v8::Local<v8::Value> resultObj; | 502 v8::Local<v8::Value> resultObj; |
503 v8::Handle<v8::Function> ctor(v8::Function::Cast(*ctorObj)); | 503 v8::Handle<v8::Function> ctor(v8::Function::Cast(*ctorObj)); |
504 if (!ctor->IsNull()) { | 504 if (!ctor->IsNull()) { |
505 V8Proxy* proxy = toV8Proxy(npobj); | 505 V8Proxy* proxy = toV8Proxy(npobj); |
506 ASSERT(proxy); | 506 ASSERT(proxy); |
507 | 507 |
508 // Create list of args to pass to v8. | 508 // Create list of args to pass to v8. |
509 v8::Handle<v8::Value>* argv = listFromVariantArgs(args, argCount, np
obj); | 509 v8::Handle<v8::Value>* argv = listFromVariantArgs(args, argCount, np
obj); |
510 resultObj = proxy->NewInstance(ctor, argCount, argv); | 510 resultObj = proxy->newInstance(ctor, argCount, argv); |
511 delete[] argv; | 511 delete[] argv; |
512 } | 512 } |
513 | 513 |
514 // If we had an error return false. | 514 // If we had an error return false. |
515 if (resultObj.IsEmpty()) | 515 if (resultObj.IsEmpty()) |
516 return false; | 516 return false; |
517 | 517 |
518 // Convert the result back to an NPVariant. | 518 // Convert the result back to an NPVariant. |
519 convertV8ObjectToNPVariant(resultObj, npobj, result); | 519 convertV8ObjectToNPVariant(resultObj, npobj, result); |
520 return true; | 520 return true; |
521 } | 521 } |
522 | 522 |
523 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npobj->_class) && npobj->_class->constr
uct) | 523 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npobj->_class) && npobj->_class->constr
uct) |
524 return npobj->_class->construct(npobj, args, argCount, result); | 524 return npobj->_class->construct(npobj, args, argCount, result); |
525 | 525 |
526 return false; | 526 return false; |
527 } | 527 } |
OLD | NEW |