Commit 1662df2e authored by Dirk Mueller's avatar Dirk Mueller

fix uncachable object leak

CCMAIL: 72197-done@bugs.kde.org

svn path=/trunk/kdelibs/; revision=279734
parent 8d92b1e0
2004-01-14 Dirk Mueller <mueller@kde.org>
* misc/loader.cpp: Fix uncachable image leak (#72197).
2004-01-13 Dirk Mueller <mueller@kde.org>
* css/css_ruleimpl.cpp (CSSMediaRuleImpl): set parent to 0
......
......@@ -121,7 +121,7 @@ DOMString HTMLDocument::lastModified() const
DOMString HTMLDocument::URL() const
{
if(!impl) return DOMString();
return ((HTMLDocumentImpl *)impl)->URL();
return ((HTMLDocumentImpl *)impl)->URL().url();
}
HTMLElement HTMLDocument::body() const
......
......@@ -1118,8 +1118,8 @@ Value DOMDOMImplementationProtoFunc::tryCall(ExecState *exec, Object &thisObj, c
// host/domain for security checks. The URL will be updated if Document.load() is called.
Document doc = implementation.createDocument(args[0].toString(exec).string(),args[1].toString(exec).string(),toNode(args[2]));
KHTMLPart *part = static_cast<KJS::ScriptInterpreter*>(exec->interpreter())->part();
QString url = static_cast<DocumentImpl*>(part->document().handle())->URL();
static_cast<DocumentImpl*>(doc.handle())->setURL(url);
KURL url = static_cast<DocumentImpl*>(part->document().handle())->URL();
static_cast<DocumentImpl*>(doc.handle())->setURL(url.url());
return getDOMNode(exec,doc);
}
case DOMDOMImplementation::CreateCSSStyleSheet: // DOM2
......
......@@ -429,7 +429,7 @@ void HTMLTokenizer::scriptExecution( const QString& str, const QString& scriptUR
script = false;
QString url;
if (scriptURL.isNull() && view)
url = static_cast<DocumentImpl*>(view->part()->document().handle())->URL();
url = static_cast<DocumentImpl*>(view->part()->document().handle())->URL().url();
else
url = scriptURL;
......@@ -1544,7 +1544,7 @@ void HTMLTokenizer::processToken()
dest = buffer;
#ifdef TOKEN_DEBUG
QString name = getTagName(currToken.tid).string();
QString name = QString( getTagName(currToken.tid) );
QString text;
if(currToken.text)
text = QConstString(currToken.text->s, currToken.text->l).string();
......
......@@ -120,7 +120,7 @@ namespace khtml {
PartStyleSheetLoader(KHTMLPart *part, DOM::DOMString url, DocLoader* dl)
{
m_part = part;
m_cachedSheet = Cache::requestStyleSheet(dl, url );
m_cachedSheet = dl->requestStyleSheet(url, QString::null );
if (m_cachedSheet)
m_cachedSheet->ref( this );
}
......@@ -1390,7 +1390,7 @@ void KHTMLPart::slotData( KIO::Job* kio_job, const QByteArray &data )
// Support Content-Location per section 14.14 of RFC 2616.
QString baseURL = d->m_job->queryMetaData ("content-location");
if (!baseURL.isEmpty())
d->m_doc->setBaseURL(d->m_doc->completeURL(baseURL));
d->m_doc->setBaseURL(KURL( d->m_doc->completeURL(baseURL) ));
if ( !m_url.isLocalFile() ) {
......@@ -1666,7 +1666,7 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset )
d->m_doc->attach( );
// We prefer m_baseURL over m_url because m_url changes when we are
// about to load a new page.
d->m_doc->setBaseURL( baseurl.url() );
d->m_doc->setBaseURL( baseurl );
d->m_doc->docLoader()->setShowAnimations( KHTMLFactory::defaultHTMLSettings()->showAnimations() );
emit docCreated(); // so that the parent can set the domain
......@@ -2048,7 +2048,7 @@ QString KHTMLPart::baseTarget() const
KURL KHTMLPart::completeURL( const QString &url )
{
if ( !d->m_doc ) return url;
if ( !d->m_doc ) return KURL( url );
if (d->m_decoder)
return KURL(d->m_doc->completeURL(url), d->m_decoder->codec()->mibEnum());
......@@ -2079,7 +2079,8 @@ void KHTMLPart::slotRedirect()
QString u = d->m_redirectURL;
d->m_delayRedirect = 0;
d->m_redirectURL = QString::null;
d->m_referrer = "";
// SYNC check with ecma/kjs_window.cpp::goURL !
if ( u.find( QString::fromLatin1( "javascript:" ), 0, false ) == 0 )
{
......@@ -3263,12 +3264,12 @@ void KHTMLPart::urlSelected( const QString &url, int button, int state, const QS
args.metaData().insert("PropagateHttpHeader", "true");
args.metaData().insert("ssl_was_in_use", d->m_ssl_in_use ? "TRUE":"FALSE");
args.metaData().insert("ssl_activate_warnings", "TRUE");
// WABA: When we select the link explicitly we should treat this new URL as the
// WABA: When we select the link explicitly we should treat this new URL as the
// toplevel url and it should never be considered cross-domain.
// However this function is also called for javascript and META-tag based
// redirections:
// - In such case, we don't take cross-domain-ness in consideration if we are the
// toplevel frame because the new URL may be in a different domain as the current URL
// - In such case, we don't take cross-domain-ness in consideration if we are the
// toplevel frame because the new URL may be in a different domain as the current URL
// but that's ok.
// - If we are not the toplevel frame then we check against the toplevelURL()
if (args.redirectedRequest() && parentPart())
......@@ -4892,7 +4893,7 @@ QString KHTMLPart::referrer() const
QString KHTMLPart::pageReferrer() const
{
KURL referrerURL = d->m_pageReferrer;
KURL referrerURL = KURL( d->m_pageReferrer );
if (referrerURL.isValid())
{
QString protocol = referrerURL.protocol();
......@@ -6072,10 +6073,10 @@ KURL KHTMLPart::toplevelURL()
KHTMLPart* part = this;
while (part->parentPart())
part = part->parentPart();
if (!part)
return KURL();
return part->url();
}
......
......@@ -147,9 +147,9 @@ bool KHTMLImage::openURL( const KURL &url )
impl->docLoader()->setCachePolicy( KIO::CC_Refresh );
khtml::DocLoader *dl = impl ? impl->docLoader() : 0;
m_image = khtml::Cache::requestImage( dl, m_url.url(), true /*reload*/ );
assert( m_image );
m_image->ref( this );
m_image = dl->requestImage( m_url.url() );
if ( m_image )
m_image->ref( this );
m_khtml->write( html.arg( m_url.url() ) );
m_khtml->end();
......
......@@ -1565,7 +1565,7 @@ void KHTMLView::print(bool quick)
// this only works on Unix - we assume 72dpi
KPrinter *printer = new KPrinter(true, QPrinter::PrinterResolution);
printer->addDialogPage(new KHTMLPrintSettings());
QString docname = m_part->xmlDocImpl()->URL();
QString docname = m_part->xmlDocImpl()->URL().prettyURL();
if ( !docname.isEmpty() )
docname = KStringHandler::csqueeze(docname, 80);
if(quick || printer->setup(this, i18n("Print %1").arg(docname))) {
......
This diff is collapsed.
......@@ -92,26 +92,22 @@ namespace khtml
};
enum Status {
NotCached, // this URL is not cached
Unknown, // let imagecache decide what to do with it
New, // inserting new image
Pending, // only partially loaded
Persistent, // never delete this pixmap
Cached, // regular case
Uncacheable // to big to be cached,
}; // will be destroyed as soon as possible
Cached // regular case
};
CachedObject(const DOM::DOMString &url, Type type, KIO::CacheControl _cachePolicy, time_t _expireDate, int size)
CachedObject(const DOM::DOMString &url, Type type, KIO::CacheControl _cachePolicy, int size)
: m_url(url), m_type(type), m_cachePolicy(_cachePolicy),
m_expireDate(_expireDate), m_size(size)
m_expireDate(0), m_size(size)
{
m_status = Pending;
m_accessCount = 0;
m_cachePolicy = _cachePolicy;
m_request = 0;
m_expireDate = _expireDate;
m_deleted = false;
m_expireDateChanged = false;
m_free = false;
m_hadError = false;
m_prev = m_next = 0;
......@@ -137,14 +133,7 @@ namespace khtml
int size() const { return m_size; }
/**
* computes the status of an object after loading.
* the result depends on the objects size and the size of the cache
* also updates the expire date on the cache entry file
*/
virtual void finish();
void setFree();
bool free() const { return m_free; }
KIO::CacheControl cachePolicy() const { return m_cachePolicy; }
......@@ -152,11 +141,12 @@ namespace khtml
bool canDelete() const { return (m_clients.count() == 0 && !m_request); }
void setExpireDate(time_t _expireDate, bool changeHttpCache);
void setExpireDate(time_t _expireDate) { m_expireDate = _expireDate; }
bool isExpired() const;
virtual bool schedule() const { return false; }
virtual void finish();
/**
* List of acceptable mimetypes separated by ",". A mimetype may contain a wildcard.
......@@ -179,12 +169,11 @@ namespace khtml
int m_size;
bool m_deleted : 1;
bool m_loading : 1;
bool m_expireDateChanged : 1;
bool m_free : 1;
bool m_hadError : 1;
private:
bool allowInLRUList() const { return canDelete() && status() != Persistent; }
bool allowInLRUList() const { return canDelete() && !m_free && status() != Persistent; }
CachedObject* m_next;
CachedObject* m_prev;
friend class Cache;
......@@ -200,19 +189,18 @@ namespace khtml
{
public:
CachedCSSStyleSheet(DocLoader* dl, const DOM::DOMString &url, KIO::CacheControl cachePolicy,
time_t _expireDate, const QString& charset, const char *accept);
const char *accept);
CachedCSSStyleSheet(const DOM::DOMString &url, const QString &stylesheet_data);
virtual ~CachedCSSStyleSheet();
const DOM::DOMString &sheet() const { return m_sheet; }
virtual void ref(CachedObjectClient *consumer);
virtual void deref(CachedObjectClient *consumer);
virtual void data( QBuffer &buffer, bool eof );
virtual void error( int err, const char *text );
virtual bool schedule() const { return true; }
void setCharset( const QString& charset ) { m_charset = charset; }
protected:
void checkNotify();
......@@ -229,14 +217,12 @@ namespace khtml
class CachedScript : public CachedObject
{
public:
CachedScript(DocLoader* dl, const DOM::DOMString &url, KIO::CacheControl cachePolicy, time_t _expireDate, const QString& charset);
CachedScript(DocLoader* dl, const DOM::DOMString &url, KIO::CacheControl cachePolicy, const char* accept );
CachedScript(const DOM::DOMString &url, const QString &script_data);
virtual ~CachedScript();
const DOM::DOMString &script() const { return m_script; }
virtual void ref(CachedObjectClient *consumer);
virtual void deref(CachedObjectClient *consumer);
virtual void data( QBuffer &buffer, bool eof );
virtual void error( int err, const char *text );
......@@ -246,6 +232,7 @@ namespace khtml
void checkNotify();
bool isLoaded() const { return !m_loading; }
void setCharset( const QString& charset ) { m_charset = charset; }
protected:
QString m_charset;
......@@ -261,7 +248,7 @@ namespace khtml
{
Q_OBJECT
public:
CachedImage(DocLoader* dl, const DOM::DOMString &url, KIO::CacheControl cachePolicy, time_t _expireDate);
CachedImage(DocLoader* dl, const DOM::DOMString &url, KIO::CacheControl cachePolicy, const char* accept);
virtual ~CachedImage();
const QPixmap &pixmap() const;
......@@ -347,9 +334,10 @@ namespace khtml
void setCacheCreationDate( time_t );
void setExpireDate( time_t, bool relative );
void setAutoloadImages( bool );
void setCachePolicy( KIO::CacheControl cachePolicy );
void setCachePolicy( KIO::CacheControl cachePolicy ) { m_cachePolicy = cachePolicy; }
void setShowAnimations( KHTMLSettings::KAnimationAdvice );
void removeCachedObject( CachedObject*) const;
void insertCachedObject( CachedObject* o ) const;
void removeCachedObject( CachedObject* o) const { m_docObjects.remove( o ); }
private:
bool needReload(const KURL &fullUrl);
......@@ -358,7 +346,7 @@ namespace khtml
friend class DOM::DocumentImpl;
QStringList m_reloadedURLs;
mutable QPtrList<CachedObject> m_docObjects;
mutable QPtrDict<CachedObject> m_docObjects;
time_t m_expireDate;
time_t m_creationDate;
KIO::CacheControl m_cachePolicy;
......@@ -428,6 +416,10 @@ namespace khtml
class Cache
{
friend class DocLoader;
template<typename CachedObjectType, enum CachedObject::Type CachedType>
static CachedObjectType* Cache::requestObject( DocLoader* dl, const KURL& kurl, const char* accept );
public:
/**
* init the cache in case it's not already. This needs to get called once
......@@ -441,50 +433,22 @@ namespace khtml
* if the DocLoader is zero, the url must be full-qualified.
* Otherwise, it is automatically base-url expanded
*/
static CachedImage *requestImage( DocLoader* l, const DOM::DOMString &url, bool reload=false, time_t _expireDate=0);
/**
* Ask the cache for some url. Will return a cachedObject, and
* load the requested data in case it's not cached
*/
static CachedCSSStyleSheet *requestStyleSheet( DocLoader* l, const DOM::DOMString &url, bool reload=false,
time_t _expireDate=0, const QString& charset = QString::null,
const char *accept = "text/css");
// static CachedImage *requestImage(const KURL& url)
// { return Cache::requestObject<CachedImage, CachedObject::Image>( 0, url, 0 ); }
/**
* Pre-loads a stylesheet into the cache.
*/
static void preloadStyleSheet(const QString &url, const QString &stylesheet_data);
/**
* Ask the cache for some url. Will return a cachedObject, and
* load the requested data in case it's not cached
*/
static CachedScript *requestScript( DocLoader* l, const DOM::DOMString &url, bool reload=false, time_t _expireDate=0, const QString& charset=QString::null);
/**
* Pre-loads a script into the cache.
*/
static void preloadScript(const QString &url, const QString &script_data);
/**
* sets the size of the cache. This will only hod approximately, since the size some
* cached objects (like stylesheets) take up in memory is not exaclty known.
*/
static void setSize( int bytes );
/**
* returns the size of the cache
*/
static int size() { return maxSize; };
/**
* prints some statistics to stdout
*/
static void statistics();
/**
* clean up cache
*/
static void flush(bool force=false);
/**
......@@ -504,7 +468,7 @@ namespace khtml
private:
static void flushFreeList();
static void checkLRUAndUncacheableListIntegrity();
friend class CachedObject;
......@@ -513,28 +477,13 @@ namespace khtml
static QPtrList<CachedObject> *freeList;
static void insertInLRUList(CachedObject*);
static void removeFromLRUList(CachedObject*);
static bool adjustSize(CachedObject*, int sizeDelta);
static void moveToFront(CachedObject*);
static int totalSizeOfLRU;
static int maxSize;
static int flushCount;
static Loader *m_loader;
static int m_totalSizeOfLRULists;
static CachedObject *m_headOfUncacheableList;
static int m_countOfLRUAndUncacheableLists;
static unsigned long s_ulRefCnt;
};
inline void CachedObject::setFree() {
if (!m_free) {
Cache::freeList->append(this);
m_free = true;
}
}
} // namespace
#endif
......@@ -19,7 +19,7 @@
* Boston, MA 02111-1307, USA.
*
*/
#ifndef html_seed_h
#define html_seed_h
......@@ -27,14 +27,14 @@
namespace khtml {
static const int primes_t[] =
static const int primes_t[] =
{
31, 61, 107, 233, 353, 541,
821, 1237, 1861, 2797, 4201, 6311,
821, 1237, 1861, 2797, 4201, 6311,
9467, 14207, 21313, 31973, 47963, 0
};
int nextSeed(int curSize) {
static inline int nextSeed(int curSize) {
for (int i = 0 ; primes_t[i] ; i++)
if (primes_t[i] > curSize)
return primes_t[i];
......
......@@ -642,7 +642,7 @@ void RenderPartObject::updateWidget()
}
}
params.append( QString::fromLatin1("__KHTML__PLUGINEMBED=\"YES\"") );
params.append( QString::fromLatin1("__KHTML__PLUGINBASEURL=\"%1\"").arg(element()->getDocument()->baseURL()));
params.append( QString::fromLatin1("__KHTML__PLUGINBASEURL=\"%1\"").arg(element()->getDocument()->baseURL().url()));
if ( element()->id() == ID_EMBED ) {
......
......@@ -1177,7 +1177,7 @@ void DocumentImpl::setUserStyleSheet( const QString& sheet )
CSSStyleSheetImpl* DocumentImpl::elementSheet()
{
if (!m_elemSheet) {
m_elemSheet = new CSSStyleSheetImpl(this, baseURL() );
m_elemSheet = new CSSStyleSheetImpl(this, baseURL().url() );
m_elemSheet->ref();
}
return m_elemSheet;
......@@ -1482,7 +1482,7 @@ void DocumentImpl::processHttpEquiv(const DOMString &equiv, const DOMString &con
str = parseURL( DOMString(str) ).string();
QString newURL = getDocument()->completeURL( str );
if ( ok || !fract)
v->part()->scheduleRedirection(delay, getDocument()->completeURL( str ), delay < 2 || newURL == URL());
v->part()->scheduleRedirection(delay, getDocument()->completeURL( str ), delay < 2 || newURL == URL().url());
}
}
else if(strcasecmp(equiv, "expires") == 0)
......@@ -1811,7 +1811,7 @@ void DocumentImpl::recalcStyleSelector()
QPtrList<StyleSheetImpl> oldStyleSheets = m_styleSheets->styleSheets;
m_styleSheets->styleSheets.clear();
QString sheetUsed = view() ? view()->part()->d->m_sheetUsed : QString();
bool autoselect = sheetUsed.isEmpty();
bool autoselect = sheetUsed.isEmpty();
if (autoselect && !m_preferredStylesheetSet.isEmpty())
sheetUsed = m_preferredStylesheetSet.string();
NodeImpl *n;
......@@ -1912,7 +1912,7 @@ void DocumentImpl::recalcStyleSelector()
// we're done if we don't select an alternative sheet
// or we found the sheet we selected
if (sheetUsed.isEmpty() ||
(!canResetSheet && tokenizer()) ||
(!canResetSheet && tokenizer()) ||
m_availableSheets.contains(sheetUsed)) {
break;
}
......@@ -1920,7 +1920,7 @@ void DocumentImpl::recalcStyleSelector()
// the alternative sheet we used doesn't exist anymore
// so try from scratch again
if (view())
view()->part()->d->m_sheetUsed = QString::null;
view()->part()->d->m_sheetUsed = QString::null;
if (!m_preferredStylesheetSet.isEmpty() && !(sheetUsed == m_preferredStylesheetSet))
sheetUsed = m_preferredStylesheetSet.string();
else
......
......@@ -249,11 +249,11 @@ public:
void writeln ( const DOMString &text );
void finishParsing ( );
QString URL() const { return m_url; }
KURL URL() const { return m_url; }
void setURL(const QString& url) { m_url = url; }
QString baseURL() const { return m_baseURL.isEmpty() ? m_url : m_baseURL; }
void setBaseURL(const QString& baseURL) { m_baseURL = baseURL; }
KURL baseURL() const { return m_baseURL.isEmpty() ? m_url : m_baseURL; }
void setBaseURL(const KURL& baseURL) { m_baseURL = baseURL; }
QString baseTarget() const { return m_baseTarget; }
void setBaseTarget(const QString& baseTarget) { m_baseTarget = baseTarget; }
......@@ -430,8 +430,8 @@ protected:
khtml::DocLoader *m_docLoader;
Tokenizer *m_tokenizer;
QString m_url;
QString m_baseURL;
KURL m_url;
KURL m_baseURL;
QString m_baseTarget;
DocumentTypeImpl *m_doctype;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment