OLD | NEW |
---|---|
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | 6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
7 | 7 |
8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); | 85 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); |
86 | 86 |
87 // |c| might be removed in didAppendFirstData, so ensure it is still a | 87 // |c| might be removed in didAppendFirstData, so ensure it is still a |
88 // client. | 88 // client. |
89 if (hasClient(c) && !isLoading()) | 89 if (hasClient(c) && !isLoading()) |
90 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(resourceRequ est().url(), response().url(), encoding(), this); | 90 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(resourceRequ est().url(), response().url(), encoding(), this); |
91 } | 91 } |
92 | 92 |
93 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const | 93 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const |
94 { | 94 { |
95 if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck)) | 95 if (!canUseSheet(mimeTypeCheck)) |
96 return String(); | 96 return String(); |
97 | 97 |
98 if (!m_decodedSheetText.isNull()) | 98 // Use cached decoded sheet text when available |
99 if (!m_decodedSheetText.isNull()) { | |
100 // We should have the decoded sheet text cached when the resource is ful ly loaded. | |
101 DCHECK(getStatus() != Resource::Cached); | |
Charlie Harrison
2016/08/31 13:01:18
nit: DCHECK_NE
kouhei (in TOK)
2016/09/02 03:43:42
Done.
| |
102 | |
99 return m_decodedSheetText; | 103 return m_decodedSheetText; |
104 } | |
100 | 105 |
101 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory | 106 if (!data() || data()->isEmpty()) |
107 return String(); | |
108 | |
102 return decodedText(); | 109 return decodedText(); |
103 } | 110 } |
104 | 111 |
105 void CSSStyleSheetResource::appendData(const char* data, size_t length) | 112 void CSSStyleSheetResource::appendData(const char* data, size_t length) |
106 { | 113 { |
107 Resource::appendData(data, length); | 114 Resource::appendData(data, length); |
108 if (m_didNotifyFirstData) | 115 if (m_didNotifyFirstData) |
109 return; | 116 return; |
110 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 117 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
111 while (StyleSheetResourceClient* c = w.next()) | 118 while (StyleSheetResourceClient* c = w.next()) |
112 c->didAppendFirstData(this); | 119 c->didAppendFirstData(this); |
113 m_didNotifyFirstData = true; | 120 m_didNotifyFirstData = true; |
114 } | 121 } |
115 | 122 |
116 void CSSStyleSheetResource::checkNotify() | 123 void CSSStyleSheetResource::checkNotify() |
117 { | 124 { |
118 // Decode the data to find out the encoding and keep the sheet text around d uring checkNotify() | 125 // Decode the data to find out the encoding and cache the decoded sheet text . |
Charlie Harrison
2016/08/31 13:01:18
Also comment that clearData() only clears the raw
kouhei (in TOK)
2016/09/02 03:43:42
Done.
| |
119 if (data()) | 126 if (data()) { |
120 m_decodedSheetText = decodedText(); | 127 m_decodedSheetText = decodedText(); |
128 clearData(); | |
129 } | |
121 | 130 |
122 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 131 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
123 while (StyleSheetResourceClient* c = w.next()) | 132 while (StyleSheetResourceClient* c = w.next()) |
124 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding( ), this); | 133 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding( ), this); |
125 // Clear the decoded text as it is unlikely to be needed immediately again a nd is cheap to regenerate. | |
126 m_decodedSheetText = String(); | |
127 } | 134 } |
128 | 135 |
129 void CSSStyleSheetResource::destroyDecodedDataIfPossible() | 136 void CSSStyleSheetResource::destroyDecodedDataIfPossible() |
130 { | 137 { |
131 if (!m_parsedStyleSheetCache) | 138 if (!m_parsedStyleSheetCache) |
132 return; | 139 return; |
133 | 140 |
134 setParsedStyleSheetCache(nullptr); | 141 setParsedStyleSheetCache(nullptr); |
135 setDecodedSize(0); | 142 setDecodedSize(0); |
143 | |
144 } | |
145 | |
146 void CSSStyleSheetResource::destroyDecodedDataIfPossible() | |
Charlie Harrison
2016/08/31 13:01:18
duplicate method?
kouhei (in TOK)
2016/09/02 03:43:42
Done.
kouhei (in TOK)
2016/09/02 03:43:42
Done.
| |
147 { | |
148 m_decodedSheetText = String(); | |
149 destroyDecodedDataIfPossible(); | |
136 } | 150 } |
137 | 151 |
138 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const | 152 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const |
139 { | 153 { |
140 if (errorOccurred()) | 154 if (errorOccurred()) |
141 return false; | 155 return false; |
142 | 156 |
143 // This check exactly matches Firefox. Note that we grab the Content-Type | 157 // This check exactly matches Firefox. Note that we grab the Content-Type |
144 // header directly because we want to see what the value is BEFORE content | 158 // header directly because we want to see what the value is BEFORE content |
145 // sniffing. Firefox does this by setting a "type hint" on the channel. | 159 // sniffing. Firefox does this by setting a "type hint" on the channel. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 // This stylesheet resource did conflict with another resource and was | 196 // This stylesheet resource did conflict with another resource and was |
183 // not added to the cache. | 197 // not added to the cache. |
184 setParsedStyleSheetCache(nullptr); | 198 setParsedStyleSheetCache(nullptr); |
185 return; | 199 return; |
186 } | 200 } |
187 setParsedStyleSheetCache(sheet); | 201 setParsedStyleSheetCache(sheet); |
188 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 202 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
189 } | 203 } |
190 | 204 |
191 } // namespace blink | 205 } // namespace blink |
OLD | NEW |