Chromium Code Reviews| Index: Source/core/dom/StyleElement.cpp |
| diff --git a/Source/core/dom/StyleElement.cpp b/Source/core/dom/StyleElement.cpp |
| index 6a6037c85f0ca3a36eec38648178e60bb09e0cfa..4652d5f67448e8232a48930c2cf007fd21aacfa0 100644 |
| --- a/Source/core/dom/StyleElement.cpp |
| +++ b/Source/core/dom/StyleElement.cpp |
| @@ -35,6 +35,8 @@ |
| namespace WebCore { |
| +static const unsigned cacheableTextContentSizeLimit = (unsigned)-1; // UNLIMITED |
|
esprehn
2013/10/30 21:33:50
Not used, remove this constant.
|
| + |
| static bool isCSS(Element* element, const AtomicString& type) |
| { |
| return type.isEmpty() || (element->isHTMLElement() ? equalIgnoringCase(type, "text/css") : (type == "text/css")); |
| @@ -115,7 +117,12 @@ void StyleElement::process(Element* element) |
| void StyleElement::clearSheet() |
| { |
| ASSERT(m_sheet); |
| + // If the sheet was cached one(=!m_sheetText.isEmpty()), the cached sheet has an owner document and |
| + // document is not destroyed (not in ~Document), we need to deref the cached item. |
| + if (!m_sheetText.isEmpty() && m_sheet->ownerDocument() && m_sheet->ownerDocument()->isActive()) |
| + m_sheet->ownerDocument()->styleEngine()->styleSheetContentsCache().remove(m_sheetText); |
|
esprehn
2013/10/30 21:33:50
I don't think you should need this.
|
| m_sheet.release()->clearOwnerNode(); |
| + m_sheetText = AtomicString(); |
|
esprehn
2013/10/30 21:33:50
You shouldn't need to store the string like this,
|
| } |
| void StyleElement::createSheet(Element* e, const String& text) |
| @@ -129,6 +136,9 @@ void StyleElement::createSheet(Element* e, const String& text) |
| clearSheet(); |
| } |
| + ASSERT(!isHTMLStyleElement(e) || m_sheetText.isEmpty()); |
| + AtomicString sheetText = isHTMLStyleElement(e) ? AtomicString(text.impl()) : AtomicString(); |
| + |
| // If type is empty or CSS, this is a CSS style sheet. |
| const AtomicString& type = this->type(); |
| bool passesContentSecurityPolicyChecks = document.contentSecurityPolicy()->allowStyleNonce(e->fastGetAttribute(HTMLNames::nonceAttr)) || document.contentSecurityPolicy()->allowInlineStyle(e->document().url(), m_startPosition.m_line); |
| @@ -142,17 +152,30 @@ void StyleElement::createSheet(Element* e, const String& text) |
| m_loading = true; |
| TextPosition startPosition = m_startPosition == TextPosition::belowRangePosition() ? TextPosition::minimumPosition() : m_startPosition; |
| - m_sheet = CSSStyleSheet::createInline(e, KURL(), startPosition, document.inputEncoding()); |
| - m_sheet->setMediaQueries(mediaQueries.release()); |
| - m_sheet->setTitle(e->title()); |
| - m_sheet->contents()->parseStringAtPosition(text, startPosition, m_createdByParser); |
| - |
| + if (StyleSheetContents* contents = document.styleEngine()->styleSheetContentsCache().find(sheetText)) { |
|
esprehn
2013/10/30 21:33:50
You should just always go through the cache and en
|
| + // FIXME: should we use registerClient to avoid allocating a new StyleSheetContents? |
| + // In this case, StyleSheetContents::singleOwnerNode() doesn't work. So need to modify |
| + // codes depending on singleOwnerNode(). |
| + m_sheet = CSSStyleSheet::createInline(contents->copy(), e, startPosition); |
|
esprehn
2013/10/30 21:33:50
Why are you creating a copy? That's bad.
tasak
2013/11/06 10:18:22
If we don't copy, 1 stylesheetcontents has multipl
|
| + m_sheet->setMediaQueries(mediaQueries.release()); |
| + m_sheet->setTitle(e->title()); |
| + } else { |
| + m_sheet = CSSStyleSheet::createInline(e, KURL(), startPosition, document.inputEncoding()); |
| + m_sheet->setMediaQueries(mediaQueries.release()); |
| + m_sheet->setTitle(e->title()); |
| + m_sheet->contents()->parseStringAtPosition(text, startPosition, m_createdByParser); |
| + } |
| m_loading = false; |
| } |
| } |
| - if (m_sheet) |
| + if (m_sheet) { |
| m_sheet->contents()->checkLoaded(); |
| + if (!sheetText.isEmpty() && m_sheet->contents()->isCacheable()) { |
| + m_sheetText = sheetText; |
| + document.styleEngine()->styleSheetContentsCache().add(m_sheetText, m_sheet->contents()); |
| + } |
|
esprehn
2013/10/30 21:33:50
Remove this, it should all be handled inside Style
tasak
2013/11/06 10:18:22
However, we only knows whether a given stylesheetc
|
| + } |
| } |
| bool StyleElement::isLoading() const |