From 7e0a9512326c6845e082ade40ef21f82f60e3bd2 Mon Sep 17 00:00:00 2001 From: Chris Clime Date: Fri, 8 Feb 2019 23:45:39 +0100 Subject: [PATCH] add custom user scripts for webapps defined in webapp-properties.json (#140) --- src/app/webcontainer/webapp-container.qml | 40 +++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/app/webcontainer/webapp-container.qml b/src/app/webcontainer/webapp-container.qml index 79aa0c60f..65dc7dd59 100644 --- a/src/app/webcontainer/webapp-container.qml +++ b/src/app/webcontainer/webapp-container.qml @@ -179,9 +179,43 @@ BrowserWindow { focus: true onLoaded: { - var context = item.currentWebview.context - onlineAccountsController.setupWebcontextForAccount(context) - item.currentWebview.settings.localContentCanAccessRemoteUrls = localContentCanAccessRemoteUrls + var context = item.currentWebview.context; + onlineAccountsController.setupWebcontextForAccount(context); + item.currentWebview.settings.localContentCanAccessRemoteUrls = localContentCanAccessRemoteUrls; + + loadCustomUserScripts(); + } + + function loadCustomUserScripts() { + + var scripts = []; + + // app specific user scripts + var idx = webappModel.getWebappIndex(getWebappName()); + var customScripts = webappModel.data(idx, UnityWebApps.UnityWebappsAppModel.Scripts); + + if (customScripts.length === 0) + { + return; + } + + var i; + for (i = 0; i < customScripts.length; i++) + { + var script = Qt.createQmlObject('import QtWebEngine 1.7; WebEngineScript {}', webappViewLoader); + script.sourceUrl = customScripts[i]; + script.injectionPoint = WebEngineScript.DocumentCreation; + script.worldId = WebEngineScript.MainWorld; + script.runOnSubframes = true; + scripts.push(script); + } + + // global user scripts + for (i = 0; i < item.currentWebview.profile.userScripts.length; i++) { + scripts.push(item.currentWebview.profile.userScripts[i]); + } + + item.currentWebview.profile.userScripts = scripts; } }