| Index: Source/core/dom/StyleElement.cpp
|
| diff --git a/Source/core/dom/StyleElement.cpp b/Source/core/dom/StyleElement.cpp
|
| index 6a6037c85f0ca3a36eec38648178e60bb09e0cfa..97605624bb69348ae9f5835469ea371489b4d05e 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
|
| +
|
| 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 unregister.
|
| + if (!m_sheetText.isEmpty() && m_sheet->ownerDocument() && m_sheet->ownerDocument()->isActive())
|
| + m_sheet->ownerDocument()->styleEngine()->unregisterStyleSheetContents(m_sheetText);
|
| m_sheet.release()->clearOwnerNode();
|
| + m_sheetText = AtomicString();
|
| }
|
|
|
| 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()->findStyleSheetContents(sheetText)) {
|
| + // 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);
|
| + 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()->registerStyleSheetContents(m_sheetText, m_sheet->contents());
|
| + }
|
| + }
|
| }
|
|
|
| bool StyleElement::isLoading() const
|
|
|