Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp

Issue 2389643002: Reflow comments in core/fetch (Closed)
Patch Set: yoavs comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 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 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, 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. 21 Boston, MA 02110-1301, USA.
22 22
23 This class provides all functionality needed for loading images, style sheet s and html 23 This class provides all functionality needed for loading images, style
24 pages from the web. It has a memory cache for these objects. 24 sheets and html pages from the web. It has a memory cache for these objects.
25 */ 25 */
26 26
27 #include "core/fetch/CSSStyleSheetResource.h" 27 #include "core/fetch/CSSStyleSheetResource.h"
28 28
29 #include "core/css/StyleSheetContents.h" 29 #include "core/css/StyleSheetContents.h"
30 #include "core/fetch/FetchRequest.h" 30 #include "core/fetch/FetchRequest.h"
31 #include "core/fetch/MemoryCache.h" 31 #include "core/fetch/MemoryCache.h"
32 #include "core/fetch/ResourceClientWalker.h" 32 #include "core/fetch/ResourceClientWalker.h"
33 #include "core/fetch/ResourceFetcher.h" 33 #include "core/fetch/ResourceFetcher.h"
34 #include "core/fetch/StyleSheetResourceClient.h" 34 #include "core/fetch/StyleSheetResourceClient.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 m_parsedStyleSheetCache->setReferencedFromResource(this); 75 m_parsedStyleSheetCache->setReferencedFromResource(this);
76 } 76 }
77 77
78 DEFINE_TRACE(CSSStyleSheetResource) { 78 DEFINE_TRACE(CSSStyleSheetResource) {
79 visitor->trace(m_parsedStyleSheetCache); 79 visitor->trace(m_parsedStyleSheetCache);
80 StyleSheetResource::trace(visitor); 80 StyleSheetResource::trace(visitor);
81 } 81 }
82 82
83 void CSSStyleSheetResource::didAddClient(ResourceClient* c) { 83 void CSSStyleSheetResource::didAddClient(ResourceClient* c) {
84 DCHECK(StyleSheetResourceClient::isExpectedType(c)); 84 DCHECK(StyleSheetResourceClient::isExpectedType(c));
85 // Resource::didAddClient() must be before setCSSStyleSheet(), 85 // Resource::didAddClient() must be before setCSSStyleSheet(), because
86 // because setCSSStyleSheet() may cause scripts to be executed, which could de stroy 'c' if it is an instance of HTMLLinkElement. 86 // setCSSStyleSheet() may cause scripts to be executed, which could destroy
87 // see the comment of HTMLLinkElement::setCSSStyleSheet. 87 // 'c' if it is an instance of HTMLLinkElement. see the comment of
88 // HTMLLinkElement::setCSSStyleSheet.
88 Resource::didAddClient(c); 89 Resource::didAddClient(c);
89 if (m_didNotifyFirstData) 90 if (m_didNotifyFirstData)
90 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); 91 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this);
91 92
92 // |c| might be removed in didAppendFirstData, so ensure it is still a 93 // |c| might be removed in didAppendFirstData, so ensure it is still a client.
93 // client.
94 if (hasClient(c) && !isLoading()) 94 if (hasClient(c) && !isLoading())
95 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet( 95 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(
96 resourceRequest().url(), response().url(), encoding(), this); 96 resourceRequest().url(), response().url(), encoding(), this);
97 } 97 }
98 98
99 const String CSSStyleSheetResource::sheetText( 99 const String CSSStyleSheetResource::sheetText(
100 MIMETypeCheck mimeTypeCheck) const { 100 MIMETypeCheck mimeTypeCheck) const {
101 if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck)) 101 if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck))
102 return String(); 102 return String();
103 103
104 if (!m_decodedSheetText.isNull()) 104 if (!m_decodedSheetText.isNull())
105 return m_decodedSheetText; 105 return m_decodedSheetText;
106 106
107 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory 107 // Don't cache the decoded text, regenerating is cheap and it can use quite a
108 // bit of memory
108 return decodedText(); 109 return decodedText();
109 } 110 }
110 111
111 void CSSStyleSheetResource::appendData(const char* data, size_t length) { 112 void CSSStyleSheetResource::appendData(const char* data, size_t length) {
112 Resource::appendData(data, length); 113 Resource::appendData(data, length);
113 if (m_didNotifyFirstData) 114 if (m_didNotifyFirstData)
114 return; 115 return;
115 ResourceClientWalker<StyleSheetResourceClient> w(clients()); 116 ResourceClientWalker<StyleSheetResourceClient> w(clients());
116 while (StyleSheetResourceClient* c = w.next()) 117 while (StyleSheetResourceClient* c = w.next())
117 c->didAppendFirstData(this); 118 c->didAppendFirstData(this);
118 m_didNotifyFirstData = true; 119 m_didNotifyFirstData = true;
119 } 120 }
120 121
121 void CSSStyleSheetResource::checkNotify() { 122 void CSSStyleSheetResource::checkNotify() {
122 // Decode the data to find out the encoding and keep the sheet text around dur ing checkNotify() 123 // Decode the data to find out the encoding and keep the sheet text around
124 // during checkNotify()
123 if (data()) 125 if (data())
124 m_decodedSheetText = decodedText(); 126 m_decodedSheetText = decodedText();
125 127
126 ResourceClientWalker<StyleSheetResourceClient> w(clients()); 128 ResourceClientWalker<StyleSheetResourceClient> w(clients());
127 while (StyleSheetResourceClient* c = w.next()) { 129 while (StyleSheetResourceClient* c = w.next()) {
128 markClientFinished(c); 130 markClientFinished(c);
129 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), 131 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(),
130 this); 132 this);
131 } 133 }
132 // Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate. 134 // Clear the decoded text as it is unlikely to be needed immediately again and
135 // is cheap to regenerate.
133 m_decodedSheetText = String(); 136 m_decodedSheetText = String();
134 } 137 }
135 138
136 void CSSStyleSheetResource::destroyDecodedDataIfPossible() { 139 void CSSStyleSheetResource::destroyDecodedDataIfPossible() {
137 if (!m_parsedStyleSheetCache) 140 if (!m_parsedStyleSheetCache)
138 return; 141 return;
139 142
140 setParsedStyleSheetCache(nullptr); 143 setParsedStyleSheetCache(nullptr);
141 setDecodedSize(0); 144 setDecodedSize(0);
142 } 145 }
143 146
144 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const { 147 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const {
145 if (errorOccurred()) 148 if (errorOccurred())
146 return false; 149 return false;
147 150
148 // This check exactly matches Firefox. Note that we grab the Content-Type 151 // This check exactly matches Firefox. Note that we grab the Content-Type
149 // header directly because we want to see what the value is BEFORE content 152 // header directly because we want to see what the value is BEFORE content
150 // sniffing. Firefox does this by setting a "type hint" on the channel. 153 // sniffing. Firefox does this by setting a "type hint" on the channel. This
151 // This implementation should be observationally equivalent. 154 // implementation should be observationally equivalent.
152 // 155 //
153 // This code defaults to allowing the stylesheet for non-HTTP protocols so 156 // This code defaults to allowing the stylesheet for non-HTTP protocols so
154 // folks can use standards mode for local HTML documents. 157 // folks can use standards mode for local HTML documents.
155 if (mimeTypeCheck == MIMETypeCheck::Lax) 158 if (mimeTypeCheck == MIMETypeCheck::Lax)
156 return true; 159 return true;
157 AtomicString contentType = httpContentType(); 160 AtomicString contentType = httpContentType();
158 return contentType.isEmpty() || equalIgnoringCase(contentType, "text/css") || 161 return contentType.isEmpty() || equalIgnoringCase(contentType, "text/css") ||
159 equalIgnoringCase(contentType, "application/x-unknown-content-type"); 162 equalIgnoringCase(contentType, "application/x-unknown-content-type");
160 } 163 }
161 164
162 StyleSheetContents* CSSStyleSheetResource::restoreParsedStyleSheet( 165 StyleSheetContents* CSSStyleSheetResource::restoreParsedStyleSheet(
163 const CSSParserContext& context) { 166 const CSSParserContext& context) {
164 if (!m_parsedStyleSheetCache) 167 if (!m_parsedStyleSheetCache)
165 return nullptr; 168 return nullptr;
166 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { 169 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) {
167 setParsedStyleSheetCache(nullptr); 170 setParsedStyleSheetCache(nullptr);
168 return nullptr; 171 return nullptr;
169 } 172 }
170 173
171 DCHECK(m_parsedStyleSheetCache->isCacheableForResource()); 174 DCHECK(m_parsedStyleSheetCache->isCacheableForResource());
172 DCHECK(m_parsedStyleSheetCache->isReferencedFromResource()); 175 DCHECK(m_parsedStyleSheetCache->isReferencedFromResource());
173 176
174 // Contexts must be identical so we know we would get the same exact result if we parsed again. 177 // Contexts must be identical so we know we would get the same exact result if
178 // we parsed again.
175 if (m_parsedStyleSheetCache->parserContext() != context) 179 if (m_parsedStyleSheetCache->parserContext() != context)
176 return nullptr; 180 return nullptr;
177 181
178 didAccessDecodedData(); 182 didAccessDecodedData();
179 183
180 return m_parsedStyleSheetCache; 184 return m_parsedStyleSheetCache;
181 } 185 }
182 186
183 void CSSStyleSheetResource::saveParsedStyleSheet(StyleSheetContents* sheet) { 187 void CSSStyleSheetResource::saveParsedStyleSheet(StyleSheetContents* sheet) {
184 DCHECK(sheet); 188 DCHECK(sheet);
185 DCHECK(sheet->isCacheableForResource()); 189 DCHECK(sheet->isCacheableForResource());
186 190
187 if (!memoryCache()->contains(this)) { 191 if (!memoryCache()->contains(this)) {
188 // This stylesheet resource did conflict with another resource and was 192 // This stylesheet resource did conflict with another resource and was not
189 // not added to the cache. 193 // added to the cache.
190 setParsedStyleSheetCache(nullptr); 194 setParsedStyleSheetCache(nullptr);
191 return; 195 return;
192 } 196 }
193 setParsedStyleSheetCache(sheet); 197 setParsedStyleSheetCache(sheet);
194 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); 198 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
195 } 199 }
196 200
197 } // namespace blink 201 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698