From 9c3dc7aa9c46f943c83ea863cecde5252f018ba4 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 26 May 2021 19:05:19 +0530 Subject: [PATCH] simplify some tests on the checkup page --- www/checkup/main.js | 89 ++++++++++++++++--------------------- www/checkup/sandbox/main.js | 4 +- 2 files changed, 40 insertions(+), 53 deletions(-) diff --git a/www/checkup/main.js b/www/checkup/main.js index 2b1c68ffa..2ab2cbbb0 100644 --- a/www/checkup/main.js +++ b/www/checkup/main.js @@ -574,6 +574,19 @@ define([ } }; + var deferredPostMessage = function (content, _cb) { + var cb = Util.once(Util.mkAsync(_cb)); + nThen(function (w) { + sandboxIframeReady.reg(w(function (err) { + if (!err) { return; } + w.abort(); + cb(err); + })); + }).nThen(function () { + postMessage(content, cb); + }); + }; + window.addEventListener('message', function (event) { try { var msg = JSON.parse(event.data); @@ -638,46 +651,30 @@ define([ var url = '/sheet/inner.html'; var cb = Util.once(Util.mkAsync(_cb)); msg.appendChild(CSP_WARNING(url)); - nThen(function (w) { - sandboxIframeReady.reg(w(function (err) { - if (!err) { return; } - w.abort(); - cb(err); - })); - }).nThen(function () { - postMessage({ - command: 'GET_HEADER', - content: { - url: url, - header: 'content-security-policy', - }, - }, function (content) { - var CSP_headers = parseCSP(content); - cb(hasOnlyOfficeHeaders(CSP_headers)); - }); + deferredPostMessage({ + command: 'GET_HEADER', + content: { + url: url, + header: 'content-security-policy', + }, + }, function (content) { + var CSP_headers = parseCSP(content); + cb(hasOnlyOfficeHeaders(CSP_headers)); }); }); assert(function (cb, msg) { var url = '/common/onlyoffice/v4/web-apps/apps/spreadsheeteditor/main/index.html'; msg.appendChild(CSP_WARNING(url)); - nThen(function (w) { - sandboxIframeReady.reg(w(function (err) { - if (!err) { return; } - w.abort(); - cb(err); - })); - }).nThen(function () { - postMessage({ - command: 'GET_HEADER', - content: { - url: url, - header: 'content-security-policy', - }, - }, function (content) { - var CSP_headers = parseCSP(content); - cb(hasOnlyOfficeHeaders(CSP_headers)); - }); + deferredPostMessage({ + command: 'GET_HEADER', + content: { + url: url, + header: 'content-security-policy', + }, + }, function (content) { + var CSP_headers = parseCSP(content); + cb(hasOnlyOfficeHeaders(CSP_headers)); }); }); @@ -689,22 +686,14 @@ define([ code("'cross-origin-opener-policy'"), ' headers set.', ])); - nThen(function (w) { - sandboxIframeReady.reg(w(function (err) { - if (!err) { return; } - w.abort(); - cb(err); - })); - }).nThen(function () { - postMessage({ - command: 'GET_HEADER', - content: { - url: url, - header: 'cross-origin-opener-policy', - }, - }, function (content) { - cb(content === 'same-origin'); - }); + deferredPostMessage({ + command: 'GET_HEADER', + content: { + url: url, + header: 'cross-origin-opener-policy', + }, + }, function (content) { + cb(content === 'same-origin'); }); }); diff --git a/www/checkup/sandbox/main.js b/www/checkup/sandbox/main.js index 7450ed0e3..7ddfb07f8 100644 --- a/www/checkup/sandbox/main.js +++ b/www/checkup/sandbox/main.js @@ -1,12 +1,10 @@ define([ 'jquery', - //'/bower_components/nthen/index.js', - //'/common/common-util.js', '/bower_components/tweetnacl/nacl-fast.min.js', 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/checkup/app-checkup.less', -], function ($ /*, nThen, Util */) { +], function ($) { var postMessage = function (content) { window.parent.postMessage(JSON.stringify(content), '*'); };