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

Unified Diff: Source/core/css/StyleSheetContents.cpp

Issue 28553005: Avoid parsing css text if there are identical inline style blocks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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: Source/core/css/StyleSheetContents.cpp
diff --git a/Source/core/css/StyleSheetContents.cpp b/Source/core/css/StyleSheetContents.cpp
index 272b5ebfba0647a22a76a81d12a8a8a1b102b31e..fefaf2b149af80598194591a863a9a24cc30ad66 100644
--- a/Source/core/css/StyleSheetContents.cpp
+++ b/Source/core/css/StyleSheetContents.cpp
@@ -59,7 +59,6 @@ unsigned StyleSheetContents::estimatedSizeInBytes() const
StyleSheetContents::StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext& context)
: m_ownerRule(ownerRule)
, m_originalURL(originalURL)
- , m_loadCompleted(false)
, m_hasSyntacticallyValidCSSHeader(true)
, m_didLoadErrorOccur(false)
, m_usesRemUnits(false)
@@ -79,7 +78,6 @@ StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
, m_importRules(o.m_importRules.size())
, m_childRules(o.m_childRules.size())
, m_namespaces(o.m_namespaces)
- , m_loadCompleted(true)
, m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader)
, m_didLoadErrorOccur(false)
, m_usesRemUnits(o.m_usesRemUnits)
@@ -100,10 +98,18 @@ StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
StyleSheetContents::~StyleSheetContents()
{
+ StyleEngine::removeSheet(this);
clearRules();
}
-bool StyleSheetContents::isCacheable() const
+void StyleSheetContents::setHasSyntacticallyValidCSSHeader(bool isValidCss)
+{
+ if (maybeCacheable() && !isValidCss)
+ StyleEngine::removeSheet(this);
+ m_hasSyntacticallyValidCSSHeader = isValidCss;
+}
+
+bool StyleSheetContents::maybeCacheable() const
{
// FIXME: StyleSheets with media queries can't be cached because their RuleSet
// is processed differently based off the media queries, which might resolve
@@ -118,9 +124,6 @@ bool StyleSheetContents::isCacheable() const
// FIXME: Support cached stylesheets in import rules.
if (m_ownerRule)
return false;
- // This would require dealing with multiple clients for load callbacks.
- if (!m_loadCompleted)
- return false;
if (m_didLoadErrorOccur)
return false;
// It is not the original sheet anymore.
@@ -133,6 +136,14 @@ bool StyleSheetContents::isCacheable() const
return true;
}
+bool StyleSheetContents::isCacheable() const
+{
+ // This would require dealing with multiple clients for load callbacks.
+ if (!loadCompleted())
+ return false;
+ return maybeCacheable();
+}
+
void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
{
ASSERT(!rule->isCharsetRule());
@@ -344,6 +355,20 @@ bool StyleSheetContents::isLoading() const
return false;
}
+bool StyleSheetContents::loadCompleted() const
+{
+ StyleSheetContents* parentSheet = parentStyleSheet();
+ if (parentSheet)
+ return parentSheet->loadCompleted();
+
+ StyleSheetContents* root = rootStyleSheet();
+ for (unsigned i = 0; i < root->m_clients.size(); ++i) {
+ if (!m_clients[i]->loadCompleted())
+ return false;
+ }
+ return true;
+}
+
void StyleSheetContents::checkLoaded()
{
if (isLoading())
@@ -357,17 +382,28 @@ void StyleSheetContents::checkLoaded()
StyleSheetContents* parentSheet = parentStyleSheet();
if (parentSheet) {
parentSheet->checkLoaded();
- m_loadCompleted = true;
return;
}
- RefPtr<Node> ownerNode = singleOwnerNode();
- if (!ownerNode) {
- m_loadCompleted = true;
+
+ StyleSheetContents* root = rootStyleSheet();
+ if (root->m_clients.isEmpty())
return;
+
+ Vector<CSSStyleSheet*> clients(root->m_clients);
+ for (unsigned i = 0; i < clients.size(); ++i) {
+ CSSStyleSheet* client = clients[i];
+ if (client->loadCompleted())
+ continue;
+
+ RefPtr<Node> ownerNode = client->ownerNode();
+ if (ownerNode->sheetLoaded()) {
+ // Need to check whether the client is registered or not after sheetLoaded.
+ // Because sheetLoaded() might destroy CSSStyleSheet.
esprehn 2014/01/09 10:05:32 How does this happen?
tasak 2014/01/09 11:59:05 This is the same reason above (i.e. "RefPtr<StyleS
+ if (root->m_clients.contains(client))
+ client->completeLoading();
+ ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoadErrorOccur);
+ }
}
- m_loadCompleted = ownerNode->sheetLoaded();
- if (m_loadCompleted)
- ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoadErrorOccur);
}
void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet)
@@ -382,8 +418,9 @@ void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet)
void StyleSheetContents::startLoadingDynamicSheet()
{
- if (Node* owner = singleOwnerNode())
- owner->startLoadingDynamicSheet();
+ StyleSheetContents* root = rootStyleSheet();
+ for (unsigned i = 0; i < root->m_clients.size(); ++i)
+ root->m_clients[i]->startLoadingDynamicSheet();
}
StyleSheetContents* StyleSheetContents::rootStyleSheet() const

Powered by Google App Engine
This is Rietveld 408576698