1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Make qupzilla:restore working also with disabled JavaScript

Instead of temporarily enabling JavaScript, make the page functional
without it.
This commit is contained in:
David Rosca 2018-01-06 20:01:07 +01:00
parent 7ebd4039f8
commit e41b0edf0a
5 changed files with 50 additions and 11 deletions

View File

@ -275,9 +275,6 @@ void BrowserWindow::postLaunch()
if (mApp->isStartingAfterCrash()) { if (mApp->isStartingAfterCrash()) {
addTab = false; addTab = false;
startUrl.clear(); startUrl.clear();
// qupzilla:restore needs JavaScript enabled
// correct value is then restored in MainApplication::destroyRestoreManager
mApp->webSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
m_tabWidget->addView(QUrl("falkon:restore"), Qz::NT_CleanSelectedTabAtTheEnd); m_tabWidget->addView(QUrl("falkon:restore"), Qz::NT_CleanSelectedTabAtTheEnd);
} }
else if (mApp->afterLaunch() == MainApplication::SelectSession || mApp->afterLaunch() == MainApplication::RestoreSession) { else if (mApp->afterLaunch() == MainApplication::SelectSession || mApp->afterLaunch() == MainApplication::RestoreSession) {

View File

@ -468,10 +468,6 @@ void MainApplication::destroyRestoreManager()
return; return;
} }
// Restore JavaScript settings
const bool jsEnabled = Settings().value(QSL("Web-Browser-Settings/allowJavaScript"), true).toBool();
m_webProfile->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, jsEnabled);
delete m_restoreManager; delete m_restoreManager;
m_restoreManager = 0; m_restoreManager = 0;
} }

View File

@ -120,6 +120,17 @@ li {padding: 5px;}
vertical-align: top; vertical-align: top;
} }
#listview td.js-disabled
{
text-align: center;
height: 150px;
}
#listview tbody tr.js-disabled:hover
{
background-color: transparent;
}
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
@ -299,11 +310,18 @@ function init()
</tr> </tr>
</thead> </thead>
<tbody id="recovery-items"> <tbody id="recovery-items">
<noscript>
<tr class="js-disabled">
<td class="js-disabled">%JAVASCRIPT-DISABLED%</td>
</tr>
</noscript>
</tbody> </tbody>
</table> </table>
<input class="button" type="button" id="start-new-session-button" value="%BUTTON-START-NEW%" onclick="startNewSession();"> <form>
<input class="button" type="button" id="restore-session-button" value=" %BUTTON-RESTORE% " onclick="restoreSession();"> <input class="button" type="submit" id="start-new-session-button" name="new-session" value="%BUTTON-START-NEW%" onclick="startNewSession();return false;">
<input class="button" type="submit" id="restore-session-button" name="restore-session" value=" %BUTTON-RESTORE% " onclick="restoreSession();return false;">
</form>
</div> </div>
</div> </div>
</body> </body>

View File

