36 #define CDEBUG qCDebug(KHTML_LOG) 38 #define CDEBUG qCDebug(KHTML_LOG) 49 #include <imload/imagepainter.h> 50 #include <imload/imagemanager.h> 51 #include <kfilterdev.h> 56 #define DEFCACHESIZE 2096*1024 60 #include <QApplication> 61 #include <QDesktopWidget> 67 #include <kurlauthorized.h> 69 #include <kio/jobuidelegate.h> 70 #include <kio/jobclasses.h> 71 #include <kio/scheduler.h> 72 #include <kcharsets.h> 73 #include <kiconloader.h> 74 #include "khtml_debug.h" 75 #include <kjobwidgets.h> 77 #include <khtml_global.h> 78 #include <khtml_part.h> 82 #include <kfilemetainfo.h> 83 #include <qtemporaryfile.h> 86 #include "html/html_documentimpl.h" 87 #include "css/css_stylesheetimpl.h" 88 #include "xml/dom_docimpl.h" 90 #include "blocked_icon.cpp" 92 #include <QPaintEngine> 94 using namespace khtml;
98 #define MAX_LRU_LISTS 20 103 LRUList() : m_head(nullptr), m_tail(nullptr) {}
106 static LRUList m_LRULists[MAX_LRU_LISTS];
109 CachedObjectClient::~CachedObjectClient()
113 CachedObject::~CachedObject()
115 Cache::removeFromLRUList(
this);
118 void CachedObject::finish()
123 bool CachedObject::isExpired()
const 125 if (!m_expireDate.isValid()) {
129 return (now >= m_expireDate);
132 void CachedObject::setRequest(
Request *_request)
134 if (_request && !m_request) {
138 if (allowInLRUList()) {
139 Cache::removeFromLRUList(
this);
142 m_request = _request;
144 if (allowInLRUList()) {
145 Cache::insertInLRUList(
this);
151 if (m_preloadResult == PreloadNotReferenced) {
153 m_preloadResult = PreloadReferencedWhileComplete;
154 }
else if (m_prospectiveRequest) {
155 m_preloadResult = PreloadReferencedWhileLoading;
157 m_preloadResult = PreloadReferenced;
164 m_clients.insertMulti(c, c);
165 Cache::removeFromLRUList(
this);
172 assert(m_clients.count());
173 assert(!canDelete());
174 assert(m_clients.contains(c));
180 if (allowInLRUList()) {
181 Cache::insertInLRUList(
this);
185 void CachedObject::setSize(
int size)
189 if (!m_next && !m_prev && getLRUListFor(
this)->m_head !=
this) {
192 sizeChanged = (size - m_size) != 0;
197 if (sizeChanged && allowInLRUList()) {
198 Cache::removeFromLRUList(
this);
203 if (sizeChanged && allowInLRUList()) {
204 Cache::insertInLRUList(
this);
213 uchar *d = (uchar *) buffer.
data();
214 int s = buffer.
size();
218 d[0] == 0xef && d[1] == 0xbb && d[2] == 0xbf) {
222 if (s >= 2 && ((d[0] == 0xff && d[1] == 0xfe) ||
223 (d[0] == 0xfe && d[1] == 0xff))) {
255 m_wasBlocked =
false;
262 Cache::loader()->load(dl,
this,
false, -8);
266 CachedCSSStyleSheet::CachedCSSStyleSheet(
const DOMString &url,
const QString &stylesheet_data)
270 m_status = Persistent;
274 bool khtml::isAcceptableCSSMimetype(
const DOM::DOMString &mimetype)
277 return mimetype.isEmpty() || mimetype ==
"text/css" || mimetype ==
"application/x-unknown-content-type";
282 CachedObject::ref(c);
286 c->error(m_err, m_errText);
288 c->setStyleSheet(m_url, m_sheet, m_charset, m_mimetype);
293 void CachedCSSStyleSheet::data(
QBuffer &buffer,
bool eof)
301 m_charset = checkCharset(buffer.
buffer());
303 if (!m_charset.isEmpty()) {
305 if (c->mibEnum() == 11) {
309 c = codecForBuffer(m_charsetHint, buffer.
buffer());
310 m_charset = c->name();
320 void CachedCSSStyleSheet::checkNotify()
322 if (m_loading || m_hadError) {
326 CDEBUG <<
"finishedLoading" << m_url.string();
329 it.next().value()->setStyleSheet(m_url, m_sheet, m_charset, m_mimetype);
333 void CachedCSSStyleSheet::error(
int err,
const char *text)
341 it.next().value()->error(m_err, m_errText);
347 int s = buffer.
size();
355 const char *d = buffer.
data();
356 if (strncmp(d,
"@charset \"", 10) == 0) {
358 const char *p = strchr(d + 10,
'"');
380 Cache::loader()->load(dl,
this,
false, -6);
385 CachedScript::CachedScript(
const DOMString &url,
const QString &script_data)
390 m_status = Persistent;
396 CachedObject::ref(c);
399 c->notifyFinished(
this);
403 void CachedScript::data(
QBuffer &buffer,
bool eof)
418 void CachedScript::checkNotify()
425 it.next().value()->notifyFinished(
this);
429 void CachedScript::error(
int ,
const char * )
438 static QString buildAcceptHeader()
440 return "image/png, image/jpeg, video/x-mng, image/jp2, image/gif;q=0.5,*/*;q=0.1";
453 bgColor = qRgba(0, 0, 0, 0);
455 setAccept(buildAcceptHeader());
456 i->setShowAnimations(dl->showAnimations());
459 if (KHTMLGlobal::defaultHTMLSettings()->isAdFiltered(url.string())) {
461 CachedObject::finish();
465 CachedImage::~CachedImage()
473 CachedObject::ref(c);
476 qCDebug(KHTML_LOG) <<
"image" <<
this <<
"ref'd by client" << c;
481 if (m_status >= Persistent && !pixmap_size().isNull()) {
483 qCDebug(KHTML_LOG) <<
"Notifying finished size:" << i->size().width() <<
"," << i->size().height();
485 c->updatePixmap(
QRect(
QPoint(0, 0), pixmap_size()),
this);
486 c->notifyFinished(
this);
492 CachedObject::deref(c);
497 #define BGMINWIDTH 32 498 #define BGMINHEIGHT 32 500 QPixmap CachedImage::tiled_pixmap(
const QColor &newc,
int xWidth,
int xHeight)
504 if (m_hadError || m_wasBlocked) {
505 return *Cache::nullPixmap;
509 if (i->size().width() == 0 || i->size().height() == 0) {
510 return *Cache::nullPixmap;
514 #warning "Needs some additional performance work" 517 static QRgb bgTransparent = qRgba(0, 0, 0, 0);
519 QSize s(pixmap_size());
524 xWidth = w = s.width();
527 xHeight = h = s.height();
530 if (((bgColor != bgTransparent) && (bgColor != newc.
rgba())) ||
531 (bgSize !=
QSize(xWidth, xHeight))) {
532 delete bg; bg =
nullptr;
547 if (xWidth != s.width() || xHeight != s.height()) {
548 src = scaled_pixmap(xWidth, xHeight);
553 bgSize =
QSize(xWidth, xHeight);
559 bg =
new QPixmap(xWidth, xHeight);
562 p.drawPixmap(0, 0, *src);
563 bgColor = newc.
rgba();
566 bgColor = bgTransparent;
571 if (r.
width() < BGMINWIDTH) {
572 w = ((BGMINWIDTH - 1) / xWidth + 1) * xWidth;
574 if (r.
height() < BGMINHEIGHT) {
575 h = ((BGMINHEIGHT - 1) / xHeight + 1) * xHeight;
579 if (w != xWidth || h != xHeight) {
584 if (newc.
isValid() && (bgColor != bgTransparent)) {
592 p.drawTiledPixmap(0, 0, w, h, *src);
598 }
else if (src && !bg) {
616 QPixmap *CachedImage::scaled_pixmap(
int xWidth,
int xHeight)
619 if (m_hadError || m_wasBlocked) {
620 return Cache::nullPixmap;
624 if (i->size().width() == 0 || i->size().height() == 0) {
625 return Cache::nullPixmap;
629 if (scaled->width() == xWidth && scaled->height() == xHeight) {
642 pi.paint(0, 0, &paint);
650 QPixmap CachedImage::pixmap()
const 653 return *Cache::brokenPixmap;
657 return *Cache::blockedPixmap;
661 int h = i->size().height();
669 pi.paint(0, 0, &paint);
680 pi.paint(0, 0, &paint);
686 QSize CachedImage::pixmap_size()
const 689 return Cache::blockedPixmap->size();
692 return Cache::brokenPixmap->size();
703 qCDebug(KHTML_LOG) <<
this <<
"got geometry" << width <<
"x" <<
height;
706 do_notify(
QRect(0, 0, width, height));
712 qCDebug(KHTML_LOG) <<
"Image" <<
this <<
"change" <<
713 region.
x() <<
"," << region.
y() <<
":" << region.
width() <<
"x" << region.
height();
724 void CachedImage::doNotifyFinished()
727 it.next().value()->notifyFinished(
this);
739 qCDebug(KHTML_LOG) <<
"Image is done:" <<
this;
741 m_status = Persistent;
752 void CachedImage::do_notify(
const QRect &r)
756 qCDebug(KHTML_LOG) <<
"image" <<
this <<
"notify of geom client" << it.peekNext().value();
758 it.next().value()->updatePixmap(r,
this);
762 void CachedImage::setShowAnimations(KHTMLSettings::KAnimationAdvice showAnimations)
765 i->setShowAnimations(showAnimations);
769 void CachedImage::clear()
772 delete scaled; scaled =
nullptr;
773 bgColor = qRgba(0, 0, 0, 0xff);
774 delete bg; bg =
nullptr;
775 bgSize =
QSize(-1, -1);
780 void CachedImage::data(
QBuffer &_buffer,
bool eof)
783 qCDebug(KHTML_LOG) <<
this <<
"buffersize =" << _buffer.
buffer().
size() <<
", eof =" << eof <<
", pos :" << _buffer.
pos();
785 i->processData((uchar *)_buffer.
data().
data(), _buffer.
pos());
794 void CachedImage::finish()
796 CachedObject::finish();
798 QSize s = pixmap_size();
802 void CachedImage::error(
int ,
const char * )
807 do_notify(
QRect(0, 0, 16, 16));
809 it.next().value()->notifyFinished(
this);
819 Cache::loader()->load(dl,
this,
false, 2);
825 CachedObject::ref(c);
828 c->notifyFinished(
this);
832 void CachedSound::data(
QBuffer &buffer,
bool eof)
840 m_sound = buffer.
buffer();
845 void CachedSound::checkNotify()
852 it.next().value()->notifyFinished(
this);
856 void CachedSound::error(
int ,
const char * )
871 Cache::loader()->load(dl,
this,
false , -4);
877 CachedObject::ref(c);
880 c->notifyFinished(
this);
884 void CachedFont::data(
QBuffer &buffer,
bool eof)
897 m_font = dev->readAll();
902 int woffStatus = eWOFF_ok;
903 if (
int need = WOFF::getDecodedSize(m_font.constData(), m_font.size(), &woffStatus)) {
907 if (WOFF_FAILURE(woffStatus)) {
913 woffStatus = eWOFF_ok;
914 WOFF::decodeToBuffer(m_font.constData(), m_font.size(), wbuffer.
data(), wbuffer.
size(), &len, &woffStatus);
915 if (WOFF_FAILURE(woffStatus)) {
922 }
else if (m_font.isEmpty()) {
927 setSize(m_font.size());
933 void CachedFont::checkNotify()
940 it.next().value()->notifyFinished(
this);
944 void CachedFont::error(
int ,
const char * )
956 object->setRequest(
this);
957 incremental = _incremental;
958 priority = _priority;
964 object->setRequest(
nullptr);
973 m_bautoloadImages =
true;
974 m_showAnimations = KHTMLSettings::KAnimationEnabled;
978 Cache::docloader->append(
this);
981 DocLoader::~DocLoader()
984 Cache::loader()->cancelRequests(
this);
985 Cache::docloader->removeAll(
this);
988 void DocLoader::setCacheCreationDate(
const QDateTime &_creationDate)
991 m_creationDate = _creationDate;
997 void DocLoader::setExpireDate(
const QDateTime &_expireDate)
999 m_expireDate = _expireDate;
1006 void DocLoader::setRelativeExpireDate(qint64 seconds)
1008 m_expireDate = m_creationDate.addSecs(seconds);
1011 void DocLoader::insertCachedObject(
CachedObject *o)
const 1013 m_docObjects.insert(o);
1019 if (m_cachePolicy == KIO::CC_Verify) {
1020 if (!m_reloadedURLs.contains(fullURL)) {
1021 if (existing && existing->isExpired() && !existing->isPreloaded()) {
1022 Cache::removeCacheEntry(existing);
1023 m_reloadedURLs.append(fullURL);
1027 }
else if ((m_cachePolicy == KIO::CC_Reload) || (m_cachePolicy == KIO::CC_Refresh)) {
1028 if (!m_reloadedURLs.contains(fullURL)) {
1029 if (existing && !existing->isPreloaded()) {
1030 Cache::removeCacheEntry(existing);
1032 if (!existing || !existing->isPreloaded()) {
1033 m_reloadedURLs.append(fullURL);
1041 void DocLoader::registerPreload(
CachedObject *resource)
1043 if (!resource || resource->isLoaded() || m_preloads.contains(resource)) {
1046 resource->increasePreloadCount();
1047 m_preloads.insert(resource);
1048 resource->setProspectiveRequest();
1049 #ifdef PRELOAD_DEBUG 1050 fprintf(stderr,
"PRELOADING %s\n", resource->url().string().
toLatin1().
data());
1054 void DocLoader::clearPreloads()
1056 printPreloadStats();
1060 res->decreasePreloadCount();
1061 if (res->preloadResult() == CachedObject::PreloadNotReferenced || res->hadError()) {
1062 Cache::removeCacheEntry(res);
1068 void DocLoader::printPreloadStats()
1070 #ifdef PRELOAD_DEBUG 1071 unsigned scripts = 0;
1072 unsigned scriptMisses = 0;
1073 unsigned stylesheets = 0;
1074 unsigned stylesheetMisses = 0;
1075 unsigned images = 0;
1076 unsigned imageMisses = 0;
1080 if (res->preloadResult() == CachedObject::PreloadNotReferenced) {
1081 fprintf(stderr,
"!! UNREFERENCED PRELOAD %s\n", res->url().string().
toLatin1().
data());
1082 }
else if (res->preloadResult() == CachedObject::PreloadReferencedWhileComplete) {
1083 fprintf(stderr,
"HIT COMPLETE PRELOAD %s\n", res->url().string().
toLatin1().
data());
1084 }
else if (res->preloadResult() == CachedObject::PreloadReferencedWhileLoading) {
1085 fprintf(stderr,
"HIT LOADING PRELOAD %s\n", res->url().string().
toLatin1().
data());
1088 if (res->type() == CachedObject::Script) {
1090 if (res->preloadResult() < CachedObject::PreloadReferencedWhileLoading) {
1093 }
else if (res->type() == CachedObject::CSSStyleSheet) {
1095 if (res->preloadResult() < CachedObject::PreloadReferencedWhileLoading) {
1100 if (res->preloadResult() < CachedObject::PreloadReferencedWhileLoading) {
1106 fprintf(stderr,
"SCRIPTS: %d (%d hits, hit rate %d%%)\n", scripts, scripts - scriptMisses, (scripts - scriptMisses) * 100 / scripts);
1109 fprintf(stderr,
"STYLESHEETS: %d (%d hits, hit rate %d%%)\n", stylesheets, stylesheets - stylesheetMisses, (stylesheets - stylesheetMisses) * 100 / stylesheets);
1112 fprintf(stderr,
"IMAGES: %d (%d hits, hit rate %d%%)\n", images, images - imageMisses, (images - imageMisses) * 100 / images);
1118 bool doRedirectCheck,
bool isImg)
1126 if (doRedirectCheck && doc) {
1137 #define DOCLOADER_SECCHECK_IMP(doRedirectCheck,isImg,failValue) \ 1138 QUrl fullURL(m_doc->completeURL(url.string())); \ 1139 if (!securityCheckUrl(fullURL, m_part, m_doc, doRedirectCheck, isImg)) \ 1142 #define DOCLOADER_SECCHECK(doRedirectCheck) DOCLOADER_SECCHECK_IMP(doRedirectCheck, false, nullptr) 1143 #define DOCLOADER_SECCHECK_BOOL(doRedirectCheck) DOCLOADER_SECCHECK_IMP(doRedirectCheck, false, false) 1144 #define DOCLOADER_SECCHECK_IMG(doRedirectCheck) DOCLOADER_SECCHECK_IMP(doRedirectCheck, true, nullptr) 1148 DOCLOADER_SECCHECK_BOOL(
true);
1155 DOCLOADER_SECCHECK_IMG(
true);
1157 CachedImage *i = Cache::requestObject<CachedImage, CachedObject::Image>(
this, fullURL,
nullptr);
1159 if (i && i->status() == CachedObject::Unknown && autoloadImages()) {
1160 Cache::loader()->load(
this, i,
true );
1167 const char *accept,
bool userSheet)
1169 DOCLOADER_SECCHECK(!userSheet);
1172 if (s && !charset.
isEmpty()) {
1173 s->setCharsetHint(charset);
1180 DOCLOADER_SECCHECK(
true);
1181 if (! KHTMLGlobal::defaultHTMLSettings()->isJavaScriptEnabled(fullURL.host()) ||
1182 KHTMLGlobal::defaultHTMLSettings()->isAdFiltered(fullURL.url())) {
1186 CachedScript *s = Cache::requestObject<CachedScript, CachedObject::Script>(
this, fullURL,
nullptr);
1187 if (s && !charset.
isEmpty()) {
1188 s->setCharset(charset);
1195 DOCLOADER_SECCHECK(
true);
1196 CachedSound *s = Cache::requestObject<CachedSound, CachedObject::Sound>(
this, fullURL,
nullptr);
1202 DOCLOADER_SECCHECK(
true);
1203 CachedFont *s = Cache::requestObject<CachedFont, CachedObject::Font>(
this, fullURL,
nullptr);
1207 #undef DOCLOADER_SECCHECK 1209 void DocLoader::setAutoloadImages(
bool enable)
1211 if (enable == m_bautoloadImages) {
1215 m_bautoloadImages = enable;
1217 if (!m_bautoloadImages) {
1223 if (cur->type() == CachedObject::Image) {
1226 CachedObject::Status
status = img->status();
1227 if (status != CachedObject::Unknown) {
1231 Cache::loader()->load(
this, img,
true );
1236 void DocLoader::setShowAnimations(KHTMLSettings::KAnimationAdvice showAnimations)
1238 if (showAnimations == m_showAnimations) {
1241 m_showAnimations = showAnimations;
1245 if (cur->type() == CachedObject::Image) {
1248 img->setShowAnimations(m_showAnimations);
1257 m_supportedImageTypes = khtmlImLoad::ImageManager::loaderDatabase()->supportedMimeTypes();
1262 qDeleteAll(m_requestsLoading);
1268 scheduleRequest(req);
1269 emit requestStarted(req->m_docLoader, req->object);
1272 void Loader::scheduleRequest(
Request *req)
1275 qCDebug(KHTML_LOG) <<
"starting Loader url =" << req->object->url().string();
1278 QUrl u(req->object->url().string());
1281 job->addMetaData(
"cache", KIO::getCacheControlString(req->object->cachePolicy()));
1283 job->addMetaData(
"accept", req->object->
accept());
1285 if (req->m_docLoader) {
1286 job->addMetaData(
"referrer", req->m_docLoader->doc()->URL().
url());
1287 KHTMLPart *part = req->m_docLoader->part();
1303 m_requestsLoading.insertMulti(job, req);
1308 Request *r = m_requestsLoading.value(j);
1323 void Loader::slotFinished(
KJob *job)
1326 Request *r = m_requestsLoading.take(j);
1332 bool reqFailed =
false;
1336 if (r->object->type() == CachedObject::Image && m_supportedImageTypes.contains(r->object->m_mimetype)) {
1346 qCDebug(KHTML_LOG) <<
"ERROR: job->error() =" << j->error() <<
", job->isErrorPage() =" << j->
isErrorPage();
1349 emit requestFailed(r->m_docLoader, r->object);
1353 r->object->setCharset(cs);
1355 r->object->data(r->m_buffer,
true);
1356 emit requestDone(r->m_docLoader, r->object);
1359 qCDebug(KHTML_LOG) <<
"url =" << j->
url().
url();
1361 r->object->setExpireDate(expireDate);
1363 if (r->object->type() == CachedObject::Image) {
1365 static_cast<CachedImage *
>(r->object)->setSuggestedFilename(fn);
1367 static_cast<CachedImage *
>(r->object)->setSuggestedTitle(fn);
1373 if (!kfmi.isEmpty()) {
1374 KFileMetaInfoItem i = kfmi.item(
"Name");
1376 static_cast<CachedImage *
>(r->object)->setSuggestedTitle(i.string());
1378 i = kfmi.item(
"Title");
1380 static_cast<CachedImage *
>(r->object)->setSuggestedTitle(i.string());
1388 r->object->finish();
1391 qCDebug(KHTML_LOG) <<
"JOB FINISHED" << r->object <<
":" << r->object->url().string();
1399 Request *r = m_requestsLoading.value(job);
1401 qCDebug(KHTML_LOG) <<
"got data for unknown request!";
1405 if (!r->m_buffer.
isOpen()) {
1411 if (r->incremental) {
1412 r->object->data(r->m_buffer,
false);
1416 int Loader::numRequests(
DocLoader *dl)
const 1419 foreach (
Request *req, m_requestsLoading)
1420 if (req->m_docLoader == dl) {
1427 void Loader::cancelRequests(
DocLoader *dl)
1430 while (lIt.hasNext()) {
1432 if (lIt.value()->m_docLoader == dl) {
1435 Cache::removeCacheEntry(lIt.value()->object);
1446 while (it.hasNext()) {
1448 if (it.value()->object && it.value()->object->url() == url) {
1449 return static_cast<KIO::Job *
>(it.key());
1463 int Cache::maxSize = DEFCACHESIZE;
1464 int Cache::totalSizeOfLRU;
1468 QPixmap *Cache::blockedPixmap;
1484 if (!brokenPixmap) {
1488 if (!blockedPixmap) {
1489 blockedPixmap =
new QPixmap();
1490 blockedPixmap->loadFromData(blocked_icon_data, blocked_icon_len);
1508 qCDebug(KHTML_LOG) <<
"CLEAR!";
1515 if (!co->canDelete()) {
1516 qCDebug(KHTML_LOG) <<
" Object in cache still linked to";
1517 qCDebug(KHTML_LOG) <<
" -> URL :" << co->url();
1518 qCDebug(KHTML_LOG) <<
" -> #clients :" << co->count();
1524 if (!co->canDelete()) {
1525 qCDebug(KHTML_LOG) <<
" Object in freelist still linked to";
1526 qCDebug(KHTML_LOG) <<
" -> URL :" << co->url();
1527 qCDebug(KHTML_LOG) <<
" -> #clients :" << co->count();
1543 delete cache; cache =
nullptr;
1544 delete nullPixmap; nullPixmap =
nullptr;
1545 delete brokenPixmap; brokenPixmap =
nullptr;
1546 delete blockedPixmap; blockedPixmap =
nullptr;
1547 delete m_loader; m_loader =
nullptr;
1548 delete docloader; docloader =
nullptr;
1549 qDeleteAll(*freeList);
1550 delete freeList; freeList =
nullptr;
1553 template<
typename CachedObjectType, enum CachedObject::Type CachedType>
1554 CachedObjectType *Cache::requestObject(
DocLoader *dl,
const QUrl &kurl,
const char *accept)
1561 if (o && o->type() != CachedType) {
1562 removeCacheEntry(o);
1566 if (o && dl->needReload(o, url)) {
1568 assert(!cache->contains(url));
1573 qCDebug(KHTML_LOG) <<
"new:" << kurl.
url();
1575 CachedObjectType *cot =
new CachedObjectType(dl, url, cachePolicy, accept);
1576 cache->insert(url, cot);
1577 if (cot->allowInLRUList()) {
1578 insertInLRUList(cot);
1584 qCDebug(KHTML_LOG) <<
"using pending/cached:" << kurl.
url();
1588 dl->insertCachedObject(o);
1590 return static_cast<CachedObjectType *
>(o);
1595 if (cache->contains(url)) {
1596 removeCacheEntry(cache->value(url));
1600 cache->insert(url, stylesheet);
1605 if (cache->contains(url)) {
1606 removeCacheEntry(cache->value(url));
1610 cache->insert(url, script);
1613 void Cache::flush(
bool force)
1617 if (force || totalSizeOfLRU > maxSize + maxSize / 4) {
1618 for (
int i = MAX_LRU_LISTS - 1; i >= 0 && totalSizeOfLRU > maxSize; --i)
1619 while (totalSizeOfLRU > maxSize && m_LRULists[i].m_tail) {
1620 removeCacheEntry(m_LRULists[i].m_tail);
1631 if (p->canDelete()) {
1638 void Cache::setSize(
int bytes)
1644 void Cache::statistics()
1654 int stylesheets = 0;
1658 switch (o->type()) {
1659 case CachedObject::Image: {
1669 case CachedObject::CSSStyleSheet:
1672 case CachedObject::Script:
1675 case CachedObject::Sound:
1678 case CachedObject::Font:
1686 qCDebug(KHTML_LOG) <<
"------------------------- image cache statistics -------------------";
1687 qCDebug(KHTML_LOG) <<
"Number of items in cache:" << cache->count();
1688 qCDebug(KHTML_LOG) <<
"Number of cached images:" << images;
1689 qCDebug(KHTML_LOG) <<
"Number of cached movies:" << movie;
1690 qCDebug(KHTML_LOG) <<
"Number of cached scripts:" << scripts;
1691 qCDebug(KHTML_LOG) <<
"Number of cached stylesheets:" << stylesheets;
1692 qCDebug(KHTML_LOG) <<
"Number of cached sounds:" << sound;
1693 qCDebug(KHTML_LOG) <<
"Number of cached fonts:" << fonts;
1694 qCDebug(KHTML_LOG) <<
"pixmaps: allocated space approx." << size <<
"kB";
1695 qCDebug(KHTML_LOG) <<
"movies : allocated space approx." << msize / 1024 <<
"kB";
1696 qCDebug(KHTML_LOG) <<
"--------------------------------------------------------------------";
1701 QString key =
object->url().string();
1704 removeFromLRUList(
object);
1707 dl->removeCachedObject(
object);
1710 if (!object->free()) {
1711 Cache::freeList->
append(
object);
1712 object->m_free =
true;
1716 static inline int FastLog2(
unsigned int j)
1724 log2 += 16, j >>= 16;
1744 int accessCount = o->accessCount();
1746 if (accessCount == 0) {
1749 int sizeLog = FastLog2(o->size());
1750 queueIndex = sizeLog / o->accessCount() - 1;
1751 if (queueIndex < 0) {
1754 if (queueIndex >= MAX_LRU_LISTS) {
1755 queueIndex = MAX_LRU_LISTS - 1;
1758 return &m_LRULists[queueIndex];
1766 LRUList *list = getLRUListFor(
object);
1769 if (next ==
nullptr && prev ==
nullptr && head !=
object) {
1773 object->m_next =
nullptr;
1774 object->m_prev =
nullptr;
1777 next->m_prev = prev;
1778 }
else if (list->m_tail ==
object) {
1779 list->m_tail = prev;
1783 prev->m_next =
next;
1784 }
else if (head ==
object) {
1788 totalSizeOfLRU -=
object->size();
1793 removeFromLRUList(
object);
1796 assert(!object->free());
1797 assert(object->canDelete());
1798 assert(object->allowInLRUList());
1800 LRUList *list = getLRUListFor(
object);
1804 object->m_next = head;
1806 head->m_prev = object;
1810 if (object->m_next ==
nullptr) {
1811 list->m_tail = object;
1814 totalSizeOfLRU +=
object->size();
1821 void CachedObjectClient::notifyFinished(
CachedObject * ) {}
1822 void CachedObjectClient::error(
int ,
const QString &) {}
QString url(QUrl::FormattingOptions options) const const
QTextCodec * codecForName(const QString &name) const
An image represents a static picture or an animation, that may be incrementally loaded.
virtual qint64 size() const const override
static void setJobPriority(SimpleJob *job, int priority)
bool onlyLocalReferences() const
Returns whether only file:/ or data:/ references are allowed to be loaded ( default false )...
bool hasNext() const const
bool hasNext() const const
This file is part of the HTML rendering engine for KDE.
This class is khtml's main class.
QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags)
virtual QWidget * widget()
QString & remove(int position, int n)
An image painter let's one paint an image at the given size.
QString queryMetaData(const QString &key)
bool hasAlphaChannel() const const
QDateTime fromTime_t(uint seconds)
const QList< QKeySequence > & reload()
static CompressionType compressionTypeForMimeType(const QString &mimetype)
The CSSStyleSheet interface is a concrete interface used to represent a CSS style sheet i...
bool forcePermitLocalImages() const
If true, local image files will be loaded even when forbidden by the Kiosk/KAuthorized policies ( def...
bool hasNext() const const
bool isEmpty() const const
const char * constData() const const
QUrl toplevelURL()
Returns the toplevel (origin) URL of this document, even if this part is a frame or an iframe...
void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
This class implements the basic string we use in the DOM.
virtual bool open(QIODevice::OpenMode flags) override
bool isOpen() const const
QString scheme() const const
virtual qint64 pos() const const override
const QByteArray & data() const const
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
bool isNull() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
static KCharsets * charsets()
virtual int mibEnum() const const =0
virtual QString fileName() const const override
bool isValid() const const
long toLong(bool *ok, int base) const const
This library provides a full-featured HTML parser and widget.
const QList< QKeySequence > & end()
virtual void close() override
bool isValid() const const
QDateTime currentDateTime()
QByteArray toLatin1() const const
QPixmap pixmap(QWizard::WizardPixmap which) const const
QString mid(int position, int n) const const
bool hasAlpha() const const
QDesktopWidget * desktop()
qint64 secsTo(const QDateTime &other) const const
QTextCodec * codecForName(const QByteArray &name)
QTextCodec * codecForMib(int mib)
qint64 write(const char *data, qint64 maxSize)
QString fromLatin1(const char *str, int size)
bool hasFeature(QPaintEngine::PaintEngineFeatures feature) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void append(const T &value)
QString errorText() const
QString accept() const
List of acceptable mimetypes separated by ",".
bool isValid() const const
bool authorizeUrlAction(const QString &action, const QUrl &baseUrl, const QUrl &destUrl)