Secure share modal

pull/1/head
yflory 6 years ago
parent bfba5ff33b
commit fb0827107b

@ -32,6 +32,14 @@
height: 100%; height: 100%;
border: 0; border: 0;
} }
#sbox-share-iframe {
position: fixed;
top:0; left:0;
bottom:0; right:0;
width:100%;
height: 100%;
border: 0;
}
</style> </style>
</head> </head>
<body> <body>

@ -351,6 +351,9 @@ define([
var close = function (el) { var close = function (el) {
var $el = $(el).fadeOut(150, function () { var $el = $(el).fadeOut(150, function () {
$el.detach(); $el.detach();
if (opt.onClose) {
opt.onClose();
}
}); });
}; };

@ -205,7 +205,7 @@ define([
if (content === oldThumbnailState) { return; } if (content === oldThumbnailState) { return; }
oldThumbnailState = content; oldThumbnailState = content;
Thumb.fromDOM(opts, function (err, b64) { Thumb.fromDOM(opts, function (err, b64) {
Thumb.setPadThumbnail(common, opts.href, null, b64); Thumb.setPadThumbnail(common, opts.type, null, b64);
}); });
}; };
var nafa = Util.notAgainForAnother(mkThumbnail, Thumb.UPDATE_INTERVAL); var nafa = Util.notAgainForAnother(mkThumbnail, Thumb.UPDATE_INTERVAL);
@ -243,11 +243,10 @@ define([
var getKey = function (type, channel) { var getKey = function (type, channel) {
return 'thumbnail-' + type + '-' + channel; return 'thumbnail-' + type + '-' + channel;
}; };
Thumb.setPadThumbnail = function (common, href, channel, b64, cb) { Thumb.setPadThumbnail = function (common, type, channel, b64, cb) {
cb = cb || function () {}; cb = cb || function () {};
var parsed = Hash.parsePadUrl(href);
channel = channel || common.getMetadataMgr().getPrivateData().channel; channel = channel || common.getMetadataMgr().getPrivateData().channel;
var k = getKey(parsed.type, channel); var k = getKey(type, channel);
common.setThumbnail(k, b64, cb); common.setThumbnail(k, b64, cb);
}; };
Thumb.displayThumbnail = function (common, href, channel, password, $container, cb) { Thumb.displayThumbnail = function (common, href, channel, password, $container, cb) {
@ -270,7 +269,7 @@ define([
if (!v) { if (!v) {
v = 'EMPTY'; v = 'EMPTY';
} }
Thumb.setPadThumbnail(common, href, hexFileName, v, function (err) { Thumb.setPadThumbnail(common, parsed.type, hexFileName, v, function (err) {
if (!metadata.thumbnail) { return; } if (!metadata.thumbnail) { return; }
addThumbnail(err, metadata.thumbnail, $container, cb); addThumbnail(err, metadata.thumbnail, $container, cb);
}); });

@ -322,6 +322,8 @@ define([
var hashes = config.hashes; var hashes = config.hashes;
var common = config.common; var common = config.common;
if (!hashes) { return; }
// Share link tab // Share link tab
var link = h('div.cp-share-modal', [ var link = h('div.cp-share-modal', [
h('label', Messages.share_linkAccess), h('label', Messages.share_linkAccess),
@ -403,7 +405,10 @@ define([
}, },
keys: [[13, 'ctrl']] keys: [[13, 'ctrl']]
}]; }];
var frameLink = UI.dialog.customModal(link, {buttons: linkButtons}); var frameLink = UI.dialog.customModal(link, {
buttons: linkButtons,
onClose: config.onClose
});
// Embed tab // Embed tab
var getEmbedValue = function () { var getEmbedValue = function () {
@ -464,7 +469,9 @@ define([
$(link).find('#cp-share-link-preview').val(getLinkValue(val)); $(link).find('#cp-share-link-preview').val(getLinkValue(val));
}); });
common.getMetadataMgr().onChange(function () { common.getMetadataMgr().onChange(function () {
hashes = common.getMetadataMgr().getPrivateData().availableHashes; // "hashes" is only available is the secure "share" app
hashes = common.getMetadataMgr().getPrivateData().hashes;
if (!hashes) { return; }
$(link).find('#cp-share-link-preview').val(getLinkValue()); $(link).find('#cp-share-link-preview').val(getLinkValue());
}); });
return tabs; return tabs;

@ -357,16 +357,14 @@ define([
UI.removeLoadingScreen(emitResize); UI.removeLoadingScreen(emitResize);
var privateDat = cpNfInner.metadataMgr.getPrivateData(); var privateDat = cpNfInner.metadataMgr.getPrivateData();
var hash = privateDat.availableHashes.editHash || var type = privateDat.app;
privateDat.availableHashes.viewHash;
var href = privateDat.pathname + '#' + hash;
if (AppConfig.textAnalyzer && textContentGetter) { if (AppConfig.textAnalyzer && textContentGetter) {
AppConfig.textAnalyzer(textContentGetter, privateDat.channel); AppConfig.textAnalyzer(textContentGetter, privateDat.channel);
} }
if (options.thumbnail && privateDat.thumbnails) { if (options.thumbnail && privateDat.thumbnails) {
if (hash) { if (type) {
options.thumbnail.href = href; options.thumbnail.type = type;
options.thumbnail.getContent = function () { options.thumbnail.getContent = function () {
if (!cpNfInner.chainpad) { return; } if (!cpNfInner.chainpad) { return; }
return cpNfInner.chainpad.getUserDoc(); return cpNfInner.chainpad.getUserDoc();

@ -19,6 +19,7 @@ define([
var SFrameChannel; var SFrameChannel;
var sframeChan; var sframeChan;
var FilePicker; var FilePicker;
var Share;
var Messaging; var Messaging;
var Notifier; var Notifier;
var Utils = { var Utils = {
@ -38,6 +39,7 @@ define([
'/common/cryptget.js', '/common/cryptget.js',
'/common/outer/worker-channel.js', '/common/outer/worker-channel.js',
'/filepicker/main.js', '/filepicker/main.js',
'/share/main.js',
'/common/common-messaging.js', '/common/common-messaging.js',
'/common/common-notifier.js', '/common/common-notifier.js',
'/common/common-hash.js', '/common/common-hash.js',
@ -49,7 +51,7 @@ define([
'/customize/application_config.js', '/customize/application_config.js',
'/common/test.js', '/common/test.js',
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel, ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel,
_FilePicker, _Messaging, _Notifier, _Hash, _Util, _Realtime, _FilePicker, _Share, _Messaging, _Notifier, _Hash, _Util, _Realtime,
_Constants, _Feedback, _LocalStore, _AppConfig, _Test) { _Constants, _Feedback, _LocalStore, _AppConfig, _Test) {
CpNfOuter = _CpNfOuter; CpNfOuter = _CpNfOuter;
Cryptpad = _Cryptpad; Cryptpad = _Cryptpad;
@ -57,6 +59,7 @@ define([
Cryptget = _Cryptget; Cryptget = _Cryptget;
SFrameChannel = _SFrameChannel; SFrameChannel = _SFrameChannel;
FilePicker = _FilePicker; FilePicker = _FilePicker;
Share = _Share;
Messaging = _Messaging; Messaging = _Messaging;
Notifier = _Notifier; Notifier = _Notifier;
Utils.Hash = _Hash; Utils.Hash = _Hash;
@ -269,9 +272,6 @@ define([
sessionStorage[Utils.Constants.displayPadCreationScreen]; sessionStorage[Utils.Constants.displayPadCreationScreen];
delete sessionStorage[Utils.Constants.displayPadCreationScreen]; delete sessionStorage[Utils.Constants.displayPadCreationScreen];
var updateMeta = function () { var updateMeta = function () {
// TODO availableHashes in privateData may need updates once we have
// a better privileges workflow
//console.log('EV_METADATA_UPDATE'); //console.log('EV_METADATA_UPDATE');
var metaObj, isTemplate; var metaObj, isTemplate;
nThen(function (waitFor) { nThen(function (waitFor) {
@ -290,12 +290,12 @@ define([
type: cfg.type || parsed.type type: cfg.type || parsed.type
}; };
var additionalPriv = { var additionalPriv = {
app: parsed.type,
accountName: Utils.LocalStore.getAccountName(), accountName: Utils.LocalStore.getAccountName(),
origin: window.location.origin, origin: window.location.origin,
pathname: window.location.pathname, pathname: window.location.pathname,
fileHost: ApiConfig.fileHost, fileHost: ApiConfig.fileHost,
readOnly: readOnly, readOnly: readOnly,
availableHashes: hashes,
isTemplate: isTemplate, isTemplate: isTemplate,
feedbackAllowed: Utils.Feedback.state, feedbackAllowed: Utils.Feedback.state,
isPresent: parsed.hashData && parsed.hashData.present, isPresent: parsed.hashData && parsed.hashData.present,
@ -326,6 +326,10 @@ define([
additionalPriv.registeredOnly = true; additionalPriv.registeredOnly = true;
} }
if (['debug', 'profile'].indexOf(parsed.type) !== -1) {
additionalPriv.hashes = hashes;
}
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; } for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
if (cfg.addData) { if (cfg.addData) {
@ -380,6 +384,19 @@ define([
}); });
}); });
sframeChan.on('Q_GET_ATTRIBUTE', function (data, cb) {
Cryptpad.getAttribute(data.key, function (e, data) {
cb({
error: e,
data: data
});
});
});
sframeChan.on('Q_SET_ATTRIBUTE', function (data, cb) {
Cryptpad.setAttribute(data.key, data.value, function (e) {
cb({error:e});
});
});
}; };
addCommonRpc(sframeChan); addCommonRpc(sframeChan);
@ -589,20 +606,6 @@ define([
}, href); }, href);
}); });
sframeChan.on('Q_GET_ATTRIBUTE', function (data, cb) {
Cryptpad.getAttribute(data.key, function (e, data) {
cb({
error: e,
data: data
});
});
});
sframeChan.on('Q_SET_ATTRIBUTE', function (data, cb) {
Cryptpad.setAttribute(data.key, data.value, function (e) {
cb({error:e});
});
});
sframeChan.on('Q_DRIVE_GETDELETED', function (data, cb) { sframeChan.on('Q_DRIVE_GETDELETED', function (data, cb) {
Cryptpad.getDeletedPads(data, function (err, obj) { Cryptpad.getDeletedPads(data, function (err, obj) {
if (err) { return void console.error(err); } if (err) { return void console.error(err); }
@ -711,6 +714,44 @@ define([
initFilePicker(data); initFilePicker(data);
}); });
// Share modal
var ShareModal = {};
var initShareModal = function (cfg) {
cfg.hashes = hashes;
cfg.password = password;
// cfg.hidden means pre-loading the filepicker while keeping it hidden.
// if cfg.hidden is true and the iframe already exists, do nothing
if (!ShareModal.$iframe) {
var config = {};
config.onShareAction = function (data) {
sframeChan.event('EV_SHARE_ACTION', data);
};
config.onClose = function () {
ShareModal.$iframe.hide();
};
config.data = cfg;
config.addCommonRpc = addCommonRpc;
config.modules = {
Cryptpad: Cryptpad,
SFrameChannel: SFrameChannel,
Utils: Utils
};
ShareModal.$iframe = $('<iframe>', {id: 'sbox-share-iframe'}).appendTo($('body'));
ShareModal.modal = Share.create(config);
} else if (!cfg.hidden) {
ShareModal.$iframe.show();
ShareModal.modal.refresh(cfg);
}
if (cfg.hidden) {
ShareModal.$iframe.hide();
return;
}
ShareModal.$iframe.focus();
};
sframeChan.on('EV_SHARE_OPEN', function (data) {
initShareModal(data || {});
});
sframeChan.on('Q_TEMPLATE_USE', function (data, cb) { sframeChan.on('Q_TEMPLATE_USE', function (data, cb) {
Cryptpad.useTemplate(data, Cryptget, cb); Cryptpad.useTemplate(data, Cryptget, cb);
}); });

@ -121,13 +121,9 @@ define([
return '<script src="' + origin + '/common/media-tag-nacl.min.js"></script>'; return '<script src="' + origin + '/common/media-tag-nacl.min.js"></script>';
}; };
funcs.getMediatagFromHref = function (obj) { funcs.getMediatagFromHref = function (obj) {
if (!obj || !obj.hash) { return; }
var data = ctx.metadataMgr.getPrivateData(); var data = ctx.metadataMgr.getPrivateData();
var secret; var secret = Hash.getSecrets('file', obj.hash, obj.password);
if (obj) {
secret = Hash.getSecrets('file', obj.hash, obj.password);
} else {
secret = Hash.getSecrets('file', data.availableHashes.fileHash, data.password);
}
if (secret.keys && secret.channel) { if (secret.keys && secret.channel) {
var key = Hash.encodeBase64(secret.keys && secret.keys.cryptKey); var key = Hash.encodeBase64(secret.keys && secret.keys.cryptKey);
var hexFileName = secret.channel; var hexFileName = secret.channel;
@ -391,12 +387,6 @@ define([
} }
}; };
funcs.isStrongestStored = function () {
var data = ctx.metadataMgr.getPrivateData();
if (data.availableHashes.fileHash) { return true; }
return !data.readOnly || !data.availableHashes.editHash;
};
funcs.setDisplayName = function (name, cb) { funcs.setDisplayName = function (name, cb) {
cb = cb || $.noop; cb = cb || $.noop;
ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, cb); ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, cb);

@ -523,23 +523,16 @@ MessengerUI, Messages) {
if (!config.metadataMgr) { if (!config.metadataMgr) {
throw new Error("You must provide a `metadataMgr` to display the userlist"); throw new Error("You must provide a `metadataMgr` to display the userlist");
} }
var metadataMgr = config.metadataMgr;
var origin = config.metadataMgr.getPrivateData().origin;
var pathname = config.metadataMgr.getPrivateData().pathname;
var hashes = metadataMgr.getPrivateData().availableHashes;
var $shareBlock = $('<button>', { var $shareBlock = $('<button>', {
'class': 'fa fa-shhare-alt cp-toolbar-share-button', 'class': 'fa fa-shhare-alt cp-toolbar-share-button',
title: Messages.shareButton title: Messages.shareButton
}); });
var modal = UIElements.createShareModal({ Common.getSframeChannel().event('EV_SHARE_OPEN', {
origin: origin, hidden: true
pathname: pathname,
hashes: hashes,
common: Common
}); });
$shareBlock.click(function () { $shareBlock.click(function () {
UI.openCustomModal(UI.dialog.tabs(modal)); Common.getSframeChannel().event('EV_SHARE_OPEN', {});
}); });
toolbar.$leftside.append($shareBlock); toolbar.$leftside.append($shareBlock);
@ -552,23 +545,19 @@ MessengerUI, Messages) {
if (!config.metadataMgr) { if (!config.metadataMgr) {
throw new Error("You must provide a `metadataMgr` to display the userlist"); throw new Error("You must provide a `metadataMgr` to display the userlist");
} }
var metadataMgr = config.metadataMgr;
var origin = config.metadataMgr.getPrivateData().origin;
var pathname = config.metadataMgr.getPrivateData().pathname;
var hashes = metadataMgr.getPrivateData().availableHashes;
var $shareBlock = $('<button>', { var $shareBlock = $('<button>', {
'class': 'fa fa-shhare-alt cp-toolbar-share-button', 'class': 'fa fa-shhare-alt cp-toolbar-share-button',
title: Messages.shareButton title: Messages.shareButton
}); });
var modal = UIElements.createFileShareModal({ Common.getSframeChannel().event('EV_SHARE_OPEN', {
origin: origin, hidden: true,
pathname: pathname, file: true
hashes: hashes,
common: Common
}); });
$shareBlock.click(function () { $shareBlock.click(function () {
UI.openCustomModal(UI.dialog.tabs(modal)); Common.getSframeChannel().event('EV_SHARE_OPEN', {
file: true
});
}); });
toolbar.$leftside.append($shareBlock); toolbar.$leftside.append($shareBlock);

@ -229,7 +229,7 @@ define([
}; };
var getGraph = function (chainpad, cb) { var getGraph = function (chainpad, cb) {
var hashes = metadataMgr.getPrivateData().availableHashes; var hashes = metadataMgr.getPrivateData().hashes;
var hash = hashes.editHash || hashes.viewHash; var hash = hashes.editHash || hashes.viewHash;
var chan = Hash.hrefToHexChannelId('/drive/#'+hash); var chan = Hash.hrefToHexChannelId('/drive/#'+hash);

@ -24,6 +24,14 @@
padding:0; padding:0;
overflow:hidden; overflow:hidden;
} }
#sbox-share-iframe {
position: fixed;
top:0; left:0;
bottom:0; right:0;
width:100%;
height: 100%;
border: 0;
}
</style> </style>
</head> </head>
<body> <body>

@ -50,7 +50,8 @@ define([
var postMsg = function (data) { var postMsg = function (data) {
iframe.postMessage(data, '*'); iframe.postMessage(data, '*');
}; };
var whenReady = waitFor(function (msg) { var w = waitFor();
var whenReady = function (msg) {
if (msg.source !== iframe) { return; } if (msg.source !== iframe) { return; }
var data = JSON.parse(msg.data); var data = JSON.parse(msg.data);
if (!data.txid) { return; } if (!data.txid) { return; }
@ -67,7 +68,8 @@ define([
config.modules.SFrameChannel.create(msgEv, postMsg, waitFor(function (sfc) { config.modules.SFrameChannel.create(msgEv, postMsg, waitFor(function (sfc) {
sframeChan = sfc; sframeChan = sfc;
})); }));
}); w();
};
window.addEventListener('message', whenReady); window.addEventListener('message', whenReady);
}).nThen(function () { }).nThen(function () {
var updateMeta = function () { var updateMeta = function () {

@ -739,10 +739,6 @@ define([
var initThumbnails = function () { var initThumbnails = function () {
var privateDat = metadataMgr.getPrivateData(); var privateDat = metadataMgr.getPrivateData();
if (!privateDat.thumbnails) { return; } // Thumbnails are disabled if (!privateDat.thumbnails) { return; } // Thumbnails are disabled
var hash = privateDat.availableHashes.editHash ||
privateDat.availableHashes.viewHash;
if (!hash) { return; }
var href = privateDat.pathname + '#' + hash;
var $el = $('.cp-app-poll-realtime'); var $el = $('.cp-app-poll-realtime');
//var $el = $('#cp-app-poll-table'); //var $el = $('#cp-app-poll-table');
var scrollTop; var scrollTop;
@ -771,7 +767,7 @@ define([
.css('position', ''); .css('position', '');
$('#cp-app-poll-form').scrollTop(scrollTop); $('#cp-app-poll-form').scrollTop(scrollTop);
}, },
href: href, type: 'poll',
getContent: function () { return JSON.stringify(APP.proxy.content); } getContent: function () { return JSON.stringify(APP.proxy.content); }
}; };
Thumb.initPadThumbnails(common, options); Thumb.initPadThumbnails(common, options);

@ -93,7 +93,7 @@ define([
return; return;
} }
var hash = common.getMetadataMgr().getPrivateData().availableHashes.viewHash; var hash = common.getMetadataMgr().getPrivateData().hashes.viewHash;
var url = APP.origin + '/profile/#' + hash; var url = APP.origin + '/profile/#' + hash;
var $button = $('<button>', { var $button = $('<button>', {

@ -0,0 +1,14 @@
@import (reference) '../../customize/src/less2/include/colortheme-all.less';
@import (reference) '../../customize/src/less2/include/modal.less';
@import (reference) '../../customize/src/less2/include/alertify.less';
@import (reference) '../../customize/src/less2/include/tippy.less';
@import (reference) '../../customize/src/less2/include/checkmark.less';
@import (reference) '../../customize/src/less2/include/password-input.less';
&.cp-app-share {
.alertify_main();
.tippy_main();
.checkmark_main(20px);
.password_main();
.modal_main();
}

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>CryptPad</title>
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="no-referrer" />
<script async data-bootload="main.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
<style>
html, body {
margin: 0px;
padding: 0px;
}
#sbox-iframe {
position:fixed;
top:0px;
left:0px;
bottom:0px;
right:0px;
width:100%;
height:100%;
border:none;
margin:0;
padding:0;
overflow:hidden;
}
</style>
</head>
<body>
<iframe id="sbox-iframe">

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html style="height: 100%; background: transparent;">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<script async data-bootload="/share/inner.js" data-main="/common/sframe-boot.js?ver=1.6" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
<style>
.loading-hidden { display: none; }
body #cp-loading {
display: none;
position: absolute;
top: 15vh;
bottom: 15vh;
left: 10vw;
right: 10vw;
z-index: 200000;
overflow: hidden;
}
body #cp-loading .cp-loading-container {
margin-top: 35vh;
}
body #cp-loading .cp-loading-cryptofist {
display: none;
}
</style>
</head>
<body class="cp-app-share" style="background: transparent;">
</body>
</html>

@ -0,0 +1,86 @@
define([
'jquery',
'/bower_components/nthen/index.js',
'/common/sframe-common.js',
'/common/common-ui-elements.js',
'/common/common-interface.js',
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
'less!/share/app-share.less',
], function (
$,
nThen,
SFCommon,
UIElements,
UI)
{
var APP = window.APP = {};
var andThen = function (common) {
var metadataMgr = common.getMetadataMgr();
var sframeChan = common.getSframeChannel();
var hideShareDialog = function () {
sframeChan.event('EV_SHARE_CLOSE');
};
/*
var onShareAction = function (data) {
hideShareDialog();
sframeChan.event("EV_SHARE_ACTION", {
// XXX data
});
};
*/
var createShareDialog = function (data) {
var priv = metadataMgr.getPrivateData();
var hashes = priv.hashes;
var origin = priv.origin;
var pathname = priv.pathname;
var f = (data && data.file) ? UIElements.createFileShareModal
: UIElements.createShareModal;
var modal = f({
origin: origin,
pathname: pathname,
hashes: hashes,
common: common,
onClose: function () {
hideShareDialog();
},
fileData: {
hash: hashes.fileHash,
password: priv.password
}
});
UI.openCustomModal(UI.dialog.tabs(modal));
};
sframeChan.on('EV_SHARE_REFRESH', function (data) {
createShareDialog(data);
});
//UI.removeLoadingScreen();
};
var main = function () {
var common;
nThen(function (waitFor) {
$(waitFor(function () {
UI.removeLoadingScreen();
//UI.addLoadingScreen({hideTips: true, hideLogo: true});
}));
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
}).nThen(function (/*waitFor*/) {
var metadataMgr = common.getMetadataMgr();
if (metadataMgr.getMetadataLazy() !== 'uninitialized') {
andThen(common);
return;
}
metadataMgr.onChange(function () {
andThen(common);
});
});
};
main();
});

@ -0,0 +1,132 @@
// Load #1, load as little as possible because we are in a race to get the loading screen up.
define([
'/bower_components/nthen/index.js',
'/api/config',
'jquery',
'/common/requireconfig.js',
], function (nThen, ApiConfig, $, RequireConfig) {
var requireConfig = RequireConfig();
var create = function (config) {
// Loaded in load #2
var sframeChan;
nThen(function (waitFor) {
$(waitFor());
}).nThen(function (waitFor) {
var req = {
cfg: requireConfig,
req: [ '/common/loading.js' ],
pfx: window.location.origin
};
window.rc = requireConfig;
window.apiconf = ApiConfig;
$('#sbox-share-iframe').attr('src',
ApiConfig.httpSafeOrigin + '/share/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req)));
// This is a cheap trick to avoid loading sframe-channel in parallel with the
// loading screen setup.
var done = waitFor();
var onMsg = function (msg) {
var data = JSON.parse(msg.data);
if (data.q !== 'READY') { return; }
window.removeEventListener('message', onMsg);
var _done = done;
done = function () { };
_done();
};
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
var Cryptpad = config.modules.Cryptpad;
var Utils = config.modules.Utils;
nThen(function (waitFor) {
// The inner iframe tries to get some data from us every ms (cache, store...).
// It will send a "READY" message and wait for our answer with the correct txid.
// First, we have to answer to this message, otherwise we're going to block
// sframe-boot.js. Then we can start the channel.
var msgEv = Utils.Util.mkEvent();
var iframe = $('#sbox-share-iframe')[0].contentWindow;
var postMsg = function (data) {
iframe.postMessage(data, '*');
};
var w = waitFor();
var whenReady = function (msg) {
if (msg.source !== iframe) { return; }
var data = JSON.parse(msg.data);
if (!data.txid) { return; }
// Remove the listener once we've received the READY message
window.removeEventListener('message', whenReady);
// Answer with the requested data
postMsg(JSON.stringify({ txid: data.txid, language: Cryptpad.getLanguage() }));
// Then start the channel
window.addEventListener('message', function (msg) {
if (msg.source !== iframe) { return; }
msgEv.fire(msg);
});
config.modules.SFrameChannel.create(msgEv, postMsg, waitFor(function (sfc) {
sframeChan = sfc;
}));
w();
};
window.addEventListener('message', whenReady);
}).nThen(function () {
var updateMeta = function () {
//console.log('EV_METADATA_UPDATE');
var metaObj;
nThen(function (waitFor) {
Cryptpad.getMetadata(waitFor(function (err, n) {
if (err) { console.log(err); }
metaObj = n;
}));
}).nThen(function (/*waitFor*/) {
metaObj.doc = {};
var additionalPriv = {
accountName: Utils.LocalStore.getAccountName(),
origin: window.location.origin,
pathname: window.location.pathname,
feedbackAllowed: Utils.Feedback.state,
hashes: config.data.hashes,
password: config.data.password,
file: config.data.file
};
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
sframeChan.event('EV_METADATA_UPDATE', metaObj);
});
};
Cryptpad.onMetadataChanged(updateMeta);
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
config.addCommonRpc(sframeChan);
sframeChan.on('Q_GET_FILES_LIST', function (types, cb) {
Cryptpad.getSecureFilesList(types, function (err, data) {
cb({
error: err,
data: data
});
});
});
sframeChan.on('EV_SHARE_CLOSE', function () {
config.onClose();
});
sframeChan.on('EV_SHARE_ACTION', function (data) {
config.onShareAction(data);
});
});
});
var refresh = function (data) {
if (!sframeChan) { return; }
sframeChan.event('EV_SHARE_REFRESH', data);
};
return {
refresh: refresh
};
};
return {
create: create
};
});

@ -445,11 +445,7 @@ define([
var oldThumbnailState; var oldThumbnailState;
var privateDat = metadataMgr.getPrivateData(); var privateDat = metadataMgr.getPrivateData();
if (!privateDat.thumbnails) { return; } if (!privateDat.thumbnails) { return; }
var hash = privateDat.availableHashes.editHash ||
privateDat.availableHashes.viewHash;
var href = privateDat.pathname + '#' + hash;
var mkThumbnail = function () { var mkThumbnail = function () {
if (!hash) { return; }
if (framework.getState() !== 'READY') { return; } if (framework.getState() !== 'READY') { return; }
if (!framework._.cpNfInner.chainpad) { return; } if (!framework._.cpNfInner.chainpad) { return; }
var content = framework._.cpNfInner.chainpad.getUserDoc(); var content = framework._.cpNfInner.chainpad.getUserDoc();
@ -457,7 +453,7 @@ define([
var D = Thumb.getResizedDimensions($canvas[0], 'pad'); var D = Thumb.getResizedDimensions($canvas[0], 'pad');
Thumb.fromCanvas($canvas[0], D, function (err, b64) { Thumb.fromCanvas($canvas[0], D, function (err, b64) {
oldThumbnailState = content; oldThumbnailState = content;
Thumb.setPadThumbnail(framework._.sfCommon, href, privateDat.channel, b64); Thumb.setPadThumbnail(framework._.sfCommon, 'whiteboard', privateDat.channel, b64);
}); });
}; };
window.setInterval(mkThumbnail, Thumb.UPDATE_INTERVAL); window.setInterval(mkThumbnail, Thumb.UPDATE_INTERVAL);

Loading…
Cancel
Save