| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 StyleElement::~StyleElement() | 57 StyleElement::~StyleElement() |
| 58 { | 58 { |
| 59 #if !ENABLE(OILPAN) | 59 #if !ENABLE(OILPAN) |
| 60 if (m_sheet) | 60 if (m_sheet) |
| 61 clearSheet(); | 61 clearSheet(); |
| 62 #endif | 62 #endif |
| 63 } | 63 } |
| 64 | 64 |
| 65 void StyleElement::processStyleSheet(Document& document, Element* element) | 65 StyleElement::ProcessingResult StyleElement::processStyleSheet(Document& documen
t, Element* element) |
| 66 { | 66 { |
| 67 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); | 67 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); |
| 68 ASSERT(element); | 68 ASSERT(element); |
| 69 ASSERT(element->inDocument()); | 69 ASSERT(element->inDocument()); |
| 70 | 70 |
| 71 m_registeredAsCandidate = true; | 71 m_registeredAsCandidate = true; |
| 72 document.styleEngine().addStyleSheetCandidateNode(element, m_createdByParser
); | 72 document.styleEngine().addStyleSheetCandidateNode(element, m_createdByParser
); |
| 73 if (m_createdByParser) | 73 if (m_createdByParser) |
| 74 return; | 74 return ProcessingSuccessful; |
| 75 | 75 |
| 76 process(element); | 76 return process(element); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void StyleElement::insertedInto(Element* element, ContainerNode* insertionPoint) | 79 void StyleElement::insertedInto(Element* element, ContainerNode* insertionPoint) |
| 80 { | 80 { |
| 81 if (!insertionPoint->inDocument() || !element->isInShadowTree()) | 81 if (!insertionPoint->inDocument() || !element->isInShadowTree()) |
| 82 return; | 82 return; |
| 83 if (ShadowRoot* scope = element->containingShadowRoot()) | 83 if (ShadowRoot* scope = element->containingShadowRoot()) |
| 84 scope->registerScopedHTMLStyleChild(); | 84 scope->registerScopedHTMLStyleChild(); |
| 85 } | 85 } |
| 86 | 86 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 114 { | 114 { |
| 115 if (m_sheet) | 115 if (m_sheet) |
| 116 m_sheet->clearOwnerNode(); | 116 m_sheet->clearOwnerNode(); |
| 117 | 117 |
| 118 if (m_registeredAsCandidate) { | 118 if (m_registeredAsCandidate) { |
| 119 ASSERT(element->inDocument()); | 119 ASSERT(element->inDocument()); |
| 120 document.styleEngine().removeStyleSheetCandidateNode(element, element->t
reeScope()); | 120 document.styleEngine().removeStyleSheetCandidateNode(element, element->t
reeScope()); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 void StyleElement::childrenChanged(Element* element) | 124 StyleElement::ProcessingResult StyleElement::childrenChanged(Element* element) |
| 125 { | 125 { |
| 126 ASSERT(element); | 126 ASSERT(element); |
| 127 if (m_createdByParser) | 127 if (m_createdByParser) |
| 128 return; | 128 return ProcessingSuccessful; |
| 129 | 129 |
| 130 process(element); | 130 return process(element); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void StyleElement::finishParsingChildren(Element* element) | 133 StyleElement::ProcessingResult StyleElement::finishParsingChildren(Element* elem
ent) |
| 134 { | 134 { |
| 135 ASSERT(element); | 135 ASSERT(element); |
| 136 process(element); | 136 ProcessingResult result = process(element); |
| 137 m_createdByParser = false; | 137 m_createdByParser = false; |
| 138 return result; |
| 138 } | 139 } |
| 139 | 140 |
| 140 void StyleElement::process(Element* element) | 141 StyleElement::ProcessingResult StyleElement::process(Element* element) |
| 141 { | 142 { |
| 142 if (!element || !element->inDocument()) | 143 if (!element || !element->inDocument()) |
| 143 return; | 144 return ProcessingSuccessful; |
| 144 createSheet(element, element->textFromChildren()); | 145 return createSheet(element, element->textFromChildren()); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void StyleElement::clearSheet(Element* ownerElement) | 148 void StyleElement::clearSheet(Element* ownerElement) |
| 148 { | 149 { |
| 149 ASSERT(m_sheet); | 150 ASSERT(m_sheet); |
| 150 | 151 |
| 151 if (ownerElement && m_sheet->isLoading()) | 152 if (ownerElement && m_sheet->isLoading()) |
| 152 ownerElement->document().styleEngine().removePendingSheet(ownerElement); | 153 ownerElement->document().styleEngine().removePendingSheet(ownerElement); |
| 153 | 154 |
| 154 m_sheet.release()->clearOwnerNode(); | 155 m_sheet.release()->clearOwnerNode(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 static bool shouldBypassMainWorldCSP(Element* element) | 158 static bool shouldBypassMainWorldCSP(Element* element) |
| 158 { | 159 { |
| 159 // Main world CSP is bypassed within an isolated world. | 160 // Main world CSP is bypassed within an isolated world. |
| 160 LocalFrame* frame = element->document().frame(); | 161 LocalFrame* frame = element->document().frame(); |
| 161 if (frame && frame->script().shouldBypassMainWorldCSP()) | 162 if (frame && frame->script().shouldBypassMainWorldCSP()) |
| 162 return true; | 163 return true; |
| 163 | 164 |
| 164 // Main world CSP is bypassed for style elements in user agent shadow DOM. | 165 // Main world CSP is bypassed for style elements in user agent shadow DOM. |
| 165 ShadowRoot* root = element->containingShadowRoot(); | 166 ShadowRoot* root = element->containingShadowRoot(); |
| 166 if (root && root->type() == ShadowRoot::ClosedShadowRoot) | 167 if (root && root->type() == ShadowRoot::ClosedShadowRoot) |
| 167 return true; | 168 return true; |
| 168 | 169 |
| 169 return false; | 170 return false; |
| 170 } | 171 } |
| 171 | 172 |
| 172 void StyleElement::createSheet(Element* e, const String& text) | 173 StyleElement::ProcessingResult StyleElement::createSheet(Element* e, const Strin
g& text) |
| 173 { | 174 { |
| 174 ASSERT(e); | 175 ASSERT(e); |
| 175 ASSERT(e->inDocument()); | 176 ASSERT(e->inDocument()); |
| 176 Document& document = e->document(); | 177 Document& document = e->document(); |
| 177 if (m_sheet) | 178 if (m_sheet) |
| 178 clearSheet(e); | 179 clearSheet(e); |
| 179 | 180 |
| 180 const ContentSecurityPolicy* csp = document.contentSecurityPolicy(); | 181 const ContentSecurityPolicy* csp = document.contentSecurityPolicy(); |
| 181 bool passesContentSecurityPolicyChecks = shouldBypassMainWorldCSP(e) | 182 bool passesContentSecurityPolicyChecks = shouldBypassMainWorldCSP(e) |
| 182 || csp->allowStyleWithHash(text) | 183 || csp->allowStyleWithHash(text) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 194 m_loading = true; | 195 m_loading = true; |
| 195 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; | 196 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; |
| 196 m_sheet = document.styleEngine().createSheet(e, text, startPosition,
m_createdByParser); | 197 m_sheet = document.styleEngine().createSheet(e, text, startPosition,
m_createdByParser); |
| 197 m_sheet->setMediaQueries(mediaQueries.release()); | 198 m_sheet->setMediaQueries(mediaQueries.release()); |
| 198 m_loading = false; | 199 m_loading = false; |
| 199 } | 200 } |
| 200 } | 201 } |
| 201 | 202 |
| 202 if (m_sheet) | 203 if (m_sheet) |
| 203 m_sheet->contents()->checkLoaded(); | 204 m_sheet->contents()->checkLoaded(); |
| 205 |
| 206 return passesContentSecurityPolicyChecks ? ProcessingSuccessful : Processing
FatalError; |
| 204 } | 207 } |
| 205 | 208 |
| 206 bool StyleElement::isLoading() const | 209 bool StyleElement::isLoading() const |
| 207 { | 210 { |
| 208 if (m_loading) | 211 if (m_loading) |
| 209 return true; | 212 return true; |
| 210 return m_sheet ? m_sheet->isLoading() : false; | 213 return m_sheet ? m_sheet->isLoading() : false; |
| 211 } | 214 } |
| 212 | 215 |
| 213 bool StyleElement::sheetLoaded(Document& document) | 216 bool StyleElement::sheetLoaded(Document& document) |
| 214 { | 217 { |
| 215 if (isLoading()) | 218 if (isLoading()) |
| 216 return false; | 219 return false; |
| 217 | 220 |
| 218 document.styleEngine().removePendingSheet(m_sheet->ownerNode()); | 221 document.styleEngine().removePendingSheet(m_sheet->ownerNode()); |
| 219 return true; | 222 return true; |
| 220 } | 223 } |
| 221 | 224 |
| 222 void StyleElement::startLoadingDynamicSheet(Document& document) | 225 void StyleElement::startLoadingDynamicSheet(Document& document) |
| 223 { | 226 { |
| 224 document.styleEngine().addPendingSheet(); | 227 document.styleEngine().addPendingSheet(); |
| 225 } | 228 } |
| 226 | 229 |
| 227 DEFINE_TRACE(StyleElement) | 230 DEFINE_TRACE(StyleElement) |
| 228 { | 231 { |
| 229 visitor->trace(m_sheet); | 232 visitor->trace(m_sheet); |
| 230 } | 233 } |
| 231 | 234 |
| 232 } | 235 } |
| OLD | NEW |