Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a new JsPy module every time the editor is expanded. (To work …
…around crashes.)
- Loading branch information
1 parent
a01632a
commit 3ad8dd2
Showing
9 changed files
with
132 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//HACK: some way to reload module? | ||
|
||
var jspy; | ||
|
||
var DEBUG = true; | ||
|
||
var waiting_callback; | ||
|
||
function initModule(callback) { | ||
if (DEBUG) console.log('JsPy init'); | ||
if (jspy) { | ||
jspy.parentNode.removeChild(jspy); | ||
} | ||
jspy = document.createElement('embed'); | ||
jspy.src = '/jspy/jspy.nmf'; | ||
jspy.type = 'application/x-nacl'; | ||
document.body.appendChild(jspy); | ||
waiting_callback = function() { console.error('Should never be called'); }; | ||
jspy.addEventListener('load', function() { initModuleMessageHandler(callback); }); | ||
} | ||
|
||
function initModuleMessageHandler(initCallback) { | ||
if (DEBUG) console.log('JsPy Module loaded'); | ||
waiting_callback = null; | ||
jspy.addEventListener('message', messageHandler); | ||
initCallback(); | ||
} | ||
|
||
function messageHandler(e) { | ||
if (DEBUG) console.log('From JsPy:', e.data); | ||
if (!waiting_callback) { | ||
console.error('No waiting callback'); | ||
} else { | ||
waiting_callback(e.data); | ||
waiting_callback = null; | ||
} | ||
} | ||
|
||
function handleContentScriptMessage(msg, sender, sendResponse) { | ||
if (DEBUG) console.log('To JsPy:', msg); | ||
if (msg === 'init') { | ||
initModule(sendResponse); | ||
return; | ||
} | ||
if (waiting_callback) { | ||
sendResponse('stderr:JSPY error: outstanding callback'); | ||
return; | ||
} | ||
waiting_callback = sendResponse; | ||
jspy.postMessage(msg); | ||
} | ||
|
||
|
||
chrome.extension.onRequest.addListener(handleContentScriptMessage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters