From 90664879c51167eac792139ae65a48da11268244 Mon Sep 17 00:00:00 2001 From: Alexander Lukichev Date: Tue, 21 Jan 2020 20:53:46 +0100 Subject: [PATCH] Option for internal PDFium-based viewer on Qt 5.13+ Summary: Qt 5.13+ has a built-in PDFium-based PDF viewer enabled in QWebEngineSettings by default. There is no way to disable it at run time by the user, and leaving it "as is" changes the browser's behavior, depending on which version of Qt is installed on a target system. The built-in plugin currently has quite a limited functionality and, e.g., misses ability to download the document being viewed. This adds a checkbox in Preferences->Browsing->Web configuration to enable/disable usage of internal Qt's PDF viewer on systems with Qt 5.13 and above. The feature uses Pepper plugin API (PPAPI) of QtWebEngine. The corresponding checkbox's text has been renamed to better reflect its impact on QtWebEngine's operation ("Allow Pepper Plugins (Flash plugin)" -> "Enable Pepper plugin API (PPAPI)"). To clarify dependency of internal PDF viewer on PPAPI, the checkbox gets disabled when the user unchecks "Enable Pepper plugin API (PPAPI)" checkbox. Also, the dependency is mentioned in its text. Reviewers: #falkon, SGOrava Reviewed By: #falkon, SGOrava Subscribers: pshaw, SGOrava, falkon, alukichev Tags: #falkon Differential Revision: https://phabricator.kde.org/D26753 --- src/lib/app/mainapplication.cpp | 4 ++++ src/lib/preferences/preferences.cpp | 13 +++++++++++++ src/lib/preferences/preferences.h | 1 + src/lib/preferences/preferences.ui | 9 ++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 360d3efdb..919fc74a6 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -974,6 +974,10 @@ void MainApplication::loadSettings() webSettings->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, settings.value(QSL("DNSPrefetch"), true).toBool()); #endif +#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 13, 0) + webSettings->setAttribute(QWebEngineSettings::PdfViewerEnabled, settings.value(QSL("intPDFViewer"), false).toBool()); +#endif + webSettings->setDefaultTextEncoding(settings.value(QSL("DefaultEncoding"), webSettings->defaultTextEncoding()).toString()); setWheelScrollLines(settings.value(QSL("wheelScrollLines"), wheelScrollLines()).toInt()); diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 91c581a1a..f3e6f1a05 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -121,6 +121,10 @@ Preferences::Preferences(BrowserWindow* window) ui->dnsPrefetch->setVisible(false); #endif +#if QTWEBENGINEWIDGETS_VERSION < QT_VERSION_CHECK(5, 13, 0) + ui->intPDFViewer->setVisible(false); +#endif + auto setCategoryIcon = [this](int index, const QIcon &icon) { ui->listWidget->item(index)->setIcon(QIcon(icon.pixmap(32))); }; @@ -284,6 +288,7 @@ Preferences::Preferences(BrowserWindow* window) // BROWSING settings.beginGroup("Web-Browser-Settings"); ui->allowPlugins->setChecked(settings.value("allowPlugins", true).toBool()); + connect(ui->allowPlugins, &QAbstractButton::toggled, this, &Preferences::allowPluginsToggled); ui->allowJavaScript->setChecked(settings.value("allowJavaScript", true).toBool()); ui->linksInFocusChain->setChecked(settings.value("IncludeLinkInFocusChain", false).toBool()); ui->spatialNavigation->setChecked(settings.value("SpatialNavigation", false).toBool()); @@ -295,6 +300,8 @@ Preferences::Preferences(BrowserWindow* window) ui->disableVideoAutoPlay->setChecked(settings.value("DisableVideoAutoPlay", false).toBool()); ui->webRTCPublicIpOnly->setChecked(settings.value("WebRTCPublicIpOnly", true).toBool()); ui->dnsPrefetch->setChecked(settings.value("DNSPrefetch", true).toBool()); + ui->intPDFViewer->setChecked(settings.value("intPDFViewer", false).toBool()); + ui->intPDFViewer->setEnabled(ui->allowPlugins->isChecked()); const auto levels = WebView::zoomLevels(); for (int level : levels) { @@ -539,6 +546,11 @@ Preferences::Preferences(BrowserWindow* window) QzTools::setWmClass("Preferences", this); } +void Preferences::allowPluginsToggled(bool checked) +{ + ui->intPDFViewer->setEnabled(checked); +} + void Preferences::chooseExternalDownloadManager() { QString path = QzTools::getOpenFileName("Preferences-ExternalDownloadManager", this, tr("Choose executable location..."), QDir::homePath()); @@ -959,6 +971,7 @@ void Preferences::saveSettings() settings.setValue("DisableVideoAutoPlay", ui->disableVideoAutoPlay->isChecked()); settings.setValue("WebRTCPublicIpOnly", ui->webRTCPublicIpOnly->isChecked()); settings.setValue("DNSPrefetch", ui->dnsPrefetch->isChecked()); + settings.setValue("intPDFViewer", ui->intPDFViewer->isChecked()); #ifdef Q_OS_WIN settings.setValue("CheckDefaultBrowser", ui->checkDefaultBrowser->isChecked()); diff --git a/src/lib/preferences/preferences.h b/src/lib/preferences/preferences.h index 052551c1e..7905fd30a 100644 --- a/src/lib/preferences/preferences.h +++ b/src/lib/preferences/preferences.h @@ -74,6 +74,7 @@ private Q_SLOTS: void setManualProxyConfigurationEnabled(bool state); void useExternalDownManagerChanged(bool state); void changeCachePathClicked(); + void allowPluginsToggled(bool checked); void newTabChanged(int value); void afterLaunchChanged(int value); diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index bb041486b..215d4fccd 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -1008,7 +1008,14 @@ - Allow Pepper Plugins (Flash plugin) + Enable Pepper plugin API (PPAPI) + + + + + + + Use built-in PDF viewer (requires PPAPI)