mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Remove unnecessary debug statements
This commit is contained in:
parent
9932a11d26
commit
ef5a2ab1db
|
@ -339,6 +339,7 @@ qt5_add_resources(SRCS
|
||||||
data/icons.qrc
|
data/icons.qrc
|
||||||
data/breeze-fallback.qrc
|
data/breeze-fallback.qrc
|
||||||
adblock/adblock.qrc
|
adblock/adblock.qrc
|
||||||
|
sync/sync.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(FalkonPrivate SHARED ${SRCS})
|
add_library(FalkonPrivate SHARED ${SRCS})
|
||||||
|
|
16
src/lib/sync/data/inject.js
Normal file
16
src/lib/sync/data/inject.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
function sendMessage(response) {
|
||||||
|
let e = new window.CustomEvent('WebChannelMessageToContent',
|
||||||
|
{detail: response}
|
||||||
|
);
|
||||||
|
window.dispatchEvent(e);
|
||||||
|
}
|
|
@ -28,20 +28,19 @@
|
||||||
FxALoginPage::FxALoginPage(QWidget* parent)
|
FxALoginPage::FxALoginPage(QWidget* parent)
|
||||||
: QWebEngineView(parent)
|
: QWebEngineView(parent)
|
||||||
{
|
{
|
||||||
page = new QWebEnginePage();
|
m_page = new QWebEnginePage();
|
||||||
channel = new QWebChannel(page);
|
m_channel = new QWebChannel(m_page);
|
||||||
page->setWebChannel(channel);
|
m_page->setWebChannel(m_channel);
|
||||||
|
m_page->load(FxALoginUrl);
|
||||||
page->load(FxALoginUrl);
|
this->setPage(m_page);
|
||||||
this->setPage(page);
|
connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(pageLoadFinished(bool)));
|
||||||
connect(page, SIGNAL(loadFinished(bool)), this, SLOT(pageLoadFinished(bool)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FxALoginPage::~FxALoginPage()
|
FxALoginPage::~FxALoginPage()
|
||||||
{
|
{
|
||||||
delete communicator;
|
delete m_communicator;
|
||||||
delete channel;
|
delete m_channel;
|
||||||
delete page;
|
delete m_page;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FxALoginPage::pageLoadFinished(bool pageLoaded)
|
void FxALoginPage::pageLoadFinished(bool pageLoaded)
|
||||||
|
@ -53,74 +52,72 @@ void FxALoginPage::pageLoadFinished(bool pageLoaded)
|
||||||
}
|
}
|
||||||
QString apiScript = QString::fromLatin1(apiFile.readAll());
|
QString apiScript = QString::fromLatin1(apiFile.readAll());
|
||||||
apiFile.close();
|
apiFile.close();
|
||||||
page->runJavaScript(apiScript);
|
m_page->runJavaScript(apiScript);
|
||||||
|
|
||||||
communicator = new MessageReceiver(this);
|
m_communicator = new MessageReceiver(this);
|
||||||
connect(communicator, SIGNAL(signalMessageReceived()),
|
connect(m_communicator, SIGNAL(signalMessageReceived()),
|
||||||
this, SLOT(slotMessageReceived()));
|
this, SLOT(slotMessageReceived()));
|
||||||
|
m_channel->registerObject(QString("communicator"), m_communicator);
|
||||||
|
|
||||||
channel->registerObject(QString("communicator"), communicator);
|
QFile scriptFile(":/data/inject.js");
|
||||||
|
if(!scriptFile.open(QIODevice::ReadOnly)) {
|
||||||
page->runJavaScript("new QWebChannel(qt.webChannelTransport, function(channel) {"
|
qDebug() << "Couldn't load JavaScript file to inject.";
|
||||||
" communicator = channel.objects.communicator;"
|
}
|
||||||
" window.comm = communicator;"
|
QString injectScript = QString::fromLatin1(scriptFile.readAll());
|
||||||
"});"
|
scriptFile.close();
|
||||||
"window.addEventListener('WebChannelMessageToChrome', function(event) {"
|
m_page->runJavaScript(injectScript);
|
||||||
" let e = {type: event.type, detail: event.detail};"
|
|
||||||
" window.comm.receiveJSON(e);"
|
|
||||||
"});"
|
|
||||||
"function sendMessage(response) { let e = new window.CustomEvent('WebChannelMessageToContent', {detail: response}); window.dispatchEvent(e)};"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FxALoginPage::slotMessageReceived()
|
void FxALoginPage::slotMessageReceived()
|
||||||
{
|
{
|
||||||
qDebug() << "===Msg Rcvd by FxALoginPage===";
|
QJsonObject *message = m_communicator->getMessage();
|
||||||
QJsonObject *message = communicator->getMessage();
|
qDebug() << ">>> Received from server:\n " << (*message);
|
||||||
qDebug() << "Message Recieved: ";
|
parseMessage(message);
|
||||||
QJsonObject *response = parseMessage(message);
|
|
||||||
sendMessage(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject * FxALoginPage::parseMessage(QJsonObject *msg)
|
void FxALoginPage::parseMessage(QJsonObject *msg)
|
||||||
{
|
{
|
||||||
/* TODO:
|
QJsonValue command = (*msg).value("detail").toObject().value("message").toObject().value("command");
|
||||||
* Parse the recived message and respond with proper resonse
|
if(command.toString() == QString("fxaccounts:can_link_account")) {
|
||||||
*/
|
QJsonObject responseData;
|
||||||
QJsonValue type = msg->value("type");
|
responseData.insert("ok", true);
|
||||||
QJsonObject detail = msg->value("detail").toObject();
|
QJsonObject message;
|
||||||
|
message.insert("command", command);
|
||||||
|
message.insert("data", responseData);
|
||||||
|
message.insert("messageId", (*msg).value("detail").toObject().value("message").toObject().value("messageId"));
|
||||||
|
QJsonObject response;
|
||||||
|
response.insert("id", (*msg).value("detail").toObject().value("id"));
|
||||||
|
response.insert("message", message);
|
||||||
|
sendMessage(response);
|
||||||
|
}
|
||||||
|
else if(command.toString() == QString("fxaccounts:login")) {
|
||||||
|
QJsonObject data = (*msg).value("detail").toObject().value("message").toObject().value("data").toObject();
|
||||||
|
QString email = data.value("email").toString();
|
||||||
|
QString uid = data.value("uid").toString();
|
||||||
|
QString session_token = data.value("sessionToken").toString();
|
||||||
|
QString key_fetch_token = data.value("keyFetchToken").toString();
|
||||||
|
QString unwrap_kb = data.value("unwrapBKey").toString();
|
||||||
|
|
||||||
QJsonValue channelId = detail.value("id");
|
qDebug() << "===Recieved login credentials:===\n"
|
||||||
QJsonObject message = detail.value("message").toObject();
|
<< " Email: " << email << '\n'
|
||||||
|
<< " UID: " << uid << '\n'
|
||||||
QJsonValue command = message.value("command");
|
<< " Session Token: " << session_token << '\n'
|
||||||
QJsonObject data = message.value("data").toObject();
|
<< " Key Fetch Token: " << key_fetch_token << '\n'
|
||||||
QJsonValue messageId = message.value("messageId");
|
<< " unwrapBKey: " << unwrap_kb << '\n'
|
||||||
|
<< "=================================\n";
|
||||||
QJsonObject resp_data;
|
}
|
||||||
resp_data.insert("ok", QJsonValue(true));
|
|
||||||
|
|
||||||
QJsonObject resp_message;
|
|
||||||
resp_message.insert("command", command);
|
|
||||||
resp_message.insert("data", QJsonValue(resp_data));
|
|
||||||
resp_message.insert("messageId", messageId);
|
|
||||||
|
|
||||||
QJsonObject *response = new QJsonObject();
|
|
||||||
response->insert("id", channelId);
|
|
||||||
response->insert("message", QJsonValue(resp_message));
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FxALoginPage::sendMessage(QJsonObject* msg)
|
void FxALoginPage::sendMessage(QJsonObject msg)
|
||||||
{
|
{
|
||||||
QJsonDocument doc(*msg);
|
QJsonDocument doc(msg);
|
||||||
QString stringMsg(doc.toJson(QJsonDocument::Compact));
|
QString stringMsg(doc.toJson(QJsonDocument::Compact));
|
||||||
qDebug() << ">>> Sending to server: " << stringMsg;
|
qDebug() << "<<< Sending to server:\n " << stringMsg;
|
||||||
|
|
||||||
QString srcCode = "sendMessage(" + stringMsg + ");";
|
QString srcCode = "sendMessage(" + stringMsg + ");";
|
||||||
page->runJavaScript(srcCode);
|
m_page->runJavaScript(srcCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,18 +128,17 @@ MessageReceiver::MessageReceiver(QObject *parent)
|
||||||
|
|
||||||
MessageReceiver::~MessageReceiver()
|
MessageReceiver::~MessageReceiver()
|
||||||
{
|
{
|
||||||
delete message;
|
delete m_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageReceiver::receiveJSON(const QVariantMap &data)
|
void MessageReceiver::receiveJSON(const QVariantMap &data)
|
||||||
{
|
{
|
||||||
QJsonObject obj = QJsonObject::fromVariantMap(data);
|
QJsonObject obj = QJsonObject::fromVariantMap(data);
|
||||||
qDebug() << "Received JSON:\n " << obj;
|
m_message = new QJsonObject(obj);
|
||||||
message = new QJsonObject(obj);
|
|
||||||
emit signalMessageReceived();
|
emit signalMessageReceived();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject * MessageReceiver::getMessage()
|
QJsonObject * MessageReceiver::getMessage()
|
||||||
{
|
{
|
||||||
return message;
|
return m_message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,12 @@ protected slots:
|
||||||
void slotMessageReceived();
|
void slotMessageReceived();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QJsonObject * parseMessage(QJsonObject *msg);
|
void parseMessage(QJsonObject *msg);
|
||||||
void sendMessage(QJsonObject *msg);
|
void sendMessage(QJsonObject msg);
|
||||||
|
|
||||||
QWebEnginePage *page;
|
QWebEnginePage *m_page;
|
||||||
QWebChannel *channel;
|
QWebChannel *m_channel;
|
||||||
MessageReceiver *communicator;
|
MessageReceiver *m_communicator;
|
||||||
|
|
||||||
const QUrl FxALoginUrl = QUrl("https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3");
|
const QUrl FxALoginUrl = QUrl("https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3");
|
||||||
};
|
};
|
||||||
|
@ -67,5 +67,5 @@ signals:
|
||||||
void signalMessageReceived();
|
void signalMessageReceived();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QJsonObject *message;
|
QJsonObject *m_message;
|
||||||
};
|
};
|
||||||
|
|
5
src/lib/sync/sync.qrc
Normal file
5
src/lib/sync/sync.qrc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>data/inject.js</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
Loading…
Reference in New Issue
Block a user