Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 static bool isCSS(Element* element, const AtomicString& type) | 41 static bool isCSS(Element* element, const AtomicString& type) |
| 42 { | 42 { |
| 43 return type.isEmpty() || (element->isHTMLElement() ? equalIgnoringCase(type, "text/css") : (type == "text/css")); | 43 return type.isEmpty() || (element->isHTMLElement() ? equalIgnoringCase(type, "text/css") : (type == "text/css")); |
| 44 } | 44 } |
| 45 | 45 |
| 46 StyleElement::StyleElement(Document* document, bool createdByParser) | 46 StyleElement::StyleElement(Document* document, bool createdByParser) |
| 47 : m_createdByParser(createdByParser) | 47 : m_createdByParser(createdByParser) |
| 48 , m_loading(false) | 48 , m_loading(false) |
| 49 , m_registeredAsCandidate(false) | 49 , m_registeredAsCandidate(false) |
| 50 , m_beforeBody(false) | |
| 50 , m_startPosition(TextPosition::belowRangePosition()) | 51 , m_startPosition(TextPosition::belowRangePosition()) |
| 51 { | 52 { |
| 52 if (createdByParser && document && document->scriptableDocumentParser() && ! document->isInDocumentWrite()) | 53 if (createdByParser && document && document->scriptableDocumentParser() && ! document->isInDocumentWrite()) |
| 53 m_startPosition = document->scriptableDocumentParser()->textPosition(); | 54 m_startPosition = document->scriptableDocumentParser()->textPosition(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 StyleElement::~StyleElement() | 57 StyleElement::~StyleElement() |
| 57 { | 58 { |
| 58 } | 59 } |
| 59 | 60 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 if (!element || !element->inShadowIncludingDocument()) | 140 if (!element || !element->inShadowIncludingDocument()) |
| 140 return ProcessingSuccessful; | 141 return ProcessingSuccessful; |
| 141 return createSheet(element, element->textFromChildren()); | 142 return createSheet(element, element->textFromChildren()); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void StyleElement::clearSheet(Element* ownerElement) | 145 void StyleElement::clearSheet(Element* ownerElement) |
| 145 { | 146 { |
| 146 DCHECK(m_sheet); | 147 DCHECK(m_sheet); |
| 147 | 148 |
| 148 if (ownerElement && m_sheet->isLoading()) | 149 if (ownerElement && m_sheet->isLoading()) |
| 149 ownerElement->document().styleEngine().removePendingSheet(ownerElement); | 150 ownerElement->document().styleEngine().removePendingSheet(ownerElement, m_beforeBody); |
| 150 | 151 |
| 151 m_sheet.release()->clearOwnerNode(); | 152 m_sheet.release()->clearOwnerNode(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 static bool shouldBypassMainWorldCSP(Element* element) | 155 static bool shouldBypassMainWorldCSP(Element* element) |
| 155 { | 156 { |
| 156 // Main world CSP is bypassed within an isolated world. | 157 // Main world CSP is bypassed within an isolated world. |
| 157 LocalFrame* frame = element->document().frame(); | 158 LocalFrame* frame = element->document().frame(); |
| 158 if (frame && frame->script().shouldBypassMainWorldCSP()) | 159 if (frame && frame->script().shouldBypassMainWorldCSP()) |
| 159 return true; | 160 return true; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 184 // If type is empty or CSS, this is a CSS style sheet. | 185 // If type is empty or CSS, this is a CSS style sheet. |
| 185 const AtomicString& type = this->type(); | 186 const AtomicString& type = this->type(); |
| 186 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { | 187 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { |
| 187 MediaQuerySet* mediaQueries = MediaQuerySet::create(media()); | 188 MediaQuerySet* mediaQueries = MediaQuerySet::create(media()); |
| 188 | 189 |
| 189 MediaQueryEvaluator screenEval("screen", true); | 190 MediaQueryEvaluator screenEval("screen", true); |
| 190 MediaQueryEvaluator printEval("print", true); | 191 MediaQueryEvaluator printEval("print", true); |
| 191 if (screenEval.eval(mediaQueries) || printEval.eval(mediaQueries)) { | 192 if (screenEval.eval(mediaQueries) || printEval.eval(mediaQueries)) { |
| 192 m_loading = true; | 193 m_loading = true; |
| 193 TextPosition startPosition = m_startPosition == TextPosition::belowR angePosition() ? TextPosition::minimumPosition() : m_startPosition; | 194 TextPosition startPosition = m_startPosition == TextPosition::belowR angePosition() ? TextPosition::minimumPosition() : m_startPosition; |
| 194 newSheet = document.styleEngine().createSheet(e, text, startPosition ); | 195 m_beforeBody = m_beforeBody || !document.body(); |
|
esprehn
2016/05/06 21:50:15
Can we move this into the StyleEngine instead?
Pat Meenan
2016/05/09 18:51:05
The main issue is that we need to keep track of if
| |
| 196 newSheet = document.styleEngine().createSheet(e, text, startPosition , m_beforeBody); | |
| 195 newSheet->setMediaQueries(mediaQueries); | 197 newSheet->setMediaQueries(mediaQueries); |
| 196 m_loading = false; | 198 m_loading = false; |
| 197 } | 199 } |
| 198 } | 200 } |
| 199 | 201 |
| 200 if (m_sheet) | 202 if (m_sheet) |
| 201 clearSheet(e); | 203 clearSheet(e); |
| 202 | 204 |
| 203 m_sheet = newSheet; | 205 m_sheet = newSheet; |
| 204 if (m_sheet) | 206 if (m_sheet) |
| 205 m_sheet->contents()->checkLoaded(); | 207 m_sheet->contents()->checkLoaded(); |
| 206 | 208 |
| 207 return passesContentSecurityPolicyChecks ? ProcessingSuccessful : Processing FatalError; | 209 return passesContentSecurityPolicyChecks ? ProcessingSuccessful : Processing FatalError; |
| 208 } | 210 } |
| 209 | 211 |
| 210 bool StyleElement::isLoading() const | 212 bool StyleElement::isLoading() const |
| 211 { | 213 { |
| 212 if (m_loading) | 214 if (m_loading) |
| 213 return true; | 215 return true; |
| 214 return m_sheet ? m_sheet->isLoading() : false; | 216 return m_sheet ? m_sheet->isLoading() : false; |
| 215 } | 217 } |
| 216 | 218 |
| 217 bool StyleElement::sheetLoaded(Document& document) | 219 bool StyleElement::sheetLoaded(Document& document) |
| 218 { | 220 { |
| 219 if (isLoading()) | 221 if (isLoading()) |
| 220 return false; | 222 return false; |
| 221 | 223 |
| 222 document.styleEngine().removePendingSheet(m_sheet->ownerNode()); | 224 document.styleEngine().removePendingSheet(m_sheet->ownerNode(), m_beforeBody ); |
| 223 return true; | 225 return true; |
| 224 } | 226 } |
| 225 | 227 |
| 226 void StyleElement::startLoadingDynamicSheet(Document& document) | 228 void StyleElement::startLoadingDynamicSheet(Document& document) |
| 227 { | 229 { |
| 228 document.styleEngine().addPendingSheet(); | 230 m_beforeBody = m_beforeBody || !document.body(); |
| 231 document.styleEngine().addPendingSheet(m_beforeBody); | |
| 229 } | 232 } |
| 230 | 233 |
| 231 DEFINE_TRACE(StyleElement) | 234 DEFINE_TRACE(StyleElement) |
| 232 { | 235 { |
| 233 visitor->trace(m_sheet); | 236 visitor->trace(m_sheet); |
| 234 } | 237 } |
| 235 | 238 |
| 236 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |