diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index f4f6881f5..834f129a3 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -216,6 +216,7 @@ set(SRCS ${SRCS} sidebar/bookmarkssidebar.cpp sidebar/historysidebar.cpp sidebar/sidebar.cpp + sync/communicator.cpp sync/fxalogin.cpp sync/synccrypto.cpp tabwidget/combotabbar.cpp diff --git a/src/lib/sync/communicator.cpp b/src/lib/sync/communicator.cpp new file mode 100644 index 000000000..8243484c9 --- /dev/null +++ b/src/lib/sync/communicator.cpp @@ -0,0 +1,42 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2019 Prasenjit Kumar Shaw +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "communicator.h" + +#include + +Communicator::Communicator(QObject *parent) + : QObject(parent) +{ +} + +Communicator::~Communicator() +{ + delete m_message; +} + +void Communicator::receiveJSON(const QVariantMap &data) +{ + QJsonObject obj = QJsonObject::fromVariantMap(data); + m_message = new QJsonObject(obj); + emit signalMessageReceived(); +} + +QJsonObject * Communicator::getMessage() +{ + return m_message; +} diff --git a/src/lib/sync/communicator.h b/src/lib/sync/communicator.h new file mode 100644 index 000000000..1a0575739 --- /dev/null +++ b/src/lib/sync/communicator.h @@ -0,0 +1,40 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2019 Prasenjit Kumar Shaw +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#pragma once + +#include +#include + +class Communicator : public QObject +{ + Q_OBJECT + +public: + Communicator(QObject *parent = nullptr); + ~Communicator(); + QJsonObject *getMessage(); + +public Q_SLOTS: + void receiveJSON(const QVariantMap &data); + +Q_SIGNALS: + void signalMessageReceived(); + +private: + QJsonObject *m_message; +}; diff --git a/src/lib/sync/fxalogin.cpp b/src/lib/sync/fxalogin.cpp index 9b007a561..a97222c2e 100644 --- a/src/lib/sync/fxalogin.cpp +++ b/src/lib/sync/fxalogin.cpp @@ -18,10 +18,9 @@ #include "fxalogin.h" #include "javascript/externaljsobject.h" #include "webpage.h" +#include "communicator.h" +#include "qztools.h" -#include -#include -#include #include #include #include @@ -30,10 +29,10 @@ FxALoginPage::FxALoginPage(QWidget* parent) : QWebEngineView(parent) { - m_communicator = new MessageReceiver(this); + m_communicator = new Communicator(this); ExternalJsObject::registerExtraObject(QString("communicator"), m_communicator); - connect(m_communicator, &MessageReceiver::signalMessageReceived, - this, &FxALoginPage::slotMessageReceived); + connect(m_communicator, &Communicator::signalMessageReceived, + this, &FxALoginPage::slotMessageReceived); m_page = new WebPage(this); m_page->load(FxALoginUrl); @@ -49,12 +48,7 @@ FxALoginPage::~FxALoginPage() void FxALoginPage::pageLoadFinished(bool pageLoaded) { if (pageLoaded) { - 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(); + QString injectScript = QzTools::readAllFileContents(":/data/inject.js"); m_page->runJavaScript(injectScript, WebPage::SafeJsWorld); } } @@ -109,25 +103,3 @@ void FxALoginPage::sendMessage(QJsonObject msg) m_page->runJavaScript(srcCode, WebPage::SafeJsWorld); } - -MessageReceiver::MessageReceiver(QObject *parent) - : QObject(parent) -{ -} - -MessageReceiver::~MessageReceiver() -{ - delete m_message; -} - -void MessageReceiver::receiveJSON(const QVariantMap &data) -{ - QJsonObject obj = QJsonObject::fromVariantMap(data); - m_message = new QJsonObject(obj); - emit signalMessageReceived(); -} - -QJsonObject * MessageReceiver::getMessage() -{ - return m_message; -} diff --git a/src/lib/sync/fxalogin.h b/src/lib/sync/fxalogin.h index 2658d4097..f853a26cc 100644 --- a/src/lib/sync/fxalogin.h +++ b/src/lib/sync/fxalogin.h @@ -21,12 +21,9 @@ #include #include -class QWebChannel; -class QWebEngineScript; -class QWebEnginePage; class QJsonObject; -class MessageReceiver; class WebPage; +class Communicator; class FxALoginPage : public QWebEngineView { @@ -45,27 +42,7 @@ private: void sendMessage(QJsonObject msg); WebPage *m_page; - MessageReceiver *m_communicator; + Communicator *m_communicator; const QUrl FxALoginUrl = QUrl("https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3"); }; - - -class MessageReceiver : public QObject -{ - Q_OBJECT - -public: - MessageReceiver(QObject *parent = nullptr); - ~MessageReceiver(); - QJsonObject *getMessage(); - -public Q_SLOTS: - void receiveJSON(const QVariantMap &data); - -Q_SIGNALS: - void signalMessageReceived(); - -private: - QJsonObject *m_message; -};