OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2006, 2007, 2012 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 , m_hasFontFaceRule(false) | 68 , m_hasFontFaceRule(false) |
69 , m_hasMediaQueries(false) | 69 , m_hasMediaQueries(false) |
70 , m_hasSingleOwnerDocument(true) | 70 , m_hasSingleOwnerDocument(true) |
71 , m_parserContext(context) | 71 , m_parserContext(context) |
72 { | 72 { |
73 } | 73 } |
74 | 74 |
75 StyleSheetContents::StyleSheetContents(const StyleSheetContents& o) | 75 StyleSheetContents::StyleSheetContents(const StyleSheetContents& o) |
76 : m_ownerRule(nullptr) | 76 : m_ownerRule(nullptr) |
77 , m_originalURL(o.m_originalURL) | 77 , m_originalURL(o.m_originalURL) |
78 , m_encodingFromCharsetRule(o.m_encodingFromCharsetRule) | |
79 , m_importRules(o.m_importRules.size()) | 78 , m_importRules(o.m_importRules.size()) |
80 , m_childRules(o.m_childRules.size()) | 79 , m_childRules(o.m_childRules.size()) |
81 , m_namespaces(o.m_namespaces) | 80 , m_namespaces(o.m_namespaces) |
82 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) | 81 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) |
83 , m_didLoadErrorOccur(false) | 82 , m_didLoadErrorOccur(false) |
84 , m_usesRemUnits(o.m_usesRemUnits) | 83 , m_usesRemUnits(o.m_usesRemUnits) |
85 , m_isMutable(false) | 84 , m_isMutable(false) |
86 , m_isInMemoryCache(false) | 85 , m_isInMemoryCache(false) |
87 , m_hasFontFaceRule(o.m_hasFontFaceRule) | 86 , m_hasFontFaceRule(o.m_hasFontFaceRule) |
88 , m_hasMediaQueries(o.m_hasMediaQueries) | 87 , m_hasMediaQueries(o.m_hasMediaQueries) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return false; | 138 return false; |
140 // If the header is valid we are not going to need to check the SecurityOrig
in. | 139 // If the header is valid we are not going to need to check the SecurityOrig
in. |
141 // FIXME: Valid mime type avoids the check too. | 140 // FIXME: Valid mime type avoids the check too. |
142 if (!m_hasSyntacticallyValidCSSHeader) | 141 if (!m_hasSyntacticallyValidCSSHeader) |
143 return false; | 142 return false; |
144 return true; | 143 return true; |
145 } | 144 } |
146 | 145 |
147 void StyleSheetContents::parserAppendRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule) | 146 void StyleSheetContents::parserAppendRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule) |
148 { | 147 { |
149 ASSERT(!rule->isCharsetRule()); | |
150 if (rule->isImportRule()) { | 148 if (rule->isImportRule()) { |
151 // Parser enforces that @import rules come before anything else except @
charset. | 149 // Parser enforces that @import rules come before anything else |
152 ASSERT(m_childRules.isEmpty()); | 150 ASSERT(m_childRules.isEmpty()); |
153 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); | 151 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); |
154 if (importRule->mediaQueries()) | 152 if (importRule->mediaQueries()) |
155 setHasMediaQueries(); | 153 setHasMediaQueries(); |
156 m_importRules.append(importRule); | 154 m_importRules.append(importRule); |
157 m_importRules.last()->setParentStyleSheet(this); | 155 m_importRules.last()->setParentStyleSheet(this); |
158 m_importRules.last()->requestStyleSheet(); | 156 m_importRules.last()->requestStyleSheet(); |
159 return; | 157 return; |
160 } | 158 } |
161 | 159 |
(...skipping 10 matching lines...) Expand all Loading... |
172 { | 170 { |
173 m_hasMediaQueries = true; | 171 m_hasMediaQueries = true; |
174 if (parentStyleSheet()) | 172 if (parentStyleSheet()) |
175 parentStyleSheet()->setHasMediaQueries(); | 173 parentStyleSheet()->setHasMediaQueries(); |
176 } | 174 } |
177 | 175 |
178 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const | 176 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const |
179 { | 177 { |
180 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 178 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
181 | 179 |
182 unsigned childVectorIndex = index; | 180 if (index < m_importRules.size()) |
183 if (hasCharsetRule()) { | 181 return m_importRules[index].get(); |
184 if (index == 0) | |
185 return 0; | |
186 --childVectorIndex; | |
187 } | |
188 if (childVectorIndex < m_importRules.size()) | |
189 return m_importRules[childVectorIndex].get(); | |
190 | 182 |
191 childVectorIndex -= m_importRules.size(); | 183 index -= m_importRules.size(); |
192 return m_childRules[childVectorIndex].get(); | 184 return m_childRules[index].get(); |
193 } | 185 } |
194 | 186 |
195 unsigned StyleSheetContents::ruleCount() const | 187 unsigned StyleSheetContents::ruleCount() const |
196 { | 188 { |
197 unsigned result = 0; | 189 return m_importRules.size() + m_childRules.size(); |
198 result += hasCharsetRule() ? 1 : 0; | |
199 result += m_importRules.size(); | |
200 result += m_childRules.size(); | |
201 return result; | |
202 } | |
203 | |
204 void StyleSheetContents::clearCharsetRule() | |
205 { | |
206 m_encodingFromCharsetRule = String(); | |
207 } | 190 } |
208 | 191 |
209 void StyleSheetContents::clearRules() | 192 void StyleSheetContents::clearRules() |
210 { | 193 { |
211 for (unsigned i = 0; i < m_importRules.size(); ++i) { | 194 for (unsigned i = 0; i < m_importRules.size(); ++i) { |
212 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); | 195 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); |
213 m_importRules[i]->clearParentStyleSheet(); | 196 m_importRules[i]->clearParentStyleSheet(); |
214 } | 197 } |
215 m_importRules.clear(); | 198 m_importRules.clear(); |
216 m_childRules.clear(); | 199 m_childRules.clear(); |
217 clearCharsetRule(); | |
218 } | |
219 | |
220 void StyleSheetContents::parserSetEncodingFromCharsetRule(const String& encoding
) | |
221 { | |
222 // Parser enforces that there is ever only one @charset. | |
223 ASSERT(m_encodingFromCharsetRule.isNull()); | |
224 m_encodingFromCharsetRule = encoding; | |
225 } | 200 } |
226 | 201 |
227 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule, unsigned index) | 202 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule, unsigned index) |
228 { | 203 { |
229 ASSERT(m_isMutable); | 204 ASSERT(m_isMutable); |
230 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); | 205 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); |
231 // Parser::parseRule doesn't currently allow @charset so we don't need to de
al with it. | |
232 ASSERT(!rule->isCharsetRule()); | |
233 | 206 |
234 unsigned childVectorIndex = index; | 207 if (index < m_importRules.size() || (index == m_importRules.size() && rule->
isImportRule())) { |
235 // m_childRules does not contain @charset which is always in index 0 if it e
xists. | |
236 if (hasCharsetRule()) { | |
237 if (childVectorIndex == 0) { | |
238 // Nothing can be inserted before @charset. | |
239 return false; | |
240 } | |
241 --childVectorIndex; | |
242 } | |
243 | |
244 if (childVectorIndex < m_importRules.size() || (childVectorIndex == m_import
Rules.size() && rule->isImportRule())) { | |
245 // Inserting non-import rule before @import is not allowed. | 208 // Inserting non-import rule before @import is not allowed. |
246 if (!rule->isImportRule()) | 209 if (!rule->isImportRule()) |
247 return false; | 210 return false; |
248 | 211 |
249 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); | 212 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); |
250 if (importRule->mediaQueries()) | 213 if (importRule->mediaQueries()) |
251 setHasMediaQueries(); | 214 setHasMediaQueries(); |
252 | 215 |
253 m_importRules.insert(childVectorIndex, importRule); | 216 m_importRules.insert(index, importRule); |
254 m_importRules[childVectorIndex]->setParentStyleSheet(this); | 217 m_importRules[index]->setParentStyleSheet(this); |
255 m_importRules[childVectorIndex]->requestStyleSheet(); | 218 m_importRules[index]->requestStyleSheet(); |
256 // FIXME: Stylesheet doesn't actually change meaningfully before the imp
orted sheets are loaded. | 219 // FIXME: Stylesheet doesn't actually change meaningfully before the imp
orted sheets are loaded. |
257 return true; | 220 return true; |
258 } | 221 } |
259 // Inserting @import rule after a non-import rule is not allowed. | 222 // Inserting @import rule after a non-import rule is not allowed. |
260 if (rule->isImportRule()) | 223 if (rule->isImportRule()) |
261 return false; | 224 return false; |
262 | 225 |
263 if (rule->isMediaRule()) | 226 if (rule->isMediaRule()) |
264 setHasMediaQueries(); | 227 setHasMediaQueries(); |
265 | 228 |
266 childVectorIndex -= m_importRules.size(); | 229 index -= m_importRules.size(); |
267 | 230 |
268 if (rule->isFontFaceRule()) | 231 if (rule->isFontFaceRule()) |
269 setHasFontFaceRule(true); | 232 setHasFontFaceRule(true); |
270 m_childRules.insert(childVectorIndex, rule); | 233 m_childRules.insert(index, rule); |
271 return true; | 234 return true; |
272 } | 235 } |
273 | 236 |
274 void StyleSheetContents::wrapperDeleteRule(unsigned index) | 237 void StyleSheetContents::wrapperDeleteRule(unsigned index) |
275 { | 238 { |
276 ASSERT(m_isMutable); | 239 ASSERT(m_isMutable); |
277 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 240 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
278 | 241 |
279 unsigned childVectorIndex = index; | 242 if (index < m_importRules.size()) { |
280 if (hasCharsetRule()) { | 243 m_importRules[index]->clearParentStyleSheet(); |
281 if (childVectorIndex == 0) { | 244 if (m_importRules[index]->isFontFaceRule()) |
282 clearCharsetRule(); | 245 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].ge
t())); |
283 return; | 246 m_importRules.remove(index); |
284 } | |
285 --childVectorIndex; | |
286 } | |
287 if (childVectorIndex < m_importRules.size()) { | |
288 m_importRules[childVectorIndex]->clearParentStyleSheet(); | |
289 if (m_importRules[childVectorIndex]->isFontFaceRule()) | |
290 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[childVect
orIndex].get())); | |
291 m_importRules.remove(childVectorIndex); | |
292 return; | 247 return; |
293 } | 248 } |
294 childVectorIndex -= m_importRules.size(); | 249 index -= m_importRules.size(); |
295 | 250 |
296 if (m_childRules[childVectorIndex]->isFontFaceRule()) | 251 if (m_childRules[index]->isFontFaceRule()) |
297 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[childVectorInd
ex].get())); | 252 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get()))
; |
298 m_childRules.remove(childVectorIndex); | 253 m_childRules.remove(index); |
299 } | 254 } |
300 | 255 |
301 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At
omicString& uri) | 256 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At
omicString& uri) |
302 { | 257 { |
303 if (uri.isNull() || prefix.isNull()) | 258 if (uri.isNull() || prefix.isNull()) |
304 return; | 259 return; |
305 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); | 260 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); |
306 if (result.isNewEntry) | 261 if (result.isNewEntry) |
307 return; | 262 return; |
308 result.storedValue->value = uri; | 263 result.storedValue->value = uri; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 visitor->trace(m_ownerRule); | 644 visitor->trace(m_ownerRule); |
690 visitor->trace(m_importRules); | 645 visitor->trace(m_importRules); |
691 visitor->trace(m_childRules); | 646 visitor->trace(m_childRules); |
692 visitor->trace(m_loadingClients); | 647 visitor->trace(m_loadingClients); |
693 visitor->trace(m_completedClients); | 648 visitor->trace(m_completedClients); |
694 visitor->trace(m_ruleSet); | 649 visitor->trace(m_ruleSet); |
695 #endif | 650 #endif |
696 } | 651 } |
697 | 652 |
698 } | 653 } |
OLD | NEW |