| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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>& info,
InvokeFunctionType functionId) | 69 static void npObjectInvokeImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
InvokeFunctionType functionId) |
| 70 { | 70 { |
| 71 NPObject* npObject; | 71 NPObject* npObject; |
| 72 v8::Isolate* isolate = info.GetIsolate(); |
| 72 | 73 |
| 73 // These three types are subtypes of HTMLPlugInElement. | 74 // These three types are subtypes of HTMLPlugInElement. |
| 74 if (V8HTMLAppletElement::hasInstance(info.Holder(), info.GetIsolate()) || V8
HTMLEmbedElement::hasInstance(info.Holder(), info.GetIsolate()) | 75 HTMLPlugInElement* element = V8HTMLAppletElement::toNativeWithTypeCheck(isol
ate, info.Holder()); |
| 75 || V8HTMLObjectElement::hasInstance(info.Holder(), info.GetIsolate())) { | 76 if (!element) { |
| 76 // The holder object is a subtype of HTMLPlugInElement. | 77 element = V8HTMLEmbedElement::toNativeWithTypeCheck(isolate, info.Holder
()); |
| 77 HTMLPlugInElement* element; | 78 if (!element) { |
| 78 if (V8HTMLAppletElement::hasInstance(info.Holder(), info.GetIsolate())) | 79 element = V8HTMLObjectElement::toNativeWithTypeCheck(isolate, info.H
older()); |
| 79 element = V8HTMLAppletElement::toNative(info.Holder()); | 80 } |
| 80 else if (V8HTMLEmbedElement::hasInstance(info.Holder(), info.GetIsolate(
))) | 81 } |
| 81 element = V8HTMLEmbedElement::toNative(info.Holder()); | 82 if (element) { |
| 82 else | |
| 83 element = V8HTMLObjectElement::toNative(info.Holder()); | |
| 84 if (RefPtr<SharedPersistent<v8::Object> > wrapper = element->pluginWrapp
er()) { | 83 if (RefPtr<SharedPersistent<v8::Object> > wrapper = element->pluginWrapp
er()) { |
| 85 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 86 v8::HandleScope handleScope(isolate); | 84 v8::HandleScope handleScope(isolate); |
| 87 npObject = v8ObjectToNPObject(wrapper->newLocal(isolate)); | 85 npObject = v8ObjectToNPObject(wrapper->newLocal(isolate)); |
| 88 } else | 86 } else |
| 89 npObject = 0; | 87 npObject = 0; |
| 90 } else { | 88 } else { |
| 91 // The holder object is not a subtype of HTMLPlugInElement, it must be a
n NPObject which has three | 89 // The holder object is not a subtype of HTMLPlugInElement, it must be a
n NPObject which has three |
| 92 // internal fields. | 90 // internal fields. |
| 93 if (info.Holder()->InternalFieldCount() != npObjectInternalFieldCount) { | 91 if (info.Holder()->InternalFieldCount() != npObjectInternalFieldCount) { |
| 94 throwError(v8ReferenceError, "NPMethod called on non-NPObject", info
.GetIsolate()); | 92 throwError(v8ReferenceError, "NPMethod called on non-NPObject", info
.GetIsolate()); |
| 95 return; | 93 return; |
| 96 } | 94 } |
| 97 | 95 |
| 98 npObject = v8ObjectToNPObject(info.Holder()); | 96 npObject = v8ObjectToNPObject(info.Holder()); |
| 99 } | 97 } |
| 100 | 98 |
| 101 // Verify that our wrapper wasn't using a NPObject which has already been de
leted. | 99 // Verify that our wrapper wasn't using a NPObject which has already been de
leted. |
| 102 if (!npObject || !_NPN_IsAlive(npObject)) { | 100 if (!npObject || !_NPN_IsAlive(npObject)) { |
| 103 throwError(v8ReferenceError, "NPObject deleted", info.GetIsolate()); | 101 throwError(v8ReferenceError, "NPObject deleted", isolate); |
| 104 return; | 102 return; |
| 105 } | 103 } |
| 106 | 104 |
| 107 // Wrap up parameters. | 105 // Wrap up parameters. |
| 108 int numArgs = info.Length(); | 106 int numArgs = info.Length(); |
| 109 OwnPtr<NPVariant[]> npArgs = adoptArrayPtr(new NPVariant[numArgs]); | 107 OwnPtr<NPVariant[]> npArgs = adoptArrayPtr(new NPVariant[numArgs]); |
| 110 | 108 |
| 111 for (int i = 0; i < numArgs; i++) | 109 for (int i = 0; i < numArgs; i++) |
| 112 convertV8ObjectToNPVariant(info[i], npObject, &npArgs[i], info.GetIsolat
e()); | 110 convertV8ObjectToNPVariant(info[i], npObject, &npArgs[i], isolate); |
| 113 | 111 |
| 114 NPVariant result; | 112 NPVariant result; |
| 115 VOID_TO_NPVARIANT(result); | 113 VOID_TO_NPVARIANT(result); |
| 116 | 114 |
| 117 bool retval = true; | 115 bool retval = true; |
| 118 switch (functionId) { | 116 switch (functionId) { |
| 119 case InvokeMethod: | 117 case InvokeMethod: |
| 120 if (npObject->_class->invoke) { | 118 if (npObject->_class->invoke) { |
| 121 v8::Handle<v8::String> functionName = v8::Handle<v8::String>::Cast(i
nfo.Data()); | 119 v8::Handle<v8::String> functionName = v8::Handle<v8::String>::Cast(i
nfo.Data()); |
| 122 NPIdentifier identifier = getStringIdentifier(functionName); | 120 NPIdentifier identifier = getStringIdentifier(functionName); |
| 123 retval = npObject->_class->invoke(npObject, identifier, npArgs.get()
, numArgs, &result); | 121 retval = npObject->_class->invoke(npObject, identifier, npArgs.get()
, numArgs, &result); |
| 124 } | 122 } |
| 125 break; | 123 break; |
| 126 case InvokeConstruct: | 124 case InvokeConstruct: |
| 127 if (npObject->_class->construct) | 125 if (npObject->_class->construct) |
| 128 retval = npObject->_class->construct(npObject, npArgs.get(), numArgs
, &result); | 126 retval = npObject->_class->construct(npObject, npArgs.get(), numArgs
, &result); |
| 129 break; | 127 break; |
| 130 case InvokeDefault: | 128 case InvokeDefault: |
| 131 if (npObject->_class->invokeDefault) | 129 if (npObject->_class->invokeDefault) |
| 132 retval = npObject->_class->invokeDefault(npObject, npArgs.get(), num
Args, &result); | 130 retval = npObject->_class->invokeDefault(npObject, npArgs.get(), num
Args, &result); |
| 133 break; | 131 break; |
| 134 default: | 132 default: |
| 135 break; | 133 break; |
| 136 } | 134 } |
| 137 | 135 |
| 138 if (!retval) | 136 if (!retval) |
| 139 throwError(v8GeneralError, "Error calling method on NPObject.", info.Get
Isolate()); | 137 throwError(v8GeneralError, "Error calling method on NPObject.", isolate)
; |
| 140 | 138 |
| 141 for (int i = 0; i < numArgs; i++) | 139 for (int i = 0; i < numArgs; i++) |
| 142 _NPN_ReleaseVariantValue(&npArgs[i]); | 140 _NPN_ReleaseVariantValue(&npArgs[i]); |
| 143 | 141 |
| 144 // Unwrap return values. | 142 // Unwrap return values. |
| 145 v8::Handle<v8::Value> returnValue; | 143 v8::Handle<v8::Value> returnValue; |
| 146 if (_NPN_IsAlive(npObject)) | 144 if (_NPN_IsAlive(npObject)) |
| 147 returnValue = convertNPVariantToV8Object(&result, npObject, info.GetIsol
ate()); | 145 returnValue = convertNPVariantToV8Object(&result, npObject, isolate); |
| 148 _NPN_ReleaseVariantValue(&result); | 146 _NPN_ReleaseVariantValue(&result); |
| 149 | 147 |
| 150 v8SetReturnValue(info, returnValue); | 148 v8SetReturnValue(info, returnValue); |
| 151 } | 149 } |
| 152 | 150 |
| 153 | 151 |
| 154 void npObjectMethodHandler(const v8::FunctionCallbackInfo<v8::Value>& info) | 152 void npObjectMethodHandler(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 155 { | 153 { |
| 156 return npObjectInvokeImpl(info, InvokeMethod); | 154 return npObjectInvokeImpl(info, InvokeMethod); |
| 157 } | 155 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 v8::HandleScope scope(isolate); | 475 v8::HandleScope scope(isolate); |
| 478 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); | 476 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); |
| 479 if (!wrapper.IsEmpty()) { | 477 if (!wrapper.IsEmpty()) { |
| 480 V8DOMWrapper::clearNativeInfo(wrapper, npObjectTypeInfo()); | 478 V8DOMWrapper::clearNativeInfo(wrapper, npObjectTypeInfo()); |
| 481 staticNPObjectMap().removeAndDispose(object); | 479 staticNPObjectMap().removeAndDispose(object); |
| 482 _NPN_ReleaseObject(object); | 480 _NPN_ReleaseObject(object); |
| 483 } | 481 } |
| 484 } | 482 } |
| 485 | 483 |
| 486 } // namespace WebCore | 484 } // namespace WebCore |
| OLD | NEW |