diff --git a/src/lib/sync/data/inject.js b/src/lib/sync/data/inject.js
index 9a6297770..4ed72f21e 100644
--- a/src/lib/sync/data/inject.js
+++ b/src/lib/sync/data/inject.js
@@ -1,11 +1,6 @@
-new QWebChannel(qt.webChannelTransport, function(channel) {
- communicator = channel.objects.communicator;
- window.comm = communicator;
-});
-
window.addEventListener('WebChannelMessageToChrome', function(event) {
let e = {type: event.type, detail: event.detail};
- window.comm.receiveJSON(e);
+ external.extra.communicator.receiveJSON(e);
});
function sendMessage(response) {
diff --git a/src/lib/sync/fxalogin.cpp b/src/lib/sync/fxalogin.cpp
index 4562bef50..9b007a561 100644
--- a/src/lib/sync/fxalogin.cpp
+++ b/src/lib/sync/fxalogin.cpp
@@ -16,6 +16,8 @@
* along with this program. If not, see .
* ============================================================ */
#include "fxalogin.h"
+#include "javascript/externaljsobject.h"
+#include "webpage.h"
#include
#include
@@ -28,43 +30,32 @@
FxALoginPage::FxALoginPage(QWidget* parent)
: QWebEngineView(parent)
{
- m_page = new QWebEnginePage(this);
- m_channel = new QWebChannel(m_page);
- m_page->setWebChannel(m_channel);
+ m_communicator = new MessageReceiver(this);
+ ExternalJsObject::registerExtraObject(QString("communicator"), m_communicator);
+ connect(m_communicator, &MessageReceiver::signalMessageReceived,
+ this, &FxALoginPage::slotMessageReceived);
+
+ m_page = new WebPage(this);
m_page->load(FxALoginUrl);
setPage(m_page);
- connect(m_page, &QWebEnginePage::loadFinished, this, &FxALoginPage::pageLoadFinished);
+ connect(m_page, &WebPage::loadFinished, this, &FxALoginPage::pageLoadFinished);
}
FxALoginPage::~FxALoginPage()
{
delete m_communicator;
- delete m_channel;
}
void FxALoginPage::pageLoadFinished(bool pageLoaded)
{
if (pageLoaded) {
- QFile apiFile(":/qtwebchannel/qwebchannel.js");
- if (!apiFile.open(QIODevice::ReadOnly)) {
- qWarning() << "Couldn't load Qt's Webchannel API!";
- }
- QString apiScript = QString::fromUtf8(apiFile.readAll());
- apiFile.close();
- m_page->runJavaScript(apiScript);
-
- m_communicator = new MessageReceiver(this);
- connect(m_communicator, &MessageReceiver::signalMessageReceived,
- this, &FxALoginPage::slotMessageReceived);
- m_channel->registerObject(QString("communicator"), m_communicator);
-
QFile scriptFile(":/data/inject.js");
if (!scriptFile.open(QIODevice::ReadOnly)) {
qWarning() << "Couldn't load JavaScript file to inject.";
}
QString injectScript = QString::fromUtf8(scriptFile.readAll());
scriptFile.close();
- m_page->runJavaScript(injectScript);
+ m_page->runJavaScript(injectScript, WebPage::SafeJsWorld);
}
}
@@ -115,7 +106,7 @@ void FxALoginPage::sendMessage(QJsonObject msg)
qDebug() << "<<< Sending to server:\n " << stringMsg;
QString srcCode = "sendMessage(" + stringMsg + ");";
- m_page->runJavaScript(srcCode);
+ m_page->runJavaScript(srcCode, WebPage::SafeJsWorld);
}
diff --git a/src/lib/sync/fxalogin.h b/src/lib/sync/fxalogin.h
index d26ec00c3..2658d4097 100644
--- a/src/lib/sync/fxalogin.h
+++ b/src/lib/sync/fxalogin.h
@@ -26,6 +26,7 @@ class QWebEngineScript;
class QWebEnginePage;
class QJsonObject;
class MessageReceiver;
+class WebPage;
class FxALoginPage : public QWebEngineView
{
@@ -43,8 +44,7 @@ private:
void parseMessage(QJsonObject *msg);
void sendMessage(QJsonObject msg);
- QWebEnginePage *m_page;
- QWebChannel *m_channel;
+ WebPage *m_page;
MessageReceiver *m_communicator;
const QUrl FxALoginUrl = QUrl("https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3");
@@ -60,10 +60,10 @@ public:
~MessageReceiver();
QJsonObject *getMessage();
-public slots:
+public Q_SLOTS:
void receiveJSON(const QVariantMap &data);
-signals:
+Q_SIGNALS:
void signalMessageReceived();
private: