OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /// @file | 5 /// @file |
6 /// This example demonstrates loading, running and scripting a very simple NaCl | 6 /// This example demonstrates loading, running and scripting a very simple NaCl |
7 /// module. To load the NaCl module, the browser first looks for the | 7 /// module. To load the NaCl module, the browser first looks for the |
8 /// CreateModule() factory method (at the end of this file). It calls | 8 /// CreateModule() factory method (at the end of this file). It calls |
9 /// CreateModule() once to load the module code from your .nexe. After the | 9 /// CreateModule() once to load the module code from your .nexe. After the |
10 /// .nexe code is loaded, CreateModule() is not called again. | 10 /// .nexe code is loaded, CreateModule() is not called again. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } else if (message.find(kReverseTextMethodId) == 0) { | 87 } else if (message.find(kReverseTextMethodId) == 0) { |
88 // The argument to reverseText is everything after the first ':'. | 88 // The argument to reverseText is everything after the first ':'. |
89 size_t sep_pos = message.find_first_of(kMessageArgumentSeparator); | 89 size_t sep_pos = message.find_first_of(kMessageArgumentSeparator); |
90 if (sep_pos != std::string::npos) { | 90 if (sep_pos != std::string::npos) { |
91 std::string string_arg = message.substr(sep_pos + 1); | 91 std::string string_arg = message.substr(sep_pos + 1); |
92 return_var = MarshallReverseText(string_arg); | 92 return_var = MarshallReverseText(string_arg); |
93 } | 93 } |
94 } | 94 } |
95 // Post the return result back to the browser. Note that HandleMessage() is | 95 // Post the return result back to the browser. Note that HandleMessage() is |
96 // always called on the main thread, so it's OK to post the return message | 96 // always called on the main thread, so it's OK to post the return message |
97 // directly from here. The return post is asynhronous: PostMessage returns | 97 // directly from here. The return post is asynchronous: PostMessage returns |
98 // immediately. | 98 // immediately. |
99 PostMessage(return_var); | 99 PostMessage(return_var); |
100 } | 100 } |
101 | 101 |
102 /// The Module class. The browser calls the CreateInstance() method to create | 102 /// The Module class. The browser calls the CreateInstance() method to create |
103 /// an instance of your NaCl module on the web page. The browser creates a new | 103 /// an instance of your NaCl module on the web page. The browser creates a new |
104 /// instance for each <embed> tag with | 104 /// instance for each <embed> tag with |
105 /// <code>type="application/x-nacl"</code>. | 105 /// <code>type="application/x-nacl"</code>. |
106 class HelloWorldModule : public pp::Module { | 106 class HelloWorldModule : public pp::Module { |
107 public: | 107 public: |
(...skipping 18 matching lines...) Expand all Loading... |
126 /// The browser keeps a singleton of this module. It calls the | 126 /// The browser keeps a singleton of this module. It calls the |
127 /// CreateInstance() method on the object you return to make instances. There | 127 /// CreateInstance() method on the object you return to make instances. There |
128 /// is one instance per <embed> tag on the page. This is the main binding | 128 /// is one instance per <embed> tag on the page. This is the main binding |
129 /// point for your NaCl module with the browser. | 129 /// point for your NaCl module with the browser. |
130 /// @return new HelloWorldModule. | 130 /// @return new HelloWorldModule. |
131 /// @note The browser is responsible for deleting returned @a Module. | 131 /// @note The browser is responsible for deleting returned @a Module. |
132 Module* CreateModule() { | 132 Module* CreateModule() { |
133 return new hello_world::HelloWorldModule(); | 133 return new hello_world::HelloWorldModule(); |
134 } | 134 } |
135 } // namespace pp | 135 } // namespace pp |
OLD | NEW |