1 | /* |
2 | Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 | Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
4 | Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 | Copyright (C) 2004-2017 Apple Inc. All rights reserved. |
6 | |
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 |
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | #include "CachedResource.h" |
26 | |
27 | namespace WebCore { |
28 | |
29 | class FrameLoader; |
30 | class StyleSheetContents; |
31 | class TextResourceDecoder; |
32 | |
33 | struct CSSParserContext; |
34 | |
35 | class CachedCSSStyleSheet final : public CachedResource { |
36 | public: |
37 | CachedCSSStyleSheet(CachedResourceRequest&&, const PAL::SessionID&, const CookieJar*); |
38 | virtual ~CachedCSSStyleSheet(); |
39 | |
40 | enum class MIMETypeCheckHint { Strict, Lax }; |
41 | const String sheetText(MIMETypeCheckHint = MIMETypeCheckHint::Strict, bool* hasValidMIMEType = nullptr) const; |
42 | |
43 | RefPtr<StyleSheetContents> restoreParsedStyleSheet(const CSSParserContext&, CachePolicy, FrameLoader&); |
44 | void saveParsedStyleSheet(Ref<StyleSheetContents>&&); |
45 | |
46 | bool mimeTypeAllowedByNosniff() const; |
47 | |
48 | private: |
49 | String responseMIMEType() const; |
50 | bool canUseSheet(MIMETypeCheckHint, bool* hasValidMIMEType) const; |
51 | bool mayTryReplaceEncodedData() const final { return true; } |
52 | |
53 | void didAddClient(CachedResourceClient&) final; |
54 | |
55 | void setEncoding(const String&) final; |
56 | String encoding() const final; |
57 | const TextResourceDecoder* textResourceDecoder() const final { return m_decoder.get(); } |
58 | void finishLoading(SharedBuffer*) final; |
59 | void destroyDecodedData() final; |
60 | |
61 | void setBodyDataFrom(const CachedResource&) final; |
62 | |
63 | protected: |
64 | void checkNotify() final; |
65 | |
66 | RefPtr<TextResourceDecoder> m_decoder; |
67 | String m_decodedSheetText; |
68 | |
69 | RefPtr<StyleSheetContents> m_parsedStyleSheetCache; |
70 | }; |
71 | |
72 | } // namespace WebCore |
73 | |
74 | SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(CachedCSSStyleSheet, CachedResource::Type::CSSStyleSheet) |
75 | |