| 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 72ee750b8984a5cdbd8a84e040f535449bb2458b..856685402a9fefd2238ded939aeca866f9121d96 100644
|
| --- a/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
|
| +++ b/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
|
| @@ -43,8 +43,12 @@ CSSStyleSheetResource* CSSStyleSheetResource::fetch(FetchRequest& request,
|
| WebURLRequest::FrameTypeNone);
|
| request.mutableResourceRequest().setRequestContext(
|
| WebURLRequest::RequestContextStyle);
|
| - return toCSSStyleSheetResource(
|
| + CSSStyleSheetResource* resource = toCSSStyleSheetResource(
|
| fetcher->requestResource(request, CSSStyleSheetResourceFactory()));
|
| + // TODO(kouhei): Dedupe this logic w/ ScriptResource::fetch
|
| + if (resource && !request.integrityMetadata().isEmpty())
|
| + resource->setIntegrityMetadata(request.integrityMetadata());
|
| + return resource;
|
| }
|
|
|
| CSSStyleSheetResource* CSSStyleSheetResource::createForTest(
|
| @@ -99,14 +103,21 @@ 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_EQ(getStatus(), Resource::Cached);
|
| +
|
| 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();
|
| }
|
|
|
| @@ -121,10 +132,10 @@ 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();
|
| + }
|
|
|
| ResourceClientWalker<StyleSheetResourceClient> w(clients());
|
| while (StyleSheetResourceClient* c = w.next()) {
|
| @@ -132,9 +143,13 @@ void CSSStyleSheetResource::checkNotify() {
|
| 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();
|
| +
|
| + // Clear raw bytes as now we have the full decoded sheet text.
|
| + // We wait for all LinkStyle::setCSSStyleSheet to run (at least once)
|
| + // as SubresourceIntegrity checks require raw bytes.
|
| + // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too,
|
| + // but is safe as we should have a cached ResourceIntegrityDisposition.
|
| + clearData();
|
| }
|
|
|
| void CSSStyleSheetResource::destroyDecodedDataIfPossible() {
|
| @@ -145,6 +160,11 @@ void CSSStyleSheetResource::destroyDecodedDataIfPossible() {
|
| setDecodedSize(0);
|
| }
|
|
|
| +void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() {
|
| + m_decodedSheetText = String();
|
| + destroyDecodedDataIfPossible();
|
| +}
|
| +
|
| bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const {
|
| if (errorOccurred())
|
| return false;
|
|
|