blob: 27040bb1c4c5becbbad3b36f017fe6d4aa4bdcee [file] [log] [blame]
eseidel94980f22006-01-09 09:29:48 +00001/*
eseidel94980f22006-01-09 09:29:48 +00002 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org>
darin91298e52006-06-12 01:10:17 +00004 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
ddkilzer@apple.com6242b772009-01-02 21:10:30 +00005 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
eseidel94980f22006-01-09 09:29:48 +00006
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
ddkilzerc8eccec2007-09-26 02:29:57 +000019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
eseidel94980f22006-01-09 09:29:48 +000021
22 This class provides all functionality needed for loading images, style sheets and html
23 pages from the web. It has a memory cache for these objects.
24*/
darinbbe64662006-01-16 17:52:23 +000025
eseidel8eddecf2007-01-16 00:49:43 +000026#ifndef CachedCSSStyleSheet_h
27#define CachedCSSStyleSheet_h
eseidel94980f22006-01-09 09:29:48 +000028
darine775cf72006-07-09 22:48:56 +000029#include "CachedResource.h"
darin91298e52006-06-12 01:10:17 +000030#include <wtf/Vector.h>
eseidel94980f22006-01-09 09:29:48 +000031
darinb3547a32006-09-06 04:40:44 +000032namespace WebCore {
33
tonyg@chromium.org4b0a55f2011-05-12 10:31:51 +000034 class CachedResourceClient;
antti@apple.com384e66f2012-05-23 17:17:43 +000035 class StyleSheetContents;
darin5b2cbe12006-10-30 00:57:20 +000036 class TextResourceDecoder;
antti@apple.com52f660f2012-04-26 22:26:35 +000037 struct CSSParserContext;
eseidel94980f22006-01-09 09:29:48 +000038
andersca@apple.com16d2dd42014-01-16 23:08:24 +000039 class CachedCSSStyleSheet final : public CachedResource {
eseidel94980f22006-01-09 09:29:48 +000040 public:
commit-queue@webkit.org9ab4d3e2014-03-05 20:11:03 +000041 CachedCSSStyleSheet(const ResourceRequest&, const String& charset, SessionID);
darind7d82ce2006-01-13 10:07:39 +000042 virtual ~CachedCSSStyleSheet();
eseidel94980f22006-01-09 09:29:48 +000043
cdumez@apple.com090a5fb2015-07-28 17:24:26 +000044 enum class MIMETypeCheck { Strict, Lax };
45 const String sheetText(MIMETypeCheck = MIMETypeCheck::Strict, bool* hasValidMIMEType = nullptr) const;
eseidel94980f22006-01-09 09:29:48 +000046
antti@apple.com6e313872015-05-13 23:09:13 +000047 PassRefPtr<StyleSheetContents> restoreParsedStyleSheet(const CSSParserContext&, CachePolicy);
akling@apple.com689f7612014-12-14 08:21:05 +000048 void saveParsedStyleSheet(Ref<StyleSheetContents>&&);
loislo@chromium.org7b6f5d92012-08-06 09:12:01 +000049
hyatt@apple.com2242c2e2008-02-11 20:17:36 +000050 private:
cdumez@apple.com090a5fb2015-07-28 17:24:26 +000051 bool canUseSheet(MIMETypeCheck, bool* hasValidMIMEType) const;
darin@apple.com11ff47c2016-03-04 16:47:55 +000052 bool mayTryReplaceEncodedData() const override { return true; }
eseidel94980f22006-01-09 09:29:48 +000053
darin@apple.com11ff47c2016-03-04 16:47:55 +000054 void didAddClient(CachedResourceClient*) override;
carlosgc@webkit.org80e15b42013-06-07 08:57:35 +000055
darin@apple.com11ff47c2016-03-04 16:47:55 +000056 void setEncoding(const String&) override;
57 String encoding() const override;
58 void finishLoading(SharedBuffer*) override;
59 void destroyDecodedData() override;
carlosgc@webkit.org80e15b42013-06-07 08:57:35 +000060
eseidel94980f22006-01-09 09:29:48 +000061 protected:
darin@apple.com11ff47c2016-03-04 16:47:55 +000062 void checkNotify() override;
japhet@chromium.org645dc1d2012-09-06 05:51:46 +000063
darin5b2cbe12006-10-30 00:57:20 +000064 RefPtr<TextResourceDecoder> m_decoder;
antti@apple.comda9077d2008-11-07 07:22:43 +000065 String m_decodedSheetText;
antti@apple.com52f660f2012-04-26 22:26:35 +000066
antti@apple.com384e66f2012-05-23 17:17:43 +000067 RefPtr<StyleSheetContents> m_parsedStyleSheetCache;
eseidel94980f22006-01-09 09:29:48 +000068 };
69
cdumez@apple.comc4a3af62014-10-06 00:31:05 +000070} // namespace WebCore
ddkilzer@apple.com4a0e4512014-02-01 16:32:11 +000071
cdumez@apple.comc4a3af62014-10-06 00:31:05 +000072SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(CachedCSSStyleSheet, CachedResource::CSSStyleSheet)
eseidel94980f22006-01-09 09:29:48 +000073
cdumez@apple.comc4a3af62014-10-06 00:31:05 +000074#endif // CachedCSSStyleSheet_h