Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Unified Diff: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp

Issue 2290983003: CSSStyleSheetResource should cache decoded text instead of raw bytes (Closed)
Patch Set: rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698