• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NPJSObject_h
27 #define NPJSObject_h
28 
29 #include <JavaScriptCore/Strong.h>
30 #include <WebCore/npruntime_internal.h>
31 #include <wtf/Noncopyable.h>
32 
33 namespace JSC {
34 
35 class JSGlobalData;
36 class JSGlobalObject;
37 class JSObject;
38 
39 }
40 
41 namespace WebKit {
42 
43 class NPRuntimeObjectMap;
44 
45 // NPJSObject is an NPObject that wraps a JSObject.
46 class NPJSObject : public NPObject {
47     WTF_MAKE_NONCOPYABLE(NPJSObject);
48 public:
49     static NPJSObject* create(JSC::JSGlobalData&, NPRuntimeObjectMap*, JSC::JSObject*);
50 
jsObject()51     JSC::JSObject* jsObject() const { return m_jsObject.get(); }
52 
53     static bool isNPJSObject(NPObject*);
54 
toNPJSObject(NPObject * npObject)55     static NPJSObject* toNPJSObject(NPObject* npObject)
56     {
57         ASSERT(isNPJSObject(npObject));
58         return static_cast<NPJSObject*>(npObject);
59     }
60 
61 private:
62     NPJSObject();
63     ~NPJSObject();
64 
65     void initialize(JSC::JSGlobalData&, NPRuntimeObjectMap*, JSC::JSObject*);
66 
67     bool hasMethod(NPIdentifier methodName);
68     bool invoke(NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
69     bool invokeDefault(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
70     bool hasProperty(NPIdentifier propertyName);
71     bool getProperty(NPIdentifier propertyName, NPVariant* result);
72     bool setProperty(NPIdentifier propertyName, const NPVariant* value);
73     bool removeProperty(NPIdentifier propertyName);
74     bool enumerate(NPIdentifier** identifiers, uint32_t* identifierCount);
75     bool construct(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
76 
77     bool invoke(JSC::ExecState*, JSC::JSGlobalObject*, JSC::JSValue function, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
78 
79     static NPClass* npClass();
80     static NPObject* NP_Allocate(NPP, NPClass*);
81     static void NP_Deallocate(NPObject*);
82     static bool NP_HasMethod(NPObject*, NPIdentifier methodName);
83     static bool NP_Invoke(NPObject*, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
84     static bool NP_InvokeDefault(NPObject*, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
85     static bool NP_HasProperty(NPObject*, NPIdentifier propertyName);
86     static bool NP_GetProperty(NPObject*, NPIdentifier propertyName, NPVariant* result);
87     static bool NP_SetProperty(NPObject*, NPIdentifier propertyName, const NPVariant* value);
88     static bool NP_RemoveProperty(NPObject*, NPIdentifier propertyName);
89     static bool NP_Enumerate(NPObject*, NPIdentifier** identifiers, uint32_t* identifierCount);
90     static bool NP_Construct(NPObject*, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
91 
92     NPRuntimeObjectMap* m_objectMap;
93     JSC::Strong<JSC::JSObject> m_jsObject;
94 };
95 
96 } // namespace WebKit
97 
98 #endif // NPJSObject_h
99