diff --git a/src/app/webcontainer/webapp-container.cpp b/src/app/webcontainer/webapp-container.cpp index 7cf425ac0..a6be242e0 100644 --- a/src/app/webcontainer/webapp-container.cpp +++ b/src/app/webcontainer/webapp-container.cpp @@ -78,6 +78,7 @@ static void clearCookiesHack(const QString &provider) } const QString WebappContainer::URL_PATTERN_SEPARATOR = ","; +const QString WebappContainer::USERSCRIPTS_SEPARATOR = ","; const QString WebappContainer::LOCAL_SCHEME_FILTER_FILENAME = "local-scheme-filter.js"; @@ -162,6 +163,7 @@ bool WebappContainer::initialize() QQmlProperty::write(m_object, QStringLiteral("openExternalUrlInOverlay"), m_openExternalUrlInOverlay); QQmlProperty::write(m_object, QStringLiteral("defaultVideoCaptureCameraPosition"), m_defaultVideoCaptureCameraPosition); QQmlProperty::write(m_object, QStringLiteral("webappUrlPatterns"), m_webappUrlPatterns); + QQmlProperty::write(m_object, QStringLiteral("userScripts"), QVariant::fromValue(m_userScripts)); QQmlContext* context = m_engine->rootContext(); if (m_storeSessionCookies) { QString sessionCookieMode = SessionUtils::firstRun(m_webappName) ? @@ -309,6 +311,7 @@ void WebappContainer::printUsage() const " [--icon=PATH]" " [--webappModelSearchPath=PATH]" " [--webappUrlPatterns=URL_PATTERNS]" + " [--user-scripts=USER_SCRIPTS]" " [--accountProvider=PROVIDER_NAME]" " [--accountSwitcher]" " [--enable-back-forward]" @@ -332,6 +335,7 @@ void WebappContainer::printUsage() const out << " --icon=PATH Icon to be shown in the splash screen. PATH can be an absolute or path relative to CWD" << endl; out << " --webappModelSearchPath=PATH alter the search path for installed webapps and set it to PATH. PATH can be an absolute or path relative to CWD" << endl; out << " --webappUrlPatterns=URL_PATTERNS list of comma-separated url patterns (wildcard based) that the webapp is allowed to navigate to" << endl; + out << " --user-scripts=USER_SCRIPTS list of comma-separated user scripts to be loaded in the webapp" << endl; out << " --accountProvider=PROVIDER_NAME Online account provider for the application if the application is to reuse a local account." << endl; out << " --accountSwitcher enable switching between different Online Accounts identities" << endl; out << " --store-session-cookies store session cookies on disk" << endl; @@ -382,6 +386,18 @@ void WebappContainer::parseCommandLine() QStringList includePatterns = tail.split(URL_PATTERN_SEPARATOR); m_webappUrlPatterns = UrlPatternUtils::filterAndTransformUrlPatterns(includePatterns); } + } else if (argument.startsWith("--user-scripts=")) { + QStringList userScriptFiles = argument.split("--user-scripts=")[1].split(USERSCRIPTS_SEPARATOR); + + Q_FOREACH(const QString& userScriptFile, userScriptFiles) + { + if (! isValidLocalResource(userScriptFile)) + { + continue; + } + QUrl userScriptUrl = QUrl::fromLocalFile(QFileInfo(userScriptFile).absoluteFilePath()); + m_userScripts.append(userScriptUrl); + } } else if (argument.startsWith("--accountProvider=")) { m_accountProvider = argument.split("--accountProvider=")[1]; } else if (argument == "--accountSwitcher") { diff --git a/src/app/webcontainer/webapp-container.h b/src/app/webcontainer/webapp-container.h index c4a99fbf7..7eb9ac9c3 100644 --- a/src/app/webcontainer/webapp-container.h +++ b/src/app/webcontainer/webapp-container.h @@ -64,6 +64,7 @@ private Q_SLOTS: QString m_webappIcon; QString m_webappModelSearchPath; QStringList m_webappUrlPatterns; + QList m_userScripts; QString m_accountProvider; bool m_accountSwitcher; bool m_storeSessionCookies; @@ -82,6 +83,7 @@ private Q_SLOTS: bool m_localContentCanAccessRemoteUrls; static const QString URL_PATTERN_SEPARATOR; + static const QString USERSCRIPTS_SEPARATOR; static const QString LOCAL_SCHEME_FILTER_FILENAME; }; diff --git a/src/app/webcontainer/webapp-container.qml b/src/app/webcontainer/webapp-container.qml index e92705580..4851e56d1 100644 --- a/src/app/webcontainer/webapp-container.qml +++ b/src/app/webcontainer/webapp-container.qml @@ -39,6 +39,7 @@ BrowserWindow { property string webappName: "" property string webappModelSearchPath: "" property var webappUrlPatterns + property var userScripts property string accountProvider: "" property bool accountSwitcher: false property string popupRedirectionUrlPrefixPattern: "" @@ -194,8 +195,7 @@ BrowserWindow { var scripts = []; - // app specific user scripts - var customScripts = [] + var customScripts = root.userScripts; if ((typeof customScripts === "undefined") || (customScripts.length === 0)) {