Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

add parameter "--user-scripts" for custom user scripts #527

Open
wants to merge 1 commit into
base: xenial
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/app/webcontainer/webapp-container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand Down Expand Up @@ -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) ?
Expand Down Expand Up @@ -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]"
Expand All @@ -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;
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 2 additions & 0 deletions src/app/webcontainer/webapp-container.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private Q_SLOTS:
QString m_webappIcon;
QString m_webappModelSearchPath;
QStringList m_webappUrlPatterns;
QList<QUrl> m_userScripts;
QString m_accountProvider;
bool m_accountSwitcher;
bool m_storeSessionCookies;
Expand All @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions src/app/webcontainer/webapp-container.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down Expand Up @@ -194,8 +195,7 @@ BrowserWindow {

var scripts = [];

// app specific user scripts
var customScripts = []
var customScripts = root.userScripts;

if ((typeof customScripts === "undefined") || (customScripts.length === 0))
{
Expand Down