Merge pull request #2765 from ONLYOFFICE/fix/pdf-check

Fix send params to frame
This commit is contained in:
Julia Radzhabova
2023-12-26 20:51:36 +03:00
committed by GitHub
11 changed files with 75 additions and 68 deletions

View File

@ -517,6 +517,20 @@
if (_config.editorConfig.customization && _config.editorConfig.customization.integrationMode==='embed')
window.AscEmbed && window.AscEmbed.initWorker(iframe);
if (_config.document && (_config.document.isForm===undefined)) {
iframe.onload = function() {
_sendCommand({
command: 'checkParams',
data: {
url: _config.document.url,
directUrl: _config.document.directUrl,
token: _config.document.token,
key: _config.document.key
}
})
};
}
if (iframe.src) {
var pathArray = iframe.src.split('/');
this.frameOrigin = pathArray[0] + '//' + pathArray[2];
@ -1016,14 +1030,15 @@
if (config.frameEditorId)
params += "&frameEditorId=" + config.frameEditorId;
var type = config.document ? /^(?:(pdf))$/.exec(config.document.fileType) : null,
isPdf = type && typeof type[1] === 'string';
if (!isPdf && (config.editorConfig && config.editorConfig.mode == 'view' ||
var type = config.document ? /^(?:(pdf))$/.exec(config.document.fileType) : null;
if (!(type && typeof type[1] === 'string') && (config.editorConfig && config.editorConfig.mode == 'view' ||
config.document && config.document.permissions && (config.document.permissions.edit === false && !config.document.permissions.review )))
params += "&mode=view";
config.document.isForm = isPdf ? config.document.isForm : false;
if (config.document && (config.document.isForm!==undefined))
params += "&isForm=" + config.document.isForm;
if (config.document) {
config.document.isForm = (type && typeof type[1] === 'string') ? config.document.isForm : false;
(config.document.isForm!==undefined) && (params += "&isForm=" + config.document.isForm);
}
if (config.editorConfig && config.editorConfig.customization && !!config.editorConfig.customization.compactHeader)
params += "&compact=true";
@ -1040,20 +1055,6 @@
if (config.document && config.document.fileType)
params += "&fileType=" + config.document.fileType;
if (isPdf) {
if (config.document && config.document.directUrl)
params += "&directUrl=" + encodeURIComponent(config.document.directUrl);
if (config.document && config.document.key)
params += "&key=" + config.document.key;
if (config.document && config.document.url)
params += "&url=" + encodeURIComponent(config.document.url);
if (config.document && config.document.token)
params += "&token=" + config.document.token;
}
return params;
}

View File

@ -116,4 +116,46 @@ function downloadPartialy(url, limit, headers, callback) {
}
}
xhr.send();
}
}
var startCallback;
var eventFn = function(msg) {
if (msg.origin !== window.parentOrigin && msg.origin !== window.location.origin && !(msg.origin==="null" && (window.parentOrigin==="file://" || window.location.origin==="file://"))) return;
var data = msg.data;
if (Object.prototype.toString.apply(data) !== '[object String]' || !window.JSON) {
return;
}
try {
data = window.JSON.parse(data)
} catch(e) {
data = '';
}
if (data && data.command==="checkParams") {
data = data.data || {};
checkExtendedPDF(data.directUrl, data.key, data.url, data.token, startCallback);
_unbindWindowEvents();
}
};
var _bindWindowEvents = function() {
if (window.addEventListener) {
window.addEventListener("message", eventFn, false)
} else if (window.attachEvent) {
window.attachEvent("onmessage", eventFn);
}
};
var _unbindWindowEvents = function() {
if (window.removeEventListener) {
window.removeEventListener("message", eventFn)
} else if (window.detachEvent) {
window.detachEvent("onmessage", eventFn);
}
};
function listenApiMsg(callback) {
startCallback = callback;
_bindWindowEvents();
}

View File

@ -197,10 +197,6 @@
var params = getUrlParams(),
lang = (params["lang"] || 'en').split(/[\-\_]/)[0],
logo = params["headerlogo"] ? encodeUrlParam(params["headerlogo"]) : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
@ -306,7 +302,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -189,11 +189,7 @@
var params = getUrlParams(),
lang = (params["lang"] || 'en').split(/[\-\_]/)[0],
logo = params["headerlogo"] ? encodeUrlParam(params["headerlogo"]) : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
window.parentOrigin = params["parentOrigin"];
@ -281,7 +277,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -237,10 +237,6 @@
margin = (customer !== '') ? 50 : 20,
loading = 'Loading...',
logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
@ -365,7 +361,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -229,10 +229,6 @@
margin = (customer !== '') ? 50 : 20,
loading = 'Loading...',
logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
@ -342,7 +338,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -51,12 +51,8 @@ const startApp = () => {
const params = getUrlParams(),
isForm = params["isForm"];
if (isForm===undefined && checkExtendedPDF) {
const directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '';
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
if (isForm===undefined && listenApiMsg) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -257,10 +257,6 @@
lang = (params["lang"] || 'en').split(/[\-\_]/)[0],
logo = params["headerlogo"] ? encodeUrlParam(params["headerlogo"]) : null,
logoDark = params["headerlogodark"] ? encodeUrlParam(params["headerlogodark"]) : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
@ -382,7 +378,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -230,10 +230,6 @@
lang = (params["lang"] || 'en').split(/[\-\_]/)[0],
logo = params["headerlogo"] ? encodeUrlParam(params["headerlogo"]) : null,
logoDark = params["headerlogodark"] ? encodeUrlParam(params["headerlogodark"]) : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
@ -340,7 +336,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -220,10 +220,6 @@
margin = (customer !== '') ? 50 : 20,
loading = 'Loading...',
logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
@ -315,7 +311,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});

View File

@ -242,10 +242,6 @@
margin = (customer !== '') ? 50 : 20,
loading = 'Loading...',
logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null,
directUrl = params["directUrl"] ? encodeUrlParam(params["directUrl"]) : null,
url = params["url"] ? encodeUrlParam(params["url"]) : null,
fileKey = params["key"] || '',
token = params["token"] || '',
isForm = params["isForm"];
window.frameEditorId = params["frameEditorId"];
@ -335,7 +331,7 @@
document.body.appendChild(script);
}
if (isForm===undefined) {
checkExtendedPDF(directUrl, fileKey, url, token, function (isform) {
listenApiMsg(function (isform) {
window.isPDFForm = !!isform;
startApp();
});