wip
parent
65dfd99171
commit
35a55a15ed
@ -1,10 +1,9 @@
|
|||||||
// Stage 0, this gets cached which means we can't change it. boot2-sframe.js is changable.
|
// Stage 0, this gets cached which means we can't change it. boot2-sframe.js is changable.
|
||||||
// Note that this file is meant to be executed only inside of a sandbox iframe.
|
// Note that this file is meant to be executed only inside of a sandbox iframe.
|
||||||
window.addEventListener('message', function (msg) {
|
window.addEventListener('message', function (msg) {
|
||||||
var data = msg.data;
|
var data = JSON.parse(msg.data);
|
||||||
if (data.q !== 'INIT') { return; }
|
if (data.q !== 'INIT') { return; }
|
||||||
msg.source.postMessage({ txid: data.txid, res: 'OK' }, '*');
|
msg.source.postMessage({ txid: data.txid, content: 'OK' }, '*');
|
||||||
if (data.requireConf) { require.config(data.requireConf); }
|
if (data.content && data.content.requireConf) { require.config(data.content.requireConf); }
|
||||||
require(['/common/sframe-boot2.js'], function () { });
|
require(['/common/sframe-boot2.js'], function () { });
|
||||||
});
|
});
|
||||||
console.log('boot');
|
|
@ -0,0 +1,46 @@
|
|||||||
|
// This file provides the internal API for talking from inside of the sandbox iframe
|
||||||
|
// The external API is in sframe-ctrl.js
|
||||||
|
define([], function () {
|
||||||
|
var iframe;
|
||||||
|
var handlers = {};
|
||||||
|
var queries = {};
|
||||||
|
var module = { exports: {} };
|
||||||
|
|
||||||
|
var mkTxid = function () {
|
||||||
|
return Math.random().toString(16).replace('0.', '') + Math.random().toString(16).replace('0.', '');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.query = function (q, content, cb) {
|
||||||
|
if (!iframe) { throw new Error('not yet initialized'); }
|
||||||
|
var txid = mkTxid();
|
||||||
|
var timeout = setTimeout(function () {
|
||||||
|
delete queries[txid];
|
||||||
|
cb("Timeout making query " + q);
|
||||||
|
});
|
||||||
|
queries[txid] = function (data, msg) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
delete queries[txid];
|
||||||
|
cb(undefined, data.content, msg);
|
||||||
|
};
|
||||||
|
iframe.contentWindow.postMessage(JSON.stringify({
|
||||||
|
txid: txid,
|
||||||
|
content: content,
|
||||||
|
q: q
|
||||||
|
}), '*');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.registerHandler = function (queryType, handler) {
|
||||||
|
if (typeof(handlers[queryType]) !== 'undefined') { throw new Error('already registered'); }
|
||||||
|
handlers[queryType] = function (msg) {
|
||||||
|
var data = JSON.parse(msg.data);
|
||||||
|
handler(data.content, function (replyContent) {
|
||||||
|
msg.source.postMessage(JSON.stringify({
|
||||||
|
txid: data.txid,
|
||||||
|
content: replyContent
|
||||||
|
}), '*');
|
||||||
|
}, msg);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return module.exports;
|
||||||
|
});
|
@ -0,0 +1,5 @@
|
|||||||
|
// This file defines all of the RPC calls
|
||||||
|
// The internal API is in sframe-channel.js
|
||||||
|
define({
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue