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