OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef O3D_GPU_PLUGIN_NP_UTILS_BASE_NP_OBJECT_H_ | |
6 #define O3D_GPU_PLUGIN_NP_UTILS_BASE_NP_OBJECT_H_ | |
7 | |
8 #include "third_party/npapi/bindings/npapi.h" | |
9 #include "third_party/npapi/bindings/npruntime.h" | |
10 | |
11 namespace o3d { | |
12 namespace gpu_plugin { | |
13 | |
14 // This class is a base class for NPObjects implemented in C++. It forwards | |
15 // The NPObject calls through to virtual functions implemented by the subclass. | |
16 class BaseNPObject : public NPObject { | |
17 public: | |
18 // Returns the NPClass for the concrete BaseNPObject subclass T. | |
19 template <typename NPObjectType> | |
20 static const NPClass* GetNPClass(); | |
21 | |
22 NPP npp() const { | |
23 return npp_; | |
24 } | |
25 | |
26 // Override these in subclass. | |
27 virtual void Invalidate(); | |
28 | |
29 virtual bool HasMethod(NPIdentifier name); | |
30 | |
31 virtual bool Invoke(NPIdentifier name, | |
32 const NPVariant* args, | |
33 uint32_t num_args, | |
34 NPVariant* result); | |
35 | |
36 virtual bool InvokeDefault(const NPVariant* args, | |
37 uint32_t num_args, | |
38 NPVariant* result); | |
39 | |
40 virtual bool HasProperty(NPIdentifier name); | |
41 | |
42 virtual bool GetProperty(NPIdentifier name, NPVariant* result); | |
43 | |
44 virtual bool SetProperty(NPIdentifier name, const NPVariant* value); | |
45 | |
46 virtual bool RemoveProperty(NPIdentifier name); | |
47 | |
48 virtual bool Enumerate(NPIdentifier** names, | |
49 uint32_t* count); | |
50 | |
51 virtual bool Construct(const NPVariant* args, | |
52 uint32_t num_args, | |
53 NPVariant* result); | |
54 | |
55 protected: | |
56 | |
57 explicit BaseNPObject(NPP npp); | |
58 virtual ~BaseNPObject(); | |
59 | |
60 private: | |
61 // This template version of the NPClass allocate function creates a subclass | |
62 // of BaseNPObject. | |
63 template <typename NPObjectType> | |
64 static NPObject* AllocateImpl(NPP npp, NPClass*) { | |
65 return new NPObjectType(npp); | |
66 } | |
67 | |
68 // These implementations of the NPClass functions forward to the virtual | |
69 // functions in BaseNPObject. | |
70 static void DeallocateImpl(NPObject* object); | |
71 | |
72 static void InvalidateImpl(NPObject* object); | |
73 | |
74 static bool HasMethodImpl(NPObject* object, NPIdentifier name); | |
75 | |
76 static bool InvokeImpl(NPObject* object, | |
77 NPIdentifier name, | |
78 const NPVariant* args, | |
79 uint32_t num_args, | |
80 NPVariant* result); | |
81 | |
82 static bool InvokeDefaultImpl(NPObject* object, | |
83 const NPVariant* args, | |
84 uint32_t num_args, | |
85 NPVariant* result); | |
86 | |
87 static bool HasPropertyImpl(NPObject* object, NPIdentifier name); | |
88 | |
89 static bool GetPropertyImpl(NPObject* object, | |
90 NPIdentifier name, | |
91 NPVariant* result); | |
92 | |
93 static bool SetPropertyImpl(NPObject* object, | |
94 NPIdentifier name, | |
95 const NPVariant* value); | |
96 | |
97 static bool RemovePropertyImpl(NPObject* object, NPIdentifier name); | |
98 | |
99 static bool EnumerateImpl(NPObject* object, | |
100 NPIdentifier** names, | |
101 uint32_t* count); | |
102 | |
103 static bool ConstructImpl(NPObject* object, | |
104 const NPVariant* args, | |
105 uint32_t num_args, | |
106 NPVariant* result); | |
107 | |
108 NPP npp_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(BaseNPObject); | |
111 }; | |
112 | |
113 template <typename NPObjectType> | |
114 const NPClass* BaseNPObject::GetNPClass() { | |
115 static NPClass np_class = { | |
116 NP_CLASS_STRUCT_VERSION, | |
117 AllocateImpl<NPObjectType>, | |
118 DeallocateImpl, | |
119 InvalidateImpl, | |
120 HasMethodImpl, | |
121 InvokeImpl, | |
122 InvokeDefaultImpl, | |
123 HasPropertyImpl, | |
124 GetPropertyImpl, | |
125 SetPropertyImpl, | |
126 RemovePropertyImpl, | |
127 EnumerateImpl, | |
128 ConstructImpl, | |
129 }; | |
130 return &np_class; | |
131 }; | |
132 } // namespace gpu_plugin | |
133 } // namespace o3d | |
134 | |
135 #endif // O3D_GPU_PLUGIN_NP_UTILS_BASE_NP_OBJECT_H_ | |
OLD | NEW |