Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: webkit/port/bindings/v8/V8NPObject.cpp

Issue 149086: Use upstream V8Proxy and V8Utilities (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/port/bindings/v8/NPV8Object.cpp ('k') | webkit/port/bindings/v8/V8NPUtils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // FIXME: need comments. 56 // FIXME: need comments.
57 // Params: holder could be HTMLEmbedElement or NPObject 57 // Params: holder could be HTMLEmbedElement or NPObject
58 static v8::Handle<v8::Value> npObjectInvokeImpl(const v8::Arguments& args, Invok eFunctionType functionId) 58 static v8::Handle<v8::Value> npObjectInvokeImpl(const v8::Arguments& args, Invok eFunctionType functionId)
59 { 59 {
60 NPObject* npObject; 60 NPObject* npObject;
61 61
62 // These three types are subtypes of HTMLPlugInElement. 62 // These three types are subtypes of HTMLPlugInElement.
63 if (V8HTMLAppletElement::HasInstance(args.Holder()) || V8HTMLEmbedElement::H asInstance(args.Holder()) 63 if (V8HTMLAppletElement::HasInstance(args.Holder()) || V8HTMLEmbedElement::H asInstance(args.Holder())
64 || V8HTMLObjectElement::HasInstance(args.Holder())) { 64 || V8HTMLObjectElement::HasInstance(args.Holder())) {
65 // The holder object is a subtype of HTMLPlugInElement. 65 // The holder object is a subtype of HTMLPlugInElement.
66 HTMLPlugInElement* element = V8Proxy::DOMWrapperToNode<HTMLPlugInElement >(args.Holder()); 66 HTMLPlugInElement* element = V8Proxy::convertDOMWrapperToNode<HTMLPlugIn Element>(args.Holder());
67 ScriptInstance scriptInstance = element->getInstance(); 67 ScriptInstance scriptInstance = element->getInstance();
68 if (scriptInstance) 68 if (scriptInstance)
69 npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, scriptInstance->instance()); 69 npObject = V8Proxy::convertToNativeObject<NPObject>(V8ClassIndex::NP OBJECT, scriptInstance->instance());
70 else 70 else
71 npObject = 0; 71 npObject = 0;
72 } else { 72 } else {
73 // The holder object is not a subtype of HTMLPlugInElement, it 73 // The holder object is not a subtype of HTMLPlugInElement, it
74 // must be an NPObject which has three internal fields. 74 // must be an NPObject which has three internal fields.
75 if (args.Holder()->InternalFieldCount() != V8Custom::kNPObjectInternalFi eldCount) 75 if (args.Holder()->InternalFieldCount() != V8Custom::kNPObjectInternalFi eldCount)
76 return throwError("NPMethod called on non-NPObject", V8Proxy::REFERENC E_ERROR); 76 return throwError("NPMethod called on non-NPObject", V8Proxy::Referenc eError);
77 77
78 npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, arg s.Holder()); 78 npObject = V8Proxy::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJE CT, args.Holder());
79 } 79 }
80 80
81 // Verify that our wrapper wasn't using a NPObject which 81 // Verify that our wrapper wasn't using a NPObject which
82 // has already been deleted. 82 // has already been deleted.
83 if (!npObject || !_NPN_IsAlive(npObject)) 83 if (!npObject || !_NPN_IsAlive(npObject))
84 return throwError("NPObject deleted", V8Proxy::REFERENCE_ERROR); 84 return throwError("NPObject deleted", V8Proxy::ReferenceError);
85 85
86 // Wrap up parameters. 86 // Wrap up parameters.
87 int numArgs = args.Length(); 87 int numArgs = args.Length();
88 OwnArrayPtr<NPVariant> npArgs(new NPVariant[numArgs]); 88 OwnArrayPtr<NPVariant> npArgs(new NPVariant[numArgs]);
89 89
90 for (int i = 0; i < numArgs; i++) 90 for (int i = 0; i < numArgs; i++)
91 convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i]); 91 convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i]);
92 92
93 NPVariant result; 93 NPVariant result;
94 VOID_TO_NPVARIANT(result); 94 VOID_TO_NPVARIANT(result);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 ASSERT(staticTemplateMap.contains(identifier)); 151 ASSERT(staticTemplateMap.contains(identifier));
152 152
153 staticTemplateMap.forget(identifier); 153 staticTemplateMap.forget(identifier);
154 } 154 }
155 155
156 156
157 static v8::Handle<v8::Value> npObjectGetProperty(v8::Local<v8::Object> self, 157 static v8::Handle<v8::Value> npObjectGetProperty(v8::Local<v8::Object> self,
158 NPIdentifier identifier, 158 NPIdentifier identifier,
159 v8::Local<v8::Value> key) 159 v8::Local<v8::Value> key)
160 { 160 {
161 NPObject* npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJEC T, self); 161 NPObject* npObject = V8Proxy::convertToNativeObject<NPObject>(V8ClassIndex:: NPOBJECT, self);
162 162
163 // Verify that our wrapper wasn't using a NPObject which 163 // Verify that our wrapper wasn't using a NPObject which
164 // has already been deleted. 164 // has already been deleted.
165 if (!npObject || !_NPN_IsAlive(npObject)) 165 if (!npObject || !_NPN_IsAlive(npObject))
166 return throwError("NPObject deleted", V8Proxy::REFERENCE_ERROR); 166 return throwError("NPObject deleted", V8Proxy::ReferenceError);
167 167
168 168
169 if (npObject->_class->hasProperty && npObject->_class->hasProperty(npObject, identifier) 169 if (npObject->_class->hasProperty && npObject->_class->hasProperty(npObject, identifier)
170 && npObject->_class->getProperty) { 170 && npObject->_class->getProperty) {
171 171
172 NPVariant result; 172 NPVariant result;
173 VOID_TO_NPVARIANT(result); 173 VOID_TO_NPVARIANT(result);
174 if (!npObject->_class->getProperty(npObject, identifier, &result)) 174 if (!npObject->_class->getProperty(npObject, identifier, &result))
175 return v8::Handle<v8::Value>(); 175 return v8::Handle<v8::Value>();
176 176
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 uint32_t index) 224 uint32_t index)
225 { 225 {
226 NPIdentifier identifier = NPN_GetIntIdentifier(index); 226 NPIdentifier identifier = NPN_GetIntIdentifier(index);
227 return npObjectGetProperty(self, identifier, v8::Number::New(index)); 227 return npObjectGetProperty(self, identifier, v8::Number::New(index));
228 } 228 }
229 229
230 static v8::Handle<v8::Value> npObjectSetProperty(v8::Local<v8::Object> self, 230 static v8::Handle<v8::Value> npObjectSetProperty(v8::Local<v8::Object> self,
231 NPIdentifier identifier, 231 NPIdentifier identifier,
232 v8::Local<v8::Value> value) 232 v8::Local<v8::Value> value)
233 { 233 {
234 NPObject* npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJEC T, self); 234 NPObject* npObject = V8Proxy::convertToNativeObject<NPObject>(V8ClassIndex:: NPOBJECT, self);
235 235
236 // Verify that our wrapper wasn't using a NPObject which 236 // Verify that our wrapper wasn't using a NPObject which
237 // has already been deleted. 237 // has already been deleted.
238 if (!npObject || !_NPN_IsAlive(npObject)) { 238 if (!npObject || !_NPN_IsAlive(npObject)) {
239 throwError("NPObject deleted", V8Proxy::REFERENCE_ERROR); 239 throwError("NPObject deleted", V8Proxy::ReferenceError);
240 return value; // Intercepted, but an exception was thrown. 240 return value; // Intercepted, but an exception was thrown.
241 } 241 }
242 242
243 if (npObject->_class->hasProperty && npObject->_class->hasProperty(npObject, identifier) 243 if (npObject->_class->hasProperty && npObject->_class->hasProperty(npObject, identifier)
244 && npObject->_class->setProperty) { 244 && npObject->_class->setProperty) {
245 245
246 NPVariant npValue; 246 NPVariant npValue;
247 VOID_TO_NPVARIANT(npValue); 247 VOID_TO_NPVARIANT(npValue);
248 convertV8ObjectToNPVariant(value, npObject, &npValue); 248 convertV8ObjectToNPVariant(value, npObject, &npValue);
249 bool success = npObject->_class->setProperty(npObject, identifier, &npVa lue); 249 bool success = npObject->_class->setProperty(npObject, identifier, &npVa lue);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // The same Wrapper type can be used by DOM bindings. 332 // The same Wrapper type can be used by DOM bindings.
333 if (npObjectDesc.IsEmpty()) { 333 if (npObjectDesc.IsEmpty()) {
334 npObjectDesc = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTem plate::New()); 334 npObjectDesc = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTem plate::New());
335 npObjectDesc->InstanceTemplate()->SetInternalFieldCount(V8Custom::kNPObj ectInternalFieldCount); 335 npObjectDesc->InstanceTemplate()->SetInternalFieldCount(V8Custom::kNPObj ectInternalFieldCount);
336 npObjectDesc->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedP ropertyGetter, npObjectNamedPropertySetter); 336 npObjectDesc->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedP ropertyGetter, npObjectNamedPropertySetter);
337 npObjectDesc->InstanceTemplate()->SetIndexedPropertyHandler(npObjectInde xedPropertyGetter, npObjectIndexedPropertySetter); 337 npObjectDesc->InstanceTemplate()->SetIndexedPropertyHandler(npObjectInde xedPropertyGetter, npObjectIndexedPropertySetter);
338 npObjectDesc->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvok eDefaultHandler); 338 npObjectDesc->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvok eDefaultHandler);
339 } 339 }
340 340
341 v8::Handle<v8::Function> v8Function = npObjectDesc->GetFunction(); 341 v8::Handle<v8::Function> v8Function = npObjectDesc->GetFunction();
342 v8::Local<v8::Object> value = SafeAllocation::NewInstance(v8Function); 342 v8::Local<v8::Object> value = SafeAllocation::newInstance(v8Function);
343 343
344 // If we were unable to allocate the instance, we avoid wrapping 344 // If we were unable to allocate the instance, we avoid wrapping
345 // and registering the NP object. 345 // and registering the NP object.
346 if (value.IsEmpty()) 346 if (value.IsEmpty())
347 return value; 347 return value;
348 348
349 wrapNPObject(value, object); 349 wrapNPObject(value, object);
350 350
351 // KJS retains the object as part of its wrapper (see Bindings::CInstance). 351 // KJS retains the object as part of its wrapper (see Bindings::CInstance).
352 NPN_RetainObject(object); 352 NPN_RetainObject(object);
353 353
354 _NPN_RegisterObject(object, root); 354 _NPN_RegisterObject(object, root);
355 355
356 // Maintain a weak pointer for v8 so we can cleanup the object. 356 // Maintain a weak pointer for v8 so we can cleanup the object.
357 v8::Persistent<v8::Object> weakRef = v8::Persistent<v8::Object>::New(value); 357 v8::Persistent<v8::Object> weakRef = v8::Persistent<v8::Object>::New(value);
358 staticNPObjectMap.set(object, weakRef); 358 staticNPObjectMap.set(object, weakRef);
359 359
360 return value; 360 return value;
361 } 361 }
362 362
363 void forgetV8ObjectForNPObject(NPObject* object) 363 void forgetV8ObjectForNPObject(NPObject* object)
364 { 364 {
365 if (staticNPObjectMap.contains(object)) { 365 if (staticNPObjectMap.contains(object)) {
366 v8::HandleScope scope; 366 v8::HandleScope scope;
367 v8::Persistent<v8::Object> handle(staticNPObjectMap.get(object)); 367 v8::Persistent<v8::Object> handle(staticNPObjectMap.get(object));
368 WebCore::V8Proxy::SetDOMWrapper(handle, WebCore::V8ClassIndex::NPOBJECT, 0); 368 WebCore::V8Proxy::setDOMWrapper(handle, WebCore::V8ClassIndex::NPOBJECT, 0);
369 staticNPObjectMap.forget(object); 369 staticNPObjectMap.forget(object);
370 NPN_ReleaseObject(object); 370 NPN_ReleaseObject(object);
371 } 371 }
372 } 372 }
OLDNEW
« no previous file with comments | « webkit/port/bindings/v8/NPV8Object.cpp ('k') | webkit/port/bindings/v8/V8NPUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698