2 This file is part of the KDE libraries
4 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
5 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
6 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
7 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
8 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.
25 This class provides all functionality needed for loading images, style sheets and html
26 pages from the web. It has a memory cache for these objects.
30 #include "CachedCSSStyleSheet.h"
33 #include "CachedResourceClient.h"
34 #include "CachedResourceClientWalker.h"
36 #include "DeprecatedString.h"
37 #include "LoaderFunctions.h"
39 #include <wtf/Vector.h>
43 CachedCSSStyleSheet::CachedCSSStyleSheet(DocLoader* dl, const String& url, CachePolicy cachePolicy, time_t _expireDate, const String& charset)
44 : CachedResource(url, CSSStyleSheet, cachePolicy, _expireDate)
45 , m_decoder(new Decoder("text/css", charset))
48 setAccept("text/css");
50 Cache::loader()->load(dl, this, false);
54 CachedCSSStyleSheet::~CachedCSSStyleSheet()
58 void CachedCSSStyleSheet::ref(CachedResourceClient *c)
60 CachedResource::ref(c);
63 c->setCSSStyleSheet(m_url, m_decoder->encoding().name(), m_sheet);
66 void CachedCSSStyleSheet::deref(CachedResourceClient *c)
69 CachedResource::deref(c);
70 if (canDelete() && m_free)
74 void CachedCSSStyleSheet::setCharset(const String& chs)
76 m_decoder->setEncoding(chs, Decoder::EncodingFromHTTPHeader);
79 void CachedCSSStyleSheet::data(Vector<char>& data, bool allDataReceived)
85 m_sheet = m_decoder->decode(data.data(), size());
86 m_sheet += m_decoder->flush();
91 void CachedCSSStyleSheet::checkNotify()
96 CachedResourceClientWalker w(m_clients);
97 while (CachedResourceClient *c = w.next()) {
98 if (m_response && !IsResponseURLEqualToURL(m_response, m_url))
99 c->setCSSStyleSheet(ResponseURL(m_response), m_decoder->encoding().name(), m_sheet);
101 c->setCSSStyleSheet(m_url, m_decoder->encoding().name(), m_sheet);
105 void CachedCSSStyleSheet::error()