OLD | NEW |
| (Empty) |
1 // Copyright 2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // DispatchHost hosts an IDispatch object inside a NPObject to allow scripting | |
17 // of COM objects from a NPAPI environment. Types are automatically marshalled | |
18 // between NPVariant and VARIANT using the functions in variant_utils.h. | |
19 // Limitations: | |
20 // - IDispatch methods/properties may only take arguments of type VT_VOID, | |
21 // VT_NULL, VT_BOOL, VT_I4, VT_R8, and VT_BSTR | |
22 // - Multiple out parameters are not supported. | |
23 // - IDispatch methods/properties may only return a value of type VT_EMPTY, | |
24 // VT_VOID, VT_NULL, VT_BOOL, VT_I4, VT_UI4, VT_R8, VT_BSTR, and VT_DISPATCH | |
25 // - A method and property a property that takes additional arguments may not | |
26 // have the same identifier--the method will not be callable through | |
27 // DispatchHost. | |
28 | |
29 #ifndef OMAHA_PLUGINS_UPDATE_NPAPI_DISPATCH_HOST_H_ | |
30 #define OMAHA_PLUGINS_UPDATE_NPAPI_DISPATCH_HOST_H_ | |
31 | |
32 #include <atlbase.h> | |
33 #include <atlcom.h> | |
34 | |
35 #include "base/basictypes.h" | |
36 #include "third_party/npapi/bindings/nphostapi.h" | |
37 | |
38 namespace omaha { | |
39 | |
40 class DispatchHostTest; | |
41 | |
42 class DispatchHost : public NPObject { | |
43 public: | |
44 static DispatchHost* CreateInstance(NPP npp, IDispatch* dispatch); | |
45 | |
46 private: | |
47 explicit DispatchHost(NPP npp); | |
48 ~DispatchHost(); | |
49 | |
50 DISPID GetDispatchId(NPIdentifier name); | |
51 bool IsProperty(DISPID dispatch_id); | |
52 HRESULT InvokeHelper(DISPID dispatch_id, WORD flags, const NPVariant* args, | |
53 uint32_t arg_count, NPP npp, NPVariant* result); | |
54 | |
55 static NPObject* Allocate(NPP npp, NPClass *class_functions); | |
56 static void Deallocate(NPObject* object); | |
57 static bool HasMethod(NPObject* object, NPIdentifier name); | |
58 static bool Invoke(NPObject* object, NPIdentifier name, const NPVariant* args, | |
59 uint32_t arg_count, NPVariant* result); | |
60 static bool InvokeDefault(NPObject* object, const NPVariant* args, | |
61 uint32_t arg_count, NPVariant* result); | |
62 static bool HasProperty(NPObject* object, NPIdentifier name); | |
63 static bool GetProperty(NPObject* object, NPIdentifier name, | |
64 NPVariant* result); | |
65 static bool SetProperty(NPObject* object, NPIdentifier name, | |
66 const NPVariant* value); | |
67 static bool RemoveProperty(NPObject* object, NPIdentifier name); | |
68 static bool Enumerate(NPObject* object, NPIdentifier** names, | |
69 uint32_t* count); | |
70 static bool Construct(NPObject* object, const NPVariant* args, | |
71 uint32_t arg_count, NPVariant* result); | |
72 | |
73 NPP npp_; | |
74 // The hosted dispatch object. | |
75 CComPtr<IDispatch> dispatch_; | |
76 | |
77 // The NPObject vtable. | |
78 static NPClass kNPClass_; | |
79 | |
80 friend class DispatchHostTest; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(DispatchHost); | |
83 }; | |
84 | |
85 } // namespace omaha | |
86 | |
87 #endif // OMAHA_PLUGINS_UPDATE_NPAPI_DISPATCH_HOST_H_ | |
OLD | NEW |