OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_CPP_MODULE_H_ | 5 #ifndef PPAPI_CPP_MODULE_H_ |
6 #define PPAPI_CPP_MODULE_H_ | 6 #define PPAPI_CPP_MODULE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 class Module { | 29 class Module { |
30 public: | 30 public: |
31 typedef std::map<PP_Instance, Instance*> InstanceMap; | 31 typedef std::map<PP_Instance, Instance*> InstanceMap; |
32 | 32 |
33 // You may not call any other PP functions from the constructor, put them | 33 // You may not call any other PP functions from the constructor, put them |
34 // in Init instead. Various things will not be set up until the constructor | 34 // in Init instead. Various things will not be set up until the constructor |
35 // completes. | 35 // completes. |
36 Module(); | 36 Module(); |
37 virtual ~Module(); | 37 virtual ~Module(); |
38 | 38 |
39 // Returns the global instance of this module object, or NULL if the module | 39 /// Get() returns the global instance of this module object, or NULL if the |
40 // is not initialized yet. | 40 /// module is not initialized yet. |
| 41 /// |
| 42 /// @return The global instance of the module object. |
41 static Module* Get(); | 43 static Module* Get(); |
42 | 44 |
43 // This function will be automatically called after the object is created. | 45 /// Init() is automatically called after the object is created. This is where |
44 // This is where you can put functions that rely on other parts of the API, | 46 /// you can put functions that rely on other parts of the API, now that the |
45 // now that the module has been created. | 47 /// module has been created. |
| 48 /// |
| 49 /// @return true if successful, otherwise false. |
46 virtual bool Init(); | 50 virtual bool Init(); |
47 | 51 |
48 // Returns the internal module handle. | 52 /// The pp_module() function returns the internal module handle. |
| 53 /// |
| 54 /// @return A <code>PP_Module</code> internal module handle. |
49 PP_Module pp_module() const { return pp_module_; } | 55 PP_Module pp_module() const { return pp_module_; } |
50 | 56 |
51 // Returns the internal get_browser_interface pointer. | 57 /// The get_browser_interface() function returns the internal |
52 // TODO(sehr): This should be removed once the NaCl browser plugin no longer | 58 /// <code>get_browser_interface</code> pointer. |
53 // needs it. | 59 /// TODO(sehr): This should be removed once the NaCl browser plugin no longer |
| 60 /// needs it. |
| 61 /// |
| 62 /// @return A <code>PPB_GetInterface</code> internal pointer. |
54 PPB_GetInterface get_browser_interface() const { | 63 PPB_GetInterface get_browser_interface() const { |
55 return get_browser_interface_; | 64 return get_browser_interface_; |
56 } | 65 } |
57 | 66 |
58 // Returns the core interface for doing basic global operations. This is | 67 /// The core() function returns the core interface for doing basic |
59 // guaranteed to be non-NULL once the module has successfully initialized | 68 /// global operations. The return value is guaranteed to be non-NULL once the |
60 // and during the Init() call. | 69 /// module has successfully initialized and during the Init() call. |
61 // | 70 /// |
62 // It will be NULL before Init() has been called. | 71 /// It will be NULL before Init() has been called. |
| 72 /// |
| 73 /// @return The core interface for doing basic global operations. |
63 Core* core() { return core_; } | 74 Core* core() { return core_; } |
64 | 75 |
65 // Implements GetInterface for the browser to get plugin interfaces. If you | 76 /// GetPluginInterface() implements <code>GetInterface</code> for the browser |
66 // need to provide your own implementations of new interfaces, you can use | 77 /// to get module interfaces. If you need to provide your own implementations |
67 // AddPluginInterface which this function will use. | 78 /// of new interfaces, use AddPluginInterface() which this function will use. |
| 79 /// |
| 80 /// @param[in] interface_name The module interface for the browser to get. |
68 const void* GetPluginInterface(const char* interface_name); | 81 const void* GetPluginInterface(const char* interface_name); |
69 | 82 |
70 // Returns an interface in the browser. | 83 /// GetBrowserInterface() returns interfaces which the browser implements |
| 84 /// (i.e. PPB interfaces). |
| 85 /// @param[in] interface_name The browser interface for the moduel to get. |
71 const void* GetBrowserInterface(const char* interface_name); | 86 const void* GetBrowserInterface(const char* interface_name); |
72 | 87 |
73 // Returns the object associated with this PP_Instance, or NULL if one is | 88 /// InstanceForPPInstance() returns the object associated with this |
74 // not found. | 89 /// <code>PP_Instance</code>, or NULL if one is not found. |
| 90 /// |
| 91 /// @param[in] instance This <code>PP_Instance</code>. |
| 92 /// |
| 93 /// @return The object associated with this <code>PP_Instance</code>, |
| 94 /// or NULL if one is not found. |
75 Instance* InstanceForPPInstance(PP_Instance instance); | 95 Instance* InstanceForPPInstance(PP_Instance instance); |
76 | 96 |
77 // Adds a handler for a given interface name. When the browser requests | 97 /// AddPluginInterface() adds a handler for a provided interface name. When |
78 // that interface name, the given |vtable| will be returned. | 98 /// the browser requests that interface name, the provided |
79 // | 99 /// <code>vtable</code> will be returned. |
80 // In general, plugins will not need to call this directly. Instead, the | 100 /// |
81 // C++ wrappers for each interface will register themselves with this | 101 /// In general, modules will not need to call this directly. Instead, the |
82 // function. | 102 /// C++ wrappers for each interface will register themselves with this |
83 // | 103 /// function. |
84 // This function may be called more than once with the same interface name | 104 /// |
85 // and vtable with no effect. However, it may not be used to register a | 105 /// This function may be called more than once with the same interface name |
86 // different vtable for an already-registered interface. It will assert for | 106 /// and vtable with no effect. However, it may not be used to register a |
87 // a different registration for an already-registered interface in debug | 107 /// different vtable for an already-registered interface. It will assert for |
88 // mode, and just ignore the registration in release mode. | 108 /// a different registration for an already-registered interface in debug |
| 109 /// mode, and just ignore the registration in release mode. |
| 110 /// |
| 111 /// @param[in] interface_name The interface name that will receive a handler. |
| 112 /// @param[in,out] vtable The vtable to return for |
| 113 /// <code>interface_name</code>. |
89 void AddPluginInterface(const std::string& interface_name, | 114 void AddPluginInterface(const std::string& interface_name, |
90 const void* vtable); | 115 const void* vtable); |
91 | 116 |
92 // Sets the browser interface and calls the regular init function that | 117 // InternalInit() sets the browser interface and calls the regular Init() |
93 // can be overridden by the base classes. | 118 /// function that can be overridden by the base classes. |
94 // | 119 /// |
95 // TODO(brettw) make this private when I can figure out how to make the | 120 /// TODO(brettw) make this private when I can figure out how to make the |
96 // initialize function a friend. | 121 /// initialize function a friend. |
| 122 /// |
| 123 /// @param[in] mod A <code>PP_Module</code>. |
| 124 /// @param[in] get_browser_interface The browser interface to set. |
| 125 /// |
| 126 /// @return true if successful, otherwise false. |
97 bool InternalInit(PP_Module mod, | 127 bool InternalInit(PP_Module mod, |
98 PPB_GetInterface get_browser_interface); | 128 PPB_GetInterface get_browser_interface); |
99 | 129 |
100 // Allows iteration over the current instances in the module. | 130 /// The current_instances() function allows iteration over the |
| 131 /// current instances in the module. |
| 132 /// |
| 133 /// @return An <code>InstanceMap</code> of all instances in the module. |
101 const InstanceMap& current_instances() const { return current_instances_; } | 134 const InstanceMap& current_instances() const { return current_instances_; } |
102 | 135 |
103 protected: | 136 protected: |
104 // Override to create your own plugin type. | 137 /// CreateInstance() should be overridden to create your own module type. |
| 138 /// |
| 139 /// @param[in] instance A <code>PP_Instance</code>. |
| 140 /// |
| 141 /// @return The resulting instance. |
105 virtual Instance* CreateInstance(PP_Instance instance) = 0; | 142 virtual Instance* CreateInstance(PP_Instance instance) = 0; |
106 | 143 |
107 private: | 144 private: |
108 friend PP_Bool Instance_DidCreate(PP_Instance pp_instance, | 145 friend PP_Bool Instance_DidCreate(PP_Instance pp_instance, |
109 uint32_t argc, | 146 uint32_t argc, |
110 const char* argn[], | 147 const char* argn[], |
111 const char* argv[]); | 148 const char* argv[]); |
112 friend void Instance_DidDestroy(PP_Instance instance); | 149 friend void Instance_DidDestroy(PP_Instance instance); |
113 | 150 |
114 // Unimplemented (disallow copy and assign). | 151 // Unimplemented (disallow copy and assign). |
(...skipping 10 matching lines...) Expand all Loading... |
125 | 162 |
126 // All additional interfaces this plugin can handle as registered by | 163 // All additional interfaces this plugin can handle as registered by |
127 // AddPluginInterface. | 164 // AddPluginInterface. |
128 typedef std::map<std::string, const void*> InterfaceMap; | 165 typedef std::map<std::string, const void*> InterfaceMap; |
129 InterfaceMap additional_interfaces_; | 166 InterfaceMap additional_interfaces_; |
130 }; | 167 }; |
131 | 168 |
132 } // namespace pp | 169 } // namespace pp |
133 | 170 |
134 #endif // PPAPI_CPP_MODULE_H_ | 171 #endif // PPAPI_CPP_MODULE_H_ |
OLD | NEW |