OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2008 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
7 | |
8 // The abstract portable scriptable object base class. | |
9 | |
10 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_PORTABLE_HANDLE_H_ | |
11 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_PORTABLE_HANDLE_H_ | |
12 | |
13 #include <stdio.h> | |
14 #include <map> | |
15 | |
16 #include "native_client/src/include/nacl_macros.h" | |
17 #include "native_client/src/trusted/plugin/srpc/method_map.h" | |
18 #include "native_client/src/trusted/plugin/srpc/utility.h" | |
19 | |
20 | |
21 struct NaClDesc; | |
22 | |
23 namespace nacl { | |
24 class DescWrapper; | |
25 } // namespace | |
26 | |
27 namespace plugin { | |
28 | |
29 // Forward declarations for externals. | |
30 class BrowserInterface; | |
31 class Plugin; | |
32 class ScriptableHandle; | |
33 class ServiceRuntime; | |
34 | |
35 typedef enum { | |
36 METHOD_CALL = 0, | |
37 PROPERTY_GET, | |
38 PROPERTY_SET | |
39 } CallType; | |
40 | |
41 | |
42 // PortableHandle represents scriptable objects used by the browser plugin. | |
43 // The classes in this hierarchy are independent of the browser plugin API | |
44 // used to implement them. PortableHandle is an abstract base class. | |
45 class PortableHandle { | |
46 public: | |
47 // Delete this object. | |
48 void Delete() { delete this; } | |
49 | |
50 // A call to Invalidate() means the object should discard any | |
51 // refcounted objects it holds, without using Unref(), e.g. by | |
52 // setting the pointers to NULL. These objects have either already | |
53 // been deallocated or will be deallocated shortly. | |
54 virtual void Invalidate() = 0; | |
55 | |
56 // Generic NPAPI/IDispatch interface | |
57 bool Invoke(uintptr_t method_id, CallType call_type, SrpcParams* params); | |
58 bool HasMethod(uintptr_t method_id, CallType call_type); | |
59 | |
60 // Get the method signature so ScriptableHandle can marshal the inputs | |
61 bool InitParams(uintptr_t method_id, CallType call_type, SrpcParams* params); | |
62 | |
63 // The interface to the browser. | |
64 virtual BrowserInterface* browser_interface() const = 0; | |
65 | |
66 // Every portable object has a pointer to the root plugin object. | |
67 virtual Plugin* plugin() const = 0; | |
68 | |
69 // DescBasedHandle objects encapsulate a descriptor. | |
70 virtual nacl::DescWrapper* wrapper() const { return NULL; } | |
71 virtual NaClDesc* desc() const { return NULL; } | |
72 | |
73 // SharedMemory objects are mapped in at a non-NULL address and have a | |
74 // non-zero size. | |
75 virtual void* shm_addr() const { return NULL; } | |
76 virtual size_t shm_size() const { return 0; } | |
77 | |
78 // SocketAddress objects can be connected to, returning a ConnectedSocket. | |
79 virtual ScriptableHandle* Connect() { | |
80 return NULL; | |
81 } | |
82 // This is only virtual because although Connect() always returns a | |
83 // ConnectedSocket, it cannot be declared as doing so, because of | |
84 // the PortableHandle/ScriptableHandle split. | |
85 virtual void StartJSObjectProxy(Plugin* plugin) { | |
86 UNREFERENCED_PARAMETER(plugin); | |
87 } | |
88 | |
89 protected: | |
90 PortableHandle(); | |
91 virtual ~PortableHandle(); | |
92 | |
93 // Derived classes can set the properties and methods they export by | |
94 // the following three methods. | |
95 void AddPropertyGet(RpcFunction function_ptr, | |
96 const char* name, | |
97 const char* outs); | |
98 void AddPropertySet(RpcFunction function_ptr, | |
99 const char* name, | |
100 const char* ins); | |
101 void AddMethodCall(RpcFunction function_ptr, | |
102 const char* name, | |
103 const char* ins, | |
104 const char* outs); | |
105 | |
106 // Every derived class should provide an implementation for these functions | |
107 // to allow handling of method calls that cannot be registered at build time. | |
108 virtual bool InitParamsEx(uintptr_t method_id, | |
109 CallType call_type, | |
110 SrpcParams* params); | |
111 virtual bool InvokeEx(uintptr_t method_id, | |
112 CallType call_type, | |
113 SrpcParams* params); | |
114 virtual bool HasMethodEx(uintptr_t method_id, CallType call_type); | |
115 | |
116 private: | |
117 NACL_DISALLOW_COPY_AND_ASSIGN(PortableHandle); | |
118 MethodInfo* GetMethodInfo(uintptr_t method_id, CallType call_type); | |
119 MethodMap methods_; | |
120 MethodMap property_get_methods_; | |
121 MethodMap property_set_methods_; | |
122 }; | |
123 | |
124 } // namespace plugin | |
125 | |
126 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_PORTABLE_HANDLE_H_ | |
OLD | NEW |