| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 union { | 60 union { |
| 61 const char* m_string; | 61 const char* m_string; |
| 62 int m_number; | 62 int m_number; |
| 63 } m_value; | 63 } m_value; |
| 64 bool m_isString; | 64 bool m_isString; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 // FIXME: need comments. | 67 // FIXME: need comments. |
| 68 // Params: holder could be HTMLEmbedElement or NPObject | 68 // Params: holder could be HTMLEmbedElement or NPObject |
| 69 static void npObjectInvokeImpl(const v8::FunctionCallbackInfo<v8::Value>& args,
InvokeFunctionType functionId) | 69 static void npObjectInvokeImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
InvokeFunctionType functionId) |
| 70 { | 70 { |
| 71 NPObject* npObject; | 71 NPObject* npObject; |
| 72 | 72 |
| 73 WrapperWorldType currentWorldType = worldType(args.GetIsolate()); | 73 WrapperWorldType currentWorldType = worldType(info.GetIsolate()); |
| 74 // These three types are subtypes of HTMLPlugInElement. | 74 // These three types are subtypes of HTMLPlugInElement. |
| 75 if (V8HTMLAppletElement::HasInstance(args.Holder(), args.GetIsolate(), curre
ntWorldType) || V8HTMLEmbedElement::HasInstance(args.Holder(), args.GetIsolate()
, currentWorldType) | 75 if (V8HTMLAppletElement::HasInstance(info.Holder(), info.GetIsolate(), curre
ntWorldType) || V8HTMLEmbedElement::HasInstance(info.Holder(), info.GetIsolate()
, currentWorldType) |
| 76 || V8HTMLObjectElement::HasInstance(args.Holder(), args.GetIsolate(), cu
rrentWorldType)) { | 76 || V8HTMLObjectElement::HasInstance(info.Holder(), info.GetIsolate(), cu
rrentWorldType)) { |
| 77 // The holder object is a subtype of HTMLPlugInElement. | 77 // The holder object is a subtype of HTMLPlugInElement. |
| 78 HTMLPlugInElement* element; | 78 HTMLPlugInElement* element; |
| 79 if (V8HTMLAppletElement::HasInstance(args.Holder(), args.GetIsolate(), c
urrentWorldType)) | 79 if (V8HTMLAppletElement::HasInstance(info.Holder(), info.GetIsolate(), c
urrentWorldType)) |
| 80 element = V8HTMLAppletElement::toNative(args.Holder()); | 80 element = V8HTMLAppletElement::toNative(info.Holder()); |
| 81 else if (V8HTMLEmbedElement::HasInstance(args.Holder(), args.GetIsolate(
), currentWorldType)) | 81 else if (V8HTMLEmbedElement::HasInstance(info.Holder(), info.GetIsolate(
), currentWorldType)) |
| 82 element = V8HTMLEmbedElement::toNative(args.Holder()); | 82 element = V8HTMLEmbedElement::toNative(info.Holder()); |
| 83 else | 83 else |
| 84 element = V8HTMLObjectElement::toNative(args.Holder()); | 84 element = V8HTMLObjectElement::toNative(info.Holder()); |
| 85 if (RefPtr<SharedPersistent<v8::Object> > wrapper = element->pluginWrapp
er()) { | 85 if (RefPtr<SharedPersistent<v8::Object> > wrapper = element->pluginWrapp
er()) { |
| 86 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 86 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 87 v8::HandleScope handleScope(isolate); | 87 v8::HandleScope handleScope(isolate); |
| 88 npObject = v8ObjectToNPObject(wrapper->newLocal(isolate)); | 88 npObject = v8ObjectToNPObject(wrapper->newLocal(isolate)); |
| 89 } else | 89 } else |
| 90 npObject = 0; | 90 npObject = 0; |
| 91 } else { | 91 } else { |
| 92 // The holder object is not a subtype of HTMLPlugInElement, it must be a
n NPObject which has three | 92 // The holder object is not a subtype of HTMLPlugInElement, it must be a
n NPObject which has three |
| 93 // internal fields. | 93 // internal fields. |
| 94 if (args.Holder()->InternalFieldCount() != npObjectInternalFieldCount) { | 94 if (info.Holder()->InternalFieldCount() != npObjectInternalFieldCount) { |
| 95 throwError(v8ReferenceError, "NPMethod called on non-NPObject", args
.GetIsolate()); | 95 throwError(v8ReferenceError, "NPMethod called on non-NPObject", info
.GetIsolate()); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 npObject = v8ObjectToNPObject(args.Holder()); | 99 npObject = v8ObjectToNPObject(info.Holder()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Verify that our wrapper wasn't using a NPObject which has already been de
leted. | 102 // Verify that our wrapper wasn't using a NPObject which has already been de
leted. |
| 103 if (!npObject || !_NPN_IsAlive(npObject)) { | 103 if (!npObject || !_NPN_IsAlive(npObject)) { |
| 104 throwError(v8ReferenceError, "NPObject deleted", args.GetIsolate()); | 104 throwError(v8ReferenceError, "NPObject deleted", info.GetIsolate()); |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Wrap up parameters. | 108 // Wrap up parameters. |
| 109 int numArgs = args.Length(); | 109 int numArgs = info.Length(); |
| 110 OwnPtr<NPVariant[]> npArgs = adoptArrayPtr(new NPVariant[numArgs]); | 110 OwnPtr<NPVariant[]> npArgs = adoptArrayPtr(new NPVariant[numArgs]); |
| 111 | 111 |
| 112 for (int i = 0; i < numArgs; i++) | 112 for (int i = 0; i < numArgs; i++) |
| 113 convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i], args.GetIsolat
e()); | 113 convertV8ObjectToNPVariant(info[i], npObject, &npArgs[i], info.GetIsolat
e()); |
| 114 | 114 |
| 115 NPVariant result; | 115 NPVariant result; |
| 116 VOID_TO_NPVARIANT(result); | 116 VOID_TO_NPVARIANT(result); |
| 117 | 117 |
| 118 bool retval = true; | 118 bool retval = true; |
| 119 switch (functionId) { | 119 switch (functionId) { |
| 120 case InvokeMethod: | 120 case InvokeMethod: |
| 121 if (npObject->_class->invoke) { | 121 if (npObject->_class->invoke) { |
| 122 v8::Handle<v8::String> functionName = v8::Handle<v8::String>::Cast(a
rgs.Data()); | 122 v8::Handle<v8::String> functionName = v8::Handle<v8::String>::Cast(i
nfo.Data()); |
| 123 NPIdentifier identifier = getStringIdentifier(functionName); | 123 NPIdentifier identifier = getStringIdentifier(functionName); |
| 124 retval = npObject->_class->invoke(npObject, identifier, npArgs.get()
, numArgs, &result); | 124 retval = npObject->_class->invoke(npObject, identifier, npArgs.get()
, numArgs, &result); |
| 125 } | 125 } |
| 126 break; | 126 break; |
| 127 case InvokeConstruct: | 127 case InvokeConstruct: |
| 128 if (npObject->_class->construct) | 128 if (npObject->_class->construct) |
| 129 retval = npObject->_class->construct(npObject, npArgs.get(), numArgs
, &result); | 129 retval = npObject->_class->construct(npObject, npArgs.get(), numArgs
, &result); |
| 130 break; | 130 break; |
| 131 case InvokeDefault: | 131 case InvokeDefault: |
| 132 if (npObject->_class->invokeDefault) | 132 if (npObject->_class->invokeDefault) |
| 133 retval = npObject->_class->invokeDefault(npObject, npArgs.get(), num
Args, &result); | 133 retval = npObject->_class->invokeDefault(npObject, npArgs.get(), num
Args, &result); |
| 134 break; | 134 break; |
| 135 default: | 135 default: |
| 136 break; | 136 break; |
| 137 } | 137 } |
| 138 | 138 |
| 139 if (!retval) | 139 if (!retval) |
| 140 throwError(v8GeneralError, "Error calling method on NPObject.", args.Get
Isolate()); | 140 throwError(v8GeneralError, "Error calling method on NPObject.", info.Get
Isolate()); |
| 141 | 141 |
| 142 for (int i = 0; i < numArgs; i++) | 142 for (int i = 0; i < numArgs; i++) |
| 143 _NPN_ReleaseVariantValue(&npArgs[i]); | 143 _NPN_ReleaseVariantValue(&npArgs[i]); |
| 144 | 144 |
| 145 // Unwrap return values. | 145 // Unwrap return values. |
| 146 v8::Handle<v8::Value> returnValue; | 146 v8::Handle<v8::Value> returnValue; |
| 147 if (_NPN_IsAlive(npObject)) | 147 if (_NPN_IsAlive(npObject)) |
| 148 returnValue = convertNPVariantToV8Object(&result, npObject, args.GetIsol
ate()); | 148 returnValue = convertNPVariantToV8Object(&result, npObject, info.GetIsol
ate()); |
| 149 _NPN_ReleaseVariantValue(&result); | 149 _NPN_ReleaseVariantValue(&result); |
| 150 | 150 |
| 151 v8SetReturnValue(args, returnValue); | 151 v8SetReturnValue(info, returnValue); |
| 152 } | 152 } |
| 153 | 153 |
| 154 | 154 |
| 155 void npObjectMethodHandler(const v8::FunctionCallbackInfo<v8::Value>& args) | 155 void npObjectMethodHandler(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 156 { | 156 { |
| 157 return npObjectInvokeImpl(args, InvokeMethod); | 157 return npObjectInvokeImpl(info, InvokeMethod); |
| 158 } | 158 } |
| 159 | 159 |
| 160 | 160 |
| 161 void npObjectInvokeDefaultHandler(const v8::FunctionCallbackInfo<v8::Value>& arg
s) | 161 void npObjectInvokeDefaultHandler(const v8::FunctionCallbackInfo<v8::Value>& inf
o) |
| 162 { | 162 { |
| 163 if (args.IsConstructCall()) { | 163 if (info.IsConstructCall()) { |
| 164 npObjectInvokeImpl(args, InvokeConstruct); | 164 npObjectInvokeImpl(info, InvokeConstruct); |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 | 167 |
| 168 npObjectInvokeImpl(args, InvokeDefault); | 168 npObjectInvokeImpl(info, InvokeDefault); |
| 169 } | 169 } |
| 170 | 170 |
| 171 class V8NPTemplateMap { | 171 class V8NPTemplateMap { |
| 172 public: | 172 public: |
| 173 // NPIdentifier is PrivateIdentifier*. | 173 // NPIdentifier is PrivateIdentifier*. |
| 174 typedef HashMap<PrivateIdentifier*, UnsafePersistent<v8::FunctionTemplate> >
MapType; | 174 typedef HashMap<PrivateIdentifier*, UnsafePersistent<v8::FunctionTemplate> >
MapType; |
| 175 | 175 |
| 176 UnsafePersistent<v8::FunctionTemplate> get(PrivateIdentifier* key) | 176 UnsafePersistent<v8::FunctionTemplate> get(PrivateIdentifier* key) |
| 177 { | 177 { |
| 178 return m_map.get(key); | 178 return m_map.get(key); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 v8::HandleScope scope(isolate); | 469 v8::HandleScope scope(isolate); |
| 470 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); | 470 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); |
| 471 if (!wrapper.IsEmpty()) { | 471 if (!wrapper.IsEmpty()) { |
| 472 V8DOMWrapper::clearNativeInfo(wrapper, npObjectTypeInfo()); | 472 V8DOMWrapper::clearNativeInfo(wrapper, npObjectTypeInfo()); |
| 473 staticNPObjectMap().removeAndDispose(object); | 473 staticNPObjectMap().removeAndDispose(object); |
| 474 _NPN_ReleaseObject(object); | 474 _NPN_ReleaseObject(object); |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 | 477 |
| 478 } // namespace WebCore | 478 } // namespace WebCore |
| OLD | NEW |