OLD | NEW |
1 .. _devcycle-native-client-modules: | 1 .. _devcycle-native-client-modules: |
2 | 2 |
3 ##################### | 3 ##################### |
4 Native Client Modules | 4 Native Client Modules |
5 ##################### | 5 ##################### |
6 | 6 |
7 This document describes the classes and functions that you need to implement in | 7 This document describes the classes and functions that you need to implement in |
8 a Native Client module in order for Chrome to load, initialize, and run it. The | 8 a Native Client module in order for Chrome to load, initialize, and run it. The |
9 requirements are the same regardless of whether or not the module uses PNaCl, | 9 requirements are the same regardless of whether or not the module uses PNaCl, |
10 but depend on whether the module is written in C or C++. | 10 but depend on whether the module is written in C or C++. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 * Code that defines your own Instance class (derived from the ``pp:Instance`` | 133 * Code that defines your own Instance class (derived from the ``pp:Instance`` |
134 class) | 134 class) |
135 | 135 |
136 In the "Hello tutorial" example (in the ``getting_started/part1`` directory of | 136 In the "Hello tutorial" example (in the ``getting_started/part1`` directory of |
137 the NaCl SDK), these three components are specified in the file | 137 the NaCl SDK), these three components are specified in the file |
138 ``hello_tutorial.cc``. Here is the factory function: | 138 ``hello_tutorial.cc``. Here is the factory function: |
139 | 139 |
140 .. naclcode:: | 140 .. naclcode:: |
141 | 141 |
142 namespace pp { | 142 namespace pp { |
143 Module* CreateModule() { | 143 Module* CreateModule() { |
144 return new HelloTutorialModule(); | 144 return new HelloTutorialModule(); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 The ``CreateModule()`` factory function is the main binding point between a | 148 The ``CreateModule()`` factory function is the main binding point between a |
149 module and the browser, and serves as the entry point into the module. The | 149 module and the browser, and serves as the entry point into the module. The |
150 browser calls ``CreateModule()`` when a module is first loaded; this function | 150 browser calls ``CreateModule()`` when a module is first loaded; this function |
151 returns a Module object derived from the ``pp::Module`` class. The browser keeps | 151 returns a Module object derived from the ``pp::Module`` class. The browser keeps |
152 a singleton of the Module object. | 152 a singleton of the Module object. |
153 | 153 |
154 Below is the Module class from the "Hello tutorial" example: | 154 Below is the Module class from the "Hello tutorial" example: |
155 | 155 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 instance's ``HandleMessage()`` function every time the JavaScript code in an | 188 instance's ``HandleMessage()`` function every time the JavaScript code in an |
189 application calls ``postMessage()`` to send a message to the instance. See the | 189 application calls ``postMessage()`` to send a message to the instance. See the |
190 :doc:`Native Client messaging system<message-system>` for more information about | 190 :doc:`Native Client messaging system<message-system>` for more information about |
191 how to send messages between JavaScript code and Native Client modules. | 191 how to send messages between JavaScript code and Native Client modules. |
192 | 192 |
193 While the ``CreateModule()`` factory function, the ``Module`` class, and the | 193 While the ``CreateModule()`` factory function, the ``Module`` class, and the |
194 ``Instance`` class are required for a Native Client application, the code | 194 ``Instance`` class are required for a Native Client application, the code |
195 samples shown above don't actually do anything. Subsequent documents in the | 195 samples shown above don't actually do anything. Subsequent documents in the |
196 Developer's Guide build on these code samples and add more interesting | 196 Developer's Guide build on these code samples and add more interesting |
197 functionality. | 197 functionality. |
OLD | NEW |