00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "khtml_settings.h"
00021 #include "khtmldefaults.h"
00022 #include <kglobalsettings.h>
00023 #include <kconfig.h>
00024 #include <kconfiggroup.h>
00025 #include <kglobal.h>
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 #include <QtCore/QRegExp>
00029 #include <QtGui/QFontDatabase>
00030 #include <kmessagebox.h>
00031 #include <khtml_filter_p.h>
00032
00037 struct KPerDomainSettings {
00038 bool m_bEnableJava : 1;
00039 bool m_bEnableJavaScript : 1;
00040 bool m_bEnablePlugins : 1;
00041
00042 KHTMLSettings::KJSWindowOpenPolicy m_windowOpenPolicy : 2;
00043 KHTMLSettings::KJSWindowStatusPolicy m_windowStatusPolicy : 1;
00044 KHTMLSettings::KJSWindowFocusPolicy m_windowFocusPolicy : 1;
00045 KHTMLSettings::KJSWindowMovePolicy m_windowMovePolicy : 1;
00046 KHTMLSettings::KJSWindowResizePolicy m_windowResizePolicy : 1;
00047
00048 #ifdef DEBUG_SETTINGS
00049 void dump(const QString &infix = QString()) const {
00050 kDebug() << "KPerDomainSettings " << infix << " @" << this << ":";
00051 kDebug() << " m_bEnableJava: " << m_bEnableJava;
00052 kDebug() << " m_bEnableJavaScript: " << m_bEnableJavaScript;
00053 kDebug() << " m_bEnablePlugins: " << m_bEnablePlugins;
00054 kDebug() << " m_windowOpenPolicy: " << m_windowOpenPolicy;
00055 kDebug() << " m_windowStatusPolicy: " << m_windowStatusPolicy;
00056 kDebug() << " m_windowFocusPolicy: " << m_windowFocusPolicy;
00057 kDebug() << " m_windowMovePolicy: " << m_windowMovePolicy;
00058 kDebug() << " m_windowResizePolicy: " << m_windowResizePolicy;
00059 }
00060 #endif
00061 };
00062
00063 QString *KHTMLSettings::avFamilies = 0;
00064 typedef QMap<QString,KPerDomainSettings> PolicyMap;
00065
00066 class KHTMLSettingsPrivate
00067 {
00068 public:
00069 bool m_bChangeCursor : 1;
00070 bool m_bOpenMiddleClick : 1;
00071 bool m_bBackRightClick : 1;
00072 bool m_underlineLink : 1;
00073 bool m_hoverLink : 1;
00074 bool m_bEnableJavaScriptDebug : 1;
00075 bool m_bEnableJavaScriptErrorReporting : 1;
00076 bool enforceCharset : 1;
00077 bool m_bAutoLoadImages : 1;
00078 bool m_bUnfinishedImageFrame : 1;
00079 bool m_formCompletionEnabled : 1;
00080 bool m_autoDelayedActionsEnabled : 1;
00081 bool m_jsErrorsEnabled : 1;
00082 bool m_follow_system_colors : 1;
00083 bool m_allowTabulation : 1;
00084 bool m_autoSpellCheck : 1;
00085 bool m_adFilterEnabled : 1;
00086 bool m_hideAdsEnabled : 1;
00087 bool m_jsPopupBlockerPassivePopup : 1;
00088 bool m_accessKeysEnabled : 1;
00089
00090
00091 KPerDomainSettings global;
00092
00093 int m_fontSize;
00094 int m_minFontSize;
00095 int m_maxFormCompletionItems;
00096 KHTMLSettings::KAnimationAdvice m_showAnimations;
00097 KHTMLSettings::KSmoothScrollingMode m_smoothScrolling;
00098
00099 QString m_encoding;
00100 QString m_userSheet;
00101
00102 QColor m_textColor;
00103 QColor m_baseColor;
00104 QColor m_linkColor;
00105 QColor m_vLinkColor;
00106
00107 PolicyMap domainPolicy;
00108 QStringList fonts;
00109 QStringList defaultFonts;
00110
00111 khtml::FilterSet adBlackList;
00112 khtml::FilterSet adWhiteList;
00113 QList< QPair< QString, QChar > > m_fallbackAccessKeysAssignments;
00114 };
00115
00116
00120 static KPerDomainSettings &setup_per_domain_policy(
00121 KHTMLSettingsPrivate* const d,
00122 const QString &domain) {
00123 if (domain.isEmpty()) {
00124 kWarning() << "setup_per_domain_policy: domain is empty";
00125 }
00126 const QString ldomain = domain.toLower();
00127 PolicyMap::iterator it = d->domainPolicy.find(ldomain);
00128 if (it == d->domainPolicy.end()) {
00129
00130
00131 it = d->domainPolicy.insert(ldomain,d->global);
00132 }
00133 return *it;
00134 }
00135
00136
00137 KHTMLSettings::KJavaScriptAdvice KHTMLSettings::strToAdvice(const QString& _str)
00138 {
00139 KJavaScriptAdvice ret = KJavaScriptDunno;
00140
00141 if (_str.isNull())
00142 ret = KJavaScriptDunno;
00143
00144 if (_str.toLower() == QLatin1String("accept"))
00145 ret = KJavaScriptAccept;
00146 else if (_str.toLower() == QLatin1String("reject"))
00147 ret = KJavaScriptReject;
00148
00149 return ret;
00150 }
00151
00152 const char* KHTMLSettings::adviceToStr(KJavaScriptAdvice _advice)
00153 {
00154 switch( _advice ) {
00155 case KJavaScriptAccept: return I18N_NOOP("Accept");
00156 case KJavaScriptReject: return I18N_NOOP("Reject");
00157 default: return 0;
00158 }
00159 return 0;
00160 }
00161
00162
00163 void KHTMLSettings::splitDomainAdvice(const QString& configStr, QString &domain,
00164 KJavaScriptAdvice &javaAdvice, KJavaScriptAdvice& javaScriptAdvice)
00165 {
00166 QString tmp(configStr);
00167 int splitIndex = tmp.indexOf(':');
00168 if ( splitIndex == -1)
00169 {
00170 domain = configStr.toLower();
00171 javaAdvice = KJavaScriptDunno;
00172 javaScriptAdvice = KJavaScriptDunno;
00173 }
00174 else
00175 {
00176 domain = tmp.left(splitIndex).toLower();
00177 QString adviceString = tmp.mid( splitIndex+1, tmp.length() );
00178 int splitIndex2 = adviceString.indexOf( ':' );
00179 if( splitIndex2 == -1 ) {
00180
00181 javaAdvice = strToAdvice( adviceString );
00182 javaScriptAdvice = KJavaScriptDunno;
00183 } else {
00184
00185 javaAdvice = strToAdvice( adviceString.left( splitIndex2 ) );
00186 javaScriptAdvice = strToAdvice( adviceString.mid( splitIndex2+1,
00187 adviceString.length() ) );
00188 }
00189 }
00190 }
00191
00192 void KHTMLSettings::readDomainSettings(const KConfigGroup &config, bool reset,
00193 bool global, KPerDomainSettings &pd_settings) {
00194 QString jsPrefix = global ? QString()
00195 : QString::fromLatin1("javascript.");
00196 QString javaPrefix = global ? QString()
00197 : QString::fromLatin1("java.");
00198 QString pluginsPrefix = global ? QString()
00199 : QString::fromLatin1("plugins.");
00200
00201
00202 QString key = javaPrefix + QLatin1String("EnableJava");
00203 if ( (global && reset) || config.hasKey( key ) )
00204 pd_settings.m_bEnableJava = config.readEntry( key, false );
00205 else if ( !global )
00206 pd_settings.m_bEnableJava = d->global.m_bEnableJava;
00207
00208
00209 key = pluginsPrefix + QLatin1String("EnablePlugins");
00210 if ( (global && reset) || config.hasKey( key ) )
00211 pd_settings.m_bEnablePlugins = config.readEntry( key, true );
00212 else if ( !global )
00213 pd_settings.m_bEnablePlugins = d->global.m_bEnablePlugins;
00214
00215
00216 key = jsPrefix + QLatin1String("EnableJavaScript");
00217 if ( (global && reset) || config.hasKey( key ) )
00218 pd_settings.m_bEnableJavaScript = config.readEntry( key, true );
00219 else if ( !global )
00220 pd_settings.m_bEnableJavaScript = d->global.m_bEnableJavaScript;
00221
00222
00223 key = jsPrefix + QLatin1String("WindowOpenPolicy");
00224 if ( (global && reset) || config.hasKey( key ) )
00225 pd_settings.m_windowOpenPolicy = (KJSWindowOpenPolicy)
00226 config.readEntry( key, uint(KJSWindowOpenSmart) );
00227 else if ( !global )
00228 pd_settings.m_windowOpenPolicy = d->global.m_windowOpenPolicy;
00229
00230 key = jsPrefix + QLatin1String("WindowMovePolicy");
00231 if ( (global && reset) || config.hasKey( key ) )
00232 pd_settings.m_windowMovePolicy = (KJSWindowMovePolicy)
00233 config.readEntry( key, uint(KJSWindowMoveAllow) );
00234 else if ( !global )
00235 pd_settings.m_windowMovePolicy = d->global.m_windowMovePolicy;
00236
00237 key = jsPrefix + QLatin1String("WindowResizePolicy");
00238 if ( (global && reset) || config.hasKey( key ) )
00239 pd_settings.m_windowResizePolicy = (KJSWindowResizePolicy)
00240 config.readEntry( key, uint(KJSWindowResizeAllow) );
00241 else if ( !global )
00242 pd_settings.m_windowResizePolicy = d->global.m_windowResizePolicy;
00243
00244 key = jsPrefix + QLatin1String("WindowStatusPolicy");
00245 if ( (global && reset) || config.hasKey( key ) )
00246 pd_settings.m_windowStatusPolicy = (KJSWindowStatusPolicy)
00247 config.readEntry( key, uint(KJSWindowStatusAllow) );
00248 else if ( !global )
00249 pd_settings.m_windowStatusPolicy = d->global.m_windowStatusPolicy;
00250
00251 key = jsPrefix + QLatin1String("WindowFocusPolicy");
00252 if ( (global && reset) || config.hasKey( key ) )
00253 pd_settings.m_windowFocusPolicy = (KJSWindowFocusPolicy)
00254 config.readEntry( key, uint(KJSWindowFocusAllow) );
00255 else if ( !global )
00256 pd_settings.m_windowFocusPolicy = d->global.m_windowFocusPolicy;
00257
00258 }
00259
00260
00261 KHTMLSettings::KHTMLSettings()
00262 :d (new KHTMLSettingsPrivate())
00263 {
00264 init();
00265 }
00266
00267 KHTMLSettings::KHTMLSettings(const KHTMLSettings &other)
00268 :d(new KHTMLSettingsPrivate())
00269 {
00270 *d = *other.d;
00271 }
00272
00273 KHTMLSettings::~KHTMLSettings()
00274 {
00275 delete d;
00276 }
00277
00278 bool KHTMLSettings::changeCursor() const
00279 {
00280 return d->m_bChangeCursor;
00281 }
00282
00283 bool KHTMLSettings::underlineLink() const
00284 {
00285 return d->m_underlineLink;
00286 }
00287
00288 bool KHTMLSettings::hoverLink() const
00289 {
00290 return d->m_hoverLink;
00291 }
00292
00293 void KHTMLSettings::init()
00294 {
00295 KConfig global( "khtmlrc", KConfig::NoGlobals );
00296 init( &global, true );
00297
00298 KSharedConfig::Ptr local = KGlobal::config();
00299 if ( !local )
00300 return;
00301
00302 init( local.data(), false );
00303 }
00304
00305 void KHTMLSettings::init( KConfig * config, bool reset )
00306 {
00307 KConfigGroup cg( config, "MainView Settings" );
00308 if (reset || cg.exists() )
00309 {
00310 if ( reset || cg.hasKey( "OpenMiddleClick" ) )
00311 d->m_bOpenMiddleClick = cg.readEntry( "OpenMiddleClick", true );
00312
00313 if ( reset || cg.hasKey( "BackRightClick" ) )
00314 d->m_bBackRightClick = cg.readEntry( "BackRightClick", false );
00315 }
00316
00317 KConfigGroup cgAccess(config,"Access Keys" );
00318 if (reset || cgAccess.exists() ) {
00319 d->m_accessKeysEnabled = cgAccess.readEntry( "Enabled", true );
00320 }
00321
00322 KConfigGroup cgFilter( config, "Filter Settings" );
00323
00324 if (reset || cgFilter.exists() )
00325 {
00326 d->m_adFilterEnabled = cgFilter.readEntry("Enabled", false);
00327 d->m_hideAdsEnabled = cgFilter.readEntry("Shrink", false);
00328
00329 d->adBlackList.clear();
00330 d->adWhiteList.clear();
00331
00332 QMap<QString,QString> entryMap = cgFilter.entryMap();
00333 QMap<QString,QString>::ConstIterator it;
00334 for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
00335 {
00336 QString name = it.key();
00337 QString url = it.value();
00338
00339 if (name.startsWith("Filter"))
00340 {
00341 if (url.startsWith(QLatin1String("@@")))
00342 d->adWhiteList.addFilter(url);
00343 else
00344 d->adBlackList.addFilter(url);
00345 }
00346 }
00347 }
00348
00349 KConfigGroup cgHtml( config, "HTML Settings" );
00350 if (reset || cgHtml.exists() )
00351 {
00352
00353 if( reset ) {
00354 d->defaultFonts = QStringList();
00355 d->defaultFonts.append( cgHtml.readEntry( "StandardFont", KGlobalSettings::generalFont().family() ) );
00356 d->defaultFonts.append( cgHtml.readEntry( "FixedFont", KGlobalSettings::fixedFont().family() ) );
00357 d->defaultFonts.append( cgHtml.readEntry( "SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) );
00358 d->defaultFonts.append( cgHtml.readEntry( "SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) );
00359 d->defaultFonts.append( cgHtml.readEntry( "CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) );
00360 d->defaultFonts.append( cgHtml.readEntry( "FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) );
00361 d->defaultFonts.append( QString( "0" ) );
00362 }
00363
00364 if ( reset || cgHtml.hasKey( "MinimumFontSize" ) )
00365 d->m_minFontSize = cgHtml.readEntry( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE );
00366
00367 if ( reset || cgHtml.hasKey( "MediumFontSize" ) )
00368 d->m_fontSize = cgHtml.readEntry( "MediumFontSize", 12 );
00369
00370 d->fonts = cgHtml.readEntry( "Fonts", QStringList() );
00371
00372 if ( reset || cgHtml.hasKey( "DefaultEncoding" ) )
00373 d->m_encoding = cgHtml.readEntry( "DefaultEncoding", "" );
00374
00375 if ( reset || cgHtml.hasKey( "EnforceDefaultCharset" ) )
00376 d->enforceCharset = cgHtml.readEntry( "EnforceDefaultCharset", false );
00377
00378
00379 if ( reset || cgHtml.hasKey( "ChangeCursor" ) )
00380 d->m_bChangeCursor = cgHtml.readEntry( "ChangeCursor", KDE_DEFAULT_CHANGECURSOR );
00381
00382 if ( reset || cgHtml.hasKey("UnderlineLinks") )
00383 d->m_underlineLink = cgHtml.readEntry( "UnderlineLinks", true );
00384
00385 if ( reset || cgHtml.hasKey( "HoverLinks" ) )
00386 {
00387 if ( (d->m_hoverLink = cgHtml.readEntry( "HoverLinks", false )))
00388 d->m_underlineLink = false;
00389 }
00390
00391 if ( reset || cgHtml.hasKey( "AllowTabulation" ) )
00392 d->m_allowTabulation = cgHtml.readEntry( "AllowTabulation", false );
00393
00394 if ( reset || cgHtml.hasKey( "AutoSpellCheck" ) )
00395 d->m_autoSpellCheck = cgHtml.readEntry( "AutoSpellCheck", true );
00396
00397
00398 if ( reset || cgHtml.hasKey( "AutoLoadImages" ) )
00399 d->m_bAutoLoadImages = cgHtml.readEntry( "AutoLoadImages", true );
00400
00401 if ( reset || cgHtml.hasKey( "UnfinishedImageFrame" ) )
00402 d->m_bUnfinishedImageFrame = cgHtml.readEntry( "UnfinishedImageFrame", true );
00403
00404 if ( reset || cgHtml.hasKey( "ShowAnimations" ) )
00405 {
00406 QString value = cgHtml.readEntry( "ShowAnimations").toLower();
00407 if (value == "disabled")
00408 d->m_showAnimations = KAnimationDisabled;
00409 else if (value == "looponce")
00410 d->m_showAnimations = KAnimationLoopOnce;
00411 else
00412 d->m_showAnimations = KAnimationEnabled;
00413 }
00414
00415 if ( reset || cgHtml.hasKey( "SmoothScrolling" ) )
00416 {
00417 QString value = cgHtml.readEntry( "SmoothScrolling", "whenefficient" ).toLower();
00418 if (value == "disabled")
00419 d->m_smoothScrolling = KSmoothScrollingDisabled;
00420 else if (value == "whenefficient")
00421 d->m_smoothScrolling = KSmoothScrollingWhenEfficient;
00422 else
00423 d->m_smoothScrolling = KSmoothScrollingEnabled;
00424 }
00425
00426 if ( cgHtml.readEntry( "UserStyleSheetEnabled", false ) == true ) {
00427 if ( reset || cgHtml.hasKey( "UserStyleSheet" ) )
00428 d->m_userSheet = cgHtml.readEntry( "UserStyleSheet", "" );
00429 }
00430
00431 d->m_formCompletionEnabled = cgHtml.readEntry("FormCompletion", true);
00432 d->m_maxFormCompletionItems = cgHtml.readEntry("MaxFormCompletionItems", 10);
00433 d->m_autoDelayedActionsEnabled = cgHtml.readEntry ("AutoDelayedActions", true);
00434 d->m_jsErrorsEnabled = cgHtml.readEntry("ReportJSErrors", true);
00435 const QStringList accesskeys = cgHtml.readEntry("FallbackAccessKeysAssignments", QStringList());
00436 d->m_fallbackAccessKeysAssignments.clear();
00437 for( QStringList::ConstIterator it = accesskeys.begin(); it != accesskeys.end(); ++it )
00438 if( (*it).length() > 2 && (*it)[ 1 ] == ':' )
00439 d->m_fallbackAccessKeysAssignments.append( qMakePair( (*it).mid( 2 ), (*it)[ 0 ] ));
00440 }
00441
00442
00443
00444 if ( reset || cg.hasKey( "FollowSystemColors" ) )
00445 d->m_follow_system_colors = cg.readEntry( "FollowSystemColors", false );
00446
00447 KConfigGroup cgGeneral( config, "General" );
00448 if ( reset || cgGeneral.exists( ) )
00449 {
00450 if ( reset || cgGeneral.hasKey( "foreground" ) ) {
00451 QColor def(HTML_DEFAULT_TXT_COLOR);
00452 d->m_textColor = cgGeneral.readEntry( "foreground", def );
00453 }
00454
00455 if ( reset || cgGeneral.hasKey( "linkColor" ) ) {
00456 QColor def(HTML_DEFAULT_LNK_COLOR);
00457 d->m_linkColor = cgGeneral.readEntry( "linkColor", def );
00458 }
00459
00460 if ( reset || cgGeneral.hasKey( "visitedLinkColor" ) ) {
00461 QColor def(HTML_DEFAULT_VLNK_COLOR);
00462 d->m_vLinkColor = cgGeneral.readEntry( "visitedLinkColor", def);
00463 }
00464
00465 if ( reset || cgGeneral.hasKey( "background" ) ) {
00466 QColor def(HTML_DEFAULT_BASE_COLOR);
00467 d->m_baseColor = cgGeneral.readEntry( "background", def);
00468 }
00469 }
00470
00471 KConfigGroup cgJava( config, "Java/JavaScript Settings" );
00472 if( reset || cgJava.exists() )
00473 {
00474
00475
00476 if ( reset || cgJava.hasKey( "EnableJavaScriptDebug" ) )
00477 d->m_bEnableJavaScriptDebug = cgJava.readEntry( "EnableJavaScriptDebug", false );
00478
00479
00480 if ( reset || cgJava.hasKey( "ReportJavaScriptErrors" ) )
00481 d->m_bEnableJavaScriptErrorReporting = cgJava.readEntry( "ReportJavaScriptErrors", false );
00482
00483
00484 if ( reset || cgJava.hasKey( "PopupBlockerPassivePopup" ) )
00485 d->m_jsPopupBlockerPassivePopup = cgJava.readEntry("PopupBlockerPassivePopup", true );
00486
00487
00488 readDomainSettings(cgJava,reset,true,d->global);
00489 #ifdef DEBUG_SETTINGS
00490 d->global.dump("init global");
00491 #endif
00492
00493
00494
00495 static const char *const domain_keys[] = {
00496 "ECMADomains", "JavaDomains", "PluginDomains"
00497 };
00498 bool check_old_ecma_settings = true;
00499 bool check_old_java_settings = true;
00500
00501 QMap<QString,int> domainList;
00502 for (unsigned i = 0; i < sizeof domain_keys/sizeof domain_keys[0]; ++i) {
00503 if ( reset || cgJava.hasKey(domain_keys[i]) ) {
00504 if (i == 0) check_old_ecma_settings = false;
00505 else if (i == 1) check_old_java_settings = false;
00506 const QStringList dl = cgJava.readEntry( domain_keys[i], QStringList() );
00507 const QMap<QString,int>::Iterator notfound = domainList.end();
00508 QStringList::ConstIterator it = dl.begin();
00509 const QStringList::ConstIterator itEnd = dl.end();
00510 for (; it != itEnd; ++it) {
00511 const QString domain = (*it).toLower();
00512 QMap<QString,int>::Iterator pos = domainList.find(domain);
00513 if (pos == notfound) domainList.insert(domain,0);
00514 }
00515 }
00516 }
00517
00518 if (reset)
00519 d->domainPolicy.clear();
00520
00521 {
00522 QMap<QString,int>::ConstIterator it = domainList.begin();
00523 const QMap<QString,int>::ConstIterator itEnd = domainList.end();
00524 for ( ; it != itEnd; ++it)
00525 {
00526 const QString domain = it.key();
00527 KConfigGroup cg( config, domain );
00528 readDomainSettings(cg,reset,false,d->domainPolicy[domain]);
00529 #ifdef DEBUG_SETTINGS
00530 d->domainPolicy[domain].dump("init "+domain);
00531 #endif
00532 }
00533 }
00534
00535 bool check_old_java = true;
00536 if( ( reset || cgJava.hasKey( "JavaDomainSettings" ) )
00537 && check_old_java_settings )
00538 {
00539 check_old_java = false;
00540 const QStringList domainList = cgJava.readEntry( "JavaDomainSettings", QStringList() );
00541 QStringList::ConstIterator it = domainList.begin();
00542 const QStringList::ConstIterator itEnd = domainList.end();
00543 for ( ; it != itEnd; ++it)
00544 {
00545 QString domain;
00546 KJavaScriptAdvice javaAdvice;
00547 KJavaScriptAdvice javaScriptAdvice;
00548 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00549 setup_per_domain_policy(d,domain).m_bEnableJava =
00550 javaAdvice == KJavaScriptAccept;
00551 #ifdef DEBUG_SETTINGS
00552 setup_per_domain_policy(d,domain).dump("JavaDomainSettings 4 "+domain);
00553 #endif
00554 }
00555 }
00556
00557 bool check_old_ecma = true;
00558 if( ( reset || cgJava.hasKey( "ECMADomainSettings" ) )
00559 && check_old_ecma_settings )
00560 {
00561 check_old_ecma = false;
00562 const QStringList domainList = cgJava.readEntry( "ECMADomainSettings", QStringList() );
00563 QStringList::ConstIterator it = domainList.begin();
00564 const QStringList::ConstIterator itEnd = domainList.end();
00565 for ( ; it != itEnd; ++it)
00566 {
00567 QString domain;
00568 KJavaScriptAdvice javaAdvice;
00569 KJavaScriptAdvice javaScriptAdvice;
00570 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00571 setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00572 javaScriptAdvice == KJavaScriptAccept;
00573 #ifdef DEBUG_SETTINGS
00574 setup_per_domain_policy(d,domain).dump("ECMADomainSettings 4 "+domain);
00575 #endif
00576 }
00577 }
00578
00579 if( ( reset || cgJava.hasKey( "JavaScriptDomainAdvice" ) )
00580 && ( check_old_java || check_old_ecma )
00581 && ( check_old_ecma_settings || check_old_java_settings ) )
00582 {
00583 const QStringList domainList = cgJava.readEntry( "JavaScriptDomainAdvice", QStringList() );
00584 QStringList::ConstIterator it = domainList.begin();
00585 const QStringList::ConstIterator itEnd = domainList.end();
00586 for ( ; it != itEnd; ++it)
00587 {
00588 QString domain;
00589 KJavaScriptAdvice javaAdvice;
00590 KJavaScriptAdvice javaScriptAdvice;
00591 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00592 if( check_old_java )
00593 setup_per_domain_policy(d,domain).m_bEnableJava =
00594 javaAdvice == KJavaScriptAccept;
00595 if( check_old_ecma )
00596 setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00597 javaScriptAdvice == KJavaScriptAccept;
00598 #ifdef DEBUG_SETTINGS
00599 setup_per_domain_policy(d,domain).dump("JavaScriptDomainAdvice 4 "+domain);
00600 #endif
00601 }
00602
00603
00604 #if 0
00605 if( check_old_java )
00606 {
00607 QStringList domainConfig;
00608 PolicyMap::Iterator it;
00609 for( it = d->javaDomainPolicy.begin(); it != d->javaDomainPolicy.end(); ++it )
00610 {
00611 QByteArray javaPolicy = adviceToStr( it.value() );
00612 QByteArray javaScriptPolicy = adviceToStr( KJavaScriptDunno );
00613 domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00614 }
00615 cg.writeEntry( "JavaDomainSettings", domainConfig );
00616 }
00617
00618 if( check_old_ecma )
00619 {
00620 QStringList domainConfig;
00621 PolicyMap::Iterator it;
00622 for( it = d->javaScriptDomainPolicy.begin(); it != d->javaScriptDomainPolicy.end(); ++it )
00623 {
00624 QByteArray javaPolicy = adviceToStr( KJavaScriptDunno );
00625 QByteArray javaScriptPolicy = adviceToStr( it.value() );
00626 domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00627 }
00628 cg.writeEntry( "ECMADomainSettings", domainConfig );
00629 }
00630 #endif
00631 }
00632 }
00633 }
00634
00635
00640 static const KPerDomainSettings &lookup_hostname_policy(
00641 const KHTMLSettingsPrivate* const d,
00642 const QString& hostname)
00643 {
00644 #ifdef DEBUG_SETTINGS
00645 kDebug() << "lookup_hostname_policy(" << hostname << ")";
00646 #endif
00647 if (hostname.isEmpty()) {
00648 #ifdef DEBUG_SETTINGS
00649 d->global.dump("global");
00650 #endif
00651 return d->global;
00652 }
00653
00654 const PolicyMap::const_iterator notfound = d->domainPolicy.end();
00655
00656
00657 PolicyMap::const_iterator it = d->domainPolicy.find(hostname);
00658 if( it != notfound ) {
00659 #ifdef DEBUG_SETTINGS
00660 kDebug() << "perfect match";
00661 (*it).dump(hostname);
00662 #endif
00663
00664 return *it;
00665 }
00666
00667
00668
00669 QString host_part = hostname;
00670 int dot_idx = -1;
00671 while( (dot_idx = host_part.indexOf(QChar('.'))) >= 0 ) {
00672 host_part.remove(0,dot_idx);
00673 it = d->domainPolicy.find(host_part);
00674 Q_ASSERT(notfound == d->domainPolicy.end());
00675 if( it != notfound ) {
00676 #ifdef DEBUG_SETTINGS
00677 kDebug() << "partial match";
00678 (*it).dump(host_part);
00679 #endif
00680 return *it;
00681 }
00682
00683 host_part.remove(0,1);
00684 }
00685
00686
00687 #ifdef DEBUG_SETTINGS
00688 kDebug() << "no match";
00689 d->global.dump("global");
00690 #endif
00691 return d->global;
00692 }
00693
00694 bool KHTMLSettings::isOpenMiddleClickEnabled()
00695 {
00696 return d->m_bOpenMiddleClick;
00697 }
00698
00699 bool KHTMLSettings::isBackRightClickEnabled()
00700 {
00701 return d->m_bBackRightClick;
00702 }
00703
00704 bool KHTMLSettings::accessKeysEnabled() const
00705 {
00706 return d->m_accessKeysEnabled;
00707 }
00708
00709 bool KHTMLSettings::isAdFilterEnabled() const
00710 {
00711 return d->m_adFilterEnabled;
00712 }
00713
00714 bool KHTMLSettings::isHideAdsEnabled() const
00715 {
00716 return d->m_hideAdsEnabled;
00717 }
00718
00719 bool KHTMLSettings::isAdFiltered( const QString &url ) const
00720 {
00721 if (d->m_adFilterEnabled)
00722 {
00723 if (!url.startsWith("data:"))
00724 {
00725
00726 return d->adBlackList.isUrlMatched(url) && !d->adWhiteList.isUrlMatched(url);
00727 }
00728 }
00729 return false;
00730 }
00731
00732 void KHTMLSettings::addAdFilter( const QString &url )
00733 {
00734 KConfigGroup config = KSharedConfig::openConfig( "khtmlrc", KConfig::NoGlobals )->group( "Filter Settings" );
00735
00736 QRegExp rx;
00737
00738
00739
00740 if (url.length()>2 && url[0]=='/' && url[url.length()-1] == '/')
00741 {
00742 QString inside = url.mid(1, url.length()-2);
00743 rx.setPattern(inside);
00744 }
00745 else
00746 {
00747 rx.setPatternSyntax(QRegExp::Wildcard);
00748 rx.setPattern(url);
00749 }
00750
00751 if (rx.isValid())
00752 {
00753 int last=config.readEntry("Count", 0);
00754 QString key = "Filter-" + QString::number(last);
00755 config.writeEntry(key, url);
00756 config.writeEntry("Count",last+1);
00757 config.sync();
00758 if (url.startsWith(QLatin1String("@@")))
00759 d->adWhiteList.addFilter(url);
00760 else
00761 d->adBlackList.addFilter(url);
00762 }
00763 else
00764 {
00765 KMessageBox::error(0,
00766 rx.errorString(),
00767 i18n("Filter error"));
00768 }
00769 }
00770
00771 bool KHTMLSettings::isJavaEnabled( const QString& hostname ) const
00772 {
00773 return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJava;
00774 }
00775
00776 bool KHTMLSettings::isJavaScriptEnabled( const QString& hostname ) const
00777 {
00778 return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJavaScript;
00779 }
00780
00781 bool KHTMLSettings::isJavaScriptDebugEnabled( const QString& ) const
00782 {
00783
00784 return d->m_bEnableJavaScriptDebug;
00785 }
00786
00787 bool KHTMLSettings::isJavaScriptErrorReportingEnabled( const QString& ) const
00788 {
00789
00790 return d->m_bEnableJavaScriptErrorReporting;
00791 }
00792
00793 bool KHTMLSettings::isPluginsEnabled( const QString& hostname ) const
00794 {
00795 return lookup_hostname_policy(d,hostname.toLower()).m_bEnablePlugins;
00796 }
00797
00798 KHTMLSettings::KJSWindowOpenPolicy KHTMLSettings::windowOpenPolicy(
00799 const QString& hostname) const {
00800 return lookup_hostname_policy(d,hostname.toLower()).m_windowOpenPolicy;
00801 }
00802
00803 KHTMLSettings::KJSWindowMovePolicy KHTMLSettings::windowMovePolicy(
00804 const QString& hostname) const {
00805 return lookup_hostname_policy(d,hostname.toLower()).m_windowMovePolicy;
00806 }
00807
00808 KHTMLSettings::KJSWindowResizePolicy KHTMLSettings::windowResizePolicy(
00809 const QString& hostname) const {
00810 return lookup_hostname_policy(d,hostname.toLower()).m_windowResizePolicy;
00811 }
00812
00813 KHTMLSettings::KJSWindowStatusPolicy KHTMLSettings::windowStatusPolicy(
00814 const QString& hostname) const {
00815 return lookup_hostname_policy(d,hostname.toLower()).m_windowStatusPolicy;
00816 }
00817
00818 KHTMLSettings::KJSWindowFocusPolicy KHTMLSettings::windowFocusPolicy(
00819 const QString& hostname) const {
00820 return lookup_hostname_policy(d,hostname.toLower()).m_windowFocusPolicy;
00821 }
00822
00823 int KHTMLSettings::mediumFontSize() const
00824 {
00825 return d->m_fontSize;
00826 }
00827
00828 int KHTMLSettings::minFontSize() const
00829 {
00830 return d->m_minFontSize;
00831 }
00832
00833 QString KHTMLSettings::settingsToCSS() const
00834 {
00835
00836 QString str = "a:link {\ncolor: ";
00837 str += d->m_linkColor.name();
00838 str += ';';
00839 if(d->m_underlineLink)
00840 str += "\ntext-decoration: underline;";
00841
00842 if( d->m_bChangeCursor )
00843 {
00844 str += "\ncursor: pointer;";
00845 str += "\n}\ninput[type=image] { cursor: pointer;";
00846 }
00847 str += "\n}\n";
00848 str += "a:visited {\ncolor: ";
00849 str += d->m_vLinkColor.name();
00850 str += ';';
00851 if(d->m_underlineLink)
00852 str += "\ntext-decoration: underline;";
00853
00854 if( d->m_bChangeCursor )
00855 str += "\ncursor: pointer;";
00856 str += "\n}\n";
00857
00858 if(d->m_hoverLink)
00859 str += "a:link:hover, a:visited:hover { text-decoration: underline; }\n";
00860
00861 return str;
00862 }
00863
00864 const QString &KHTMLSettings::availableFamilies()
00865 {
00866 if ( !avFamilies ) {
00867 avFamilies = new QString;
00868 QFontDatabase db;
00869 QStringList families = db.families();
00870 QStringList s;
00871 QRegExp foundryExp(" \\[.+\\]");
00872
00873
00874 QStringList::Iterator f = families.begin();
00875 const QStringList::Iterator fEnd = families.end();
00876
00877 for ( ; f != fEnd; ++f ) {
00878 (*f).replace( foundryExp, "");
00879 if (!s.contains(*f))
00880 s << *f;
00881 }
00882 s.sort();
00883
00884 *avFamilies = ',' + s.join(",") + ',';
00885 }
00886
00887 return *avFamilies;
00888 }
00889
00890 QString KHTMLSettings::lookupFont(int i) const
00891 {
00892 QString font;
00893 if (d->fonts.count() > i)
00894 font = d->fonts[i];
00895 if (font.isEmpty())
00896 font = d->defaultFonts[i];
00897 return font;
00898 }
00899
00900 QString KHTMLSettings::stdFontName() const
00901 {
00902 return lookupFont(0);
00903 }
00904
00905 QString KHTMLSettings::fixedFontName() const
00906 {
00907 return lookupFont(1);
00908 }
00909
00910 QString KHTMLSettings::serifFontName() const
00911 {
00912 return lookupFont(2);
00913 }
00914
00915 QString KHTMLSettings::sansSerifFontName() const
00916 {
00917 return lookupFont(3);
00918 }
00919
00920 QString KHTMLSettings::cursiveFontName() const
00921 {
00922 return lookupFont(4);
00923 }
00924
00925 QString KHTMLSettings::fantasyFontName() const
00926 {
00927 return lookupFont(5);
00928 }
00929
00930 void KHTMLSettings::setStdFontName(const QString &n)
00931 {
00932 while(d->fonts.count() <= 0)
00933 d->fonts.append(QString());
00934 d->fonts[0] = n;
00935 }
00936
00937 void KHTMLSettings::setFixedFontName(const QString &n)
00938 {
00939 while(d->fonts.count() <= 1)
00940 d->fonts.append(QString());
00941 d->fonts[1] = n;
00942 }
00943
00944 QString KHTMLSettings::userStyleSheet() const
00945 {
00946 return d->m_userSheet;
00947 }
00948
00949 bool KHTMLSettings::isFormCompletionEnabled() const
00950 {
00951 return d->m_formCompletionEnabled;
00952 }
00953
00954 int KHTMLSettings::maxFormCompletionItems() const
00955 {
00956 return d->m_maxFormCompletionItems;
00957 }
00958
00959 const QString &KHTMLSettings::encoding() const
00960 {
00961 return d->m_encoding;
00962 }
00963
00964 bool KHTMLSettings::followSystemColors() const
00965 {
00966 return d->m_follow_system_colors;
00967 }
00968
00969 const QColor& KHTMLSettings::textColor() const
00970 {
00971 return d->m_textColor;
00972 }
00973
00974 const QColor& KHTMLSettings::baseColor() const
00975 {
00976 return d->m_baseColor;
00977 }
00978
00979 const QColor& KHTMLSettings::linkColor() const
00980 {
00981 return d->m_linkColor;
00982 }
00983
00984 const QColor& KHTMLSettings::vLinkColor() const
00985 {
00986 return d->m_vLinkColor;
00987 }
00988
00989 bool KHTMLSettings::autoLoadImages() const
00990 {
00991 return d->m_bAutoLoadImages;
00992 }
00993
00994 bool KHTMLSettings::unfinishedImageFrame() const
00995 {
00996 return d->m_bUnfinishedImageFrame;
00997 }
00998
00999 KHTMLSettings::KAnimationAdvice KHTMLSettings::showAnimations() const
01000 {
01001 return d->m_showAnimations;
01002 }
01003
01004 KHTMLSettings::KSmoothScrollingMode KHTMLSettings::smoothScrolling() const
01005 {
01006 return d->m_smoothScrolling;
01007 }
01008
01009 bool KHTMLSettings::isAutoDelayedActionsEnabled() const
01010 {
01011 return d->m_autoDelayedActionsEnabled;
01012 }
01013
01014 bool KHTMLSettings::jsErrorsEnabled() const
01015 {
01016 return d->m_jsErrorsEnabled;
01017 }
01018
01019 void KHTMLSettings::setJSErrorsEnabled(bool enabled)
01020 {
01021 d->m_jsErrorsEnabled = enabled;
01022
01023 KConfigGroup cg( KGlobal::config(), "HTML Settings");
01024 cg.writeEntry("ReportJSErrors", enabled);
01025 cg.sync();
01026 }
01027
01028 bool KHTMLSettings::allowTabulation() const
01029 {
01030 return d->m_allowTabulation;
01031 }
01032
01033 bool KHTMLSettings::autoSpellCheck() const
01034 {
01035 return d->m_autoSpellCheck;
01036 }
01037
01038 QList< QPair< QString, QChar > > KHTMLSettings::fallbackAccessKeysAssignments() const
01039 {
01040 return d->m_fallbackAccessKeysAssignments;
01041 }
01042
01043 void KHTMLSettings::setJSPopupBlockerPassivePopup(bool enabled)
01044 {
01045 d->m_jsPopupBlockerPassivePopup = enabled;
01046
01047 KConfigGroup cg( KGlobal::config(), "Java/JavaScript Settings");
01048 cg.writeEntry("PopupBlockerPassivePopup", enabled);
01049 cg.sync();
01050 }
01051
01052 bool KHTMLSettings::jsPopupBlockerPassivePopup() const
01053 {
01054 return d->m_jsPopupBlockerPassivePopup;
01055 }