1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef JSNPObject_h 27#define JSNPObject_h 28 29#if ENABLE(NETSCAPE_PLUGIN_API) 30 31#include <JavaScriptCore/JSGlobalObject.h> 32#include <JavaScriptCore/JSObject.h> 33#include <JavaScriptCore/ObjectPrototype.h> 34 35typedef void* NPIdentifier; 36struct NPObject; 37 38namespace WebKit { 39 40class NPRuntimeObjectMap; 41 42// JSNPObject is a JSObject that wraps an NPObject. 43 44class JSNPObject : public JSC::JSDestructibleObject { 45public: 46 typedef JSC::JSDestructibleObject Base; 47 48 static JSNPObject* create(JSC::JSGlobalObject* globalObject, NPRuntimeObjectMap* objectMap, NPObject* npObject) 49 { 50 JSC::Structure* structure = createStructure(globalObject->vm(), globalObject, globalObject->objectPrototype()); 51 JSNPObject* object = new (JSC::allocateCell<JSNPObject>(globalObject->vm().heap)) JSNPObject(globalObject, structure, objectMap, npObject); 52 object->finishCreation(globalObject); 53 return object; 54 } 55 56 ~JSNPObject(); 57 static void destroy(JSCell*); 58 59 void invalidate(); 60 61 // Used to invalidate an NPObject asynchronously. 62 NPObject* leakNPObject(); 63 64 JSC::JSValue callMethod(JSC::ExecState*, NPIdentifier methodName); 65 JSC::JSValue callObject(JSC::ExecState*); 66 JSC::JSValue callConstructor(JSC::ExecState*); 67 68 DECLARE_INFO; 69 70 NPObject* npObject() const { return m_npObject; } 71 72protected: 73 void finishCreation(JSC::JSGlobalObject*); 74 75private: 76 JSNPObject(JSC::JSGlobalObject*, JSC::Structure*, NPRuntimeObjectMap*, NPObject*); 77 78 static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesGetPropertyNames | JSObject::StructureFlags; 79 80 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) 81 { 82 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); 83 } 84 85 static JSC::CallType getCallData(JSC::JSCell*, JSC::CallData&); 86 static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&); 87 88 static bool getOwnPropertySlot(JSC::JSObject*, JSC::ExecState*, JSC::PropertyName, JSC::PropertySlot&); 89 static void put(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, JSC::JSValue, JSC::PutPropertySlot&); 90 91 static bool deleteProperty(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName); 92 static bool deletePropertyByIndex(JSC::JSCell*, JSC::ExecState*, unsigned propertyName); 93 94 bool deleteProperty(JSC::ExecState*, NPIdentifier propertyName); 95 96 static void getOwnPropertyNames(JSC::JSObject*, JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode); 97 98 static JSC::EncodedJSValue propertyGetter(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName); 99 static JSC::EncodedJSValue methodGetter(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName); 100 static JSC::JSObject* throwInvalidAccessError(JSC::ExecState*); 101 102 NPRuntimeObjectMap* m_objectMap; 103 NPObject* m_npObject; 104}; 105 106} // namespace WebKit 107 108#endif // ENABLE(NETSCAPE_PLUGIN_API) 109 110#endif // JSNPObject_h 111