From fc728617210e7658d9869883e6fd30adbeb21f69 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 22 Aug 2019 14:01:07 +0200 Subject: [PATCH] Prevent users from opening a pad with the wrong app --- www/common/sframe-app-framework.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index e2a0bd0a2..e5a992343 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -314,11 +314,21 @@ define([ var newPad = false; if (newContentStr === '') { newPad = true; } + var privateDat = cpNfInner.metadataMgr.getPrivateData(); + var type = privateDat.app; + // contentUpdate may be async so we need an nthen here nThen(function (waitFor) { if (!newPad) { var newContent = JSON.parse(newContentStr); - cpNfInner.metadataMgr.updateMetadata(extractMetadata(newContent)); + var metadata = extractMetadata(newContent); + if (metadata && typeof(metadata.type) !== 'undefined' && metadata.type !== type) { + var errorText = Messages.typeError; + UI.errorLoadingScreen(errorText); + waitFor.abort(); + return; + } + cpNfInner.metadataMgr.updateMetadata(metadata); newContent = normalize(newContent); contentUpdate(newContent, waitFor); } else { @@ -356,8 +366,6 @@ define([ UI.removeLoadingScreen(emitResize); - var privateDat = cpNfInner.metadataMgr.getPrivateData(); - var type = privateDat.app; if (AppConfig.textAnalyzer && textContentGetter) { AppConfig.textAnalyzer(textContentGetter, privateDat.channel); }