OLD | NEW |
1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
2 // All rights reserved. | 2 // 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 28 matching lines...) Expand all Loading... |
39 #include "V8DOMMap.h" | 39 #include "V8DOMMap.h" |
40 #include "HTMLPlugInElement.h" | 40 #include "HTMLPlugInElement.h" |
41 #include "V8HTMLAppletElement.h" | 41 #include "V8HTMLAppletElement.h" |
42 #include "V8HTMLEmbedElement.h" | 42 #include "V8HTMLEmbedElement.h" |
43 #include "V8HTMLObjectElement.h" | 43 #include "V8HTMLObjectElement.h" |
44 | 44 |
45 using namespace WebCore; | 45 using namespace WebCore; |
46 | 46 |
47 enum InvokeFunctionType { | 47 enum InvokeFunctionType { |
48 INVOKE_METHOD = 1, | 48 INVOKE_METHOD = 1, |
49 INVOKE_DEFAULT = 2 | 49 INVOKE_CONSTRUCT = 2, |
| 50 INVOKE_DEFAULT = 3 |
50 }; | 51 }; |
51 | 52 |
52 // TODO(mbelshe): need comments. | 53 // TODO(mbelshe): need comments. |
53 // Params: holder could be HTMLEmbedElement or NPObject | 54 // Params: holder could be HTMLEmbedElement or NPObject |
54 static v8::Handle<v8::Value> NPObjectInvokeImpl(const v8::Arguments& args, Invok
eFunctionType funcId) | 55 static v8::Handle<v8::Value> NPObjectInvokeImpl(const v8::Arguments& args, Invok
eFunctionType funcId) |
55 { | 56 { |
56 NPObject* npobject; | 57 NPObject* npobject; |
57 | 58 |
58 // These three types are subtypes of HTMLPlugInElement. | 59 // These three types are subtypes of HTMLPlugInElement. |
59 if (V8HTMLAppletElement::HasInstance(args.Holder()) || | 60 if (V8HTMLAppletElement::HasInstance(args.Holder()) || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 VOID_TO_NPVARIANT(result); | 95 VOID_TO_NPVARIANT(result); |
95 | 96 |
96 switch (funcId) { | 97 switch (funcId) { |
97 case INVOKE_METHOD: | 98 case INVOKE_METHOD: |
98 if (npobject->_class->invoke) { | 99 if (npobject->_class->invoke) { |
99 v8::Handle<v8::String> function_name(v8::String::Cast(*args.Data()))
; | 100 v8::Handle<v8::String> function_name(v8::String::Cast(*args.Data()))
; |
100 NPIdentifier ident = getStringIdentifier(function_name); | 101 NPIdentifier ident = getStringIdentifier(function_name); |
101 npobject->_class->invoke(npobject, ident, npArgs, argc, &result); | 102 npobject->_class->invoke(npobject, ident, npArgs, argc, &result); |
102 } | 103 } |
103 break; | 104 break; |
| 105 case INVOKE_CONSTRUCT: |
| 106 if (npobject->_class->construct) |
| 107 npobject->_class->construct(npobject, npArgs, argc, &result); |
| 108 break; |
104 case INVOKE_DEFAULT: | 109 case INVOKE_DEFAULT: |
105 if (npobject->_class->invokeDefault) | 110 if (npobject->_class->invokeDefault) |
106 npobject->_class->invokeDefault(npobject, npArgs, argc, &result); | 111 npobject->_class->invokeDefault(npobject, npArgs, argc, &result); |
107 // The call might be a construct call on an NPObject. | |
108 // See http://code.google.com/p/chromium/issues/detail?id=3285 | |
109 // | |
110 // TODO: when V8 passes in the correct flag args.is_construct_call_, | |
111 // make a separate NPN_Construct case. | |
112 else if (npobject->_class->construct) | |
113 npobject->_class->construct(npobject, npArgs, argc, &result); | |
114 break; | 112 break; |
115 default: | 113 default: |
116 break; | 114 break; |
117 } | 115 } |
118 | 116 |
119 for (int i=0; i < argc; i++) | 117 for (int i=0; i < argc; i++) |
120 NPN_ReleaseVariantValue(&npArgs[i]); | 118 NPN_ReleaseVariantValue(&npArgs[i]); |
121 delete[] npArgs; | 119 delete[] npArgs; |
122 | 120 |
123 // unwrap return values | 121 // unwrap return values |
124 v8::Handle<v8::Value> rv = convertNPVariantToV8Object(&result, npobject); | 122 v8::Handle<v8::Value> rv = convertNPVariantToV8Object(&result, npobject); |
125 NPN_ReleaseVariantValue(&result); | 123 NPN_ReleaseVariantValue(&result); |
126 | 124 |
127 return rv; | 125 return rv; |
128 } | 126 } |
129 | 127 |
130 | 128 |
131 v8::Handle<v8::Value> NPObjectMethodHandler(const v8::Arguments& args) | 129 v8::Handle<v8::Value> NPObjectMethodHandler(const v8::Arguments& args) |
132 { | 130 { |
133 return NPObjectInvokeImpl(args, INVOKE_METHOD); | 131 return NPObjectInvokeImpl(args, INVOKE_METHOD); |
134 } | 132 } |
135 | 133 |
136 | 134 |
137 v8::Handle<v8::Value> NPObjectInvokeDefaultHandler(const v8::Arguments& args) | 135 v8::Handle<v8::Value> NPObjectInvokeDefaultHandler(const v8::Arguments& args) |
138 { | 136 { |
139 return NPObjectInvokeImpl(args, INVOKE_DEFAULT); | 137 if (args.IsConstructCall()) |
| 138 return NPObjectInvokeImpl(args, INVOKE_CONSTRUCT); |
| 139 else |
| 140 return NPObjectInvokeImpl(args, INVOKE_DEFAULT); |
140 } | 141 } |
141 | 142 |
142 | 143 |
143 static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param); | 144 static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param); |
144 | 145 |
145 // NPIdentifier is PrivateIdentifier*. | 146 // NPIdentifier is PrivateIdentifier*. |
146 static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> \ | 147 static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> \ |
147 static_template_map(&WeakTemplateCallback); | 148 static_template_map(&WeakTemplateCallback); |
148 | 149 |
149 static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param) | 150 static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param) |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 void ForgetV8ObjectForNPObject(NPObject* object) | 372 void ForgetV8ObjectForNPObject(NPObject* object) |
372 { | 373 { |
373 if (staticNpobjectMap.contains(object)) { | 374 if (staticNpobjectMap.contains(object)) { |
374 v8::HandleScope scope; | 375 v8::HandleScope scope; |
375 v8::Persistent<v8::Object> handle(staticNpobjectMap.get(object)); | 376 v8::Persistent<v8::Object> handle(staticNpobjectMap.get(object)); |
376 WebCore::V8Proxy::SetDOMWrapper(handle, WebCore::V8ClassIndex::NPOBJECT,
NULL); | 377 WebCore::V8Proxy::SetDOMWrapper(handle, WebCore::V8ClassIndex::NPOBJECT,
NULL); |
377 staticNpobjectMap.forget(object); | 378 staticNpobjectMap.forget(object); |
378 NPN_ReleaseObject(object); | 379 NPN_ReleaseObject(object); |
379 } | 380 } |
380 } | 381 } |
OLD | NEW |