File indexing completed on 2024-05-12 16:16:15

0001 /*
0002     SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "webkitsettings.h"
0008 
0009 #include "kwebkitpart_debug.h"
0010 #include "webkit_filter.h"
0011 
0012 #include <KConfig>
0013 #include <KConfigGroup>
0014 #include <KJob>
0015 #include <KIO/Job>
0016 #include <KLocalizedString>
0017 #include <KMessageBox>
0018 #include <KSharedConfig>
0019 
0020 #include <QWebSettings>
0021 #include <QFontDatabase>
0022 #include <QFileInfo>
0023 #include <QStandardPaths>
0024 #include <QGlobalStatic>
0025 
0026 // browser window color defaults -- Bernd
0027 #define HTML_DEFAULT_LNK_COLOR Qt::blue
0028 #define HTML_DEFAULT_TXT_COLOR Qt::black
0029 #define HTML_DEFAULT_VLNK_COLOR Qt::magenta
0030 #define HTML_DEFAULT_BASE_COLOR Qt::white
0031 
0032 #define HTML_DEFAULT_VIEW_FONT "Sans Serif"
0033 #define HTML_DEFAULT_VIEW_FIXED_FONT "Monospace"
0034 #define HTML_DEFAULT_VIEW_SERIF_FONT "Serif"
0035 #define HTML_DEFAULT_VIEW_SANSSERIF_FONT "Sans Serif"
0036 #define HTML_DEFAULT_VIEW_CURSIVE_FONT "Sans Serif"
0037 #define HTML_DEFAULT_VIEW_FANTASY_FONT "Sans Serif"
0038 #define HTML_DEFAULT_MIN_FONT_SIZE 7 // everything smaller is usually unreadable.
0039 
0040 /**
0041  * @internal
0042  * Contains all settings which are both available globally and per-domain
0043  */
0044 struct KPerDomainSettings {
0045     bool m_bEnableJava : 1;
0046     bool m_bEnableJavaScript : 1;
0047     bool m_bEnablePlugins : 1;
0048     // don't forget to maintain the bitfields as the enums grow
0049     KParts::HtmlSettingsInterface::JSWindowOpenPolicy m_windowOpenPolicy : 2;
0050     KParts::HtmlSettingsInterface::JSWindowStatusPolicy m_windowStatusPolicy : 1;
0051     KParts::HtmlSettingsInterface::JSWindowFocusPolicy m_windowFocusPolicy : 1;
0052     KParts::HtmlSettingsInterface::JSWindowMovePolicy m_windowMovePolicy : 1;
0053     KParts::HtmlSettingsInterface::JSWindowResizePolicy m_windowResizePolicy : 1;
0054 
0055 #ifdef DEBUG_SETTINGS
0056     void dump(const QString &infix = QString()) const {
0057       qCDebug(KWEBKITPART_LOG) << "KPerDomainSettings " << infix << " @" << this << ":";
0058       qCDebug(KWEBKITPART_LOG) << "  m_bEnableJava: " << m_bEnableJava;
0059       qCDebug(KWEBKITPART_LOG) << "  m_bEnableJavaScript: " << m_bEnableJavaScript;
0060       qCDebug(KWEBKITPART_LOG) << "  m_bEnablePlugins: " << m_bEnablePlugins;
0061       qCDebug(KWEBKITPART_LOG) << "  m_windowOpenPolicy: " << m_windowOpenPolicy;
0062       qCDebug(KWEBKITPART_LOG) << "  m_windowStatusPolicy: " << m_windowStatusPolicy;
0063       qCDebug(KWEBKITPART_LOG) << "  m_windowFocusPolicy: " << m_windowFocusPolicy;
0064       qCDebug(KWEBKITPART_LOG) << "  m_windowMovePolicy: " << m_windowMovePolicy;
0065       qCDebug(KWEBKITPART_LOG) << "  m_windowResizePolicy: " << m_windowResizePolicy;
0066     }
0067 #endif
0068 };
0069 
0070 typedef QMap<QString,KPerDomainSettings> PolicyMap;
0071 
0072 class WebKitSettingsData
0073 {
0074 public:  
0075     bool m_bChangeCursor : 1;
0076     bool m_bOpenMiddleClick : 1;
0077     bool m_underlineLink : 1;
0078     bool m_hoverLink : 1;
0079     bool m_bEnableJavaScriptDebug : 1;
0080     bool m_bEnableJavaScriptErrorReporting : 1;
0081     bool enforceCharset : 1;
0082     bool m_bAutoLoadImages : 1;
0083     bool m_bUnfinishedImageFrame : 1;
0084     bool m_formCompletionEnabled : 1;
0085     bool m_autoDelayedActionsEnabled : 1;
0086     bool m_jsErrorsEnabled : 1;
0087     bool m_follow_system_colors : 1;
0088     bool m_allowTabulation : 1;
0089     bool m_autoSpellCheck : 1;
0090     bool m_adFilterEnabled : 1;
0091     bool m_hideAdsEnabled : 1;
0092     bool m_jsPopupBlockerPassivePopup : 1;
0093     bool m_accessKeysEnabled : 1;
0094     bool m_zoomTextOnly : 1;
0095     bool m_useCookieJar : 1;
0096     bool m_bAutoRefreshPage: 1;
0097     bool m_bEnableFavicon:1;
0098     bool m_disableInternalPluginHandling:1;
0099     bool m_offerToSaveWebSitePassword:1;
0100     bool m_loadPluginsOnDemand:1;
0101     bool m_enableLocalStorage:1;
0102     bool m_enableOfflineStorageDb:1;
0103     bool m_enableOfflineWebAppCache:1;
0104     bool m_enableWebGL:1;
0105     bool m_zoomToDPI:1;
0106     bool m_allowActiveMixedContent:1;
0107     bool m_allowMixedContentDisplay:1;
0108 
0109     // the virtual global "domain"
0110     KPerDomainSettings global;
0111 
0112     int m_fontSize;
0113     int m_minFontSize;
0114     int m_maxFormCompletionItems;
0115     WebKitSettings::KAnimationAdvice m_showAnimations;
0116     WebKitSettings::KSmoothScrollingMode m_smoothScrolling;
0117 
0118     QString m_encoding;
0119     QString m_userSheet;
0120 
0121     QColor m_textColor;
0122     QColor m_baseColor;
0123     QColor m_linkColor;
0124     QColor m_vLinkColor;
0125 
0126     PolicyMap domainPolicy;
0127     QStringList fonts;
0128     QStringList defaultFonts;
0129 
0130     KDEPrivate::FilterSet adBlackList;
0131     KDEPrivate::FilterSet adWhiteList;
0132     QList< QPair< QString, QChar > > m_fallbackAccessKeysAssignments;
0133 
0134     KSharedConfig::Ptr nonPasswordStorableSites;
0135 };
0136 
0137 class WebKitSettingsPrivate : public QObject, public WebKitSettingsData
0138 {
0139     Q_OBJECT
0140 public:
0141     void adblockFilterLoadList(const QString& filename)
0142     {
0143         /** load list file and process each line */
0144         QFile file(filename);
0145         if (file.open(QIODevice::ReadOnly)) {
0146             QTextStream ts(&file);
0147             QString line = ts.readLine();
0148             while (!line.isEmpty()) {
0149                 //qCDebug(KWEBKITPART_LOG) << "Adding filter:" << line;
0150                 /** white list lines start with "@@" */
0151                 if (line.startsWith(QLatin1String("@@")))
0152                     adWhiteList.addFilter(line);
0153                 else
0154                     adBlackList.addFilter(line);
0155                 line = ts.readLine();
0156             }
0157             file.close();
0158         }
0159     }
0160 
0161 public Q_SLOTS:
0162     void adblockFilterResult(KJob *job)
0163     {
0164         KIO::StoredTransferJob *tJob = qobject_cast<KIO::StoredTransferJob*>(job);
0165         Q_ASSERT(tJob);
0166 
0167         if ( job->error() == KJob::NoError )
0168         {
0169             const QByteArray byteArray = tJob->data();
0170             const QString localFileName = tJob->property( "webkitsettings_adBlock_filename" ).toString();
0171 
0172             QFile file(localFileName);
0173             if ( file.open(QFile::WriteOnly) )
0174             {
0175                 const bool success = (file.write(byteArray) == byteArray.size());
0176                 if ( success )
0177                     adblockFilterLoadList(localFileName);
0178                 else
0179                     qCWarning(KWEBKITPART_LOG) << "Could not write" << byteArray.size() << "to file" << localFileName;
0180                 file.close();
0181             }
0182             else
0183                 qCDebug(KWEBKITPART_LOG) << "Cannot open file" << localFileName << "for filter list";
0184         }
0185         else
0186             qCDebug(KWEBKITPART_LOG) << "Downloading" << tJob->url() << "failed with message:" << job->errorText();
0187     }
0188 };
0189 
0190 
0191 /** Returns a writeable per-domains settings instance for the given domain
0192   * or a deep copy of the global settings if not existent.
0193   */
0194 static KPerDomainSettings &setup_per_domain_policy(WebKitSettingsPrivate* const d, const QString &domain)
0195 {
0196   if (domain.isEmpty())
0197     qCWarning(KWEBKITPART_LOG) << "setup_per_domain_policy: domain is empty";
0198 
0199   const QString ldomain = domain.toLower();
0200   PolicyMap::iterator it = d->domainPolicy.find(ldomain);
0201   if (it == d->domainPolicy.end()) {
0202     // simply copy global domain settings (they should have been initialized
0203     // by this time)
0204     it = d->domainPolicy.insert(ldomain,d->global);
0205   }
0206   return *it;
0207 }
0208 
0209 template<typename T>
0210 static T readEntry(const KConfigGroup& config, const QString& key, int defaultValue)
0211 {
0212     return static_cast<T>(config.readEntry(key, defaultValue));
0213 }
0214 
0215 void WebKitSettings::readDomainSettings(const KConfigGroup &config, bool reset,
0216                                         bool global, KPerDomainSettings &pd_settings)
0217 {
0218   const QString javaPrefix ((global ? QString() : QLatin1String("java.")));
0219   const QString jsPrefix ((global ? QString() : QLatin1String("javascript.")));
0220   const QString pluginsPrefix (global ? QString() : QLatin1String("plugins."));
0221 
0222   // The setting for Java
0223   QString key = javaPrefix + QLatin1String("EnableJava");
0224   if ( (global && reset) || config.hasKey( key ) )
0225     pd_settings.m_bEnableJava = config.readEntry( key, false );
0226   else if ( !global )
0227     pd_settings.m_bEnableJava = d->global.m_bEnableJava;
0228 
0229   // The setting for Plugins
0230   key = pluginsPrefix + QLatin1String("EnablePlugins");
0231   if ( (global && reset) || config.hasKey( key ) )
0232     pd_settings.m_bEnablePlugins = config.readEntry( key, true );
0233   else if ( !global )
0234     pd_settings.m_bEnablePlugins = d->global.m_bEnablePlugins;
0235 
0236   // The setting for JavaScript
0237   key = jsPrefix + QLatin1String("EnableJavaScript");
0238   if ( (global && reset) || config.hasKey( key ) )
0239     pd_settings.m_bEnableJavaScript = config.readEntry( key, true );
0240   else if ( !global )
0241     pd_settings.m_bEnableJavaScript = d->global.m_bEnableJavaScript;
0242 
0243   // window property policies
0244   key = jsPrefix + QLatin1String("WindowOpenPolicy");
0245   if ( (global && reset) || config.hasKey( key ) )
0246     pd_settings.m_windowOpenPolicy = readEntry<KParts::HtmlSettingsInterface::JSWindowOpenPolicy>(config, key, KParts::HtmlSettingsInterface::JSWindowOpenSmart);
0247   else if ( !global )
0248     pd_settings.m_windowOpenPolicy = d->global.m_windowOpenPolicy;
0249 
0250   key = jsPrefix + QLatin1String("WindowMovePolicy");
0251   if ( (global && reset) || config.hasKey( key ) )
0252     pd_settings.m_windowMovePolicy = readEntry<KParts::HtmlSettingsInterface::JSWindowMovePolicy>(config, key, KParts::HtmlSettingsInterface::JSWindowMoveAllow);
0253   else if ( !global )
0254     pd_settings.m_windowMovePolicy = d->global.m_windowMovePolicy;
0255 
0256   key = jsPrefix + QLatin1String("WindowResizePolicy");
0257   if ( (global && reset) || config.hasKey( key ) )
0258     pd_settings.m_windowResizePolicy = readEntry<KParts::HtmlSettingsInterface::JSWindowResizePolicy>(config, key, KParts::HtmlSettingsInterface::JSWindowResizeAllow);
0259   else if ( !global )
0260     pd_settings.m_windowResizePolicy = d->global.m_windowResizePolicy;
0261 
0262   key = jsPrefix + QLatin1String("WindowStatusPolicy");
0263   if ( (global && reset) || config.hasKey( key ) )
0264     pd_settings.m_windowStatusPolicy = readEntry<KParts::HtmlSettingsInterface::JSWindowStatusPolicy>(config, key, KParts::HtmlSettingsInterface::JSWindowStatusAllow);
0265   else if ( !global )
0266     pd_settings.m_windowStatusPolicy = d->global.m_windowStatusPolicy;
0267 
0268   key = jsPrefix + QLatin1String("WindowFocusPolicy");
0269   if ( (global && reset) || config.hasKey( key ) )
0270     pd_settings.m_windowFocusPolicy = readEntry<KParts::HtmlSettingsInterface::JSWindowFocusPolicy>(config, key, KParts::HtmlSettingsInterface::JSWindowFocusAllow);
0271   else if ( !global )
0272     pd_settings.m_windowFocusPolicy = d->global.m_windowFocusPolicy;
0273 }
0274 
0275 
0276 WebKitSettings::WebKitSettings()
0277   :d (new WebKitSettingsPrivate)
0278 {
0279   init();
0280 }
0281 
0282 WebKitSettings::~WebKitSettings()
0283 {
0284   delete d;
0285 }
0286 
0287 bool WebKitSettings::changeCursor() const
0288 {
0289   return d->m_bChangeCursor;
0290 }
0291 
0292 bool WebKitSettings::underlineLink() const
0293 {
0294   return d->m_underlineLink;
0295 }
0296 
0297 bool WebKitSettings::hoverLink() const
0298 {
0299   return d->m_hoverLink;
0300 }
0301 
0302 void WebKitSettings::init()
0303 {
0304   initWebKitSettings();
0305 
0306   KConfig global( "khtmlrc", KConfig::NoGlobals );
0307   init( &global, true );
0308 
0309   KSharedConfig::Ptr local = KSharedConfig::openConfig();
0310   if ( local ) {
0311       init( local.data(), false );
0312   }
0313 
0314   initNSPluginSettings();
0315   initCookieJarSettings();
0316 }
0317 
0318 void WebKitSettings::init( KConfig * config, bool reset )
0319 {
0320   KConfigGroup cg( config, "MainView Settings" );
0321   if (reset || cg.exists() )
0322   {
0323     if ( reset || cg.hasKey( "OpenMiddleClick" ) )
0324         d->m_bOpenMiddleClick = cg.readEntry( "OpenMiddleClick", true );
0325   }
0326 
0327   KConfigGroup cgAccess(config,"Access Keys" );
0328   if (reset || cgAccess.exists() ) {
0329       d->m_accessKeysEnabled = cgAccess.readEntry( "Enabled", true );
0330   }
0331 
0332   KConfigGroup cgFilter( config, "Filter Settings" );
0333 
0334   if ((reset || cgFilter.exists()) && (d->m_adFilterEnabled = cgFilter.readEntry("Enabled", false)))
0335   {
0336       d->m_hideAdsEnabled = cgFilter.readEntry("Shrink", false);
0337 
0338       d->adBlackList.clear();
0339       d->adWhiteList.clear();
0340 
0341       /** read maximum age for filter list files, minimum is one day */
0342       int htmlFilterListMaxAgeDays = cgFilter.readEntry(QString("HTMLFilterListMaxAgeDays")).toInt();
0343       if (htmlFilterListMaxAgeDays < 1)
0344           htmlFilterListMaxAgeDays = 1;
0345 
0346       QMapIterator<QString,QString> it (cgFilter.entryMap());
0347       while (it.hasNext())
0348       {
0349           it.next();
0350           int id = -1;
0351           const QString name = it.key();
0352           const QString url = it.value();
0353 
0354           if (name.startsWith(QLatin1String("Filter")))
0355           {
0356               if (url.startsWith(QLatin1String("@@")))
0357                   d->adWhiteList.addFilter(url);
0358               else
0359                   d->adBlackList.addFilter(url);
0360           }
0361           else if (name.startsWith(QLatin1String("HTMLFilterListName-")) && (id = name.mid(19).toInt()) > 0)
0362           {
0363               /** check if entry is enabled */
0364               bool filterEnabled = cgFilter.readEntry(QString("HTMLFilterListEnabled-").append(QString::number(id))) != QLatin1String("false");
0365 
0366               /** get url for HTMLFilterList */
0367               QUrl url(cgFilter.readEntry(QString("HTMLFilterListURL-").append(QString::number(id))));
0368 
0369               if (filterEnabled && url.isValid()) {
0370                   /** determine where to cache HTMLFilterList file */
0371                   QString localFile = cgFilter.readEntry(QString("HTMLFilterListLocalFilename-").append(QString::number(id)));
0372                   localFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "khtml/" + localFile;
0373 
0374                   /** determine existence and age of cache file */
0375                   QFileInfo fileInfo(localFile);
0376 
0377                   /** load cached file if it exists, irrespective of age */
0378                   if (fileInfo.exists())
0379                       d->adblockFilterLoadList( localFile );
0380 
0381                   /** if no cache list file exists or if it is too old ... */
0382                   if (!fileInfo.exists() || fileInfo.lastModified().daysTo(QDateTime::currentDateTime()) > htmlFilterListMaxAgeDays)
0383                   {
0384                       /** ... in this case, refetch list asynchronously */
0385                       // qCDebug(KWEBKITPART_LOG) << "Fetching filter list from" << url << "to" << localFile;
0386                       KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo );
0387                       QObject::connect( job, SIGNAL(result(KJob*)), d, SLOT(adblockFilterResult(KJob*)) );
0388                       /** for later reference, store name of cache file */
0389                       job->setProperty("webkitsettings_adBlock_filename", localFile);
0390                   }
0391               }
0392           }
0393       }
0394   }
0395 
0396   KConfigGroup cgHtml( config, "HTML Settings" );
0397   if (reset || cgHtml.exists() )
0398   {
0399     // Fonts and colors
0400     if( reset ) {
0401         d->defaultFonts = QStringList();
0402         d->defaultFonts.append( cgHtml.readEntry( "StandardFont", QFontDatabase::systemFont(QFontDatabase::GeneralFont).family() ) );
0403         d->defaultFonts.append( cgHtml.readEntry( "FixedFont", QFontDatabase::systemFont(QFontDatabase::FixedFont).family() ) );
0404         d->defaultFonts.append( cgHtml.readEntry( "SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) );
0405         d->defaultFonts.append( cgHtml.readEntry( "SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) );
0406         d->defaultFonts.append( cgHtml.readEntry( "CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) );
0407         d->defaultFonts.append( cgHtml.readEntry( "FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) );
0408         d->defaultFonts.append( QString( "0" ) ); // font size adjustment
0409     }
0410 
0411     if ( reset || cgHtml.hasKey( "MinimumFontSize" ) )
0412         d->m_minFontSize = cgHtml.readEntry( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE );
0413 
0414     if ( reset || cgHtml.hasKey( "MediumFontSize" ) )
0415         d->m_fontSize = cgHtml.readEntry( "MediumFontSize", 12 );
0416 
0417     d->fonts = cgHtml.readEntry( "Fonts", QStringList() );
0418 
0419     if ( reset || cgHtml.hasKey( "DefaultEncoding" ) )
0420         d->m_encoding = cgHtml.readEntry( "DefaultEncoding", "" );
0421 
0422     if ( reset || cgHtml.hasKey( "EnforceDefaultCharset" ) )
0423         d->enforceCharset = cgHtml.readEntry( "EnforceDefaultCharset", false );
0424 
0425     // Behavior
0426     if ( reset || cgHtml.hasKey( "ChangeCursor" ) )
0427         d->m_bChangeCursor = cgHtml.readEntry( "ChangeCursor", true );
0428 
0429     if ( reset || cgHtml.hasKey("UnderlineLinks") )
0430         d->m_underlineLink = cgHtml.readEntry( "UnderlineLinks", true );
0431 
0432     if ( reset || cgHtml.hasKey( "HoverLinks" ) )
0433     {
0434         if ( (d->m_hoverLink = cgHtml.readEntry( "HoverLinks", false )))
0435             d->m_underlineLink = false;
0436     }
0437 
0438     if ( reset || cgHtml.hasKey( "AllowTabulation" ) )
0439         d->m_allowTabulation = cgHtml.readEntry( "AllowTabulation", false );
0440 
0441     if ( reset || cgHtml.hasKey( "AutoSpellCheck" ) )
0442         d->m_autoSpellCheck = cgHtml.readEntry( "AutoSpellCheck", true );
0443 
0444     // Other
0445     if ( reset || cgHtml.hasKey( "AutoLoadImages" ) )
0446       d->m_bAutoLoadImages = cgHtml.readEntry( "AutoLoadImages", true );
0447 
0448     if ( reset || cgHtml.hasKey( "AutoDelayedActions" ) )
0449         d->m_bAutoRefreshPage = cgHtml.readEntry( "AutoDelayedActions", true );
0450 
0451     if ( reset || cgHtml.hasKey( "UnfinishedImageFrame" ) )
0452       d->m_bUnfinishedImageFrame = cgHtml.readEntry( "UnfinishedImageFrame", true );
0453 
0454     if ( reset || cgHtml.hasKey( "ShowAnimations" ) )
0455     {
0456       QString value = cgHtml.readEntry( "ShowAnimations").toLower();
0457       if (value == "disabled")
0458          d->m_showAnimations = KAnimationDisabled;
0459       else if (value == "looponce")
0460          d->m_showAnimations = KAnimationLoopOnce;
0461       else
0462          d->m_showAnimations = KAnimationEnabled;
0463     }
0464 
0465     if ( reset || cgHtml.hasKey( "SmoothScrolling" ) )
0466     {
0467       QString value = cgHtml.readEntry( "SmoothScrolling", "whenefficient" ).toLower();
0468       if (value == "disabled")
0469          d->m_smoothScrolling = KSmoothScrollingDisabled;
0470       else if (value == "whenefficient")
0471          d->m_smoothScrolling = KSmoothScrollingWhenEfficient;
0472       else
0473          d->m_smoothScrolling = KSmoothScrollingEnabled;
0474     } 
0475 
0476     if ( reset || cgHtml.hasKey( "ZoomTextOnly" ) ) {
0477         d->m_zoomTextOnly = cgHtml.readEntry( "ZoomTextOnly", false );
0478     }
0479 
0480     if ( reset || cgHtml.hasKey( "ZoomToDPI" ) ) {
0481         d->m_zoomToDPI = cgHtml.readEntry( "ZoomToDPI", false );
0482     }
0483 
0484     if (cgHtml.readEntry("UserStyleSheetEnabled", false)) {
0485         if (reset || cgHtml.hasKey("UserStyleSheet"))
0486             d->m_userSheet = cgHtml.readEntry("UserStyleSheet", QString());
0487     } else {
0488         d->m_userSheet.clear();
0489     }
0490 
0491     d->m_formCompletionEnabled = cgHtml.readEntry("FormCompletion", true);
0492     d->m_maxFormCompletionItems = cgHtml.readEntry("MaxFormCompletionItems", 10);
0493     d->m_autoDelayedActionsEnabled = cgHtml.readEntry ("AutoDelayedActions", true);
0494     d->m_jsErrorsEnabled = cgHtml.readEntry("ReportJSErrors", true);
0495     const QStringList accesskeys = cgHtml.readEntry("FallbackAccessKeysAssignments", QStringList());
0496     d->m_fallbackAccessKeysAssignments.clear();
0497     for( QStringList::ConstIterator it = accesskeys.begin(); it != accesskeys.end(); ++it )
0498         if( (*it).length() > 2 && (*it)[ 1 ] == ':' )
0499             d->m_fallbackAccessKeysAssignments.append( qMakePair( (*it).mid( 2 ), (*it)[ 0 ] ));
0500 
0501     d->m_bEnableFavicon = cgHtml.readEntry("EnableFavicon", true);
0502     d->m_offerToSaveWebSitePassword = cgHtml.readEntry("OfferToSaveWebsitePassword", true);
0503   }
0504 
0505   // Colors
0506   //In which group ?????
0507   if ( reset || cg.hasKey( "FollowSystemColors" ) )
0508       d->m_follow_system_colors = cg.readEntry( "FollowSystemColors", false );
0509 
0510   KConfigGroup cgGeneral( config, "General" );
0511   if ( reset || cgGeneral.exists( ) )
0512   {
0513     if ( reset || cgGeneral.hasKey( "foreground" ) ) {
0514       QColor def(HTML_DEFAULT_TXT_COLOR);
0515       d->m_textColor = cgGeneral.readEntry( "foreground", def );
0516     }
0517 
0518     if ( reset || cgGeneral.hasKey( "linkColor" ) ) {
0519       QColor def(HTML_DEFAULT_LNK_COLOR);
0520       d->m_linkColor = cgGeneral.readEntry( "linkColor", def );
0521     }
0522 
0523     if ( reset || cgGeneral.hasKey( "visitedLinkColor" ) ) {
0524       QColor def(HTML_DEFAULT_VLNK_COLOR);
0525       d->m_vLinkColor = cgGeneral.readEntry( "visitedLinkColor", def);
0526     }
0527 
0528     if ( reset || cgGeneral.hasKey( "background" ) ) {
0529       QColor def(HTML_DEFAULT_BASE_COLOR);
0530       d->m_baseColor = cgGeneral.readEntry( "background", def);
0531     }
0532   }
0533 
0534   KConfigGroup cgJava( config, "Java/JavaScript Settings" );
0535   if( reset || cgJava.exists() )
0536   {
0537     // The global setting for JavaScript debugging
0538     // This is currently always enabled by default
0539     if ( reset || cgJava.hasKey( "EnableJavaScriptDebug" ) )
0540       d->m_bEnableJavaScriptDebug = cgJava.readEntry( "EnableJavaScriptDebug", false );
0541 
0542     // The global setting for JavaScript error reporting
0543     if ( reset || cgJava.hasKey( "ReportJavaScriptErrors" ) )
0544       d->m_bEnableJavaScriptErrorReporting = cgJava.readEntry( "ReportJavaScriptErrors", false );
0545 
0546     // The global setting for popup block passive popup
0547     if ( reset || cgJava.hasKey( "PopupBlockerPassivePopup" ) )
0548       d->m_jsPopupBlockerPassivePopup = cgJava.readEntry("PopupBlockerPassivePopup", true );
0549 
0550     // Read options from the global "domain"
0551     readDomainSettings(cgJava,reset,true,d->global);
0552 #ifdef DEBUG_SETTINGS
0553     d->global.dump("init global");
0554 #endif
0555 
0556     // The domain-specific settings.
0557 
0558     static const char *const domain_keys[] = {  // always keep order of keys
0559         "ECMADomains", "JavaDomains", "PluginDomains"
0560     };
0561     bool check_old_ecma_settings = true;
0562     bool check_old_java_settings = true;
0563     // merge all domains into one list
0564     QSet<QString> domainList;
0565     for (unsigned i = 0; i < sizeof domain_keys/sizeof domain_keys[0]; ++i) {
0566         if (reset || cgJava.hasKey(domain_keys[i])) {
0567             if (i == 0) check_old_ecma_settings = false;
0568             else if (i == 1) check_old_java_settings = false;
0569             const QStringList dl = cgJava.readEntry( domain_keys[i], QStringList() );
0570             const QSet<QString>::Iterator notfound = domainList.end();
0571             QStringList::ConstIterator it = dl.begin();
0572             const QStringList::ConstIterator itEnd = dl.end();
0573             for (; it != itEnd; ++it) {
0574                 const QString domain = (*it).toLower();
0575                 QSet<QString>::Iterator pos = domainList.find(domain);
0576                 if (pos == notfound) domainList.insert(domain);
0577             }/*next it*/
0578         }
0579     }/*next i*/
0580 
0581     if (reset)
0582       d->domainPolicy.clear();
0583 
0584     {
0585       QSet<QString>::ConstIterator it = domainList.constBegin();
0586       const QSet<QString>::ConstIterator itEnd = domainList.constEnd();
0587       for ( ; it != itEnd; ++it)
0588       {
0589         const QString domain = *it;
0590         KConfigGroup cg( config, domain );
0591         readDomainSettings(cg,reset,false,d->domainPolicy[domain]);
0592 #ifdef DEBUG_SETTINGS
0593         d->domainPolicy[domain].dump("init "+domain);
0594 #endif
0595       }
0596     }
0597 
0598     bool check_old_java = true;
0599     if( (reset || cgJava.hasKey("JavaDomainSettings")) && check_old_java_settings)
0600     {
0601       check_old_java = false;
0602       const QStringList domainList = cgJava.readEntry( "JavaDomainSettings", QStringList() );
0603       QStringList::ConstIterator it = domainList.constBegin();
0604       const QStringList::ConstIterator itEnd = domainList.constEnd();
0605       for ( ; it != itEnd; ++it)
0606       {
0607         QString domain;
0608         KParts::HtmlSettingsInterface::JavaScriptAdvice javaAdvice;
0609         KParts::HtmlSettingsInterface::JavaScriptAdvice javaScriptAdvice;
0610         KParts::HtmlSettingsInterface::splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
0611         setup_per_domain_policy(d,domain).m_bEnableJava = javaAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept;
0612 #ifdef DEBUG_SETTINGS
0613         setup_per_domain_policy(d,domain).dump("JavaDomainSettings 4 "+domain);
0614 #endif
0615       }
0616     }
0617 
0618     bool check_old_ecma = true;
0619     if( ( reset || cgJava.hasKey( "ECMADomainSettings" ) ) && check_old_ecma_settings )
0620     {
0621       check_old_ecma = false;
0622       const QStringList domainList = cgJava.readEntry( "ECMADomainSettings", QStringList() );
0623       QStringList::ConstIterator it = domainList.constBegin();
0624       const QStringList::ConstIterator itEnd = domainList.constEnd();
0625       for ( ; it != itEnd; ++it)
0626       {
0627         QString domain;
0628         KParts::HtmlSettingsInterface::JavaScriptAdvice javaAdvice;
0629         KParts::HtmlSettingsInterface::JavaScriptAdvice javaScriptAdvice;
0630         KParts::HtmlSettingsInterface::splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
0631         setup_per_domain_policy(d,domain).m_bEnableJavaScript = javaScriptAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept;
0632 #ifdef DEBUG_SETTINGS
0633     setup_per_domain_policy(d,domain).dump("ECMADomainSettings 4 "+domain);
0634 #endif
0635       }
0636     }
0637 
0638     if( ( reset || cgJava.hasKey( "JavaScriptDomainAdvice" ) )
0639              && ( check_old_java || check_old_ecma )
0640          && ( check_old_ecma_settings || check_old_java_settings ) )
0641     {
0642       const QStringList domainList = cgJava.readEntry( "JavaScriptDomainAdvice", QStringList() );
0643       QStringList::ConstIterator it = domainList.constBegin();
0644       const QStringList::ConstIterator itEnd = domainList.constEnd();
0645       for ( ; it != itEnd; ++it)
0646       {
0647         QString domain;
0648         KParts::HtmlSettingsInterface::JavaScriptAdvice javaAdvice;
0649         KParts::HtmlSettingsInterface::JavaScriptAdvice javaScriptAdvice;
0650         KParts::HtmlSettingsInterface::splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
0651         if( check_old_java )
0652           setup_per_domain_policy(d,domain).m_bEnableJava = javaAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept;
0653         if( check_old_ecma )
0654           setup_per_domain_policy(d,domain).m_bEnableJavaScript = javaScriptAdvice == KParts::HtmlSettingsInterface::JavaScriptAccept;
0655 #ifdef DEBUG_SETTINGS
0656         setup_per_domain_policy(d,domain).dump("JavaScriptDomainAdvice 4 "+domain);
0657 #endif
0658       }
0659     }
0660   }
0661 
0662   // DNS Prefect support...
0663   if ( reset || cgHtml.hasKey( "DNSPrefetch" ) )
0664   {
0665     // Enabled, Disabled, OnlyWWWAndSLD
0666     QString value = cgHtml.readEntry( "DNSPrefetch", "Enabled" ).toLower();
0667     if (value == "enabled")
0668         QWebSettings::globalSettings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
0669     else
0670         QWebSettings::globalSettings()->setAttribute(QWebSettings::DnsPrefetchEnabled, false);
0671   }
0672 
0673   // Sync with QWebSettings.
0674   if (!d->m_encoding.isEmpty())
0675       QWebSettings::globalSettings()->setDefaultTextEncoding(d->m_encoding);
0676 
0677   QWebSettings::globalSettings()->setUserStyleSheetUrl(QUrl::fromUserInput(userStyleSheet()));
0678 
0679   QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, autoLoadImages());
0680   QWebSettings::globalSettings()->setAttribute(QWebSettings::JavascriptEnabled, isJavaScriptEnabled());
0681   QWebSettings::globalSettings()->setAttribute(QWebSettings::JavaEnabled, isJavaEnabled());
0682   QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, isPluginsEnabled());
0683 
0684   // By default disable JS window.open when policy is deny or smart.
0685   const KParts::HtmlSettingsInterface::JSWindowOpenPolicy policy = windowOpenPolicy();
0686   if (policy == KParts::HtmlSettingsInterface::JSWindowOpenDeny || policy == KParts::HtmlSettingsInterface::JSWindowOpenSmart)
0687       QWebSettings::globalSettings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, false);
0688   else
0689       QWebSettings::globalSettings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
0690 
0691   QWebSettings::globalSettings()->setAttribute(QWebSettings::ZoomTextOnly, zoomTextOnly());
0692   QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, isJavaScriptDebugEnabled());
0693   QWebSettings::globalSettings()->setFontFamily(QWebSettings::StandardFont, stdFontName());
0694   QWebSettings::globalSettings()->setFontFamily(QWebSettings::FixedFont, fixedFontName());
0695   QWebSettings::globalSettings()->setFontFamily(QWebSettings::SerifFont, serifFontName());
0696   QWebSettings::globalSettings()->setFontFamily(QWebSettings::SansSerifFont, sansSerifFontName());
0697   QWebSettings::globalSettings()->setFontFamily(QWebSettings::CursiveFont, cursiveFontName());
0698   QWebSettings::globalSettings()->setFontFamily(QWebSettings::FantasyFont, fantasyFontName());
0699 
0700   // TODO: Create a webkit config module that gets embedded into Konqueror's kcm.
0701   // Turn on WebGL support
0702   QWebSettings::globalSettings()->setAttribute(QWebSettings::WebGLEnabled, d->m_enableWebGL);
0703   // Turn on HTML 5 local and offline storage capabilities...
0704   QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, d->m_enableOfflineStorageDb);
0705   QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, d->m_enableOfflineWebAppCache);
0706   QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalStorageEnabled, d->m_enableLocalStorage);
0707 
0708   QWebSettings::globalSettings()->setAttribute(QWebSettings::ScrollAnimatorEnabled, smoothScrolling() != KSmoothScrollingDisabled);
0709 
0710   // These numbers should be calculated from real "logical" DPI/72, using a default dpi of 96 for now
0711   computeFontSizes(96);
0712 }
0713 
0714 
0715 void WebKitSettings::computeFontSizes( int logicalDpi )
0716 {
0717   if (zoomToDPI())
0718       logicalDpi = 96;
0719 
0720   float toPix = logicalDpi/72.0;
0721 
0722   if (toPix < 96.0/72.0)
0723       toPix = 96.0/72.0;
0724 
0725   QWebSettings::globalSettings()->setFontSize(QWebSettings::MinimumFontSize, qRound(minFontSize() * toPix));
0726   QWebSettings::globalSettings()->setFontSize(QWebSettings::DefaultFontSize, qRound(mediumFontSize() * toPix));
0727 }
0728 
0729 bool WebKitSettings::zoomToDPI() const
0730 {
0731     return d->m_zoomToDPI;
0732 }
0733 
0734 void WebKitSettings::setZoomToDPI(bool enabled)
0735 {
0736   d->m_zoomToDPI = enabled;
0737   // save it
0738   KConfigGroup cg( KSharedConfig::openConfig(), "HTML Settings");
0739   cg.writeEntry("ZoomToDPI", enabled);
0740   cg.sync();
0741 }
0742 
0743 /** Local helper for retrieving per-domain settings.
0744   *
0745   * In case of doubt, the global domain is returned.
0746   */
0747 static const KPerDomainSettings& lookup_hostname_policy(const WebKitSettingsPrivate* const d,
0748                                                         const QString& hostname)
0749 {
0750 #ifdef DEBUG_SETTINGS
0751   qCDebug(KWEBKITPART_LOG) << "lookup_hostname_policy(" << hostname << ")";
0752 #endif
0753   if (hostname.isEmpty()) {
0754 #ifdef DEBUG_SETTINGS
0755     d->global.dump("global");
0756 #endif
0757     return d->global;
0758   }
0759 
0760   const PolicyMap::const_iterator notfound = d->domainPolicy.constEnd();
0761 
0762   // First check whether there is a perfect match.
0763   PolicyMap::const_iterator it = d->domainPolicy.find(hostname);
0764   if( it != notfound ) {
0765 #ifdef DEBUG_SETTINGS
0766     qCDebug(KWEBKITPART_LOG) << "perfect match";
0767     (*it).dump(hostname);
0768 #endif
0769     // yes, use it (unless dunno)
0770     return *it;
0771   }
0772 
0773   // Now, check for partial match.  Chop host from the left until
0774   // there's no dots left.
0775   QString host_part = hostname;
0776   int dot_idx = -1;
0777   while( (dot_idx = host_part.indexOf(QChar('.'))) >= 0 ) {
0778     host_part.remove(0,dot_idx);
0779     it = d->domainPolicy.find(host_part);
0780     Q_ASSERT(notfound == d->domainPolicy.end());
0781     if( it != notfound ) {
0782 #ifdef DEBUG_SETTINGS
0783       qCDebug(KWEBKITPART_LOG) << "partial match";
0784       (*it).dump(host_part);
0785 #endif
0786       return *it;
0787     }
0788     // assert(host_part[0] == QChar('.'));
0789     host_part.remove(0,1); // Chop off the dot.
0790   }
0791 
0792   // No domain-specific entry: use global domain
0793 #ifdef DEBUG_SETTINGS
0794   qCDebug(KWEBKITPART_LOG) << "no match";
0795   d->global.dump("global");
0796 #endif
0797   return d->global;
0798 }
0799 
0800 bool WebKitSettings::isOpenMiddleClickEnabled()
0801 {
0802   return d->m_bOpenMiddleClick;
0803 }
0804 
0805 bool WebKitSettings::accessKeysEnabled() const
0806 {
0807     return d->m_accessKeysEnabled;
0808 }
0809 
0810 bool WebKitSettings::favIconsEnabled() const
0811 {
0812     return d->m_bEnableFavicon;
0813 }
0814 
0815 bool WebKitSettings::isAdFilterEnabled() const
0816 {
0817     return d->m_adFilterEnabled;
0818 }
0819 
0820 bool WebKitSettings::isHideAdsEnabled() const
0821 {
0822     return d->m_hideAdsEnabled;
0823 }
0824 
0825 bool WebKitSettings::isAdFiltered( const QString &url ) const
0826 {
0827     if (!d->m_adFilterEnabled)
0828         return false;
0829 
0830     if (url.startsWith(QLatin1String("data:")))
0831         return false;
0832 
0833     return d->adBlackList.isUrlMatched(url) && !d->adWhiteList.isUrlMatched(url);
0834 }
0835 
0836 QString WebKitSettings::adFilteredBy( const QString &url, bool *isWhiteListed ) const
0837 {
0838     QString m = d->adWhiteList.urlMatchedBy(url);
0839 
0840     if (!m.isEmpty()) {
0841         if (isWhiteListed != nullptr)
0842             *isWhiteListed = true;
0843         return m;
0844     }
0845 
0846     m = d->adBlackList.urlMatchedBy(url);
0847     if (m.isEmpty())
0848         return QString();
0849 
0850     if (isWhiteListed != nullptr)
0851         *isWhiteListed = false;
0852     return m;
0853 }
0854 
0855 void WebKitSettings::addAdFilter( const QString &url )
0856 {
0857     KConfigGroup config = KSharedConfig::openConfig( "khtmlrc", KConfig::NoGlobals )->group( "Filter Settings" );
0858 
0859     QRegExp rx;
0860 
0861     // Try compiling to avoid invalid stuff. Only support the basic syntax here...
0862     // ### refactor somewhat
0863     if (url.length()>2 && url[0]=='/' && url[url.length()-1] == '/')
0864     {
0865         const QString inside = url.mid(1, url.length()-2);
0866         rx.setPattern(inside);
0867     }
0868     else
0869     {
0870         rx.setPatternSyntax(QRegExp::Wildcard);
0871         rx.setPattern(url);
0872     }
0873 
0874     if (rx.isValid())
0875     {
0876         int last=config.readEntry("Count", 0);
0877         const QString key = "Filter-" + QString::number(last);
0878         config.writeEntry(key, url);
0879         config.writeEntry("Count",last+1);
0880         config.sync();
0881 
0882         if (url.startsWith(QLatin1String("@@")))
0883             d->adWhiteList.addFilter(url);
0884         else
0885             d->adBlackList.addFilter(url);
0886     }
0887     else
0888     {
0889         KMessageBox::error(nullptr,
0890                            rx.errorString(),
0891                            i18n("Filter error"));
0892     }
0893 }
0894 
0895 bool WebKitSettings::isJavaEnabled( const QString& hostname ) const
0896 {
0897   return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJava;
0898 }
0899 
0900 bool WebKitSettings::isJavaScriptEnabled( const QString& hostname ) const
0901 {
0902   return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJavaScript;
0903 }
0904 
0905 bool WebKitSettings::isJavaScriptDebugEnabled( const QString& /*hostname*/ ) const
0906 {
0907   // debug setting is global for now, but could change in the future
0908   return d->m_bEnableJavaScriptDebug;
0909 }
0910 
0911 bool WebKitSettings::isJavaScriptErrorReportingEnabled( const QString& /*hostname*/ ) const
0912 {
0913   // error reporting setting is global for now, but could change in the future
0914   return d->m_bEnableJavaScriptErrorReporting;
0915 }
0916 
0917 bool WebKitSettings::isPluginsEnabled( const QString& hostname ) const
0918 {
0919   return lookup_hostname_policy(d,hostname.toLower()).m_bEnablePlugins;
0920 }
0921 
0922 KParts::HtmlSettingsInterface::JSWindowOpenPolicy WebKitSettings::windowOpenPolicy(const QString& hostname) const {
0923   return lookup_hostname_policy(d,hostname.toLower()).m_windowOpenPolicy;
0924 }
0925 
0926 KParts::HtmlSettingsInterface::JSWindowMovePolicy WebKitSettings::windowMovePolicy(const QString& hostname) const {
0927   return lookup_hostname_policy(d,hostname.toLower()).m_windowMovePolicy;
0928 }
0929 
0930 KParts::HtmlSettingsInterface::JSWindowResizePolicy WebKitSettings::windowResizePolicy(const QString& hostname) const {
0931   return lookup_hostname_policy(d,hostname.toLower()).m_windowResizePolicy;
0932 }
0933 
0934 KParts::HtmlSettingsInterface::JSWindowStatusPolicy WebKitSettings::windowStatusPolicy(const QString& hostname) const {
0935   return lookup_hostname_policy(d,hostname.toLower()).m_windowStatusPolicy;
0936 }
0937 
0938 KParts::HtmlSettingsInterface::JSWindowFocusPolicy WebKitSettings::windowFocusPolicy(const QString& hostname) const {
0939   return lookup_hostname_policy(d,hostname.toLower()).m_windowFocusPolicy;
0940 }
0941 
0942 int WebKitSettings::mediumFontSize() const
0943 {
0944     return d->m_fontSize;
0945 }
0946 
0947 int WebKitSettings::minFontSize() const
0948 {
0949   return d->m_minFontSize;
0950 }
0951 
0952 QString WebKitSettings::settingsToCSS() const
0953 {
0954     // lets start with the link properties
0955     QString str = "a:link {\ncolor: ";
0956     str += d->m_linkColor.name();
0957     str += ';';
0958     if(d->m_underlineLink)
0959         str += "\ntext-decoration: underline;";
0960 
0961     if( d->m_bChangeCursor )
0962     {
0963         str += "\ncursor: pointer;";
0964         str += "\n}\ninput[type=image] { cursor: pointer;";
0965     }
0966     str += "\n}\n";
0967     str += "a:visited {\ncolor: ";
0968     str += d->m_vLinkColor.name();
0969     str += ';';
0970     if(d->m_underlineLink)
0971         str += "\ntext-decoration: underline;";
0972 
0973     if( d->m_bChangeCursor )
0974         str += "\ncursor: pointer;";
0975     str += "\n}\n";
0976 
0977     if(d->m_hoverLink)
0978         str += "a:link:hover, a:visited:hover { text-decoration: underline; }\n";
0979 
0980     return str;
0981 }
0982 
0983 QString WebKitSettings::lookupFont(int i) const
0984 {
0985     if (d->fonts.count() > i) {
0986         return d->fonts.at(i);
0987     }
0988 
0989     if (d->defaultFonts.count() > i) {
0990         return d->defaultFonts.at(i);
0991     }
0992 
0993     return QString();
0994 }
0995 
0996 QString WebKitSettings::stdFontName() const
0997 {
0998     return lookupFont(0);
0999 }
1000 
1001 QString WebKitSettings::fixedFontName() const
1002 {
1003     return lookupFont(1);
1004 }
1005 
1006 QString WebKitSettings::serifFontName() const
1007 {
1008     return lookupFont(2);
1009 }
1010 
1011 QString WebKitSettings::sansSerifFontName() const
1012 {
1013     return lookupFont(3);
1014 }
1015 
1016 QString WebKitSettings::cursiveFontName() const
1017 {
1018     return lookupFont(4);
1019 }
1020 
1021 QString WebKitSettings::fantasyFontName() const
1022 {
1023     return lookupFont(5);
1024 }
1025 
1026 void WebKitSettings::setStdFontName(const QString &n)
1027 {
1028     while(d->fonts.count() <= 0)
1029         d->fonts.append(QString());
1030     d->fonts[0] = n;
1031 }
1032 
1033 void WebKitSettings::setFixedFontName(const QString &n)
1034 {
1035     while(d->fonts.count() <= 1)
1036         d->fonts.append(QString());
1037     d->fonts[1] = n;
1038 }
1039 
1040 QString WebKitSettings::userStyleSheet() const
1041 {
1042     return d->m_userSheet;
1043 }
1044 
1045 bool WebKitSettings::isFormCompletionEnabled() const
1046 {
1047   return d->m_formCompletionEnabled;
1048 }
1049 
1050 int WebKitSettings::maxFormCompletionItems() const
1051 {
1052   return d->m_maxFormCompletionItems;
1053 }
1054 
1055 const QString &WebKitSettings::encoding() const
1056 {
1057   return d->m_encoding;
1058 }
1059 
1060 bool WebKitSettings::followSystemColors() const
1061 {
1062     return d->m_follow_system_colors;
1063 }
1064 
1065 const QColor& WebKitSettings::textColor() const
1066 {
1067   return d->m_textColor;
1068 }
1069 
1070 const QColor& WebKitSettings::baseColor() const
1071 {
1072   return d->m_baseColor;
1073 }
1074 
1075 const QColor& WebKitSettings::linkColor() const
1076 {
1077   return d->m_linkColor;
1078 }
1079 
1080 const QColor& WebKitSettings::vLinkColor() const
1081 {
1082   return d->m_vLinkColor;
1083 }
1084 
1085 bool WebKitSettings::autoPageRefresh() const
1086 {
1087   return d->m_bAutoRefreshPage;
1088 }
1089 
1090 bool WebKitSettings::autoLoadImages() const
1091 {
1092   return d->m_bAutoLoadImages;
1093 }
1094 
1095 bool WebKitSettings::unfinishedImageFrame() const
1096 {
1097   return d->m_bUnfinishedImageFrame;
1098 }
1099 
1100 WebKitSettings::KAnimationAdvice WebKitSettings::showAnimations() const
1101 {
1102   return d->m_showAnimations;
1103 }
1104 
1105 WebKitSettings::KSmoothScrollingMode WebKitSettings::smoothScrolling() const
1106 {
1107   return d->m_smoothScrolling;
1108 }
1109 
1110 bool WebKitSettings::zoomTextOnly() const
1111 {
1112   return d->m_zoomTextOnly;
1113 }
1114 
1115 bool WebKitSettings::isAutoDelayedActionsEnabled() const
1116 {
1117   return d->m_autoDelayedActionsEnabled;
1118 }
1119 
1120 bool WebKitSettings::jsErrorsEnabled() const
1121 {
1122   return d->m_jsErrorsEnabled;
1123 }
1124 
1125 void WebKitSettings::setJSErrorsEnabled(bool enabled)
1126 {
1127   d->m_jsErrorsEnabled = enabled;
1128   // save it
1129   KConfigGroup cg( KSharedConfig::openConfig(), "HTML Settings");
1130   cg.writeEntry("ReportJSErrors", enabled);
1131   cg.sync();
1132 }
1133 
1134 bool WebKitSettings::allowTabulation() const
1135 {
1136     return d->m_allowTabulation;
1137 }
1138 
1139 bool WebKitSettings::autoSpellCheck() const
1140 {
1141     return d->m_autoSpellCheck;
1142 }
1143 
1144 QList< QPair< QString, QChar > > WebKitSettings::fallbackAccessKeysAssignments() const
1145 {
1146     return d->m_fallbackAccessKeysAssignments;
1147 }
1148 
1149 void WebKitSettings::setJSPopupBlockerPassivePopup(bool enabled)
1150 {
1151     d->m_jsPopupBlockerPassivePopup = enabled;
1152     // save it
1153     KConfigGroup cg( KSharedConfig::openConfig(), "Java/JavaScript Settings");
1154     cg.writeEntry("PopupBlockerPassivePopup", enabled);
1155     cg.sync();
1156 }
1157 
1158 bool WebKitSettings::jsPopupBlockerPassivePopup() const
1159 {
1160     return d->m_jsPopupBlockerPassivePopup;
1161 }
1162 
1163 bool WebKitSettings::isCookieJarEnabled() const
1164 {
1165     return d->m_useCookieJar;
1166 }
1167 
1168 // Password storage...
1169 static KConfigGroup nonPasswordStorableSitesCg(KSharedConfig::Ptr& configPtr)
1170 {
1171     if (!configPtr) {
1172         configPtr = KSharedConfig::openConfig((QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "khtml/formcompletions"),
1173                                               KConfig::NoGlobals);
1174     }
1175 
1176     return KConfigGroup(configPtr, "NonPasswordStorableSites");
1177 }
1178 
1179 bool WebKitSettings::isNonPasswordStorableSite(const QString &host) const
1180 {
1181     KConfigGroup cg = nonPasswordStorableSitesCg(d->nonPasswordStorableSites);
1182     const QStringList sites = cg.readEntry("Sites", QStringList());
1183     return sites.contains(host);
1184 }
1185 
1186 void WebKitSettings::addNonPasswordStorableSite(const QString &host)
1187 {
1188     KConfigGroup cg = nonPasswordStorableSitesCg(d->nonPasswordStorableSites);
1189     QStringList sites = cg.readEntry("Sites", QStringList());
1190     sites.append(host);
1191     cg.writeEntry("Sites", sites);
1192     cg.sync();
1193 }
1194 
1195 void WebKitSettings::removeNonPasswordStorableSite(const QString &host)
1196 {
1197     KConfigGroup cg = nonPasswordStorableSitesCg(d->nonPasswordStorableSites);
1198     QStringList sites = cg.readEntry("Sites", QStringList());
1199     sites.removeOne(host);
1200     cg.writeEntry("Sites", sites);
1201     cg.sync();
1202 }
1203 
1204 bool WebKitSettings::askToSaveSitePassword() const
1205 {
1206     return d->m_offerToSaveWebSitePassword;
1207 }
1208 
1209 bool WebKitSettings::isInternalPluginHandlingDisabled() const
1210 {
1211     return d->m_disableInternalPluginHandling;
1212 }
1213 
1214 bool WebKitSettings::isLoadPluginsOnDemandEnabled() const
1215 {
1216     return d->m_loadPluginsOnDemand;
1217 }
1218 
1219 bool WebKitSettings::allowMixedContentDisplay() const
1220 {
1221     return d->m_allowMixedContentDisplay;
1222 }
1223 
1224 bool WebKitSettings::alowActiveMixedContent() const
1225 {
1226     return d->m_allowActiveMixedContent;
1227 }
1228 
1229 
1230 void WebKitSettings::initWebKitSettings()
1231 {
1232     KConfig cfg ("kwebkitpartrc", KConfig::NoGlobals);
1233     KConfigGroup generalCfg (&cfg, "General");
1234     d->m_disableInternalPluginHandling = generalCfg.readEntry("DisableInternalPluginHandling", false);
1235     d->m_enableLocalStorage = generalCfg.readEntry("EnableLocalStorage", true);
1236     d->m_enableOfflineStorageDb = generalCfg.readEntry("EnableOfflineStorageDatabase", true);
1237     d->m_enableOfflineWebAppCache = generalCfg.readEntry("EnableOfflineWebApplicationCache", true);
1238     d->m_enableWebGL = generalCfg.readEntry("EnableWebGL", true);
1239     d->m_allowActiveMixedContent = generalCfg.readEntry("AllowActiveMixedContent", false);
1240     d->m_allowMixedContentDisplay = generalCfg.readEntry("AllowMixedContentDisplay", true);
1241 
1242     // Force the reloading of the non password storable sites settings.
1243     d->nonPasswordStorableSites.reset();
1244 }
1245 
1246 void WebKitSettings::initCookieJarSettings()
1247 {
1248     KSharedConfig::Ptr cookieCfgPtr = KSharedConfig::openConfig("kcookiejarrc", KConfig::NoGlobals);
1249     KConfigGroup cookieCfg ( cookieCfgPtr, "Cookie Policy");
1250     d->m_useCookieJar = cookieCfg.readEntry("Cookies", false);
1251 }
1252 
1253 void WebKitSettings::initNSPluginSettings()
1254 {
1255     KSharedConfig::Ptr cookieCfgPtr = KSharedConfig::openConfig("kcmnspluginrc", KConfig::NoGlobals);
1256     KConfigGroup cookieCfg ( cookieCfgPtr, "Misc");
1257     d->m_loadPluginsOnDemand = cookieCfg.readEntry("demandLoad", false);
1258 }
1259 
1260 Q_GLOBAL_STATIC(WebKitSettings, s_webKitSettings)
1261 
1262 WebKitSettings* WebKitSettings::self()
1263 {
1264     return s_webKitSettings;
1265 }
1266 
1267 #include "webkitsettings.moc"