diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d2cf8d6c..77558ca54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,90 +1,94 @@ cmake_minimum_required(VERSION 3.0) project(Konqueror) set(QT_MIN_VERSION "5.9.0") set(KF5_MIN_VERSION "5.38.0") # get new ECM layout find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) include(FeatureSummary) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMInstallIcons) include(ECMSetupVersion) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) include(CMakePackageConfigHelpers) set(KONQUEROR_LIB_VERSION "5.0.97") set(KONQUEROR_VERSION "${KONQUEROR_LIB_VERSION}") find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Core Widgets WebEngineWidgets) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Parts KCMUtils KHtml Archive Crash WindowSystem Init IconThemes DBusAddons) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS KDELibs4Support) find_package(KF5 ${KF5_MIN_VERSION} COMPONENTS Activities DocTools) # Optional +if(NOT Qt5WebEngineWidgets_VERSION VERSION_LESS "5.13.0") + add_definitions(-DWEBENGINE_PDF_VIEWER) +endif() + find_package(X11) set(KONQ_HAVE_X11 ${X11_FOUND}) if (X11_FOUND) find_package(Qt5 REQUIRED X11Extras) endif(X11_FOUND) add_definitions(-DQT_USE_FAST_OPERATOR_PLUS) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) include (CheckSymbolExists) check_symbol_exists(mallinfo "malloc.h" KDE_MALLINFO_MALLOC) check_symbol_exists(mallinfo "stdlib.h" KDE_MALLINFO_STDLIB) # TODO KDE_MALLINFO_FIELD_hblkhd # TODO KDE_MALLINFO_FIELD_uordblks # TODO KDE_MALLINFO_FIELD_usmblks configure_file (config-konqueror.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-konqueror.h ) configure_file (konqueror-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/konqueror-version.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory( libkonq ) add_subdirectory( src ) add_subdirectory( client ) if(BUILD_TESTING) add_subdirectory( autotests ) endif() add_subdirectory( webenginepart ) add_subdirectory( about ) add_subdirectory( pics ) #add_subdirectory( sidebar ) add_subdirectory( settings ) add_subdirectory( plugins ) if (KF5DocTools_FOUND) add_subdirectory( doc ) endif() ########### install files ############### install( PROGRAMS kfmclient.desktop kfmclient_html.desktop kfmclient_war.desktop kfmclient_dir.desktop konqbrowser.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) install(FILES org.kde.konqueror.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) # Make sure kfmclient can find konqueror.desktop even if people remove it from the K menu (#62242) # This is why konqueror.desktop is installed into services. install( FILES org.kde.konqueror.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install(FILES konqy_preload.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR}) if (${ECM_VERSION} STRGREATER "5.58.0") install(FILES konqueror.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) else() install(FILES konqueror.categories DESTINATION ${KDE_INSTALL_CONFDIR}) endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/settings/konqhtml/htmlopts.cpp b/settings/konqhtml/htmlopts.cpp index f6c08e683..807eb02de 100644 --- a/settings/konqhtml/htmlopts.cpp +++ b/settings/konqhtml/htmlopts.cpp @@ -1,228 +1,246 @@ /* * "Misc Options" Tab for KFM configuration * * Copyright (C) Sven Radej 1998 * Copyright (C) David Faure 1998 * Copyright (C) 2001 Waldo Bastian * */ // Own #include "htmlopts.h" // Qt #include #include #include #include #include #include // KDE #include // get default for DEFAULT_CHANGECURSOR #include #include #include #include // Local #include #include #include //----------------------------------------------------------------------------- KMiscHTMLOptions::KMiscHTMLOptions(QWidget *parent, const QVariantList &) : KCModule(parent), m_groupname(QStringLiteral("HTML Settings")) { m_pConfig = KSharedConfig::openConfig(QStringLiteral("konquerorrc"), KConfig::NoGlobals); QVBoxLayout *lay = new QVBoxLayout(this); // Bookmarks setQuickHelp(i18n("

Konqueror Browser

