1 | /* |
2 | * Copyright (C) 2010-2019 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 | |
35 | typedef void* NPIdentifier; |
36 | struct NPObject; |
37 | |
38 | namespace WebKit { |
39 | |
40 | class NPRuntimeObjectMap; |
41 | |
42 | // JSNPObject is a JSObject that wraps an NPObject. |
43 | |
44 | class JSNPObject final : public JSC::JSDestructibleObject { |
45 | public: |
46 | typedef JSC::JSDestructibleObject Base; |
47 | static const unsigned StructureFlags = Base::StructureFlags | JSC::OverridesGetOwnPropertySlot | JSC::OverridesGetPropertyNames | JSC::OverridesGetCallData; |
48 | |
49 | template<typename CellType, JSC::SubspaceAccess> |
50 | static JSC::IsoSubspace* subspaceFor(JSC::VM& vm) |
51 | { |
52 | return subspaceForImpl(vm); |
53 | } |
54 | |
55 | static JSNPObject* create(JSC::JSGlobalObject* globalObject, NPRuntimeObjectMap* objectMap, NPObject* npObject) |
56 | { |
57 | JSC::Structure* structure = createStructure(globalObject->vm(), globalObject, globalObject->objectPrototype()); |
58 | JSNPObject* object = new (JSC::allocateCell<JSNPObject>(globalObject->vm().heap)) JSNPObject(globalObject, structure, objectMap, npObject); |
59 | object->finishCreation(globalObject); |
60 | return object; |
61 | } |
62 | |
63 | ~JSNPObject(); |
64 | static void destroy(JSCell*); |
65 | |
66 | void invalidate(); |
67 | |
68 | // Used to invalidate an NPObject asynchronously. |
69 | NPObject* leakNPObject(); |
70 | |
71 | JSC::JSValue callMethod(JSC::ExecState*, NPIdentifier methodName); |
72 | JSC::JSValue callObject(JSC::ExecState*); |
73 | JSC::JSValue callConstructor(JSC::ExecState*); |
74 | |
75 | DECLARE_INFO; |
76 | |
77 | NPObject* npObject() const { return m_npObject; } |
78 | |
79 | protected: |
80 | void finishCreation(JSC::JSGlobalObject*); |
81 | |
82 | private: |
83 | static JSC::IsoSubspace* subspaceForImpl(JSC::VM&); |
84 | |
85 | JSNPObject(JSC::JSGlobalObject*, JSC::Structure*, NPRuntimeObjectMap*, NPObject*); |
86 | |
87 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
88 | { |
89 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
90 | } |
91 | |
92 | static JSC::CallType getCallData(JSC::JSCell*, JSC::CallData&); |
93 | static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&); |
94 | |
95 | static bool getOwnPropertySlot(JSC::JSObject*, JSC::ExecState*, JSC::PropertyName, JSC::PropertySlot&); |
96 | static bool put(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, JSC::JSValue, JSC::PutPropertySlot&); |
97 | |
98 | static bool deleteProperty(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName); |
99 | static bool deletePropertyByIndex(JSC::JSCell*, JSC::ExecState*, unsigned propertyName); |
100 | |
101 | bool deleteProperty(JSC::ExecState*, NPIdentifier propertyName); |
102 | |
103 | static void getOwnPropertyNames(JSC::JSObject*, JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode); |
104 | |
105 | static JSC::EncodedJSValue propertyGetter(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
106 | static JSC::EncodedJSValue methodGetter(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
107 | static JSC::Exception* throwInvalidAccessError(JSC::ExecState*, JSC::ThrowScope&); |
108 | |
109 | NPRuntimeObjectMap* m_objectMap; |
110 | NPObject* m_npObject; |
111 | }; |
112 | |
113 | } // namespace WebKit |
114 | |
115 | #endif // ENABLE(NETSCAPE_PLUGIN_API) |
116 | |
117 | #endif // JSNPObject_h |
118 | |