@ -27,6 +27,7 @@
#include "datapaths.h" #include "datapaths.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "sessionmanager.h" #include "sessionmanager.h"
#include "restoremanager.h"
#include <QTimer> #include <QTimer>
#include <QSettings> #include <QSettings>
@ -46,6 +47,10 @@ FalkonSchemeHandler::FalkonSchemeHandler(QObject *parent)
void FalkonSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) void FalkonSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
{ {
if (handleRequest(job)) {
return;
}
QStringList knownPages; QStringList knownPages;
knownPages << "about" << "reportbug" << "start" << "speeddial" << "config" << "restore" << "adblock"; knownPages << "about" << "reportbug" << "start" << "speeddial" << "config" << "restore" << "adblock";
@ -55,6 +60,25 @@ void FalkonSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
job->fail(QWebEngineUrlRequestJob::UrlInvalid); job->fail(QWebEngineUrlRequestJob::UrlInvalid);
} }
bool FalkonSchemeHandler::handleRequest(QWebEngineUrlRequestJob *job)
{
QUrlQuery query(job->requestUrl());
if (!query.isEmpty() && job->requestUrl().path() == QL1S("restore")) {
if (mApp->restoreManager()) {
if (query.hasQueryItem(QSL("new-session"))) {
mApp->restoreManager()->clearRestoreData();
} else if (query.hasQueryItem(QSL("restore-session"))) {
mApp->restoreSession(nullptr, mApp->restoreManager()->restoreData());
}
}
mApp->destroyRestoreManager();
job->redirect(QUrl(QSL("falkon:start")));
return true;
}
return false;
}
FalkonSchemeReply::FalkonSchemeReply(QWebEngineUrlRequestJob *job, QObject *parent) FalkonSchemeReply::FalkonSchemeReply(QWebEngineUrlRequestJob *job, QObject *parent)
: QIODevice(parent) : QIODevice(parent)
, m_loaded(false) , m_loaded(false)
@ -282,7 +306,7 @@ QString FalkonSchemeReply::speeddialPage()
dPage.replace(QLatin1String("%TITLE-WARN%"), tr("Are you sure you want to remove this speed dial?")); dPage.replace(QLatin1String("%TITLE-WARN%"), tr("Are you sure you want to remove this speed dial?"));
dPage.replace(QLatin1String("%TITLE-WARN-REL%"), tr("Are you sure you want to reload all speed dials?")); dPage.replace(QLatin1String("%TITLE-WARN-REL%"), tr("Are you sure you want to reload all speed dials?"));
dPage.replace(QLatin1String("%TITLE-FETCHTITLE%"), tr("Load title from page")); dPage.replace(QLatin1String("%TITLE-FETCHTITLE%"), tr("Load title from page"));
dPage.replace(QLatin1String("%JAVASCRIPT-DISABLED%"), tr("SpeedDial requires JavaScript enabled.")); dPage.replace(QLatin1String("%JAVASCRIPT-DISABLED%"), tr("SpeedDial requires enabled JavaScript."));
dPage.replace(QLatin1String("%URL%"), tr("Url")); dPage.replace(QLatin1String("%URL%"), tr("Url"));
dPage.replace(QLatin1String("%TITLE%"), tr("Title")); dPage.replace(QLatin1String("%TITLE%"), tr("Title"));
dPage.replace(QLatin1String("%APPLY%"), tr("Apply")); dPage.replace(QLatin1String("%APPLY%"), tr("Apply"));
@ -333,6 +357,7 @@ QString FalkonSchemeReply::restorePage()
rPage.replace(QLatin1String("%WINDOWS-AND-TABS%"), tr("Windows and Tabs")); rPage.replace(QLatin1String("%WINDOWS-AND-TABS%"), tr("Windows and Tabs"));
rPage.replace(QLatin1String("%BUTTON-START-NEW%"), tr("Start New Session")); rPage.replace(QLatin1String("%BUTTON-START-NEW%"), tr("Start New Session"));
rPage.replace(QLatin1String("%BUTTON-RESTORE%"), tr("Restore")); rPage.replace(QLatin1String("%BUTTON-RESTORE%"), tr("Restore"));
rPage.replace(QLatin1String("%JAVASCRIPT-DISABLED%"), tr("Requires enabled JavaScript."));
rPage = QzTools::applyDirectionToPage(rPage); rPage = QzTools::applyDirectionToPage(rPage);
} }

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* Falkon - Qt web browser * Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -30,6 +30,9 @@ public:
explicit FalkonSchemeHandler(QObject *parent = Q_NULLPTR); explicit FalkonSchemeHandler(QObject *parent = Q_NULLPTR);
void requestStarted(QWebEngineUrlRequestJob *job) Q_DECL_OVERRIDE; void requestStarted(QWebEngineUrlRequestJob *job) Q_DECL_OVERRIDE;
private:
bool handleRequest(QWebEngineUrlRequestJob *job);
}; };
class FALKON_EXPORT FalkonSchemeReply : public QIODevice class FALKON_EXPORT FalkonSchemeReply : public QIODevice