| 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #include "config.h" | 21 #include "config.h" |
| 22 #include "core/dom/StyleElement.h" | 22 #include "core/dom/StyleElement.h" |
| 23 | 23 |
| 24 #include "bindings/v8/ScriptController.h" |
| 24 #include "core/css/MediaList.h" | 25 #include "core/css/MediaList.h" |
| 25 #include "core/css/MediaQueryEvaluator.h" | 26 #include "core/css/MediaQueryEvaluator.h" |
| 26 #include "core/css/StyleSheetContents.h" | 27 #include "core/css/StyleSheetContents.h" |
| 27 #include "core/dom/Document.h" | 28 #include "core/dom/Document.h" |
| 28 #include "core/dom/Element.h" | 29 #include "core/dom/Element.h" |
| 29 #include "core/dom/ScriptableDocumentParser.h" | 30 #include "core/dom/ScriptableDocumentParser.h" |
| 30 #include "core/dom/StyleEngine.h" | 31 #include "core/dom/StyleEngine.h" |
| 32 #include "core/frame/LocalFrame.h" |
| 31 #include "core/frame/csp/ContentSecurityPolicy.h" | 33 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 32 #include "core/html/HTMLStyleElement.h" | 34 #include "core/html/HTMLStyleElement.h" |
| 33 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
| 34 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
| 35 | 37 |
| 36 namespace WebCore { | 38 namespace WebCore { |
| 37 | 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")); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 142 } |
| 141 | 143 |
| 142 void StyleElement::createSheet(Element* e, const String& text) | 144 void StyleElement::createSheet(Element* e, const String& text) |
| 143 { | 145 { |
| 144 ASSERT(e); | 146 ASSERT(e); |
| 145 ASSERT(e->inDocument()); | 147 ASSERT(e->inDocument()); |
| 146 Document& document = e->document(); | 148 Document& document = e->document(); |
| 147 if (m_sheet) | 149 if (m_sheet) |
| 148 clearSheet(e); | 150 clearSheet(e); |
| 149 | 151 |
| 152 // Inline style added from an isolated world should bypass the main world's |
| 153 // CSP just as an inline script would. |
| 154 LocalFrame* frame = document.frame(); |
| 155 bool shouldBypassMainWorldContentSecurityPolicy = frame && frame->script().s
houldBypassMainWorldContentSecurityPolicy(); |
| 156 |
| 150 // If type is empty or CSS, this is a CSS style sheet. | 157 // If type is empty or CSS, this is a CSS style sheet. |
| 151 const AtomicString& type = this->type(); | 158 const AtomicString& type = this->type(); |
| 152 bool passesContentSecurityPolicyChecks = document.contentSecurityPolicy()->a
llowStyleHash(text) || document.contentSecurityPolicy()->allowStyleNonce(e->fast
GetAttribute(HTMLNames::nonceAttr)) || document.contentSecurityPolicy()->allowIn
lineStyle(e->document().url(), m_startPosition.m_line); | 159 bool passesContentSecurityPolicyChecks = shouldBypassMainWorldContentSecurit
yPolicy || document.contentSecurityPolicy()->allowStyleHash(text) || document.co
ntentSecurityPolicy()->allowStyleNonce(e->fastGetAttribute(HTMLNames::nonceAttr)
) || document.contentSecurityPolicy()->allowInlineStyle(e->document().url(), m_s
tartPosition.m_line); |
| 153 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { | 160 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { |
| 154 RefPtrWillBeRawPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(m
edia()); | 161 RefPtrWillBeRawPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(m
edia()); |
| 155 | 162 |
| 156 MediaQueryEvaluator screenEval("screen", true); | 163 MediaQueryEvaluator screenEval("screen", true); |
| 157 MediaQueryEvaluator printEval("print", true); | 164 MediaQueryEvaluator printEval("print", true); |
| 158 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { | 165 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { |
| 159 m_loading = true; | 166 m_loading = true; |
| 160 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; | 167 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; |
| 161 m_sheet = document.styleEngine()->createSheet(e, text, startPosition
, m_createdByParser); | 168 m_sheet = document.styleEngine()->createSheet(e, text, startPosition
, m_createdByParser); |
| 162 m_sheet->setMediaQueries(mediaQueries.release()); | 169 m_sheet->setMediaQueries(mediaQueries.release()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 188 { | 195 { |
| 189 document.styleEngine()->addPendingSheet(); | 196 document.styleEngine()->addPendingSheet(); |
| 190 } | 197 } |
| 191 | 198 |
| 192 void StyleElement::trace(Visitor* visitor) | 199 void StyleElement::trace(Visitor* visitor) |
| 193 { | 200 { |
| 194 visitor->trace(m_sheet); | 201 visitor->trace(m_sheet); |
| 195 } | 202 } |
| 196 | 203 |
| 197 } | 204 } |
| OLD | NEW |