Chromium Code Reviews| Index: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp |
| diff --git a/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp b/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp |
| index f44d16a3fcff570c6df1692629a9cc5dde000860..604edd5f735cf8d335331b9601951194355d815f 100644 |
| --- a/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp |
| +++ b/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp |
| @@ -92,13 +92,20 @@ void CSSStyleSheetResource::didAddClient(ResourceClient* c) |
| const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const |
| { |
| - if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck)) |
| + if (!canUseSheet(mimeTypeCheck)) |
| return String(); |
| - if (!m_decodedSheetText.isNull()) |
| + // Use cached decoded sheet text when available |
| + if (!m_decodedSheetText.isNull()) { |
| + // We should have the decoded sheet text cached when the resource is fully loaded. |
| + 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
|
| + |
| return m_decodedSheetText; |
| + } |
| + |
| + if (!data() || data()->isEmpty()) |
| + return String(); |
| - // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory |
| return decodedText(); |
| } |
| @@ -115,15 +122,15 @@ void CSSStyleSheetResource::appendData(const char* data, size_t length) |
| void CSSStyleSheetResource::checkNotify() |
| { |
| - // Decode the data to find out the encoding and keep the sheet text around during checkNotify() |
| - if (data()) |
| + // Decode the data to find out the encoding and cache the decoded sheet text. |
| + if (data()) { |
| m_decodedSheetText = decodedText(); |
| + clearData(); |
| + } |
| ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
| while (StyleSheetResourceClient* c = w.next()) |
| c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), this); |
| - // Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate. |
| - m_decodedSheetText = String(); |
| } |
| void CSSStyleSheetResource::destroyDecodedDataIfPossible() |
| @@ -135,6 +142,12 @@ void CSSStyleSheetResource::destroyDecodedDataIfPossible() |
| setDecodedSize(0); |
| } |
| +void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() |
| +{ |
| + m_decodedSheetText = String(); |
| + destroyDecodedDataIfPossible(); |
| +} |
| + |
| bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const |
| { |
| if (errorOccurred()) |