CachedCSSStyleSheet.cpp [plain text]
#include "config.h"
#include "CachedCSSStyleSheet.h"
#include "Cache.h"
#include "CachedResourceClient.h"
#include "CachedResourceClientWalker.h"
#include "TextResourceDecoder.h"
#include "DeprecatedString.h"
#include "loader.h"
#include <wtf/Vector.h>
namespace WebCore {
CachedCSSStyleSheet::CachedCSSStyleSheet(DocLoader* dl, const String& url, const String& charset, bool skipCanLoadCheck, bool sendResourceLoadCallbacks)
: CachedResource(url, CSSStyleSheet, true, sendResourceLoadCallbacks)
, m_decoder(new TextResourceDecoder("text/css", charset))
{
setAccept("text/css,*/*;q=0.1");
cache()->loader()->load(dl, this, false, skipCanLoadCheck, sendResourceLoadCallbacks);
m_loading = true;
}
CachedCSSStyleSheet::~CachedCSSStyleSheet()
{
}
void CachedCSSStyleSheet::ref(CachedResourceClient *c)
{
CachedResource::ref(c);
if (!m_loading)
c->setCSSStyleSheet(m_url, m_decoder->encoding().name(), errorOccurred() ? "" : m_sheet);
}
void CachedCSSStyleSheet::setEncoding(const String& chs)
{
m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
}
void CachedCSSStyleSheet::data(PassRefPtr<SharedBuffer> data, bool allDataReceived)
{
if (!allDataReceived)
return;
m_data = data;
setEncodedSize(m_data.get() ? m_data->size() : 0);
if (m_data.get()) {
m_sheet = m_decoder->decode(m_data->data(), encodedSize());
m_sheet += m_decoder->flush();
}
m_loading = false;
checkNotify();
}
void CachedCSSStyleSheet::checkNotify()
{
if (m_loading)
return;
CachedResourceClientWalker w(m_clients);
while (CachedResourceClient *c = w.next())
c->setCSSStyleSheet(m_response.url().url(), m_decoder->encoding().name(), m_sheet);
#if USE(LOW_BANDWIDTH_DISPLAY)
CachedResourceClientWalker n(m_clients);
while (CachedResourceClient* s = n.next())
s->notifyFinished(this);
#endif
}
void CachedCSSStyleSheet::error()
{
m_loading = false;
m_errorOccurred = true;
checkNotify();
}
}