Chromium Code Reviews| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 70 |
| 71 CSSStyleSheetResource::~CSSStyleSheetResource() {} | 71 CSSStyleSheetResource::~CSSStyleSheetResource() {} |
| 72 | 72 |
| 73 void CSSStyleSheetResource::setParsedStyleSheetCache( | 73 void CSSStyleSheetResource::setParsedStyleSheetCache( |
| 74 StyleSheetContents* newSheet) { | 74 StyleSheetContents* newSheet) { |
| 75 if (m_parsedStyleSheetCache) | 75 if (m_parsedStyleSheetCache) |
| 76 m_parsedStyleSheetCache->clearReferencedFromResource(); | 76 m_parsedStyleSheetCache->clearReferencedFromResource(); |
| 77 m_parsedStyleSheetCache = newSheet; | 77 m_parsedStyleSheetCache = newSheet; |
| 78 if (m_parsedStyleSheetCache) | 78 if (m_parsedStyleSheetCache) |
| 79 m_parsedStyleSheetCache->setReferencedFromResource(this); | 79 m_parsedStyleSheetCache->setReferencedFromResource(this); |
| 80 | |
| 81 // Updates the decoded size to take parsed stylesheet cache into account. | |
| 82 updateDecodedSize(); | |
| 80 } | 83 } |
| 81 | 84 |
| 82 DEFINE_TRACE(CSSStyleSheetResource) { | 85 DEFINE_TRACE(CSSStyleSheetResource) { |
| 83 visitor->trace(m_parsedStyleSheetCache); | 86 visitor->trace(m_parsedStyleSheetCache); |
| 84 StyleSheetResource::trace(visitor); | 87 StyleSheetResource::trace(visitor); |
| 85 } | 88 } |
| 86 | 89 |
| 87 void CSSStyleSheetResource::didAddClient(ResourceClient* c) { | 90 void CSSStyleSheetResource::didAddClient(ResourceClient* c) { |
| 88 DCHECK(StyleSheetResourceClient::isExpectedType(c)); | 91 DCHECK(StyleSheetResourceClient::isExpectedType(c)); |
| 89 // Resource::didAddClient() must be before setCSSStyleSheet(), because | 92 // Resource::didAddClient() must be before setCSSStyleSheet(), because |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 132 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 130 while (StyleSheetResourceClient* c = w.next()) | 133 while (StyleSheetResourceClient* c = w.next()) |
| 131 c->didAppendFirstData(this); | 134 c->didAppendFirstData(this); |
| 132 m_didNotifyFirstData = true; | 135 m_didNotifyFirstData = true; |
| 133 } | 136 } |
| 134 | 137 |
| 135 void CSSStyleSheetResource::checkNotify() { | 138 void CSSStyleSheetResource::checkNotify() { |
| 136 // Decode the data to find out the encoding and cache the decoded sheet text. | 139 // Decode the data to find out the encoding and cache the decoded sheet text. |
| 137 if (data()) { | 140 if (data()) { |
| 138 m_decodedSheetText = decodedText(); | 141 m_decodedSheetText = decodedText(); |
| 142 updateDecodedSize(); | |
|
hajimehoshi
2016/11/07 11:11:34
I'd make setDecodedSheetText and call updateDecode
hiroshige
2016/11/07 11:41:20
Done.
| |
| 139 } | 143 } |
| 140 | 144 |
| 141 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 145 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 142 while (StyleSheetResourceClient* c = w.next()) { | 146 while (StyleSheetResourceClient* c = w.next()) { |
| 143 markClientFinished(c); | 147 markClientFinished(c); |
| 144 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), | 148 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), |
| 145 this); | 149 this); |
| 146 } | 150 } |
| 147 | 151 |
| 148 // Clear raw bytes as now we have the full decoded sheet text. | 152 // Clear raw bytes as now we have the full decoded sheet text. |
| 149 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once) | 153 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once) |
| 150 // as SubresourceIntegrity checks require raw bytes. | 154 // as SubresourceIntegrity checks require raw bytes. |
| 151 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too, | 155 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too, |
| 152 // but is safe as we should have a cached ResourceIntegrityDisposition. | 156 // but is safe as we should have a cached ResourceIntegrityDisposition. |
| 153 clearData(); | 157 clearData(); |
| 158 setEncodedSizeMemoryUsage(0); | |
| 154 } | 159 } |
| 155 | 160 |
| 156 void CSSStyleSheetResource::destroyDecodedDataIfPossible() { | 161 void CSSStyleSheetResource::destroyDecodedDataIfPossible() { |
| 157 if (!m_parsedStyleSheetCache) | 162 if (!m_parsedStyleSheetCache) |
| 158 return; | 163 return; |
| 159 | 164 |
| 160 setParsedStyleSheetCache(nullptr); | 165 setParsedStyleSheetCache(nullptr); |
| 161 setDecodedSize(0); | |
| 162 } | 166 } |
| 163 | 167 |
| 164 void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() { | 168 void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() { |
| 165 m_decodedSheetText = String(); | 169 m_decodedSheetText = String(); |
| 170 updateDecodedSize(); | |
| 166 destroyDecodedDataIfPossible(); | 171 destroyDecodedDataIfPossible(); |
| 167 } | 172 } |
| 168 | 173 |
| 169 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const { | 174 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const { |
| 170 if (errorOccurred()) | 175 if (errorOccurred()) |
| 171 return false; | 176 return false; |
| 172 | 177 |
| 173 // This check exactly matches Firefox. Note that we grab the Content-Type | 178 // This check exactly matches Firefox. Note that we grab the Content-Type |
| 174 // header directly because we want to see what the value is BEFORE content | 179 // header directly because we want to see what the value is BEFORE content |
| 175 // sniffing. Firefox does this by setting a "type hint" on the channel. This | 180 // sniffing. Firefox does this by setting a "type hint" on the channel. This |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 DCHECK(sheet); | 215 DCHECK(sheet); |
| 211 DCHECK(sheet->isCacheableForResource()); | 216 DCHECK(sheet->isCacheableForResource()); |
| 212 | 217 |
| 213 if (!memoryCache()->contains(this)) { | 218 if (!memoryCache()->contains(this)) { |
| 214 // This stylesheet resource did conflict with another resource and was not | 219 // This stylesheet resource did conflict with another resource and was not |
| 215 // added to the cache. | 220 // added to the cache. |
| 216 setParsedStyleSheetCache(nullptr); | 221 setParsedStyleSheetCache(nullptr); |
| 217 return; | 222 return; |
| 218 } | 223 } |
| 219 setParsedStyleSheetCache(sheet); | 224 setParsedStyleSheetCache(sheet); |
| 220 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 225 } |
| 226 | |
| 227 void CSSStyleSheetResource::updateDecodedSize() { | |
| 228 size_t decodedSize = m_decodedSheetText.charactersSizeInBytes(); | |
| 229 if (m_parsedStyleSheetCache) | |
| 230 decodedSize += m_parsedStyleSheetCache->estimatedSizeInBytes(); | |
| 231 setDecodedSize(decodedSize); | |
| 221 } | 232 } |
| 222 | 233 |
| 223 } // namespace blink | 234 } // namespace blink |
| OLD | NEW |