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 // Javascript module pattern: | 5 // Javascript module pattern: |
6 // see http://en.wikipedia.org/wiki/Unobtrusive_JavaScript#Namespaces | 6 // see http://en.wikipedia.org/wiki/Unobtrusive_JavaScript#Namespaces |
7 // In essence, we define an anonymous function which is immediately called and | 7 // In essence, we define an anonymous function which is immediately called and |
8 // returns a new object. The new object contains only the exported definitions; | 8 // returns a new object. The new object contains only the exported definitions; |
9 // all other definitions in the anonymous function are inaccessible to external | 9 // all other definitions in the anonymous function are inaccessible to external |
10 // code. | 10 // code. |
11 var common = (function () { | 11 var common = (function () { |
12 | 12 |
13 /** | 13 /** |
14 * Create the Native Client <embed> element as a child of the DOM element | 14 * Create the Native Client <embed> element as a child of the DOM element |
15 * named "listener". | 15 * named "listener". |
16 * | 16 * |
17 * @param {string} name The name of the example. | 17 * @param {string} name The name of the example. |
18 * @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc. | 18 * @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc. |
19 * @param {number} width The width to create the plugin. | 19 * @param {number} width The width to create the plugin. |
20 * @param {number} height The height to create the plugin. | 20 * @param {number} height The height to create the plugin. |
21 */ | 21 */ |
22 function createNaClModule(name, tool, width, height) { | 22 function createNaClModule(name, tool, config, width, height) { |
23 var moduleEl = document.createElement('embed'); | 23 var moduleEl = document.createElement('embed'); |
24 moduleEl.setAttribute('name', 'nacl_module'); | 24 moduleEl.setAttribute('name', 'nacl_module'); |
25 moduleEl.setAttribute('id', 'nacl_module'); | 25 moduleEl.setAttribute('id', 'nacl_module'); |
26 moduleEl.setAttribute('width', width); | 26 moduleEl.setAttribute('width', width); |
27 moduleEl.setAttribute('height',height); | 27 moduleEl.setAttribute('height',height); |
28 moduleEl.setAttribute('src', tool + '/' + name + '.nmf'); | 28 moduleEl.setAttribute('src', tool + '/' + config + '/' + name + '.nmf'); |
29 moduleEl.setAttribute('type', 'application/x-nacl'); | 29 moduleEl.setAttribute('type', 'application/x-nacl'); |
30 | 30 |
31 // The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' | 31 // The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' |
32 // and a 'message' event listener attached. This wrapping method is used | 32 // and a 'message' event listener attached. This wrapping method is used |
33 // instead of attaching the event listeners directly to the <EMBED> element | 33 // instead of attaching the event listeners directly to the <EMBED> element |
34 // to ensure that the listeners are active before the NaCl module 'load' | 34 // to ensure that the listeners are active before the NaCl module 'load' |
35 // event fires. | 35 // event fires. |
36 var listenerDiv = document.getElementById('listener'); | 36 var listenerDiv = document.getElementById('listener'); |
37 listenerDiv.appendChild(moduleEl); | 37 listenerDiv.appendChild(moduleEl); |
38 } | 38 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 * Common entrypoint for NaCl module loading. This function should be hooked | 141 * Common entrypoint for NaCl module loading. This function should be hooked |
142 * up to the document body's onload event, for example: | 142 * up to the document body's onload event, for example: |
143 * | 143 * |
144 * <body onload="common.onload(...)"> | 144 * <body onload="common.onload(...)"> |
145 * | 145 * |
146 * @param {string} name The name of the example. | 146 * @param {string} name The name of the example. |
147 * @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc. | 147 * @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc. |
148 * @param {number} width The width to create the plugin. | 148 * @param {number} width The width to create the plugin. |
149 * @param {number} height The height to create the plugin. | 149 * @param {number} height The height to create the plugin. |
150 */ | 150 */ |
151 function pageDidLoad(name, tool, width, height) { | 151 function pageDidLoad(name, tool, config, width, height) { |
152 // If the page loads before the Native Client module loads, then set the | 152 // If the page loads before the Native Client module loads, then set the |
153 // status message indicating that the module is still loading. Otherwise, | 153 // status message indicating that the module is still loading. Otherwise, |
154 // do not change the status message. | 154 // do not change the status message. |
155 updateStatus('Page loaded.'); | 155 updateStatus('Page loaded.'); |
156 if (common.naclModule == null) { | 156 if (common.naclModule == null) { |
157 updateStatus('Creating embed: ' + tool) | 157 updateStatus('Creating embed: ' + tool) |
158 | 158 |
159 // We use a non-zero sized embed to give Chrome space to place the bad | 159 // We use a non-zero sized embed to give Chrome space to place the bad |
160 // plug-in graphic, if there is a problem. | 160 // plug-in graphic, if there is a problem. |
161 width = typeof width !== 'undefined' ? width : 200; | 161 width = typeof width !== 'undefined' ? width : 200; |
162 height = typeof height !== 'undefined' ? height : 200; | 162 height = typeof height !== 'undefined' ? height : 200; |
163 createNaClModule(name, tool, width, height); | 163 createNaClModule(name, tool, config, width, height); |
164 attachDefaultListeners(); | 164 attachDefaultListeners(); |
165 } else { | 165 } else { |
166 // It's possible that the Native Client module onload event fired | 166 // It's possible that the Native Client module onload event fired |
167 // before the page's onload event. In this case, the status message | 167 // before the page's onload event. In this case, the status message |
168 // will reflect 'SUCCESS', but won't be displayed. This call will | 168 // will reflect 'SUCCESS', but won't be displayed. This call will |
169 // display the current message. | 169 // display the current message. |
170 updateStatus('Waiting.'); | 170 updateStatus('Waiting.'); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
(...skipping 24 matching lines...) Expand all Loading... |
198 naclModule: null, | 198 naclModule: null, |
199 | 199 |
200 onload: pageDidLoad, | 200 onload: pageDidLoad, |
201 attachDefaultListeners: attachDefaultListeners, | 201 attachDefaultListeners: attachDefaultListeners, |
202 createNaClModule: createNaClModule, | 202 createNaClModule: createNaClModule, |
203 hideModule: hideModule, | 203 hideModule: hideModule, |
204 updateStatus: updateStatus | 204 updateStatus: updateStatus |
205 }; | 205 }; |
206 | 206 |
207 }()); | 207 }()); |
OLD | NEW |