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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 m_didNotifyFirstData(false) {} | 69 m_didNotifyFirstData(false) {} |
| 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); |
|
kouhei (in TOK)
2016/11/07 09:29:39
Can we add a comment here:
// update decoded size
hiroshige
2016/11/07 09:36:06
Done.
| |
| 80 updateDecodedSize(); | |
| 80 } | 81 } |
| 81 | 82 |
| 82 DEFINE_TRACE(CSSStyleSheetResource) { | 83 DEFINE_TRACE(CSSStyleSheetResource) { |
| 83 visitor->trace(m_parsedStyleSheetCache); | 84 visitor->trace(m_parsedStyleSheetCache); |
| 84 StyleSheetResource::trace(visitor); | 85 StyleSheetResource::trace(visitor); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void CSSStyleSheetResource::didAddClient(ResourceClient* c) { | 88 void CSSStyleSheetResource::didAddClient(ResourceClient* c) { |
| 88 DCHECK(StyleSheetResourceClient::isExpectedType(c)); | 89 DCHECK(StyleSheetResourceClient::isExpectedType(c)); |
| 89 // Resource::didAddClient() must be before setCSSStyleSheet(), because | 90 // 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()); | 130 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 130 while (StyleSheetResourceClient* c = w.next()) | 131 while (StyleSheetResourceClient* c = w.next()) |
| 131 c->didAppendFirstData(this); | 132 c->didAppendFirstData(this); |
| 132 m_didNotifyFirstData = true; | 133 m_didNotifyFirstData = true; |
| 133 } | 134 } |
| 134 | 135 |
| 135 void CSSStyleSheetResource::checkNotify() { | 136 void CSSStyleSheetResource::checkNotify() { |
| 136 // Decode the data to find out the encoding and cache the decoded sheet text. | 137 // Decode the data to find out the encoding and cache the decoded sheet text. |
| 137 if (data()) { | 138 if (data()) { |
| 138 m_decodedSheetText = decodedText(); | 139 m_decodedSheetText = decodedText(); |
| 140 updateDecodedSize(); | |
| 139 } | 141 } |
| 140 | 142 |
| 141 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 143 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| 142 while (StyleSheetResourceClient* c = w.next()) { | 144 while (StyleSheetResourceClient* c = w.next()) { |
| 143 markClientFinished(c); | 145 markClientFinished(c); |
| 144 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), | 146 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), |
| 145 this); | 147 this); |
| 146 } | 148 } |
| 147 | 149 |
| 148 // Clear raw bytes as now we have the full decoded sheet text. | 150 // Clear raw bytes as now we have the full decoded sheet text. |
| 149 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once) | 151 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once) |
| 150 // as SubresourceIntegrity checks require raw bytes. | 152 // as SubresourceIntegrity checks require raw bytes. |
| 151 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too, | 153 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too, |
| 152 // but is safe as we should have a cached ResourceIntegrityDisposition. | 154 // but is safe as we should have a cached ResourceIntegrityDisposition. |
| 153 clearData(); | 155 clearData(); |
| 156 setEncodedSizeMemoryUsage(0); | |
| 154 } | 157 } |
| 155 | 158 |
| 156 void CSSStyleSheetResource::destroyDecodedDataIfPossible() { | 159 void CSSStyleSheetResource::destroyDecodedDataIfPossible() { |
| 157 if (!m_parsedStyleSheetCache) | 160 if (!m_parsedStyleSheetCache) |
| 158 return; | 161 return; |
| 159 | 162 |
| 160 setParsedStyleSheetCache(nullptr); | 163 setParsedStyleSheetCache(nullptr); |
| 161 setDecodedSize(0); | |
| 162 } | 164 } |
| 163 | 165 |
| 164 void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() { | 166 void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() { |
| 165 m_decodedSheetText = String(); | 167 m_decodedSheetText = String(); |
| 168 updateDecodedSize(); | |
|
kouhei (in TOK)
2016/11/07 09:29:39
Can we skip it here? destroyDecodedDataIfPossible
hiroshige
2016/11/07 09:36:07
I thought destroyDecodedDataIfPossible() doesn't c
kouhei (in TOK)
2016/11/07 09:57:42
Makes sense. lgtm
| |
| 166 destroyDecodedDataIfPossible(); | 169 destroyDecodedDataIfPossible(); |
| 167 } | 170 } |
| 168 | 171 |
| 169 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const { | 172 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const { |
| 170 if (errorOccurred()) | 173 if (errorOccurred()) |
| 171 return false; | 174 return false; |
| 172 | 175 |
| 173 // This check exactly matches Firefox. Note that we grab the Content-Type | 176 // 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 | 177 // 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 | 178 // 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); | 213 DCHECK(sheet); |
| 211 DCHECK(sheet->isCacheableForResource()); | 214 DCHECK(sheet->isCacheableForResource()); |
| 212 | 215 |
| 213 if (!memoryCache()->contains(this)) { | 216 if (!memoryCache()->contains(this)) { |
| 214 // This stylesheet resource did conflict with another resource and was not | 217 // This stylesheet resource did conflict with another resource and was not |
| 215 // added to the cache. | 218 // added to the cache. |
| 216 setParsedStyleSheetCache(nullptr); | 219 setParsedStyleSheetCache(nullptr); |
| 217 return; | 220 return; |
| 218 } | 221 } |
| 219 setParsedStyleSheetCache(sheet); | 222 setParsedStyleSheetCache(sheet); |
| 220 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 223 } |
| 224 | |
| 225 void CSSStyleSheetResource::updateDecodedSize() { | |
| 226 size_t decodedSize = m_decodedSheetText.charactersSizeInBytes(); | |
| 227 if (m_parsedStyleSheetCache) | |
| 228 decodedSize += m_parsedStyleSheetCache->estimatedSizeInBytes(); | |
| 229 setDecodedSize(decodedSize); | |
| 221 } | 230 } |
| 222 | 231 |
| 223 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |