CachedXBLDocument.cpp [plain text]
#include "config.h"
#ifndef KHTML_NO_XBL
#include "CachedXBLDocument.h"
#include "Cache.h"
#include "CachedResourceClientWalker.h"
#include "Decoder.h"
#include "loader.h"
#include <wtf/Vector.h>
namespace WebCore {
CachedXBLDocument::CachedXBLDocument(DocLoader* dl, const String &url, CachePolicy cachePolicy)
: CachedResource(url, XBL, cachePolicy), m_document(0)
{
setAccept("text/xml, application/xml, application/xhtml+xml, text/xsl, application/rss+xml, application/atom+xml");
Cache::loader()->load(dl, this, false);
m_loading = true;
m_decoder = new Decoder;
}
CachedXBLDocument::~CachedXBLDocument()
{
if (m_document)
m_document->deref();
}
void CachedXBLDocument::ref(CachedResourceClient *c)
{
CachedResource::ref(c);
if (!m_loading)
c->setXBLDocument(m_url, m_document);
}
void CachedXBLDocument::setCharset( const DeprecatedString &chs )
{
if (!chs.isEmpty())
m_decoder->setEncoding(chs.latin1(), Decoder::EncodingFromHTTPHeader);
}
void CachedXBLDocument::data(Vector<char>& data, bool )
{
if (!allDataReceived)
return;
assert(!m_document);
m_document = new XBL::XBLDocument();
m_document->ref();
m_document->open();
m_document->write(m_decoder->decode(data.data(), data.size()));
setSize(data.size());
m_document->finishParsing();
m_document->close();
m_loading = false;
checkNotify();
}
void CachedXBLDocument::checkNotify()
{
if (m_loading)
return;
CachedResourceClientWalker w(m_clients);
while (CachedResourceClient *c = w.next())
c->setXBLDocument(m_url, m_document);
}
void CachedXBLDocument::error()
{
m_loading = false;
checkNotify();
}
}
#endif