Commit 44ebb170 authored by Ming Rui Zhang's avatar Ming Rui Zhang

messagewebview: add support for pasting and drafting js special characters

Note: it will also prevent potential js template literal

Gitlab: #250
Gitlab: #246
Change-Id: Ic925a18ae768d168b8e340f9e05ef6ddd0260c84
parent 08236cf5
......@@ -43,6 +43,10 @@ Rectangle {
signal messagesCleared
signal messagesLoaded
function setSendMessageContent(content) {
jsBridgeObject.setSendMessageContentRequest(content)
}
function focusMessageWebView() {
messageWebView.forceActiveFocus()
}
......@@ -140,6 +144,10 @@ Rectangle {
// ID, under which this object will be known at chatview.js side.
WebChannel.id: "jsbridge"
// signals to trigger functions in chatview.js
// mainly used to avoid input arg string escape
signal setSendMessageContentRequest(string content)
// Functions that are exposed, return code can be derived from js side
// by setting callback function.
function deleteInteraction(arg) {
......@@ -240,6 +248,8 @@ Rectangle {
settings.javascriptEnabled: true
settings.javascriptCanOpenWindows: true
settings.javascriptCanAccessClipboard: true
settings.javascriptCanPaste: true
settings.fullScreenSupportEnabled: true
settings.allowRunningInsecureContent: true
settings.localContentCanAccessRemoteUrls: true
......
......@@ -421,10 +421,11 @@ MessagesAdapter::pasteKeyDetected()
}
}
} else {
// Treat as text content, make chatview.js handle in order to
// avoid string escape problems
QMetaObject::invokeMethod(qmlObj_,
"webViewRunJavaScript",
Q_ARG(QVariant,
QStringLiteral("replaceText(`%1`)").arg(mimeData->text())));
Q_ARG(QVariant, QStringLiteral("replaceText()")));
}
}
......@@ -640,8 +641,7 @@ MessagesAdapter::removeInteraction(uint64_t interactionId)
void
MessagesAdapter::setSendMessageContent(const QString& content)
{
QString s = QString::fromLatin1("setSendMessageContent(`%1`);").arg(content);
QMetaObject::invokeMethod(qmlObj_, "webViewRunJavaScript", Q_ARG(QVariant, s));
QMetaObject::invokeMethod(qmlObj_, "setSendMessageContent", Q_ARG(QVariant, content));
}
void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment