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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ports/ipython_extension/background.js
diff --git a/ports/ipython_extension/background.js b/ports/ipython_extension/background.js
new file mode 100644
index 0000000000000000000000000000000000000000..98bab105de2fc982e8c5c8a5a4062cb3a4b07a95
--- /dev/null
+++ b/ports/ipython_extension/background.js
@@ -0,0 +1,46 @@
+
Sam Clegg 2014/02/18 23:39:31 Please add copyright to all files in naclports.
+var createEmbed = function(id) {
+ var embed = document.createElement('object');
+ embed.width = 0;
+ embed.height = 0;
+ embed.data = 'python.nmf';
+ embed.type = 'application/x-nacl';
+ document.body.appendChild(embed);
+
+ return embed;
+};
+
+
+chrome.runtime.onConnectExternal.addListener(function(port) {
+ var embed = null;
+ // Create an embed element that runs the NaCl kernel
+
+ port.onMessage.addListener(function(msg) {
+ if (msg.type === 'create') {
+ embed = createEmbed(msg.id);
+
+ // forward all messages across port
+ embed.addEventListener('message', function(e) {
+ var msg = e.data;
+ msg.type = 'message';
+ port.postMessage(msg);
+ });
+ embed.addEventListener('progress', function(e) {
+ var progress = Math.round(100 * e.loaded / e.total);
+ if (isNaN(progress)) { progress = 100; }
+ port.postMessage({type: 'progress', progress: progress});
+ });
+ embed.addEventListener('loadend', function(e) {
+ port.postMessage({'type': 'loadend'})
+ });
+ embed.addEventListener('crash', function() {
+ port.disconnect();
+ });
+ } else if (msg.type === 'message') {
+ embed.postMessage({json: msg.json});
+ }
+ });
+ port.onDisconnect.addListener(function() {
+ console.log("disconnected");
+ });
+});

Powered by Google App Engine
This is Rietveld 408576698