From bd6a9ed3f8d6ff42d5425da2795496bdbe3fc9ea Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 31 Jan 2019 11:57:16 +0100 Subject: [PATCH] Use the correct API for the filepicker channel --- www/filepicker/main.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/www/filepicker/main.js b/www/filepicker/main.js index 596cc0a45..5792001e5 100644 --- a/www/filepicker/main.js +++ b/www/filepicker/main.js @@ -41,10 +41,34 @@ define([ var Utils = config.modules.Utils; nThen(function (waitFor) { - config.modules.SFrameChannel.create($('#sbox-filePicker-iframe')[0].contentWindow, - waitFor(function (sfc) { + // 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-filePicker-iframe')[0].contentWindow; + var postMsg = function (data) { + iframe.postMessage(data, '*'); + }; + var whenReady = waitFor(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; })); + }); + window.addEventListener('message', whenReady); }).nThen(function () { var updateMeta = function () { //console.log('EV_METADATA_UPDATE');