OLD | NEW |
| (Empty) |
1 /* | |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | |
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | |
6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | |
7 | |
8 This library is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU Library General Public | |
10 License as published by the Free Software Foundation; either | |
11 version 2 of the License, or (at your option) any later version. | |
12 | |
13 This library is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 Library General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Library General Public License | |
19 along with this library; see the file COPYING.LIB. If not, write to | |
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
21 Boston, MA 02110-1301, USA. | |
22 | |
23 This class provides all functionality needed for loading images, style sheet
s and html | |
24 pages from the web. It has a memory cache for these objects. | |
25 */ | |
26 | |
27 #include "config.h" | |
28 #include "CachedCSSStyleSheet.h" | |
29 | |
30 #include "CachedResourceClient.h" | |
31 #include "CachedResourceClientWalker.h" | |
32 #include "TextResourceDecoder.h" | |
33 #include "loader.h" | |
34 #include <wtf/Vector.h> | |
35 | |
36 namespace WebCore { | |
37 | |
38 CachedCSSStyleSheet::CachedCSSStyleSheet(const String& url, const String& charse
t) | |
39 : CachedResource(url, CSSStyleSheet) | |
40 , m_decoder(TextResourceDecoder::create("text/css", charset)) | |
41 { | |
42 // Prefer text/css but accept any type (dell.com serves a stylesheet | |
43 // as text/html; see <http://bugs.webkit.org/show_bug.cgi?id=11451>). | |
44 setAccept("text/css,*/*;q=0.1"); | |
45 } | |
46 | |
47 CachedCSSStyleSheet::~CachedCSSStyleSheet() | |
48 { | |
49 } | |
50 | |
51 void CachedCSSStyleSheet::addClient(CachedResourceClient *c) | |
52 { | |
53 CachedResource::addClient(c); | |
54 | |
55 if (!m_loading) | |
56 c->setCSSStyleSheet(m_url, m_decoder->encoding().name(), this); | |
57 } | |
58 | |
59 void CachedCSSStyleSheet::setEncoding(const String& chs) | |
60 { | |
61 m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader); | |
62 } | |
63 | |
64 String CachedCSSStyleSheet::encoding() const | |
65 { | |
66 return m_decoder->encoding().name(); | |
67 } | |
68 | |
69 void CachedCSSStyleSheet::data(PassRefPtr<SharedBuffer> data, bool allDataReceiv
ed) | |
70 { | |
71 if (!allDataReceived) | |
72 return; | |
73 | |
74 m_data = data; | |
75 setEncodedSize(m_data.get() ? m_data->size() : 0); | |
76 if (m_data.get()) { | |
77 m_sheet = m_decoder->decode(m_data->data(), encodedSize()); | |
78 m_sheet += m_decoder->flush(); | |
79 m_data = 0; // We no longer need the raw buffer. | |
80 } | |
81 m_loading = false; | |
82 checkNotify(); | |
83 } | |
84 | |
85 void CachedCSSStyleSheet::checkNotify() | |
86 { | |
87 if (m_loading) | |
88 return; | |
89 | |
90 CachedResourceClientWalker w(m_clients); | |
91 while (CachedResourceClient *c = w.next()) | |
92 c->setCSSStyleSheet(m_response.url().string(), m_decoder->encoding().nam
e(), this); | |
93 | |
94 #if USE(LOW_BANDWIDTH_DISPLAY) | |
95 // if checkNotify() is called from error(), client's setCSSStyleSheet(...) | |
96 // can't find "this" from url, so they can't do clean up if needed. | |
97 // call notifyFinished() to make sure they have a chance. | |
98 CachedResourceClientWalker n(m_clients); | |
99 while (CachedResourceClient* s = n.next()) | |
100 s->notifyFinished(this); | |
101 #endif | |
102 } | |
103 | |
104 void CachedCSSStyleSheet::error() | |
105 { | |
106 m_loading = false; | |
107 m_errorOccurred = true; | |
108 checkNotify(); | |
109 } | |
110 | |
111 bool CachedCSSStyleSheet::canUseSheet(bool enforceMIMEType) const | |
112 { | |
113 if (errorOccurred()) | |
114 return false; | |
115 | |
116 if (!enforceMIMEType) | |
117 return true; | |
118 | |
119 // This check exactly matches Firefox. | |
120 String mimeType = response().mimeType(); | |
121 return mimeType.isEmpty() || equalIgnoringCase(mimeType, "text/css") || equa
lIgnoringCase(mimeType, "application/x-unknown-content-type"); | |
122 } | |
123 | |
124 } | |
OLD | NEW |