Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1457)

Side by Side Diff: ports/ipython_extension/background.js

Issue 165473002: Adds an IPython kernel running in NaCl, and a wrapper as a Chrome extension. Base URL: https://naclports.googlecode.com/svn/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1
Sam Clegg 2014/02/18 23:39:31 Please add copyright to all files in naclports.
2 var createEmbed = function(id) {
3 var embed = document.createElement('object');
4 embed.width = 0;
5 embed.height = 0;
6 embed.data = 'python.nmf';
7 embed.type = 'application/x-nacl';
8 document.body.appendChild(embed);
9
10 return embed;
11 };
12
13
14 chrome.runtime.onConnectExternal.addListener(function(port) {
15 var embed = null;
16 // Create an embed element that runs the NaCl kernel
17
18 port.onMessage.addListener(function(msg) {
19 if (msg.type === 'create') {
20 embed = createEmbed(msg.id);
21
22 // forward all messages across port
23 embed.addEventListener('message', function(e) {
24 var msg = e.data;
25 msg.type = 'message';
26 port.postMessage(msg);
27 });
28 embed.addEventListener('progress', function(e) {
29 var progress = Math.round(100 * e.loaded / e.total);
30 if (isNaN(progress)) { progress = 100; }
31 port.postMessage({type: 'progress', progress: progress});
32 });
33 embed.addEventListener('loadend', function(e) {
34 port.postMessage({'type': 'loadend'})
35 });
36 embed.addEventListener('crash', function() {
37 port.disconnect();
38 });
39 } else if (msg.type === 'message') {
40 embed.postMessage({json: msg.json});
41 }
42 });
43 port.onDisconnect.addListener(function() {
44 console.log("disconnected");
45 });
46 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698