CachedXSLStyleSheet.cpp [plain text]
#include "config.h"
#include "CachedXSLStyleSheet.h"
#include "CachedResourceClientWalker.h"
#include "CachedStyleSheetClient.h"
#include "SharedBuffer.h"
#include "TextResourceDecoder.h"
#include <wtf/Vector.h>
namespace WebCore {
#if ENABLE(XSLT)
CachedXSLStyleSheet::CachedXSLStyleSheet(const ResourceRequest& resourceRequest, SessionID sessionID)
: CachedResource(resourceRequest, XSLStyleSheet, sessionID)
, m_decoder(TextResourceDecoder::create("text/xsl"))
{
setAccept("text/xml, application/xml, application/xhtml+xml, text/xsl, application/rss+xml, application/atom+xml");
}
CachedXSLStyleSheet::~CachedXSLStyleSheet()
{
}
void CachedXSLStyleSheet::didAddClient(CachedResourceClient* c)
{
ASSERT(c->resourceClientType() == CachedStyleSheetClient::expectedType());
if (!isLoading())
static_cast<CachedStyleSheetClient*>(c)->setXSLStyleSheet(m_resourceRequest.url(), m_response.url(), m_sheet);
}
void CachedXSLStyleSheet::setEncoding(const String& chs)
{
m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
}
String CachedXSLStyleSheet::encoding() const
{
return m_decoder->encoding().name();
}
void CachedXSLStyleSheet::finishLoading(SharedBuffer* data)
{
m_data = data;
setEncodedSize(data ? data->size() : 0);
if (data)
m_sheet = m_decoder->decodeAndFlush(data->data(), encodedSize());
setLoading(false);
checkNotify();
}
void CachedXSLStyleSheet::checkNotify()
{
if (isLoading())
return;
CachedResourceClientWalker<CachedStyleSheetClient> w(m_clients);
while (CachedStyleSheetClient* c = w.next())
c->setXSLStyleSheet(m_resourceRequest.url(), m_response.url(), m_sheet);
}
#endif
}