Here you can configure Konqueror's browser " "functionality. Please note that the file manager " "functionality has to be configured using the \"File Manager\" " "configuration module. You can make some " "settings how Konqueror should handle the HTML code in " "the web pages it loads. It is usually not necessary to " "change anything here.")); QGroupBox *bgBookmarks = new QGroupBox(i18n("Boo&kmarks")); QVBoxLayout *laygroup1 = new QVBoxLayout; m_pAdvancedAddBookmarkCheckBox = new QCheckBox(i18n("Ask for name and folder when adding bookmarks")); laygroup1->addWidget(m_pAdvancedAddBookmarkCheckBox); m_pAdvancedAddBookmarkCheckBox->setWhatsThis(i18n("If this box is checked, Konqueror will allow you to" " change the title of the bookmark and choose a folder" " in which to store it when you add a new bookmark.")); connect(m_pAdvancedAddBookmarkCheckBox, SIGNAL(toggled(bool)), SLOT(changed())); bgBookmarks->setLayout(laygroup1); m_pOnlyMarkedBookmarksCheckBox = new QCheckBox(i18n("Show only marked bookmarks in bookmark toolbar"), bgBookmarks); laygroup1->addWidget(m_pOnlyMarkedBookmarksCheckBox); m_pOnlyMarkedBookmarksCheckBox->setWhatsThis(i18n("If this box is checked, Konqueror will show only those" " bookmarks in the bookmark toolbar which you have marked to do so in the bookmark editor.")); connect(m_pOnlyMarkedBookmarksCheckBox, SIGNAL(toggled(bool)), SLOT(changed())); lay->addWidget(bgBookmarks); // Form completion m_pFormCompletionCheckBox = new QGroupBox(i18n("Form Com&pletion"), this); m_pFormCompletionCheckBox->setCheckable(true); QFormLayout *laygroup2 = new QFormLayout(m_pFormCompletionCheckBox); m_pFormCompletionCheckBox->setWhatsThis(i18n("If this box is checked, Konqueror will remember" " the data you enter in web forms and suggest it in similar fields for all forms.")); connect(m_pFormCompletionCheckBox, SIGNAL(toggled(bool)), SLOT(changed())); m_pMaxFormCompletionItems = new KIntNumInput(this); m_pMaxFormCompletionItems->setRange(0, 100); laygroup2->addRow(i18n("&Maximum completions:"), m_pMaxFormCompletionItems); m_pMaxFormCompletionItems->setWhatsThis( i18n("Here you can select how many values Konqueror will remember for a form field.")); connect(m_pMaxFormCompletionItems, SIGNAL(valueChanged(int)), SLOT(changed())); connect(m_pFormCompletionCheckBox, SIGNAL(toggled(bool)), m_pMaxFormCompletionItems, SLOT(setEnabled(bool))); lay->addWidget(m_pFormCompletionCheckBox); // Mouse behavior QGroupBox *bgMouse = new QGroupBox(i18n("Mouse Beha&vior")); QVBoxLayout *laygroup3 = new QVBoxLayout(bgMouse); m_cbCursor = new QCheckBox(i18n("Chan&ge cursor over links")); laygroup3->addWidget(m_cbCursor); m_cbCursor->setWhatsThis(i18n("If this option is set, the shape of the cursor will change " "(usually to a hand) if it is moved over a hyperlink.")); connect(m_cbCursor, SIGNAL(toggled(bool)), SLOT(changed())); m_pOpenMiddleClick = new QCheckBox(i18n("M&iddle click opens URL in selection"), bgMouse); laygroup3->addWidget(m_pOpenMiddleClick); m_pOpenMiddleClick->setWhatsThis(i18n( "If this box is checked, you can open the URL in the selection by middle clicking on a " "Konqueror view.")); connect(m_pOpenMiddleClick, SIGNAL(toggled(bool)), SLOT(changed())); m_pBackRightClick = new QCheckBox(i18n("Right click goes &back in history"), bgMouse); laygroup3->addWidget(m_pBackRightClick); m_pBackRightClick->setWhatsThis(i18n( "If this box is checked, you can go back in history by right clicking on a Konqueror view. " "To access the context menu, press the right mouse button and move.")); connect(m_pBackRightClick, SIGNAL(toggled(bool)), SLOT(changed())); lay->addWidget(bgMouse); // Misc QGroupBox *bgMisc = new QGroupBox(i18nc("@title:group", "Miscellaneous")); QFormLayout *fl = new QFormLayout(bgMisc); m_pAutoRedirectCheckBox = new QCheckBox(i18n("Allow automatic delayed &reloading/redirecting"), this); m_pAutoRedirectCheckBox->setWhatsThis(i18n("Some web pages request an automatic reload or redirection after" " a certain period of time. By unchecking this box Konqueror will ignore these requests.")); connect(m_pAutoRedirectCheckBox, SIGNAL(toggled(bool)), SLOT(changed())); fl->addRow(m_pAutoRedirectCheckBox); // Checkbox to enable/disable Access Key activation through the Ctrl key. m_pAccessKeys = new QCheckBox(i18n("Enable Access Ke&y activation with Ctrl key"), this); m_pAccessKeys->setWhatsThis(i18n("Pressing the Ctrl key when viewing webpages activates Access Keys. Unchecking this box will disable this accessibility feature. (Konqueror needs to be restarted for this change to take effect.)")); connect(m_pAccessKeys, SIGNAL(toggled(bool)), SLOT(changed())); fl->addRow(m_pAccessKeys); m_pDoNotTrack = new QCheckBox(i18n("Send the DNT header to tell web sites you do not want to be tracked"), this); m_pDoNotTrack->setWhatsThis(i18n("Check this box if you want to inform a web site that you do not want your web browsing habits tracked.")); connect(m_pDoNotTrack, SIGNAL(toggled(bool)), SLOT(changed())); fl->addRow(m_pDoNotTrack); m_pOfferToSaveWebsitePassword = new QCheckBox(i18n("Offer to save website passwords"), this); m_pOfferToSaveWebsitePassword->setWhatsThis(i18n("Uncheck this box to prevent being prompted to save website passwords")); connect(m_pOfferToSaveWebsitePassword, SIGNAL(toggled(bool)), SLOT(changed())); fl->addRow(m_pOfferToSaveWebsitePassword); +#ifdef WEBENGINE_PDF_VIEWER + m_pdfViewer = new QCheckBox(i18n("Display online PDF files using WebEngine")); + m_pdfViewer->setWhatsThis(i18n("Uncheck this box to display online PDF files as configured in System Settings")); + fl->addRow(m_pdfViewer); + connect(m_pdfViewer, &QCheckBox::toggled, this, QOverload<>::of(&KMiscHTMLOptions::changed)); +#endif + lay->addWidget(bgMisc); lay->addStretch(5); emit changed(false); } KMiscHTMLOptions::~KMiscHTMLOptions() { } void KMiscHTMLOptions::load() { KSharedConfigPtr khtmlrcConfig = KSharedConfig::openConfig(QStringLiteral("khtmlrc"), KConfig::NoGlobals); // Read the configuration from konquerorrc with khtmlrc as fall back. KConfigGroup cg(m_pConfig, "MainView Settings"); KConfigGroup cg2(khtmlrcConfig, "MainView Settings"); m_pOpenMiddleClick->setChecked(cg.readEntry("OpenMiddleClick", cg2.readEntry("OpenMiddleClick", true))); m_pBackRightClick->setChecked(cg.readEntry("BackRightClick", cg2.readEntry("BackRightClick", false))); cg = KConfigGroup(m_pConfig, "HTML Settings"); cg2 = KConfigGroup(khtmlrcConfig, "HTML Settings"); m_cbCursor->setChecked(cg.readEntry("ChangeCursor", cg2.readEntry("ChangeCursor", KDE_DEFAULT_CHANGECURSOR))); m_pAutoRedirectCheckBox->setChecked(cg.readEntry("AutoDelayedActions", true)); m_pFormCompletionCheckBox->setChecked(cg.readEntry("FormCompletion", true)); m_pMaxFormCompletionItems->setValue(cg.readEntry("MaxFormCompletionItems", 10)); m_pMaxFormCompletionItems->setEnabled(m_pFormCompletionCheckBox->isChecked()); m_pOfferToSaveWebsitePassword->setChecked(cg.readEntry("OfferToSaveWebsitePassword", true)); +#ifdef WEBENGINE_PDF_VIEWER + m_pdfViewer->setChecked(cg.readEntry("InternalPdfViewer", false)); +#endif + cg2 = KConfigGroup(khtmlrcConfig, "Access Keys"); m_pAccessKeys->setChecked(cg2.readEntry("Enabled", true)); cg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("kbookmarkrc"), KConfig::NoGlobals), "Bookmarks"); m_pAdvancedAddBookmarkCheckBox->setChecked(cg.readEntry("AdvancedAddBookmarkDialog", false)); m_pOnlyMarkedBookmarksCheckBox->setChecked(cg.readEntry("FilteredToolbar", false)); cg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("kioslaverc"), KConfig::NoGlobals), QString()); m_pDoNotTrack->setChecked(cg.readEntry("DoNotTrack", false)); } void KMiscHTMLOptions::defaults() { bool old = m_pConfig->readDefaults(); m_pConfig->setReadDefaults(true); load(); m_pConfig->setReadDefaults(old); m_pAdvancedAddBookmarkCheckBox->setChecked(false); m_pOnlyMarkedBookmarksCheckBox->setChecked(false); m_pDoNotTrack->setChecked(false); m_pOfferToSaveWebsitePassword->setChecked(true); + +#ifdef WEBENGINE_PDF_VIEWER + m_pdfViewer->setChecked(false); +#endif } void KMiscHTMLOptions::save() { KConfigGroup cg(m_pConfig, "MainView Settings"); cg.writeEntry("OpenMiddleClick", m_pOpenMiddleClick->isChecked()); cg.writeEntry("BackRightClick", m_pBackRightClick->isChecked()); cg = KConfigGroup(m_pConfig, "HTML Settings"); cg.writeEntry("ChangeCursor", m_cbCursor->isChecked()); cg.writeEntry("AutoDelayedActions", m_pAutoRedirectCheckBox->isChecked()); cg.writeEntry("FormCompletion", m_pFormCompletionCheckBox->isChecked()); cg.writeEntry("MaxFormCompletionItems", m_pMaxFormCompletionItems->value()); cg.writeEntry("OfferToSaveWebsitePassword", m_pOfferToSaveWebsitePassword->isChecked()); +#ifdef WEBENGINE_PDF_VIEWER + cg.writeEntry("InternalPdfViewer", m_pdfViewer->isChecked()); +#endif cg.sync(); // Writes the value of m_pAccessKeys into khtmlrc to affect all applications using KHTML cg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("khtmlrc"), KConfig::NoGlobals), "Access Keys"); cg.writeEntry("Enabled", m_pAccessKeys->isChecked()); cg.sync(); cg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("kbookmarkrc"), KConfig::NoGlobals), "Bookmarks"); cg.writeEntry("AdvancedAddBookmarkDialog", m_pAdvancedAddBookmarkCheckBox->isChecked()); cg.writeEntry("FilteredToolbar", m_pOnlyMarkedBookmarksCheckBox->isChecked()); cg.sync(); cg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("kioslaverc"), KConfig::NoGlobals), QString()); cg.writeEntry("DoNotTrack", m_pDoNotTrack->isChecked()); cg.sync(); // Send signal to all konqueror instances QDBusConnection sessionBus(QDBusConnection::sessionBus()); sessionBus.send(QDBusMessage::createSignal(QStringLiteral("/KonqMain"), QStringLiteral("org.kde.Konqueror.Main"), QStringLiteral("reparseConfiguration"))); sessionBus.send(QDBusMessage::createSignal(QStringLiteral("/KBookmarkManager/konqueror"), QStringLiteral("org.kde.KIO.KBookmarkManager"), QStringLiteral("bookmarkConfigChanged"))); sessionBus.send(QDBusMessage::createSignal(QStringLiteral("/KIO/Scheduler"), QStringLiteral("org.kde.KIO.Scheduler"), QStringLiteral("reparseSlaveConfiguration"))); emit changed(false); } diff --git a/settings/konqhtml/htmlopts.h b/settings/konqhtml/htmlopts.h index e3f7639ce..d7cd96876 100644 --- a/settings/konqhtml/htmlopts.h +++ b/settings/konqhtml/htmlopts.h @@ -1,54 +1,57 @@ /* "Misc Options" Tab for KFM configuration * * Copyright (c) Sven Radej 1998 * Copyright (c) David Faure 1998 * */ #ifndef HTMLOPTS_H #define HTMLOPTS_H #include //----------------------------------------------------------------------------- // The "Misc Options" Tab for the HTML view contains : // Change cursor over links // Underline links // AutoLoad Images // ... there is room for others :)) #include #include class KIntNumInput; class QGroupBox; class KMiscHTMLOptions : public KCModule { Q_OBJECT public: KMiscHTMLOptions(QWidget *parent, const QVariantList &); ~KMiscHTMLOptions() override; void load() override; void save() override; void defaults() override; private: KSharedConfig::Ptr m_pConfig; QString m_groupname; QCheckBox *m_cbCursor; QCheckBox *m_pAutoRedirectCheckBox; QCheckBox *m_pOpenMiddleClick; QCheckBox *m_pBackRightClick; QGroupBox *m_pFormCompletionCheckBox; QCheckBox *m_pAdvancedAddBookmarkCheckBox; QCheckBox *m_pOnlyMarkedBookmarksCheckBox; QCheckBox *m_pAccessKeys; QCheckBox *m_pDoNotTrack; QCheckBox *m_pOfferToSaveWebsitePassword; KIntNumInput *m_pMaxFormCompletionItems; +#ifdef WEBENGINE_PDF_VIEWER + QCheckBox *m_pdfViewer; +#endif }; #endif // HTMLOPTS_H diff --git a/webenginepart/src/settings/webenginesettings.cpp b/webenginepart/src/settings/webenginesettings.cpp index acbebebce..208dfb3a6 100644 --- a/webenginepart/src/settings/webenginesettings.cpp +++ b/webenginepart/src/settings/webenginesettings.cpp @@ -1,1272 +1,1286 @@ /* This file is part of the KDE project Copyright (C) 1999 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "webenginesettings.h" #include "webengine_filter.h" #include #include "../../src/htmldefaults.h" #include #include #include #include #include #include #include #include #include #include /** * @internal * Contains all settings which are both available globally and per-domain */ struct KPerDomainSettings { bool m_bEnableJava : 1; bool m_bEnableJavaScript : 1; bool m_bEnablePlugins : 1; // don't forget to maintain the bitfields as the enums grow KParts::HtmlSettingsInterface::JSWindowOpenPolicy m_windowOpenPolicy : 2; KParts::HtmlSettingsInterface::JSWindowStatusPolicy m_windowStatusPolicy : 1; KParts::HtmlSettingsInterface::JSWindowFocusPolicy m_windowFocusPolicy : 1; KParts::HtmlSettingsInterface::JSWindowMovePolicy m_windowMovePolicy : 1; KParts::HtmlSettingsInterface::JSWindowResizePolicy m_windowResizePolicy : 1; #ifdef DEBUG_SETTINGS void dump(const QString &infix = QString()) const { kDebug() << "KPerDomainSettings " << infix << " @" << this << ":"; kDebug() << " m_bEnableJava: " << m_bEnableJava; kDebug() << " m_bEnableJavaScript: " << m_bEnableJavaScript; kDebug() << " m_bEnablePlugins: " << m_bEnablePlugins; kDebug() << " m_windowOpenPolicy: " << m_windowOpenPolicy; kDebug() << " m_windowStatusPolicy: " << m_windowStatusPolicy; kDebug() << " m_windowFocusPolicy: " << m_windowFocusPolicy; kDebug() << " m_windowMovePolicy: " << m_windowMovePolicy; kDebug() << " m_windowResizePolicy: " << m_windowResizePolicy; } #endif }; typedef QMap PolicyMap; class WebEngineSettingsData { public: bool m_bChangeCursor : 1; bool m_bOpenMiddleClick : 1; bool m_underlineLink : 1; bool m_hoverLink : 1; bool m_bEnableJavaScriptDebug : 1; bool m_bEnableJavaScriptErrorReporting : 1; bool enforceCharset : 1; bool m_bAutoLoadImages : 1; bool m_bUnfinishedImageFrame : 1; bool m_formCompletionEnabled : 1; bool m_autoDelayedActionsEnabled : 1; bool m_jsErrorsEnabled : 1; bool m_follow_system_colors : 1; bool m_allowTabulation : 1; bool m_autoSpellCheck : 1; bool m_adFilterEnabled : 1; bool m_hideAdsEnabled : 1; bool m_jsPopupBlockerPassivePopup : 1; bool m_accessKeysEnabled : 1; bool m_zoomTextOnly : 1; bool m_useCookieJar : 1; bool m_acceptCrossDomainCookies : 1; bool m_bAutoRefreshPage: 1; bool m_bEnableFavicon:1; bool m_disableInternalPluginHandling:1; bool m_offerToSaveWebSitePassword:1; bool m_loadPluginsOnDemand:1; bool m_enableLocalStorage:1; bool m_enableOfflineStorageDb:1; bool m_enableOfflineWebAppCache:1; bool m_enableWebGL:1; bool m_zoomToDPI:1; bool m_allowActiveMixedContent:1; bool m_allowMixedContentDisplay:1; // the virtual global "domain" KPerDomainSettings global; int m_fontSize; int m_minFontSize; int m_maxFormCompletionItems; WebEngineSettings::KAnimationAdvice m_showAnimations; WebEngineSettings::KSmoothScrollingMode m_smoothScrolling; QString m_encoding; QString m_userSheet; QColor m_textColor; QColor m_baseColor; QColor m_linkColor; QColor m_vLinkColor; PolicyMap domainPolicy; QStringList fonts; QStringList defaultFonts; KDEPrivate::FilterSet adBlackList; KDEPrivate::FilterSet adWhiteList; QList< QPair< QString, QChar > > m_fallbackAccessKeysAssignments; KSharedConfig::Ptr nonPasswordStorableSites; + bool m_internalPdfViewer; }; class WebEngineSettingsPrivate : public QObject, public WebEngineSettingsData { Q_OBJECT public: void adblockFilterLoadList(const QString& filename) { /** load list file and process each line */ QFile file(filename); if (file.open(QIODevice::ReadOnly)) { QTextStream ts(&file); QString line = ts.readLine(); while (!line.isEmpty()) { //kDebug() << "Adding filter:" << line; /** white list lines start with "@@" */ if (line.startsWith(QLatin1String("@@"))) adWhiteList.addFilter(line); else adBlackList.addFilter(line); line = ts.readLine(); } file.close(); } } public Q_SLOTS: void adblockFilterResult(KJob *job) { KIO::StoredTransferJob *tJob = qobject_cast(job); Q_ASSERT(tJob); if ( job->error() == KJob::NoError ) { const QByteArray byteArray = tJob->data(); const QString localFileName = tJob->property( "webenginesettings_adBlock_filename" ).toString(); QFile file(localFileName); if ( file.open(QFile::WriteOnly) ) { const bool success = (file.write(byteArray) == byteArray.size()); if ( success ) adblockFilterLoadList(localFileName); else qCWarning(WEBENGINEPART_LOG) << "Could not write" << byteArray.size() << "to file" << localFileName; file.close(); } else qCDebug(WEBENGINEPART_LOG) << "Cannot open file" << localFileName << "for filter list"; } else qCDebug(WEBENGINEPART_LOG) << "Downloading" << tJob->url() << "failed with message:" << job->errorText(); } }; /** Returns a writeable per-domains settings instance for the given domain * or a deep copy of the global settings if not existent. */ static KPerDomainSettings &setup_per_domain_policy(WebEngineSettingsPrivate* const d, const QString &domain) { if (domain.isEmpty()) qCWarning(WEBENGINEPART_LOG) << "setup_per_domain_policy: domain is empty"; const QString ldomain = domain.toLower(); PolicyMap::iterator it = d->domainPolicy.find(ldomain); if (it == d->domainPolicy.end()) { // simply copy global domain settings (they should have been initialized // by this time) it = d->domainPolicy.insert(ldomain,d->global); } return *it; } template static T readEntry(const KConfigGroup& config, const QString& key, int defaultValue) { return static_cast(config.readEntry(key, defaultValue)); } void WebEngineSettings::readDomainSettings(const KConfigGroup &config, bool reset, bool global, KPerDomainSettings &pd_settings) { const QString javaPrefix ((global ? QString() : QStringLiteral("java."))); const QString jsPrefix ((global ? QString() : QStringLiteral("javascript."))); const QString pluginsPrefix (global ? QString() : QStringLiteral("plugins.")); // The setting for Java QString key = javaPrefix + QLatin1String("EnableJava"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_bEnableJava = config.readEntry( key, false ); else if ( !global ) pd_settings.m_bEnableJava = d->global.m_bEnableJava; // The setting for Plugins key = pluginsPrefix + QLatin1String("EnablePlugins"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_bEnablePlugins = config.readEntry( key, true ); else if ( !global ) pd_settings.m_bEnablePlugins = d->global.m_bEnablePlugins; // The setting for JavaScript key = jsPrefix + QLatin1String("EnableJavaScript"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_bEnableJavaScript = config.readEntry( key, true ); else if ( !global ) pd_settings.m_bEnableJavaScript = d->global.m_bEnableJavaScript; // window property policies key = jsPrefix + QLatin1String("WindowOpenPolicy"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_windowOpenPolicy = readEntry(config, key, KParts::HtmlSettingsInterface::JSWindowOpenSmart); else if ( !global ) pd_settings.m_windowOpenPolicy = d->global.m_windowOpenPolicy; key = jsPrefix + QLatin1String("WindowMovePolicy"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_windowMovePolicy = readEntry(config, key, KParts::HtmlSettingsInterface::JSWindowMoveAllow); else if ( !global ) pd_settings.m_windowMovePolicy = d->global.m_windowMovePolicy; key = jsPrefix + QLatin1String("WindowResizePolicy"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_windowResizePolicy = readEntry(config, key, KParts::HtmlSettingsInterface::JSWindowResizeAllow); else if ( !global ) pd_settings.m_windowResizePolicy = d->global.m_windowResizePolicy; key = jsPrefix + QLatin1String("WindowStatusPolicy"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_windowStatusPolicy = readEntry(config, key, KParts::HtmlSettingsInterface::JSWindowStatusAllow); else if ( !global ) pd_settings.m_windowStatusPolicy = d->global.m_windowStatusPolicy; key = jsPrefix + QLatin1String("WindowFocusPolicy"); if ( (global && reset) || config.hasKey( key ) ) pd_settings.m_windowFocusPolicy = readEntry(config, key, KParts::HtmlSettingsInterface::JSWindowFocusAllow); else if ( !global ) pd_settings.m_windowFocusPolicy = d->global.m_windowFocusPolicy; } WebEngineSettings::WebEngineSettings() :d (new WebEngineSettingsPrivate) { init(); } WebEngineSettings::~WebEngineSettings() { delete d; } bool WebEngineSettings::changeCursor() const { return d->m_bChangeCursor; } bool WebEngineSettings::underlineLink() const { return d->m_underlineLink; } bool WebEngineSettings::hoverLink() const { return d->m_hoverLink; } +bool WebEngineSettings::internalPdfViewer() const +{ + return d->m_internalPdfViewer; +} + void WebEngineSettings::init() { initWebEngineSettings(); KConfig global( QStringLiteral("khtmlrc"), KConfig::NoGlobals ); init( &global, true ); KSharedConfig::Ptr local = KSharedConfig::openConfig(); if ( local ) { init( local.data(), false ); } initNSPluginSettings(); initCookieJarSettings(); } void WebEngineSettings::init( KConfig * config, bool reset ) { KConfigGroup cg( config, "MainView Settings" ); if (reset || cg.exists() ) { if ( reset || cg.hasKey( "OpenMiddleClick" ) ) d->m_bOpenMiddleClick = cg.readEntry( "OpenMiddleClick", true ); } KConfigGroup cgAccess(config,"Access Keys" ); if (reset || cgAccess.exists() ) { d->m_accessKeysEnabled = cgAccess.readEntry( "Enabled", true ); } KConfigGroup cgFilter( config, "Filter Settings" ); if ((reset || cgFilter.exists()) && (d->m_adFilterEnabled = cgFilter.readEntry("Enabled", false))) { d->m_hideAdsEnabled = cgFilter.readEntry("Shrink", false); d->adBlackList.clear(); d->adWhiteList.clear(); /** read maximum age for filter list files, minimum is one day */ int htmlFilterListMaxAgeDays = cgFilter.readEntry(QStringLiteral("HTMLFilterListMaxAgeDays")).toInt(); if (htmlFilterListMaxAgeDays < 1) htmlFilterListMaxAgeDays = 1; QMapIterator it (cgFilter.entryMap()); while (it.hasNext()) { it.next(); int id = -1; const QString name = it.key(); const QString url = it.value(); if (name.startsWith(QLatin1String("Filter"))) { if (url.startsWith(QLatin1String("@@"))) d->adWhiteList.addFilter(url); else d->adBlackList.addFilter(url); } else if (name.startsWith(QLatin1String("HTMLFilterListName-")) && (id = name.midRef(19).toInt()) > 0) { /** check if entry is enabled */ bool filterEnabled = cgFilter.readEntry(QStringLiteral("HTMLFilterListEnabled-").append(QString::number(id))) != QLatin1String("false"); /** get url for HTMLFilterList */ QUrl url(cgFilter.readEntry(QStringLiteral("HTMLFilterListURL-").append(QString::number(id)))); if (filterEnabled && url.isValid()) { /** determine where to cache HTMLFilterList file */ QString localFile = cgFilter.readEntry(QStringLiteral("HTMLFilterListLocalFilename-").append(QString::number(id))); localFile = QStandardPaths::locate(QStandardPaths::ConfigLocation, "khtml/" + localFile); /** determine existence and age of cache file */ QFileInfo fileInfo(localFile); /** load cached file if it exists, irrespective of age */ if (fileInfo.exists()) d->adblockFilterLoadList( localFile ); /** if no cache list file exists or if it is too old ... */ if (!fileInfo.exists() || fileInfo.lastModified().daysTo(QDateTime::currentDateTime()) > htmlFilterListMaxAgeDays) { /** ... in this case, refetch list asynchronously */ // kDebug() << "Fetching filter list from" << url << "to" << localFile; KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo ); QObject::connect( job, SIGNAL(result(KJob*)), d, SLOT(adblockFilterResult(KJob*)) ); /** for later reference, store name of cache file */ job->setProperty("webenginesettings_adBlock_filename", localFile); } } } } } KConfigGroup cgHtml( config, "HTML Settings" ); if (reset || cgHtml.exists() ) { // Fonts and colors if( reset ) { d->defaultFonts = QStringList(); d->defaultFonts.append( cgHtml.readEntry( "StandardFont", QFontDatabase::systemFont(QFontDatabase::GeneralFont).family() ) ); d->defaultFonts.append( cgHtml.readEntry( "FixedFont", QFontDatabase::systemFont(QFontDatabase::FixedFont).family() )); d->defaultFonts.append( cgHtml.readEntry( "SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) ); d->defaultFonts.append( cgHtml.readEntry( "SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) ); d->defaultFonts.append( cgHtml.readEntry( "CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) ); d->defaultFonts.append( cgHtml.readEntry( "FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) ); d->defaultFonts.append( QStringLiteral( "0" ) ); // font size adjustment } if ( reset || cgHtml.hasKey( "MinimumFontSize" ) ) d->m_minFontSize = cgHtml.readEntry( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE ); if ( reset || cgHtml.hasKey( "MediumFontSize" ) ) d->m_fontSize = cgHtml.readEntry( "MediumFontSize", 12 ); d->fonts = cgHtml.readEntry( "Fonts", QStringList() ); if ( reset || cgHtml.hasKey( "DefaultEncoding" ) ) d->m_encoding = cgHtml.readEntry( "DefaultEncoding", "" ); if ( reset || cgHtml.hasKey( "EnforceDefaultCharset" ) ) d->enforceCharset = cgHtml.readEntry( "EnforceDefaultCharset", false ); // Behavior if ( reset || cgHtml.hasKey("UnderlineLinks") ) d->m_underlineLink = cgHtml.readEntry( "UnderlineLinks", true ); if ( reset || cgHtml.hasKey( "HoverLinks" ) ) { if ( (d->m_hoverLink = cgHtml.readEntry( "HoverLinks", false ))) d->m_underlineLink = false; } if ( reset || cgHtml.hasKey( "AllowTabulation" ) ) d->m_allowTabulation = cgHtml.readEntry( "AllowTabulation", false ); if ( reset || cgHtml.hasKey( "AutoSpellCheck" ) ) d->m_autoSpellCheck = cgHtml.readEntry( "AutoSpellCheck", true ); // Other if ( reset || cgHtml.hasKey( "AutoLoadImages" ) ) d->m_bAutoLoadImages = cgHtml.readEntry( "AutoLoadImages", true ); if ( reset || cgHtml.hasKey( "AutoDelayedActions" ) ) d->m_bAutoRefreshPage = cgHtml.readEntry( "AutoDelayedActions", true ); if ( reset || cgHtml.hasKey( "UnfinishedImageFrame" ) ) d->m_bUnfinishedImageFrame = cgHtml.readEntry( "UnfinishedImageFrame", true ); if ( reset || cgHtml.hasKey( "ShowAnimations" ) ) { QString value = cgHtml.readEntry( "ShowAnimations").toLower(); if (value == QLatin1String("disabled")) d->m_showAnimations = KAnimationDisabled; else if (value == QLatin1String("looponce")) d->m_showAnimations = KAnimationLoopOnce; else d->m_showAnimations = KAnimationEnabled; } if ( reset || cgHtml.hasKey( "SmoothScrolling" ) ) { QString value = cgHtml.readEntry( "SmoothScrolling", "whenefficient" ).toLower(); if (value == QLatin1String("disabled")) d->m_smoothScrolling = KSmoothScrollingDisabled; else if (value == QLatin1String("whenefficient")) d->m_smoothScrolling = KSmoothScrollingWhenEfficient; else d->m_smoothScrolling = KSmoothScrollingEnabled; } if ( reset || cgHtml.hasKey( "ZoomTextOnly" ) ) { d->m_zoomTextOnly = cgHtml.readEntry( "ZoomTextOnly", false ); } if ( reset || cgHtml.hasKey( "ZoomToDPI" ) ) { d->m_zoomToDPI = cgHtml.readEntry( "ZoomToDPI", false ); } if (cgHtml.readEntry("UserStyleSheetEnabled", false)) { if (reset || cgHtml.hasKey("UserStyleSheet")) d->m_userSheet = cgHtml.readEntry("UserStyleSheet", QString()); } else { d->m_userSheet.clear(); } + if (reset || cgHtml.hasKey("InternalPdfViewer")) { + d->m_internalPdfViewer = cgHtml.readEntry("InternalPdfViewer", false); + } + d->m_formCompletionEnabled = cgHtml.readEntry("FormCompletion", true); d->m_maxFormCompletionItems = cgHtml.readEntry("MaxFormCompletionItems", 10); d->m_autoDelayedActionsEnabled = cgHtml.readEntry ("AutoDelayedActions", true); d->m_jsErrorsEnabled = cgHtml.readEntry("ReportJSErrors", true); const QStringList accesskeys = cgHtml.readEntry("FallbackAccessKeysAssignments", QStringList()); d->m_fallbackAccessKeysAssignments.clear(); for( QStringList::ConstIterator it = accesskeys.begin(); it != accesskeys.end(); ++it ) if( (*it).length() > 2 && (*it)[ 1 ] == ':' ) d->m_fallbackAccessKeysAssignments.append( qMakePair( (*it).mid( 2 ), (*it)[ 0 ] )); d->m_bEnableFavicon = cgHtml.readEntry("EnableFavicon", true); d->m_offerToSaveWebSitePassword = cgHtml.readEntry("OfferToSaveWebsitePassword", true); } // Colors //In which group ????? if ( reset || cg.hasKey( "FollowSystemColors" ) ) d->m_follow_system_colors = cg.readEntry( "FollowSystemColors", false ); KConfigGroup cgGeneral( config, "General" ); if ( reset || cgGeneral.exists( ) ) { if ( reset || cgGeneral.hasKey( "foreground" ) ) { QColor def(HTML_DEFAULT_TXT_COLOR); d->m_textColor = cgGeneral.readEntry( "foreground", def ); } if ( reset || cgGeneral.hasKey( "linkColor" ) ) { QColor def(HTML_DEFAULT_LNK_COLOR); d->m_linkColor = cgGeneral.readEntry( "linkColor", def ); } if ( reset || cgGeneral.hasKey( "visitedLinkColor" ) ) { QColor def(HTML_DEFAULT_VLNK_COLOR); d->m_vLinkColor = cgGeneral.readEntry( "visitedLinkColor", def); } if ( reset || cgGeneral.hasKey( "background" ) ) { QColor def(HTML_DEFAULT_BASE_COLOR); d->m_baseColor = cgGeneral.readEntry( "background", def); } } KConfigGroup cgJava( config, "Java/JavaScript Settings" ); if( reset || cgJava.exists() ) { // The global setting for JavaScript debugging // This is currently always enabled by default if ( reset || cgJava.hasKey( "EnableJavaScriptDebug" ) ) d->m_bEnableJavaScriptDebug = cgJava.readEntry( "EnableJavaScriptDebug", false ); // The global setting for JavaScript error reporting if ( reset || cgJava.hasKey( "ReportJavaScriptErrors" ) ) d->m_bEnableJavaScriptErrorReporting = cgJava.readEntry( "ReportJavaScriptErrors", false ); // The global setting for popup block passive popup if ( reset || cgJava.hasKey( "PopupBlockerPassivePopup" ) ) d->m_jsPopupBlockerPassivePopup = cgJava.readEntry("PopupBlockerPassivePopup", true ); // Read options from the global "domain" readDomainSettings(cgJava,reset,true,d->global); #ifdef DEBUG_SETTINGS d->global.dump("init global"); #endif // The domain-specific settings. static const char *const domain_keys[] = { // always keep order of keys "ECMADomains", "JavaDomains", "PluginDomains" }; bool check_old_ecma_settings = true; bool check_old_java_settings = true; // merge all domains into one list QSet domainList; for (unsigned i = 0; i < sizeof domain_keys/sizeof domain_keys[0]; ++i) { if (reset || cgJava.hasKey(domain_keys[i])) { if (i == 0) check_old_ecma_settings = false; else if (i == 1) check_old_java_settings = false; const QStringList dl = cgJava.readEntry( domain_keys[i], QStringList() ); const QSet::Iterator notfound = domainList.end(); QStringList::ConstIterator it = dl.begin(); const QStringList::ConstIterator itEnd = dl.end(); for (; it != itEnd; ++it) { const QString domain = (*it).toLower(); QSet::Iterator pos = domainList.find(domain); if (pos == notfound) domainList.insert(domain); }/*next it*/ } }/*next i*/ if (reset) d->domainPolicy.clear(); { QSet::ConstIterator it = domainList.constBegin(); const QSet::ConstIterator itEnd = domainList.constEnd(); for ( ; it != itEnd; ++it) { const QString domain = *it; KConfigGroup cg( config, domain ); readDomainSettings(cg,reset,false,d->domainPolicy[domain]); #ifdef DEBUG_SETTINGS d->domainPolicy[domain].dump("init "+domain); #endif } } bool check_old_java = true; if( (reset || cgJava.hasKey("JavaDomainSettings")) && check_old_java_settings) { check_old_java = false; const QStringList domainList = cgJava.readEntry( "JavaDomainSettings", QStringList() ); QStringList::ConstIterator it = domainList.constBegin(); const QStringList::ConstIterator itEnd = domainList.constEnd(); for ( ; it != itEnd; ++it) { QString domain; KParts::HtmlSettingsInterface::JavaScriptAdvice javaAdvice; KParts::HtmlSettingsInterface::JavaScriptAdvice javaScriptAdvice; KParts::HtmlSettingsInterface::splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice); setup_per_domain_policy(d,domain).m_bEnableJava = javaAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept; #ifdef DEBUG_SETTINGS setup_per_domain_policy(d,domain).dump("JavaDomainSettings 4 "+domain); #endif } } bool check_old_ecma = true; if( ( reset || cgJava.hasKey( "ECMADomainSettings" ) ) && check_old_ecma_settings ) { check_old_ecma = false; const QStringList domainList = cgJava.readEntry( "ECMADomainSettings", QStringList() ); QStringList::ConstIterator it = domainList.constBegin(); const QStringList::ConstIterator itEnd = domainList.constEnd(); for ( ; it != itEnd; ++it) { QString domain; KParts::HtmlSettingsInterface::JavaScriptAdvice javaAdvice; KParts::HtmlSettingsInterface::JavaScriptAdvice javaScriptAdvice; KParts::HtmlSettingsInterface::splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice); setup_per_domain_policy(d,domain).m_bEnableJavaScript = javaScriptAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept; #ifdef DEBUG_SETTINGS setup_per_domain_policy(d,domain).dump("ECMADomainSettings 4 "+domain); #endif } } if( ( reset || cgJava.hasKey( "JavaScriptDomainAdvice" ) ) && ( check_old_java || check_old_ecma ) && ( check_old_ecma_settings || check_old_java_settings ) ) { const QStringList domainList = cgJava.readEntry( "JavaScriptDomainAdvice", QStringList() ); QStringList::ConstIterator it = domainList.constBegin(); const QStringList::ConstIterator itEnd = domainList.constEnd(); for ( ; it != itEnd; ++it) { QString domain; KParts::HtmlSettingsInterface::JavaScriptAdvice javaAdvice; KParts::HtmlSettingsInterface::JavaScriptAdvice javaScriptAdvice; KParts::HtmlSettingsInterface::splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice); if( check_old_java ) setup_per_domain_policy(d,domain).m_bEnableJava = javaAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept; if( check_old_ecma ) setup_per_domain_policy(d,domain).m_bEnableJavaScript = javaScriptAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept; #ifdef DEBUG_SETTINGS setup_per_domain_policy(d,domain).dump("JavaScriptDomainAdvice 4 "+domain); #endif } } } #if 0 // DNS Prefect support... if ( reset || cgHtml.hasKey( "DNSPrefetch" ) ) { // Enabled, Disabled, OnlyWWWAndSLD QString value = cgHtml.readEntry( "DNSPrefetch", "Enabled" ).toLower(); if (value == "enabled") QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, true); else QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, false); } // Sync with QWebEngineSettings. if (!d->m_encoding.isEmpty()) QWebEngineSettings::defaultSettings()->setDefaultTextEncoding(d->m_encoding); QWebEngineSettings::defaultSettings()->setUserStyleSheetUrl(QUrl::fromUserInput(userStyleSheet())); #endif QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::AutoLoadImages, autoLoadImages()); QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, isJavaScriptEnabled()); // QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::JavaEnabled, isJavaEnabled()); QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, isPluginsEnabled()); // By default disable JS window.open when policy is deny or smart. const KParts::HtmlSettingsInterface::JSWindowOpenPolicy policy = windowOpenPolicy(); if (policy == KParts::HtmlSettingsInterface::JSWindowOpenDeny || policy == KParts::HtmlSettingsInterface::JSWindowOpenSmart) QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false); else QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true); // QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::ZoomTextOnly, zoomTextOnly()); // QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::DeveloperExtrasEnabled, isJavaScriptDebugEnabled()); QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::StandardFont, stdFontName()); QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::FixedFont, fixedFontName()); QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::SerifFont, serifFontName()); QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::SansSerifFont, sansSerifFontName()); QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::CursiveFont, cursiveFontName()); QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::FantasyFont, fantasyFontName()); // TODO: Create a webengine config module that gets embedded into Konqueror's kcm. // Turn on WebGL support // QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::WebGLEnabled, d->m_enableWebGL); // Turn on HTML 5 local and offline storage capabilities... // QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::OfflineStorageDatabaseEnabled, d->m_enableOfflineStorageDb); // QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::OfflineWebApplicationCacheEnabled, d->m_enableOfflineWebAppCache); QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, d->m_enableLocalStorage); QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, smoothScrolling() != KSmoothScrollingDisabled); +#ifdef WEBENGINE_PDF_VIEWER + QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PdfViewerEnabled, internalPdfViewer()); +#endif + // These numbers should be calculated from real "logical" DPI/72, using a default dpi of 96 for now computeFontSizes(96); } void WebEngineSettings::computeFontSizes( int logicalDpi ) { if (zoomToDPI()) logicalDpi = 96; float toPix = logicalDpi/72.0; if (toPix < 96.0/72.0) toPix = 96.0/72.0; QWebEngineSettings::defaultSettings()->setFontSize(QWebEngineSettings::MinimumFontSize, qRound(minFontSize() * toPix)); QWebEngineSettings::defaultSettings()->setFontSize(QWebEngineSettings::DefaultFontSize, qRound(mediumFontSize() * toPix)); } bool WebEngineSettings::zoomToDPI() const { return d->m_zoomToDPI; } void WebEngineSettings::setZoomToDPI(bool enabled) { d->m_zoomToDPI = enabled; // save it KConfigGroup cg( KSharedConfig::openConfig(), "HTML Settings"); cg.writeEntry("ZoomToDPI", enabled); cg.sync(); } /** Local helper for retrieving per-domain settings. * * In case of doubt, the global domain is returned. */ static const KPerDomainSettings& lookup_hostname_policy(const WebEngineSettingsPrivate* const d, const QString& hostname) { #ifdef DEBUG_SETTINGS kDebug() << "lookup_hostname_policy(" << hostname << ")"; #endif if (hostname.isEmpty()) { #ifdef DEBUG_SETTINGS d->global.dump("global"); #endif return d->global; } const PolicyMap::const_iterator notfound = d->domainPolicy.constEnd(); // First check whether there is a perfect match. PolicyMap::const_iterator it = d->domainPolicy.find(hostname); if( it != notfound ) { #ifdef DEBUG_SETTINGS kDebug() << "perfect match"; (*it).dump(hostname); #endif // yes, use it (unless dunno) return *it; } // Now, check for partial match. Chop host from the left until // there's no dots left. QString host_part = hostname; int dot_idx = -1; while( (dot_idx = host_part.indexOf(QChar('.'))) >= 0 ) { host_part.remove(0,dot_idx); it = d->domainPolicy.find(host_part); Q_ASSERT(notfound == d->domainPolicy.end()); if( it != notfound ) { #ifdef DEBUG_SETTINGS kDebug() << "partial match"; (*it).dump(host_part); #endif return *it; } // assert(host_part[0] == QChar('.')); host_part.remove(0,1); // Chop off the dot. } // No domain-specific entry: use global domain #ifdef DEBUG_SETTINGS kDebug() << "no match"; d->global.dump("global"); #endif return d->global; } bool WebEngineSettings::isOpenMiddleClickEnabled() { return d->m_bOpenMiddleClick; } bool WebEngineSettings::accessKeysEnabled() const { return d->m_accessKeysEnabled; } bool WebEngineSettings::favIconsEnabled() const { return d->m_bEnableFavicon; } bool WebEngineSettings::isAdFilterEnabled() const { return d->m_adFilterEnabled; } bool WebEngineSettings::isHideAdsEnabled() const { return d->m_hideAdsEnabled; } bool WebEngineSettings::isAdFiltered( const QString &url ) const { if (!d->m_adFilterEnabled) return false; if (url.startsWith(QLatin1String("data:"))) return false; return d->adBlackList.isUrlMatched(url) && !d->adWhiteList.isUrlMatched(url); } QString WebEngineSettings::adFilteredBy( const QString &url, bool *isWhiteListed ) const { QString m = d->adWhiteList.urlMatchedBy(url); if (!m.isEmpty()) { if (isWhiteListed != nullptr) *isWhiteListed = true; return m; } m = d->adBlackList.urlMatchedBy(url); if (m.isEmpty()) return QString(); if (isWhiteListed != nullptr) *isWhiteListed = false; return m; } void WebEngineSettings::addAdFilter( const QString &url ) { KConfigGroup config = KSharedConfig::openConfig( QStringLiteral("khtmlrc"), KConfig::NoGlobals )->group( "Filter Settings" ); QRegExp rx; // Try compiling to avoid invalid stuff. Only support the basic syntax here... // ### refactor somewhat if (url.length()>2 && url[0]=='/' && url[url.length()-1] == '/') { const QString inside = url.mid(1, url.length()-2); rx.setPattern(inside); } else { rx.setPatternSyntax(QRegExp::Wildcard); rx.setPattern(url); } if (rx.isValid()) { int last=config.readEntry("Count", 0); const QString key = "Filter-" + QString::number(last); config.writeEntry(key, url); config.writeEntry("Count",last+1); config.sync(); if (url.startsWith(QLatin1String("@@"))) d->adWhiteList.addFilter(url); else d->adBlackList.addFilter(url); } else { KMessageBox::error(nullptr, rx.errorString(), i18n("Filter error")); } } bool WebEngineSettings::isJavaEnabled( const QString& hostname ) const { return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJava; } bool WebEngineSettings::isJavaScriptEnabled( const QString& hostname ) const { return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJavaScript; } bool WebEngineSettings::isJavaScriptDebugEnabled( const QString& /*hostname*/ ) const { // debug setting is global for now, but could change in the future return d->m_bEnableJavaScriptDebug; } bool WebEngineSettings::isJavaScriptErrorReportingEnabled( const QString& /*hostname*/ ) const { // error reporting setting is global for now, but could change in the future return d->m_bEnableJavaScriptErrorReporting; } bool WebEngineSettings::isPluginsEnabled( const QString& hostname ) const { return lookup_hostname_policy(d,hostname.toLower()).m_bEnablePlugins; } KParts::HtmlSettingsInterface::JSWindowOpenPolicy WebEngineSettings::windowOpenPolicy(const QString& hostname) const { return lookup_hostname_policy(d,hostname.toLower()).m_windowOpenPolicy; } KParts::HtmlSettingsInterface::JSWindowMovePolicy WebEngineSettings::windowMovePolicy(const QString& hostname) const { return lookup_hostname_policy(d,hostname.toLower()).m_windowMovePolicy; } KParts::HtmlSettingsInterface::JSWindowResizePolicy WebEngineSettings::windowResizePolicy(const QString& hostname) const { return lookup_hostname_policy(d,hostname.toLower()).m_windowResizePolicy; } KParts::HtmlSettingsInterface::JSWindowStatusPolicy WebEngineSettings::windowStatusPolicy(const QString& hostname) const { return lookup_hostname_policy(d,hostname.toLower()).m_windowStatusPolicy; } KParts::HtmlSettingsInterface::JSWindowFocusPolicy WebEngineSettings::windowFocusPolicy(const QString& hostname) const { return lookup_hostname_policy(d,hostname.toLower()).m_windowFocusPolicy; } int WebEngineSettings::mediumFontSize() const { return d->m_fontSize; } int WebEngineSettings::minFontSize() const { return d->m_minFontSize; } QString WebEngineSettings::settingsToCSS() const { // lets start with the link properties QString str = QStringLiteral("a:link {\ncolor: "); str += d->m_linkColor.name(); str += ';'; if(d->m_underlineLink) str += QLatin1String("\ntext-decoration: underline;"); if( d->m_bChangeCursor ) { str += QLatin1String("\ncursor: pointer;"); str += QLatin1String("\n}\ninput[type=image] { cursor: pointer;"); } str += QLatin1String("\n}\n"); str += QLatin1String("a:visited {\ncolor: "); str += d->m_vLinkColor.name(); str += ';'; if(d->m_underlineLink) str += QLatin1String("\ntext-decoration: underline;"); if( d->m_bChangeCursor ) str += QLatin1String("\ncursor: pointer;"); str += QLatin1String("\n}\n"); if(d->m_hoverLink) str += QLatin1String("a:link:hover, a:visited:hover { text-decoration: underline; }\n"); return str; } QString WebEngineSettings::lookupFont(int i) const { if (d->fonts.count() > i) { return d->fonts.at(i); } if (d->defaultFonts.count() > i) { return d->defaultFonts.at(i); } return QString(); } QString WebEngineSettings::stdFontName() const { return lookupFont(0); } QString WebEngineSettings::fixedFontName() const { return lookupFont(1); } QString WebEngineSettings::serifFontName() const { return lookupFont(2); } QString WebEngineSettings::sansSerifFontName() const { return lookupFont(3); } QString WebEngineSettings::cursiveFontName() const { return lookupFont(4); } QString WebEngineSettings::fantasyFontName() const { return lookupFont(5); } void WebEngineSettings::setStdFontName(const QString &n) { while(d->fonts.count() <= 0) d->fonts.append(QString()); d->fonts[0] = n; } void WebEngineSettings::setFixedFontName(const QString &n) { while(d->fonts.count() <= 1) d->fonts.append(QString()); d->fonts[1] = n; } QString WebEngineSettings::userStyleSheet() const { return d->m_userSheet; } bool WebEngineSettings::isFormCompletionEnabled() const { return d->m_formCompletionEnabled; } int WebEngineSettings::maxFormCompletionItems() const { return d->m_maxFormCompletionItems; } const QString &WebEngineSettings::encoding() const { return d->m_encoding; } bool WebEngineSettings::followSystemColors() const { return d->m_follow_system_colors; } const QColor& WebEngineSettings::textColor() const { return d->m_textColor; } const QColor& WebEngineSettings::baseColor() const { return d->m_baseColor; } const QColor& WebEngineSettings::linkColor() const { return d->m_linkColor; } const QColor& WebEngineSettings::vLinkColor() const { return d->m_vLinkColor; } bool WebEngineSettings::autoPageRefresh() const { return d->m_bAutoRefreshPage; } bool WebEngineSettings::autoLoadImages() const { return d->m_bAutoLoadImages; } bool WebEngineSettings::unfinishedImageFrame() const { return d->m_bUnfinishedImageFrame; } WebEngineSettings::KAnimationAdvice WebEngineSettings::showAnimations() const { return d->m_showAnimations; } WebEngineSettings::KSmoothScrollingMode WebEngineSettings::smoothScrolling() const { return d->m_smoothScrolling; } bool WebEngineSettings::zoomTextOnly() const { return d->m_zoomTextOnly; } bool WebEngineSettings::isAutoDelayedActionsEnabled() const { return d->m_autoDelayedActionsEnabled; } bool WebEngineSettings::jsErrorsEnabled() const { return d->m_jsErrorsEnabled; } void WebEngineSettings::setJSErrorsEnabled(bool enabled) { d->m_jsErrorsEnabled = enabled; // save it KConfigGroup cg( KSharedConfig::openConfig(), "HTML Settings"); cg.writeEntry("ReportJSErrors", enabled); cg.sync(); } bool WebEngineSettings::allowTabulation() const { return d->m_allowTabulation; } bool WebEngineSettings::autoSpellCheck() const { return d->m_autoSpellCheck; } QList< QPair< QString, QChar > > WebEngineSettings::fallbackAccessKeysAssignments() const { return d->m_fallbackAccessKeysAssignments; } void WebEngineSettings::setJSPopupBlockerPassivePopup(bool enabled) { d->m_jsPopupBlockerPassivePopup = enabled; // save it KConfigGroup cg( KSharedConfig::openConfig(), "Java/JavaScript Settings"); cg.writeEntry("PopupBlockerPassivePopup", enabled); cg.sync(); } bool WebEngineSettings::jsPopupBlockerPassivePopup() const { return d->m_jsPopupBlockerPassivePopup; } bool WebEngineSettings::isCookieJarEnabled() const { return d->m_useCookieJar; } bool WebEngineSettings::acceptCrossDomainCookies() const { return d->m_acceptCrossDomainCookies; } // Password storage... static KConfigGroup nonPasswordStorableSitesCg(KSharedConfig::Ptr& configPtr) { if (!configPtr) { configPtr = KSharedConfig::openConfig(QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("khtml/formcompletions")), KConfig::NoGlobals); } return KConfigGroup(configPtr, "NonPasswordStorableSites"); } bool WebEngineSettings::isNonPasswordStorableSite(const QString &host) const { KConfigGroup cg = nonPasswordStorableSitesCg(d->nonPasswordStorableSites); const QStringList sites = cg.readEntry("Sites", QStringList()); return sites.contains(host); } void WebEngineSettings::addNonPasswordStorableSite(const QString &host) { KConfigGroup cg = nonPasswordStorableSitesCg(d->nonPasswordStorableSites); QStringList sites = cg.readEntry("Sites", QStringList()); sites.append(host); cg.writeEntry("Sites", sites); cg.sync(); } void WebEngineSettings::removeNonPasswordStorableSite(const QString &host) { KConfigGroup cg = nonPasswordStorableSitesCg(d->nonPasswordStorableSites); QStringList sites = cg.readEntry("Sites", QStringList()); sites.removeOne(host); cg.writeEntry("Sites", sites); cg.sync(); } bool WebEngineSettings::askToSaveSitePassword() const { return d->m_offerToSaveWebSitePassword; } bool WebEngineSettings::isInternalPluginHandlingDisabled() const { return d->m_disableInternalPluginHandling; } bool WebEngineSettings::isLoadPluginsOnDemandEnabled() const { return d->m_loadPluginsOnDemand; } bool WebEngineSettings::allowMixedContentDisplay() const { return d->m_allowMixedContentDisplay; } bool WebEngineSettings::alowActiveMixedContent() const { return d->m_allowActiveMixedContent; } void WebEngineSettings::initWebEngineSettings() { KConfig cfg (QStringLiteral("webenginepartrc"), KConfig::NoGlobals); KConfigGroup generalCfg (&cfg, "General"); d->m_disableInternalPluginHandling = generalCfg.readEntry("DisableInternalPluginHandling", false); d->m_enableLocalStorage = generalCfg.readEntry("EnableLocalStorage", true); d->m_enableOfflineStorageDb = generalCfg.readEntry("EnableOfflineStorageDatabase", true); d->m_enableOfflineWebAppCache = generalCfg.readEntry("EnableOfflineWebApplicationCache", true); d->m_enableWebGL = generalCfg.readEntry("EnableWebGL", true); d->m_allowActiveMixedContent = generalCfg.readEntry("AllowActiveMixedContent", false); d->m_allowMixedContentDisplay = generalCfg.readEntry("AllowMixedContentDisplay", true); // Force the reloading of the non password storable sites settings. d->nonPasswordStorableSites.reset(); } void WebEngineSettings::initCookieJarSettings() { KSharedConfig::Ptr cookieCfgPtr = KSharedConfig::openConfig(QStringLiteral("kcookiejarrc"), KConfig::NoGlobals); KConfigGroup cookieCfg ( cookieCfgPtr, "Cookie Policy"); d->m_useCookieJar = cookieCfg.readEntry("Cookies", false); d->m_acceptCrossDomainCookies = !cookieCfg.readEntry("RejectCrossDomainCookies", true); } void WebEngineSettings::initNSPluginSettings() { KSharedConfig::Ptr cookieCfgPtr = KSharedConfig::openConfig(QStringLiteral("kcmnspluginrc"), KConfig::NoGlobals); KConfigGroup cookieCfg ( cookieCfgPtr, "Misc"); d->m_loadPluginsOnDemand = cookieCfg.readEntry("demandLoad", false); } WebEngineSettings* WebEngineSettings::self() { static WebEngineSettings s_webEngineSettings; return &s_webEngineSettings; } #include "webenginesettings.moc" diff --git a/webenginepart/src/settings/webenginesettings.h b/webenginepart/src/settings/webenginesettings.h index 2bd4e4ab2..6d07466d2 100644 --- a/webenginepart/src/settings/webenginesettings.h +++ b/webenginepart/src/settings/webenginesettings.h @@ -1,216 +1,219 @@ /* This file is part of the KDE project Copyright (C) 1999 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef WEBENGINESETTINGS_H #define WEBENGINESETTINGS_H class KConfig; class KConfigGroup; #include #include #include #include #include struct KPerDomainSettings; class WebEngineSettingsPrivate; /** * Settings for the HTML view. */ class WebEngineSettings { public: enum KAnimationAdvice { KAnimationDisabled=0, KAnimationLoopOnce, KAnimationEnabled }; enum KSmoothScrollingMode { KSmoothScrollingDisabled=0, KSmoothScrollingWhenEfficient, KSmoothScrollingEnabled }; /** * Called by constructor and reparseConfiguration */ void init(); /** * Destructor. Don't delete any instance by yourself. */ virtual ~WebEngineSettings(); void computeFontSizes(int logicalDpi); bool zoomToDPI() const; void setZoomToDPI(bool b); // Automatic page reload/refresh... bool autoPageRefresh() const; bool isOpenMiddleClickEnabled(); // Java and JavaScript bool isJavaEnabled( const QString& hostname = QString() ) const; bool isJavaScriptEnabled( const QString& hostname = QString() ) const; bool isJavaScriptDebugEnabled( const QString& hostname = QString() ) const; bool isJavaScriptErrorReportingEnabled( const QString& hostname = QString() ) const; bool isPluginsEnabled( const QString& hostname = QString() ) const; bool isLoadPluginsOnDemandEnabled() const; bool isInternalPluginHandlingDisabled() const; // AdBlocK Filtering bool isAdFiltered( const QString &url ) const; bool isAdFilterEnabled() const; bool isHideAdsEnabled() const; void addAdFilter( const QString &url ); QString adFilteredBy( const QString &url, bool *isWhiteListed = nullptr ) const; // Access Keys bool accessKeysEnabled() const; // Favicons bool favIconsEnabled() const; KParts::HtmlSettingsInterface::JSWindowOpenPolicy windowOpenPolicy( const QString& hostname = QString() ) const; KParts::HtmlSettingsInterface::JSWindowMovePolicy windowMovePolicy( const QString& hostname = QString() ) const; KParts::HtmlSettingsInterface::JSWindowResizePolicy windowResizePolicy( const QString& hostname = QString() ) const; KParts::HtmlSettingsInterface::JSWindowStatusPolicy windowStatusPolicy( const QString& hostname = QString() ) const; KParts::HtmlSettingsInterface::JSWindowFocusPolicy windowFocusPolicy( const QString& hostname = QString() ) const; QString settingsToCSS() const; QString userStyleSheet() const; // Form completion bool isFormCompletionEnabled() const; int maxFormCompletionItems() const; // Meta refresh/redirect (http-equiv) bool isAutoDelayedActionsEnabled () const; // CookieJar... bool isCookieJarEnabled() const; // Cross domain cookies bool acceptCrossDomainCookies() const; // Password storage... bool isNonPasswordStorableSite(const QString &host) const; void addNonPasswordStorableSite(const QString &host); void removeNonPasswordStorableSite(const QString &host); bool askToSaveSitePassword() const; // Mixed content bool alowActiveMixedContent() const; bool allowMixedContentDisplay() const; + //Internal PDF viewer + bool internalPdfViewer() const; + // Global config object stuff. static WebEngineSettings* self(); private: /** * Read settings from @p config. * @param config is a pointer to KConfig object. * @param reset if true, settings are always set; if false, * settings are only set if the config file has a corresponding key. */ void init( KConfig * config, bool reset = true ); // Behavior settings bool changeCursor() const; bool underlineLink() const; bool hoverLink() const; bool allowTabulation() const; bool autoSpellCheck() const; KAnimationAdvice showAnimations() const; KSmoothScrollingMode smoothScrolling() const; bool zoomTextOnly() const; // Font settings QString stdFontName() const; QString fixedFontName() const; QString serifFontName() const; QString sansSerifFontName() const; QString cursiveFontName() const; QString fantasyFontName() const; // these two can be set. Mainly for historical reasons (the method in KHTMLPart exists...) void setStdFontName(const QString &n); void setFixedFontName(const QString &n); int minFontSize() const; int mediumFontSize() const; bool jsErrorsEnabled() const; void setJSErrorsEnabled(bool enabled); const QString &encoding() const; bool followSystemColors() const; // Color settings const QColor& textColor() const; const QColor& baseColor() const; const QColor& linkColor() const; const QColor& vLinkColor() const; // Autoload images bool autoLoadImages() const; bool unfinishedImageFrame() const; /** * reads from @p config's current group, forcing initialization * if @p reset is true. * @param config is a pointer to KConfig object. * @param reset true if initialization is to be forced. * @param global true if the global domain is to be read. * @param pd_settings will be initialised with the computed (inherited) * settings. */ void readDomainSettings(const KConfigGroup &config, bool reset, bool global, KPerDomainSettings &pd_settings); QList< QPair< QString, QChar > > fallbackAccessKeysAssignments() const; // Whether to show passive popup when windows are blocked void setJSPopupBlockerPassivePopup(bool enabled); bool jsPopupBlockerPassivePopup() const; QString lookupFont(int i) const; void initWebEngineSettings(); void initCookieJarSettings(); void initNSPluginSettings(); /** * @internal Constructor */ WebEngineSettings(); WebEngineSettingsPrivate* const d; }; #endif