From f87c6897a0a60de404680a6b3e0002849078b380 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 6 Jan 2018 20:33:13 +0100 Subject: [PATCH] WebPage: Always build nonblock js dialogs support Can be enabled with QUPZILLA_ENABLE_JS_NONBLOCK_DIALOGS environment variable. --- BUILDING.md | 17 +---------- CMakeLists.txt | 4 --- src/lib/webengine/webpage.cpp | 54 ++++++++++++++++------------------- 3 files changed, 25 insertions(+), 50 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 3ab466e03..cbb684512 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -66,28 +66,13 @@ Available Defines $ export NAME="value" General: - PORTABLE_BUILD Falkon won't write any data outside of path of execution. + PORTABLE_BUILD Falkon won't write any data outside of path of execution. It will also disable plugins by default. (disabled by default) example: $ export PORTABLE_BUILD="true" - - NONBLOCK_JS_DIALOGS Enable non-blocking JavaScript dialogs from alert() prompt() - and confirm() functions. They are shown inside page and are not - blocking application window. - However, due to synchronous API, there is a possible crash when - closing browser windows with opened dialogs. - If you can take this risk and/or make sure you aren't closing browser - with opened dialogs, you may enable this option. - These dialogs are much more beautiful than normal QDialogs. - (disabled by default) - - example: - $ export NONBLOCK_JS_DIALOGS="true" - - Windows specific defines: W7API Enable Windows 7 API support diff --git a/CMakeLists.txt b/CMakeLists.txt index 19790b745..2e1cee5f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,10 +55,6 @@ option(PORTABLE_BUILD "TODO" OFF) if (PORTABLE_BUILD) add_definitions(-DPORTABLE_BUILD) endif() -option(NONBLOCK_JS_DIALOGS "TODO" OFF) -if (NONBLOCK_JS_DIALOGS) - add_definitions(-DNONBLOCK_JS_DIALOGS) -endif() option(DISABLE_DBUS "TODO" OFF) if (DISABLE_DBUS) add_definitions(-DDISABLE_DBUS) diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index 8314f41ee..3e0cb6931 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -39,15 +39,10 @@ #include "networkmanager.h" #include "webhittestresult.h" #include "adblock/adblockmanager.h" - -#ifdef NONBLOCK_JS_DIALOGS #include "ui_jsconfirm.h" #include "ui_jsalert.h" #include "ui_jsprompt.h" -#include -#endif - #include #include @@ -60,12 +55,14 @@ #include #include #include +#include QString WebPage::s_lastUploadLocation = QDir::homePath(); QUrl WebPage::s_lastUnsupportedUrl; QTime WebPage::s_lastUnsupportedUrlTime; static const bool kEnableJsOutput = qEnvironmentVariableIsSet("QUPZILLA_ENABLE_JS_OUTPUT"); +static const bool kEnableJsNonBlockDialogs = qEnvironmentVariableIsSet("QUPZILLA_ENABLE_JS_NONBLOCK_DIALOGS"); WebPage::WebPage(QObject* parent) : QWebEnginePage(mApp->webProfile(), parent) @@ -429,11 +426,10 @@ QVector WebPage::autoFillData() const bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result) { - Q_UNUSED(securityOrigin) + if (!kEnableJsNonBlockDialogs) { + return QWebEnginePage::javaScriptPrompt(securityOrigin, msg, defaultValue, result); + } -#ifndef NONBLOCK_JS_DIALOGS - return QWebEnginePage::javaScriptPrompt(securityOrigin, msg, defaultValue, result); -#else if (m_runningLoop) { return false; } @@ -469,16 +465,14 @@ bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, c view()->setFocus(); return _result; -#endif } bool WebPage::javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) { - Q_UNUSED(securityOrigin) + if (!kEnableJsNonBlockDialogs) { + return QWebEnginePage::javaScriptConfirm(securityOrigin, msg); + } -#ifndef NONBLOCK_JS_DIALOGS - return QWebEnginePage::javaScriptConfirm(securityOrigin, msg); -#else if (m_runningLoop) { return false; } @@ -510,7 +504,6 @@ bool WebPage::javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) view()->setFocus(); return result; -#endif } void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) @@ -521,22 +514,24 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) return; } -#ifndef NONBLOCK_JS_DIALOGS - QString title = tr("JavaScript alert"); - if (!url().host().isEmpty()) { - title.append(QString(" - %1").arg(url().host())); - } + if (!kEnableJsNonBlockDialogs) { + QString title = tr("JavaScript alert"); + if (!url().host().isEmpty()) { + title.append(QString(" - %1").arg(url().host())); + } - CheckBoxDialog dialog(QMessageBox::Ok, view()); - dialog.setDefaultButton(QMessageBox::Ok); - dialog.setWindowTitle(title); - dialog.setText(msg); - dialog.setCheckBoxText(tr("Prevent this page from creating additional dialogs")); - dialog.setIcon(QMessageBox::Information); - dialog.exec(); + CheckBoxDialog dialog(QMessageBox::Ok, view()); + dialog.setDefaultButton(QMessageBox::Ok); + dialog.setWindowTitle(title); + dialog.setText(msg); + dialog.setCheckBoxText(tr("Prevent this page from creating additional dialogs")); + dialog.setIcon(QMessageBox::Information); + dialog.exec(); + + m_blockAlerts = dialog.isChecked(); + return; + } - m_blockAlerts = dialog.isChecked(); -#else ResizableFrame* widget = new ResizableFrame(view()->overlayWidget()); widget->setObjectName("jsFrame"); @@ -563,7 +558,6 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) delete widget; view()->setFocus(); -#endif } void WebPage::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID)