diff --git a/www/code/index.html b/www/code/index.html index 7ea06cdfc..e224b0efe 100644 --- a/www/code/index.html +++ b/www/code/index.html @@ -32,6 +32,14 @@ height: 100%; border: 0; } + #sbox-share-iframe { + position: fixed; + top:0; left:0; + bottom:0; right:0; + width:100%; + height: 100%; + border: 0; + }
diff --git a/www/common/common-interface.js b/www/common/common-interface.js index 56e2d8d3a..3b9ab5271 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -351,6 +351,9 @@ define([ var close = function (el) { var $el = $(el).fadeOut(150, function () { $el.detach(); + if (opt.onClose) { + opt.onClose(); + } }); }; diff --git a/www/common/common-thumbnail.js b/www/common/common-thumbnail.js index 767b0e92a..2a03715cd 100644 --- a/www/common/common-thumbnail.js +++ b/www/common/common-thumbnail.js @@ -205,7 +205,7 @@ define([ if (content === oldThumbnailState) { return; } oldThumbnailState = content; 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); @@ -243,11 +243,10 @@ define([ var getKey = function (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 () {}; - var parsed = Hash.parsePadUrl(href); channel = channel || common.getMetadataMgr().getPrivateData().channel; - var k = getKey(parsed.type, channel); + var k = getKey(type, channel); common.setThumbnail(k, b64, cb); }; Thumb.displayThumbnail = function (common, href, channel, password, $container, cb) { @@ -270,7 +269,7 @@ define([ if (!v) { v = 'EMPTY'; } - Thumb.setPadThumbnail(common, href, hexFileName, v, function (err) { + Thumb.setPadThumbnail(common, parsed.type, hexFileName, v, function (err) { if (!metadata.thumbnail) { return; } addThumbnail(err, metadata.thumbnail, $container, cb); }); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 68921594b..4b5f73499 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -322,6 +322,8 @@ define([ var hashes = config.hashes; var common = config.common; + if (!hashes) { return; } + // Share link tab var link = h('div.cp-share-modal', [ h('label', Messages.share_linkAccess), @@ -403,7 +405,10 @@ define([ }, keys: [[13, 'ctrl']] }]; - var frameLink = UI.dialog.customModal(link, {buttons: linkButtons}); + var frameLink = UI.dialog.customModal(link, { + buttons: linkButtons, + onClose: config.onClose + }); // Embed tab var getEmbedValue = function () { @@ -464,7 +469,9 @@ define([ $(link).find('#cp-share-link-preview').val(getLinkValue(val)); }); 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()); }); return tabs; diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 00125e1d5..f1068a6de 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -357,16 +357,14 @@ define([ UI.removeLoadingScreen(emitResize); var privateDat = cpNfInner.metadataMgr.getPrivateData(); - var hash = privateDat.availableHashes.editHash || - privateDat.availableHashes.viewHash; - var href = privateDat.pathname + '#' + hash; + var type = privateDat.app; if (AppConfig.textAnalyzer && textContentGetter) { AppConfig.textAnalyzer(textContentGetter, privateDat.channel); } if (options.thumbnail && privateDat.thumbnails) { - if (hash) { - options.thumbnail.href = href; + if (type) { + options.thumbnail.type = type; options.thumbnail.getContent = function () { if (!cpNfInner.chainpad) { return; } return cpNfInner.chainpad.getUserDoc(); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 29f84ea66..b548b4731 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -19,6 +19,7 @@ define([ var SFrameChannel; var sframeChan; var FilePicker; + var Share; var Messaging; var Notifier; var Utils = { @@ -38,6 +39,7 @@ define([ '/common/cryptget.js', '/common/outer/worker-channel.js', '/filepicker/main.js', + '/share/main.js', '/common/common-messaging.js', '/common/common-notifier.js', '/common/common-hash.js', @@ -49,7 +51,7 @@ define([ '/customize/application_config.js', '/common/test.js', ], 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) { CpNfOuter = _CpNfOuter; Cryptpad = _Cryptpad; @@ -57,6 +59,7 @@ define([ Cryptget = _Cryptget; SFrameChannel = _SFrameChannel; FilePicker = _FilePicker; + Share = _Share; Messaging = _Messaging; Notifier = _Notifier; Utils.Hash = _Hash; @@ -269,9 +272,6 @@ define([ sessionStorage[Utils.Constants.displayPadCreationScreen]; delete sessionStorage[Utils.Constants.displayPadCreationScreen]; var updateMeta = function () { - // TODO availableHashes in privateData may need updates once we have - // a better privileges workflow - //console.log('EV_METADATA_UPDATE'); var metaObj, isTemplate; nThen(function (waitFor) { @@ -290,12 +290,12 @@ define([ type: cfg.type || parsed.type }; var additionalPriv = { + app: parsed.type, accountName: Utils.LocalStore.getAccountName(), origin: window.location.origin, pathname: window.location.pathname, fileHost: ApiConfig.fileHost, readOnly: readOnly, - availableHashes: hashes, isTemplate: isTemplate, feedbackAllowed: Utils.Feedback.state, isPresent: parsed.hashData && parsed.hashData.present, @@ -326,6 +326,10 @@ define([ additionalPriv.registeredOnly = true; } + if (['debug', 'profile'].indexOf(parsed.type) !== -1) { + additionalPriv.hashes = hashes; + } + for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; } 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); @@ -589,20 +606,6 @@ define([ }, 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) { Cryptpad.getDeletedPads(data, function (err, obj) { if (err) { return void console.error(err); } @@ -711,6 +714,44 @@ define([ 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 = $('