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

Unified Diff: Source/core/dom/StyleEngine.cpp

Issue 196133034: Move inline stylesheet cache decision making from StyleSheetContents to StyleEngine (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merged to trunk Created 6 years, 9 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
« no previous file with comments | « Source/core/css/StyleSheetContents.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/StyleEngine.cpp
diff --git a/Source/core/dom/StyleEngine.cpp b/Source/core/dom/StyleEngine.cpp
index 65ed280169245b6df8811c6e0c8bccecdd1dbd00..5524bca66849b0fedbf00a3b8dcaaf63a66cb630 100644
--- a/Source/core/dom/StyleEngine.cpp
+++ b/Source/core/dom/StyleEngine.cpp
@@ -562,6 +562,21 @@ void StyleEngine::markDocumentDirty()
m_document.import()->master()->styleEngine()->markDocumentDirty();
}
+static bool isCacheableForStyleElement(const StyleSheetContents& contents)
+{
+ // FIXME: Support copying import rules.
+ if (!contents.importRules().isEmpty())
+ return false;
+ // Until import rules are supported in cached sheets it's not possible for loading to fail.
+ ASSERT(!contents.didLoadErrorOccur());
+ // It is not the original sheet anymore.
+ if (contents.isMutable())
+ return false;
+ if (!contents.hasSyntacticallyValidCSSHeader())
+ return false;
+ return true;
+}
+
PassRefPtrWillBeRawPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& text, TextPosition startPosition, bool createdByParser)
{
RefPtrWillBeRawPtr<CSSStyleSheet> styleSheet;
@@ -574,14 +589,16 @@ PassRefPtrWillBeRawPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const
HashMap<AtomicString, StyleSheetContents*>::AddResult result = m_textToSheetCache.add(textContent, 0);
if (result.isNewEntry || !result.storedValue->value) {
styleSheet = StyleEngine::parseSheet(e, text, startPosition, createdByParser);
- if (result.isNewEntry && styleSheet->contents()->maybeCacheable()) {
+ if (result.isNewEntry && isCacheableForStyleElement(*styleSheet->contents())) {
result.storedValue->value = styleSheet->contents();
m_sheetToTextCache.add(styleSheet->contents(), textContent);
}
} else {
- ASSERT(result.storedValue->value->maybeCacheable());
- ASSERT(result.storedValue->value->singleOwnerDocument() == e->document());
- styleSheet = CSSStyleSheet::createInline(result.storedValue->value, e, startPosition);
+ StyleSheetContents* contents = result.storedValue->value;
+ ASSERT(contents);
+ ASSERT(isCacheableForStyleElement(*contents));
+ ASSERT(contents->singleOwnerDocument() == e->document());
+ styleSheet = CSSStyleSheet::createInline(contents, e, startPosition);
}
} else {
// FIXME: currently we don't cache StyleSheetContents inQuirksMode.
« no previous file with comments | « Source/core/css/StyleSheetContents.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698