| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Rob Buis | 2 * Copyright (C) 2006, 2007 Rob Buis |
| 3 * Copyright (C) 2008 Apple, Inc. All rights reserved. | 3 * Copyright (C) 2008 Apple, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "core/dom/Element.h" | 28 #include "core/dom/Element.h" |
| 29 #include "core/dom/ScriptableDocumentParser.h" | 29 #include "core/dom/ScriptableDocumentParser.h" |
| 30 #include "core/dom/StyleEngine.h" | 30 #include "core/dom/StyleEngine.h" |
| 31 #include "core/html/HTMLStyleElement.h" | 31 #include "core/html/HTMLStyleElement.h" |
| 32 #include "core/frame/ContentSecurityPolicy.h" | 32 #include "core/frame/ContentSecurityPolicy.h" |
| 33 #include "wtf/text/StringBuilder.h" | 33 #include "wtf/text/StringBuilder.h" |
| 34 #include "wtf/text/TextPosition.h" | 34 #include "wtf/text/TextPosition.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 static const unsigned cacheableTextContentSizeLimit = (unsigned)-1; // UNLIMITED |
| 39 |
| 38 static bool isCSS(Element* element, const AtomicString& type) | 40 static bool isCSS(Element* element, const AtomicString& type) |
| 39 { | 41 { |
| 40 return type.isEmpty() || (element->isHTMLElement() ? equalIgnoringCase(type,
"text/css") : (type == "text/css")); | 42 return type.isEmpty() || (element->isHTMLElement() ? equalIgnoringCase(type,
"text/css") : (type == "text/css")); |
| 41 } | 43 } |
| 42 | 44 |
| 43 StyleElement::StyleElement(Document* document, bool createdByParser) | 45 StyleElement::StyleElement(Document* document, bool createdByParser) |
| 44 : m_createdByParser(createdByParser) | 46 : m_createdByParser(createdByParser) |
| 45 , m_loading(false) | 47 , m_loading(false) |
| 46 , m_startPosition(TextPosition::belowRangePosition()) | 48 , m_startPosition(TextPosition::belowRangePosition()) |
| 47 { | 49 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 void StyleElement::process(Element* element) | 110 void StyleElement::process(Element* element) |
| 109 { | 111 { |
| 110 if (!element || !element->inDocument()) | 112 if (!element || !element->inDocument()) |
| 111 return; | 113 return; |
| 112 createSheet(element, element->textFromChildren()); | 114 createSheet(element, element->textFromChildren()); |
| 113 } | 115 } |
| 114 | 116 |
| 115 void StyleElement::clearSheet() | 117 void StyleElement::clearSheet() |
| 116 { | 118 { |
| 117 ASSERT(m_sheet); | 119 ASSERT(m_sheet); |
| 120 // If the sheet was cached one(=!m_sheetText.isEmpty()), the cached sheet ha
s an owner document and |
| 121 // document is not destroyed (not in ~Document), we need to unregister. |
| 122 if (!m_sheetText.isEmpty() && m_sheet->ownerDocument() && m_sheet->ownerDocu
ment()->isActive()) |
| 123 m_sheet->ownerDocument()->styleEngine()->unregisterStyleSheetContents(m_
sheetText); |
| 118 m_sheet.release()->clearOwnerNode(); | 124 m_sheet.release()->clearOwnerNode(); |
| 125 m_sheetText = AtomicString(); |
| 119 } | 126 } |
| 120 | 127 |
| 121 void StyleElement::createSheet(Element* e, const String& text) | 128 void StyleElement::createSheet(Element* e, const String& text) |
| 122 { | 129 { |
| 123 ASSERT(e); | 130 ASSERT(e); |
| 124 ASSERT(e->inDocument()); | 131 ASSERT(e->inDocument()); |
| 125 Document& document = e->document(); | 132 Document& document = e->document(); |
| 126 if (m_sheet) { | 133 if (m_sheet) { |
| 127 if (m_sheet->isLoading()) | 134 if (m_sheet->isLoading()) |
| 128 document.styleEngine()->removePendingSheet(e); | 135 document.styleEngine()->removePendingSheet(e); |
| 129 clearSheet(); | 136 clearSheet(); |
| 130 } | 137 } |
| 131 | 138 |
| 139 ASSERT(!isHTMLStyleElement(e) || m_sheetText.isEmpty()); |
| 140 AtomicString sheetText = isHTMLStyleElement(e) ? AtomicString(text.impl()) :
AtomicString(); |
| 141 |
| 132 // If type is empty or CSS, this is a CSS style sheet. | 142 // If type is empty or CSS, this is a CSS style sheet. |
| 133 const AtomicString& type = this->type(); | 143 const AtomicString& type = this->type(); |
| 134 bool passesContentSecurityPolicyChecks = document.contentSecurityPolicy()->a
llowStyleNonce(e->fastGetAttribute(HTMLNames::nonceAttr)) || document.contentSec
urityPolicy()->allowInlineStyle(e->document().url(), m_startPosition.m_line); | 144 bool passesContentSecurityPolicyChecks = document.contentSecurityPolicy()->a
llowStyleNonce(e->fastGetAttribute(HTMLNames::nonceAttr)) || document.contentSec
urityPolicy()->allowInlineStyle(e->document().url(), m_startPosition.m_line); |
| 135 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { | 145 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { |
| 136 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); | 146 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); |
| 137 | 147 |
| 138 MediaQueryEvaluator screenEval("screen", true); | 148 MediaQueryEvaluator screenEval("screen", true); |
| 139 MediaQueryEvaluator printEval("print", true); | 149 MediaQueryEvaluator printEval("print", true); |
| 140 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { | 150 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { |
| 141 document.styleEngine()->addPendingSheet(); | 151 document.styleEngine()->addPendingSheet(); |
| 142 m_loading = true; | 152 m_loading = true; |
| 143 | 153 |
| 144 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; | 154 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; |
| 145 m_sheet = CSSStyleSheet::createInline(e, KURL(), startPosition, docu
ment.inputEncoding()); | 155 if (StyleSheetContents* contents = document.styleEngine()->findStyle
SheetContents(sheetText)) { |
| 146 m_sheet->setMediaQueries(mediaQueries.release()); | 156 // FIXME: should we use registerClient to avoid allocating a new
StyleSheetContents? |
| 147 m_sheet->setTitle(e->title()); | 157 // In this case, StyleSheetContents::singleOwnerNode() doesn't w
ork. So need to modify |
| 148 m_sheet->contents()->parseStringAtPosition(text, startPosition, m_cr
eatedByParser); | 158 // codes depending on singleOwnerNode(). |
| 149 | 159 m_sheet = CSSStyleSheet::createInline(contents->copy(), e, start
Position); |
| 160 m_sheet->setMediaQueries(mediaQueries.release()); |
| 161 m_sheet->setTitle(e->title()); |
| 162 } else { |
| 163 m_sheet = CSSStyleSheet::createInline(e, KURL(), startPosition,
document.inputEncoding()); |
| 164 m_sheet->setMediaQueries(mediaQueries.release()); |
| 165 m_sheet->setTitle(e->title()); |
| 166 m_sheet->contents()->parseStringAtPosition(text, startPosition,
m_createdByParser); |
| 167 } |
| 150 m_loading = false; | 168 m_loading = false; |
| 151 } | 169 } |
| 152 } | 170 } |
| 153 | 171 |
| 154 if (m_sheet) | 172 if (m_sheet) { |
| 155 m_sheet->contents()->checkLoaded(); | 173 m_sheet->contents()->checkLoaded(); |
| 174 if (!sheetText.isEmpty() && m_sheet->contents()->isCacheable()) { |
| 175 m_sheetText = sheetText; |
| 176 document.styleEngine()->registerStyleSheetContents(m_sheetText, m_sh
eet->contents()); |
| 177 } |
| 178 } |
| 156 } | 179 } |
| 157 | 180 |
| 158 bool StyleElement::isLoading() const | 181 bool StyleElement::isLoading() const |
| 159 { | 182 { |
| 160 if (m_loading) | 183 if (m_loading) |
| 161 return true; | 184 return true; |
| 162 return m_sheet ? m_sheet->isLoading() : false; | 185 return m_sheet ? m_sheet->isLoading() : false; |
| 163 } | 186 } |
| 164 | 187 |
| 165 bool StyleElement::sheetLoaded(Document& document) | 188 bool StyleElement::sheetLoaded(Document& document) |
| 166 { | 189 { |
| 167 if (isLoading()) | 190 if (isLoading()) |
| 168 return false; | 191 return false; |
| 169 | 192 |
| 170 document.styleEngine()->removePendingSheet(m_sheet->ownerNode()); | 193 document.styleEngine()->removePendingSheet(m_sheet->ownerNode()); |
| 171 return true; | 194 return true; |
| 172 } | 195 } |
| 173 | 196 |
| 174 void StyleElement::startLoadingDynamicSheet(Document& document) | 197 void StyleElement::startLoadingDynamicSheet(Document& document) |
| 175 { | 198 { |
| 176 document.styleEngine()->addPendingSheet(); | 199 document.styleEngine()->addPendingSheet(); |
| 177 } | 200 } |
| 178 | 201 |
| 179 } | 202 } |
| OLD | NEW |