diff --git a/customize.dist/src/less2/loading.less b/customize.dist/src/less2/loading.less
index 80d34384f..6a14fe29b 100644
--- a/customize.dist/src/less2/loading.less
+++ b/customize.dist/src/less2/loading.less
@@ -1,3 +1,8 @@
+/*
+WARNING: THIS FILE DOES NOTHING
+It exists only as a proposal of what CSS you should use in loading.js
+The CSS inside of loading.js is precompiled in order to save 200ish milliseconds to the loading screen.
+*/
@import (once) "./include/colortheme.less";
@import (once) "./include/browser.less";
diff --git a/www/code/inner.html b/www/code/inner.html
index 80d1cb707..485e06455 100644
--- a/www/code/inner.html
+++ b/www/code/inner.html
@@ -2,7 +2,7 @@
',
'
',
'
',
diff --git a/www/common/sframe-boot.js b/www/common/sframe-boot.js
index 4489db89f..0f541f7ee 100644
--- a/www/common/sframe-boot.js
+++ b/www/common/sframe-boot.js
@@ -2,36 +2,10 @@
// Note that this file is meant to be executed only inside of a sandbox iframe.
//
// IF YOU EDIT THIS FILE, bump the version (replace 1.3 in the following command with the next version.)
-// grep -nr '/common/sframe-boot.js?ver=' | sed 's/:.*$//' | while read x; do \
+// grep -nr '/common/sframe-boot.js?ver=' | sed 's/:.*$//' | grep -v 'sframe-boot.js' | while read x; do \
// sed -i -e 's@/common/sframe-boot.js?ver=[^"]*@/common/sframe-boot.js?ver=1.3@' $x; done
;(function () {
var afterLoaded = function (req) {
- var localStorage = {};
- if (req.cfg && req.cfg.urlArgs) {
- try {
- localStorage = window.localStorage;
- if (localStorage['CRYPTPAD_VERSION'] !== req.cfg.urlArgs) {
- // new version, flush
- Object.keys(localStorage).forEach(function (k) {
- if (!k.indexOf('CRYPTPAD_CACHE_')) { delete localStorage[k]; }
- });
- localStorage['CRYPTPAD_VERSION'] = req.cfg.urlArgs;
- }
- } catch (e) {
- console.error(e);
- localStorage = {};
- }
- }
- window.cryptpadCache = Object.freeze({
- put: function (k, v, cb) {
- cb = cb || function () { };
- setTimeout(function () { localStorage['CRYPTPAD_CACHE_' + k] = v; cb(); });
- },
- get: function (k, cb) {
- if (!cb) { throw new Error(); }
- setTimeout(function () { cb(localStorage['CRYPTPAD_CACHE_' + k]); });
- }
- });
req.cfg = req.cfg || {};
if (req.pfx) {
req.cfg.onNodeCreated = function (node /*, config, module, path*/) {
@@ -54,17 +28,34 @@ var afterLoaded = function (req) {
clearInterval(intr);
txid = {};
window.removeEventListener('message', onReply);
+ data.cache = data.cache || {};
+ var updated = {};
+ window.cryptpadCache = {
+ get: function (k, cb) {
+ setTimeout(function () { cb(data.cache[k]); });
+ },
+ put: function (k, v, cb) {
+ cb = cb || function () { };
+ updated[k] = v;
+ setTimeout(function () { data.cache[k] = v; cb(); });
+ },
+ updated: updated,
+ cache: data.cache
+ };
require(['/common/sframe-boot2.js'], function () { });
};
window.addEventListener('message', onReply);
};
-var intr = setInterval(function () {
+var load0 = function () {
try {
var req = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
- clearInterval(intr);
afterLoaded(req);
- } catch (e) { console.error(e); }
-}, 100);
+ } catch (e) {
+ console.error(e);
+ setTimeout(load0, 100);
+ }
+};
+load0();
}());
diff --git a/www/common/sframe-boot2.js b/www/common/sframe-boot2.js
index e6845bcbe..dd0370ca8 100644
--- a/www/common/sframe-boot2.js
+++ b/www/common/sframe-boot2.js
@@ -20,5 +20,7 @@ define(['/common/requireconfig.js'], function (RequireConfig) {
window.__defineGetter__('localStorage', function () { return mkFakeStore(); });
window.__defineGetter__('sessionStorage', function () { return mkFakeStore(); });
+ window.CRYPTPAD_INSIDE = true;
+
require([document.querySelector('script[data-bootload]').getAttribute('data-bootload')]);
});
diff --git a/www/common/sframe-channel.js b/www/common/sframe-channel.js
index 300491e1f..a091452c3 100644
--- a/www/common/sframe-channel.js
+++ b/www/common/sframe-channel.js
@@ -8,7 +8,7 @@ define([
return Math.random().toString(16).replace('0.', '') + Math.random().toString(16).replace('0.', '');
};
- var create = function (ow, cb, isSandbox) {
+ var create = function (ow, cb, isSandbox, sendData) {
var otherWindow;
var evReady = Util.mkEvent(true);
var handlers = {};
@@ -47,7 +47,6 @@ define([
// Fire an event. channel.event('EV_SOMETHING', { args: "whatever" });
var event = chan.event = function (e, content) {
- if (!otherWindow) { throw new Error('not yet initialized'); }
if (!SFrameProtocol[e]) {
throw new Error('please only fire events that are defined in sframe-protocol.js');
}
@@ -63,7 +62,6 @@ define([
// If the type is a query, your handler will be invoked with a reply function that takes
// one argument (the content to reply with).
chan.on = function (queryType, handler, quiet) {
- if (!otherWindow && !quiet) { throw new Error('not yet initialized'); }
if (!SFrameProtocol[queryType]) {
throw new Error('please only register handlers which are defined in sframe-protocol.js');
}
@@ -85,7 +83,6 @@ define([
// when that handler is first registered.
// channel.whenReg('Q_SOMETHING', function () { ...query Q_SOMETHING?... });
chan.whenReg = function (queryType, cb, always) {
- if (!otherWindow) { throw new Error('not yet initialized'); }
if (!SFrameProtocol[queryType]) {
throw new Error('please only register handlers which are defined in sframe-protocol.js');
}
@@ -109,7 +106,8 @@ define([
delete callWhenRegistered[content];
}
insideHandlers.push(content);
- }, true);
+ });
+ chan.whenReg('EV_REGISTER_HANDLER', evReady.fire);
// Make sure both iframes are ready
chan.onReady = function (h) {
@@ -131,8 +129,9 @@ define([
//console.log(msg);
} else if (!otherWindow) {
otherWindow = ow;
- evReady.fire();
- ow.postMessage(JSON.stringify({ txid: data.txid }), '*');
+ sendData = sendData || {};
+ sendData.txid = data.txid;
+ ow.postMessage(JSON.stringify(sendData), '*');
cb(chan);
} else if (typeof(data.q) === 'string' && handlers[data.q]) {
handlers[data.q].forEach(function (f) {
diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js
index 32143cb8f..00bd0e0ea 100644
--- a/www/common/sframe-common-outer.js
+++ b/www/common/sframe-common-outer.js
@@ -34,12 +34,34 @@ define([
Crypto = _Crypto;
Cryptget = _Cryptget;
FilePicker = _FilePicker;
+
+ if (localStorage.CRYPTPAD_URLARGS !== ApiConfig.requireConf.urlArgs) {
+ console.log("New version, flushing cache");
+ Object.keys(localStorage).forEach(function (k) {
+ if (k.indexOf('CRYPTPAD_CACHE|') !== 0) { return; }
+ delete localStorage[k];
+ });
+ localStorage.CRYPTPAD_URLARGS = ApiConfig.requireConf.urlArgs;
+ }
+ var cache = {};
+ Object.keys(localStorage).forEach(function (k) {
+ if (k.indexOf('CRYPTPAD_CACHE|') !== 0) { return; }
+ cache[k.slice(('CRYPTPAD_CACHE|').length)] = localStorage[k];
+ });
+
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
sframeChan = sfc;
- }));
+ }), false, { cache: cache });
Cryptpad.ready(waitFor());
}));
}).nThen(function (waitFor) {
+
+ sframeChan.on('EV_CACHE_PUT', function (x) {
+ Object.keys(x).forEach(function (k) {
+ localStorage['CRYPTPAD_CACHE|' + k] = x[k];
+ });
+ });
+
secret = Cryptpad.getSecrets();
if (!secret.channel) {
// New pad: create a new random channel id
diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js
index 35e2f3577..3df0e910e 100644
--- a/www/common/sframe-common.js
+++ b/www/common/sframe-common.js
@@ -271,6 +271,19 @@ define([
}).nThen(function () {
ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan);
+ ctx.sframeChan.whenReg('EV_CACHE_PUT', function () {
+ if (Object.keys(window.cryptpadCache.updated).length) {
+ ctx.sframeChan.event('EV_CACHE_PUT', window.cryptpadCache.updated);
+ }
+ window.cryptpadCache._put = window.cryptpadCache.put;
+ window.cryptpadCache.put = function (k, v, cb) {
+ window.cryptpadCache._put(k, v, cb);
+ var x = {};
+ x[k] = v;
+ ctx.sframeChan.event('EV_CACHE_PUT', x);
+ };
+ });
+
UI.addTooltips();
ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); });
diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js
index 1be9d7476..cab662df0 100644
--- a/www/common/sframe-protocol.js
+++ b/www/common/sframe-protocol.js
@@ -127,4 +127,7 @@ define({
// Present mode URL
'Q_PRESENT_URL_GET_VALUE': true,
'EV_PRESENT_URL_SET_VALUE': true,
+
+ // Put one or more entries to the cache which will go in localStorage.
+ 'EV_CACHE_PUT': true,
});
diff --git a/www/file/inner.html b/www/file/inner.html
index 3fce59ddd..90137b8b0 100644
--- a/www/file/inner.html
+++ b/www/file/inner.html
@@ -2,7 +2,7 @@
-
+