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 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/09/02 03:40:49
I think this DCHECK isn't quite right. We set the
kouhei (in TOK)
2016/09/02 03:43:42
Yes, that was causing the test failures. Swapped i
| |
| 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 . |
| 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); |
| 136 } | 143 } |
| 137 | 144 |
| 145 void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() | |
| 146 { | |
| 147 m_decodedSheetText = String(); | |
| 148 destroyDecodedDataIfPossible(); | |
| 149 } | |
| 150 | |
| 138 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const | 151 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const |
| 139 { | 152 { |
| 140 if (errorOccurred()) | 153 if (errorOccurred()) |
| 141 return false; | 154 return false; |
| 142 | 155 |
| 143 // This check exactly matches Firefox. Note that we grab the Content-Type | 156 // 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 | 157 // 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. | 158 // sniffing. Firefox does this by setting a "type hint" on the channel. |
| 146 // This implementation should be observationally equivalent. | 159 // This implementation should be observationally equivalent. |
| 147 // | 160 // |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // This stylesheet resource did conflict with another resource and was | 195 // This stylesheet resource did conflict with another resource and was |
| 183 // not added to the cache. | 196 // not added to the cache. |
| 184 setParsedStyleSheetCache(nullptr); | 197 setParsedStyleSheetCache(nullptr); |
| 185 return; | 198 return; |
| 186 } | 199 } |
| 187 setParsedStyleSheetCache(sheet); | 200 setParsedStyleSheetCache(sheet); |
| 188 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 201 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
| 189 } | 202 } |
| 190 | 203 |
| 191 } // namespace blink | 204 } // namespace blink |
| OLD | NEW |