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, 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 + '/' + name + '.nmf'); |
29 moduleEl.setAttribute('type', 'application/x-nacl'); | 29 if (tool == 'win') |
| 30 moduleEl.setAttribute('type', 'application/x-ppapi'); |
| 31 else |
| 32 moduleEl.setAttribute('type', 'application/x-nacl'); |
30 | 33 |
31 // The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' | 34 // 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 | 35 // and a 'message' event listener attached. This wrapping method is used |
33 // instead of attaching the event listeners directly to the <EMBED> element | 36 // instead of attaching the event listeners directly to the <EMBED> element |
34 // to ensure that the listeners are active before the NaCl module 'load' | 37 // to ensure that the listeners are active before the NaCl module 'load' |
35 // event fires. | 38 // event fires. |
36 var listenerDiv = document.getElementById('listener'); | 39 var listenerDiv = document.getElementById('listener'); |
37 listenerDiv.appendChild(moduleEl); | 40 listenerDiv.appendChild(moduleEl); |
38 } | 41 } |
39 | 42 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 naclModule: null, | 201 naclModule: null, |
199 | 202 |
200 onload: pageDidLoad, | 203 onload: pageDidLoad, |
201 attachDefaultListeners: attachDefaultListeners, | 204 attachDefaultListeners: attachDefaultListeners, |
202 createNaClModule: createNaClModule, | 205 createNaClModule: createNaClModule, |
203 hideModule: hideModule, | 206 hideModule: hideModule, |
204 updateStatus: updateStatus | 207 updateStatus: updateStatus |
205 }; | 208 }; |
206 | 209 |
207 }()); | 210 }()); |
OLD | NEW |