| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 { | 57 { |
| 58 #if !ENABLE(OILPAN) | 58 #if !ENABLE(OILPAN) |
| 59 if (m_sheet) | 59 if (m_sheet) |
| 60 clearSheet(); | 60 clearSheet(); |
| 61 #endif | 61 #endif |
| 62 } | 62 } |
| 63 | 63 |
| 64 StyleElement::ProcessingResult StyleElement::processStyleSheet(Document& documen
t, Element* element) | 64 StyleElement::ProcessingResult StyleElement::processStyleSheet(Document& documen
t, Element* element) |
| 65 { | 65 { |
| 66 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); | 66 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); |
| 67 ASSERT(element); | 67 DCHECK(element); |
| 68 ASSERT(element->inShadowIncludingDocument()); | 68 DCHECK(element->inShadowIncludingDocument()); |
| 69 | 69 |
| 70 m_registeredAsCandidate = true; | 70 m_registeredAsCandidate = true; |
| 71 document.styleEngine().addStyleSheetCandidateNode(element); | 71 document.styleEngine().addStyleSheetCandidateNode(element); |
| 72 if (m_createdByParser) | 72 if (m_createdByParser) |
| 73 return ProcessingSuccessful; | 73 return ProcessingSuccessful; |
| 74 | 74 |
| 75 return process(element); | 75 return process(element); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void StyleElement::insertedInto(Element* element, ContainerNode* insertionPoint) | 78 void StyleElement::insertedInto(Element* element, ContainerNode* insertionPoint) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 108 if (removedSheet) | 108 if (removedSheet) |
| 109 document.styleEngine().setNeedsActiveStyleUpdate(removedSheet.get(), Ana
lyzedStyleUpdate); | 109 document.styleEngine().setNeedsActiveStyleUpdate(removedSheet.get(), Ana
lyzedStyleUpdate); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void StyleElement::clearDocumentData(Document& document, Element* element) | 112 void StyleElement::clearDocumentData(Document& document, Element* element) |
| 113 { | 113 { |
| 114 if (m_sheet) | 114 if (m_sheet) |
| 115 m_sheet->clearOwnerNode(); | 115 m_sheet->clearOwnerNode(); |
| 116 | 116 |
| 117 if (m_registeredAsCandidate) { | 117 if (m_registeredAsCandidate) { |
| 118 ASSERT(element->inShadowIncludingDocument()); | 118 DCHECK(element->inShadowIncludingDocument()); |
| 119 document.styleEngine().removeStyleSheetCandidateNode(element, element->t
reeScope()); | 119 document.styleEngine().removeStyleSheetCandidateNode(element, element->t
reeScope()); |
| 120 m_registeredAsCandidate = false; | 120 m_registeredAsCandidate = false; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 StyleElement::ProcessingResult StyleElement::childrenChanged(Element* element) | 124 StyleElement::ProcessingResult StyleElement::childrenChanged(Element* element) |
| 125 { | 125 { |
| 126 ASSERT(element); | 126 DCHECK(element); |
| 127 if (m_createdByParser) | 127 if (m_createdByParser) |
| 128 return ProcessingSuccessful; | 128 return ProcessingSuccessful; |
| 129 | 129 |
| 130 return process(element); | 130 return process(element); |
| 131 } | 131 } |
| 132 | 132 |
| 133 StyleElement::ProcessingResult StyleElement::finishParsingChildren(Element* elem
ent) | 133 StyleElement::ProcessingResult StyleElement::finishParsingChildren(Element* elem
ent) |
| 134 { | 134 { |
| 135 ASSERT(element); | 135 DCHECK(element); |
| 136 ProcessingResult result = process(element); | 136 ProcessingResult result = process(element); |
| 137 m_createdByParser = false; | 137 m_createdByParser = false; |
| 138 return result; | 138 return result; |
| 139 } | 139 } |
| 140 | 140 |
| 141 StyleElement::ProcessingResult StyleElement::process(Element* element) | 141 StyleElement::ProcessingResult StyleElement::process(Element* element) |
| 142 { | 142 { |
| 143 if (!element || !element->inShadowIncludingDocument()) | 143 if (!element || !element->inShadowIncludingDocument()) |
| 144 return ProcessingSuccessful; | 144 return ProcessingSuccessful; |
| 145 return createSheet(element, element->textFromChildren()); | 145 return createSheet(element, element->textFromChildren()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void StyleElement::clearSheet(Element* ownerElement) | 148 void StyleElement::clearSheet(Element* ownerElement) |
| 149 { | 149 { |
| 150 ASSERT(m_sheet); | 150 DCHECK(m_sheet); |
| 151 | 151 |
| 152 if (ownerElement && m_sheet->isLoading()) | 152 if (ownerElement && m_sheet->isLoading()) |
| 153 ownerElement->document().styleEngine().removePendingSheet(ownerElement); | 153 ownerElement->document().styleEngine().removePendingSheet(ownerElement); |
| 154 | 154 |
| 155 m_sheet.release()->clearOwnerNode(); | 155 m_sheet.release()->clearOwnerNode(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 static bool shouldBypassMainWorldCSP(Element* element) | 158 static bool shouldBypassMainWorldCSP(Element* element) |
| 159 { | 159 { |
| 160 // Main world CSP is bypassed within an isolated world. | 160 // Main world CSP is bypassed within an isolated world. |
| 161 LocalFrame* frame = element->document().frame(); | 161 LocalFrame* frame = element->document().frame(); |
| 162 if (frame && frame->script().shouldBypassMainWorldCSP()) | 162 if (frame && frame->script().shouldBypassMainWorldCSP()) |
| 163 return true; | 163 return true; |
| 164 | 164 |
| 165 // 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. |
| 166 ShadowRoot* root = element->containingShadowRoot(); | 166 ShadowRoot* root = element->containingShadowRoot(); |
| 167 if (root && root->type() == ShadowRootType::UserAgent) | 167 if (root && root->type() == ShadowRootType::UserAgent) |
| 168 return true; | 168 return true; |
| 169 | 169 |
| 170 return false; | 170 return false; |
| 171 } | 171 } |
| 172 | 172 |
| 173 StyleElement::ProcessingResult StyleElement::createSheet(Element* e, const Strin
g& text) | 173 StyleElement::ProcessingResult StyleElement::createSheet(Element* e, const Strin
g& text) |
| 174 { | 174 { |
| 175 ASSERT(e); | 175 DCHECK(e); |
| 176 ASSERT(e->inShadowIncludingDocument()); | 176 DCHECK(e->inShadowIncludingDocument()); |
| 177 Document& document = e->document(); | 177 Document& document = e->document(); |
| 178 | 178 |
| 179 const ContentSecurityPolicy* csp = document.contentSecurityPolicy(); | 179 const ContentSecurityPolicy* csp = document.contentSecurityPolicy(); |
| 180 bool passesContentSecurityPolicyChecks = shouldBypassMainWorldCSP(e) | 180 bool passesContentSecurityPolicyChecks = shouldBypassMainWorldCSP(e) |
| 181 || csp->allowStyleWithHash(text) | 181 || csp->allowStyleWithHash(text) |
| 182 || csp->allowStyleWithNonce(e->fastGetAttribute(HTMLNames::nonceAttr)) | 182 || csp->allowStyleWithNonce(e->fastGetAttribute(HTMLNames::nonceAttr)) |
| 183 || csp->allowInlineStyle(e->document().url(), m_startPosition.m_line, te
xt); | 183 || csp->allowInlineStyle(e->document().url(), m_startPosition.m_line, te
xt); |
| 184 | 184 |
| 185 // Clearing the current sheet may remove the cache entry so create the new s
heet first | 185 // Clearing the current sheet may remove the cache entry so create the new s
heet first |
| 186 RawPtr<CSSStyleSheet> newSheet = nullptr; | 186 RawPtr<CSSStyleSheet> newSheet = nullptr; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 { | 231 { |
| 232 document.styleEngine().addPendingSheet(); | 232 document.styleEngine().addPendingSheet(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 DEFINE_TRACE(StyleElement) | 235 DEFINE_TRACE(StyleElement) |
| 236 { | 236 { |
| 237 visitor->trace(m_sheet); | 237 visitor->trace(m_sheet); |
| 238 } | 238 } |
| 239 | 239 |
| 240 } // namespace blink | 240 } // namespace blink |
| OLD | NEW |