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 {string} path Directory name where .nmf file can be found. | 19 * @param {string} path Directory name where .nmf file can be found. |
20 * @param {number} width The width to create the plugin. | 20 * @param {number} width The width to create the plugin. |
21 * @param {number} height The height to create the plugin. | 21 * @param {number} height The height to create the plugin. |
| 22 * @param {Object} optional dictionary of args to send to DidCreateInstance |
22 */ | 23 */ |
23 function createNaClModule(name, tool, path, width, height) { | 24 function createNaClModule(name, tool, path, width, height, args) { |
24 var moduleEl = document.createElement('embed'); | 25 var moduleEl = document.createElement('embed'); |
25 moduleEl.setAttribute('name', 'nacl_module'); | 26 moduleEl.setAttribute('name', 'nacl_module'); |
26 moduleEl.setAttribute('id', 'nacl_module'); | 27 moduleEl.setAttribute('id', 'nacl_module'); |
27 moduleEl.setAttribute('width', width); | 28 moduleEl.setAttribute('width', width); |
28 moduleEl.setAttribute('height',height); | 29 moduleEl.setAttribute('height',height); |
29 moduleEl.setAttribute('src', path + '/' + name + '.nmf'); | 30 moduleEl.setAttribute('src', path + '/' + name + '.nmf'); |
| 31 |
| 32 // Add any optional arguments |
| 33 if (args) { |
| 34 for (var key in args) { |
| 35 moduleEl.setAttribute(key, args[key]) |
| 36 } |
| 37 } |
| 38 |
30 // For NaCL modules use application/x-nacl. | 39 // For NaCL modules use application/x-nacl. |
31 var mimetype = 'application/x-nacl'; | 40 var mimetype = 'application/x-nacl'; |
32 var isHost = tool == 'win' || tool == 'linux' || tool == 'mac'; | 41 var isHost = tool == 'win' || tool == 'linux' || tool == 'mac'; |
33 if (isHost) { | 42 if (isHost) { |
34 // For non-nacl PPAPI plugins use the x-ppapi-debug/release | 43 // For non-nacl PPAPI plugins use the x-ppapi-debug/release |
35 // mime type. | 44 // mime type. |
36 if (path.toLowerCase().indexOf('release') != -1) | 45 if (path.toLowerCase().indexOf('release') != -1) |
37 mimetype = 'application/x-ppapi-release'; | 46 mimetype = 'application/x-ppapi-release'; |
38 else | 47 else |
39 mimetype = 'application/x-ppapi-debug'; | 48 mimetype = 'application/x-ppapi-debug'; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } else if (typeof window.domContentLoaded !== 'undefined') { | 254 } else if (typeof window.domContentLoaded !== 'undefined') { |
246 loadFunction = window.domContentLoaded; | 255 loadFunction = window.domContentLoaded; |
247 } | 256 } |
248 | 257 |
249 if (loadFunction) { | 258 if (loadFunction) { |
250 loadFunction(body.dataset.name, body.dataset.tc, body.dataset.path, | 259 loadFunction(body.dataset.name, body.dataset.tc, body.dataset.path, |
251 body.dataset.width, body.dataset.height); | 260 body.dataset.width, body.dataset.height); |
252 } | 261 } |
253 } | 262 } |
254 }); | 263 }); |
OLD | NEW |