| 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 21 matching lines...) Expand all Loading... |
| 32 #define min min | 32 #define min min |
| 33 #include <v8.h> | 33 #include <v8.h> |
| 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 "V8GCController.h" |
| 42 #include "V8Helpers.h" | 43 #include "V8Helpers.h" |
| 43 #include "V8NPUtils.h" | 44 #include "V8NPUtils.h" |
| 44 #include "V8Proxy.h" | 45 #include "V8Proxy.h" |
| 45 #include "DOMWindow.h" | 46 #include "DOMWindow.h" |
| 46 | 47 |
| 47 using WebCore::toV8Context; | 48 using WebCore::toV8Context; |
| 48 using WebCore::toV8Proxy; | 49 using WebCore::toV8Proxy; |
| 49 using WebCore::V8ClassIndex; | 50 using WebCore::V8ClassIndex; |
| 50 using WebCore::V8Custom; | 51 using WebCore::V8Custom; |
| 51 using WebCore::V8Proxy; | 52 using WebCore::V8Proxy; |
| 52 | 53 |
| 53 // FIXME(mbelshe): comments on why use malloc and free. | 54 // FIXME(mbelshe): comments on why use malloc and free. |
| 54 static NPObject* AllocV8NPObject(NPP, NPClass*) | 55 static NPObject* AllocV8NPObject(NPP, NPClass*) |
| 55 { | 56 { |
| 56 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); | 57 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); |
| 57 } | 58 } |
| 58 | 59 |
| 59 static void FreeV8NPObject(NPObject* npobj) | 60 static void FreeV8NPObject(NPObject* npobj) |
| 60 { | 61 { |
| 61 V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj); | 62 V8NPObject *object = reinterpret_cast<V8NPObject*>(npobj); |
| 62 #ifndef NDEBUG | 63 #ifndef NDEBUG |
| 63 V8Proxy::unregisterGlobalHandle(object, object->v8Object); | 64 V8GCController::unregisterGlobalHandle(object, object->v8Object); |
| 64 #endif | 65 #endif |
| 65 object->v8Object.Dispose(); | 66 object->v8Object.Dispose(); |
| 66 free(object); | 67 free(object); |
| 67 } | 68 } |
| 68 | 69 |
| 69 static v8::Handle<v8::Value>* listFromVariantArgs(const NPVariant* args, | 70 static v8::Handle<v8::Value>* listFromVariantArgs(const NPVariant* args, |
| 70 uint32_t argCount, | 71 uint32_t argCount, |
| 71 NPObject *owner) | 72 NPObject *owner) |
| 72 { | 73 { |
| 73 v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[argCount]; | 74 v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[argCount]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 object->GetInternalField(V8Custom::kDOMWrapperTypeIndex)->Uint32Value()
== V8ClassIndex::NPOBJECT) { | 107 object->GetInternalField(V8Custom::kDOMWrapperTypeIndex)->Uint32Value()
== V8ClassIndex::NPOBJECT) { |
| 107 | 108 |
| 108 NPObject* rv = V8Proxy::convertToNativeObject<NPObject>(V8ClassIndex::NP
OBJECT, object); | 109 NPObject* rv = V8Proxy::convertToNativeObject<NPObject>(V8ClassIndex::NP
OBJECT, object); |
| 109 NPN_RetainObject(rv); | 110 NPN_RetainObject(rv); |
| 110 return rv; | 111 return rv; |
| 111 } | 112 } |
| 112 | 113 |
| 113 V8NPObject* obj = reinterpret_cast<V8NPObject*>(NPN_CreateObject(npp, &V8NPO
bjectClass)); | 114 V8NPObject* obj = reinterpret_cast<V8NPObject*>(NPN_CreateObject(npp, &V8NPO
bjectClass)); |
| 114 obj->v8Object = v8::Persistent<v8::Object>::New(object); | 115 obj->v8Object = v8::Persistent<v8::Object>::New(object); |
| 115 #ifndef NDEBUG | 116 #ifndef NDEBUG |
| 116 V8Proxy::registerGlobalHandle(WebCore::NPOBJECT, obj, obj->v8Object); | 117 V8GCController::registerGlobalHandle(WebCore::NPOBJECT, obj, obj->v8Object); |
| 117 #endif | 118 #endif |
| 118 obj->rootObject = root; | 119 obj->rootObject = root; |
| 119 return reinterpret_cast<NPObject*>(obj); | 120 return reinterpret_cast<NPObject*>(obj); |
| 120 } | 121 } |
| 121 | 122 |
| 122 bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, | 123 bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, |
| 123 const NPVariant *args, uint32_t argCount, NPVariant *result) | 124 const NPVariant *args, uint32_t argCount, NPVariant *result) |
| 124 { | 125 { |
| 125 if (!npobj) | 126 if (!npobj) |
| 126 return false; | 127 return false; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 // Convert the result back to an NPVariant. | 519 // Convert the result back to an NPVariant. |
| 519 convertV8ObjectToNPVariant(resultObj, npobj, result); | 520 convertV8ObjectToNPVariant(resultObj, npobj, result); |
| 520 return true; | 521 return true; |
| 521 } | 522 } |
| 522 | 523 |
| 523 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npobj->_class) && npobj->_class->constr
uct) | 524 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npobj->_class) && npobj->_class->constr
uct) |
| 524 return npobj->_class->construct(npobj, args, argCount, result); | 525 return npobj->_class->construct(npobj, args, argCount, result); |
| 525 | 526 |
| 526 return false; | 527 return false; |
| 527 } | 528 } |
| OLD | NEW |