| 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 17 matching lines...) Expand all Loading... |
| 28 #include "sky/engine/core/css/parser/BisonCSSParser.h" | 28 #include "sky/engine/core/css/parser/BisonCSSParser.h" |
| 29 #include "sky/engine/core/dom/Document.h" | 29 #include "sky/engine/core/dom/Document.h" |
| 30 #include "sky/engine/core/dom/Node.h" | 30 #include "sky/engine/core/dom/Node.h" |
| 31 #include "sky/engine/core/dom/StyleEngine.h" | 31 #include "sky/engine/core/dom/StyleEngine.h" |
| 32 #include "sky/engine/core/frame/UseCounter.h" | 32 #include "sky/engine/core/frame/UseCounter.h" |
| 33 #include "sky/engine/platform/TraceEvent.h" | 33 #include "sky/engine/platform/TraceEvent.h" |
| 34 #include "sky/engine/wtf/Deque.h" | 34 #include "sky/engine/wtf/Deque.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 // Rough size estimate for the memory cache. | |
| 39 unsigned StyleSheetContents::estimatedSizeInBytes() const | |
| 40 { | |
| 41 // Note that this does not take into account size of the strings hanging fro
m various objects. | |
| 42 // The assumption is that nearly all of of them are atomic and would exist a
nyway. | |
| 43 unsigned size = sizeof(*this); | |
| 44 | |
| 45 // FIXME: This ignores the children of media rules. | |
| 46 // Most rules are StyleRules. | |
| 47 size += ruleCount() * StyleRule::averageSizeInBytes(); | |
| 48 return size; | |
| 49 } | |
| 50 | |
| 51 StyleSheetContents::StyleSheetContents(const String& originalURL, const CSSParse
rContext& context) | 38 StyleSheetContents::StyleSheetContents(const String& originalURL, const CSSParse
rContext& context) |
| 52 : m_originalURL(originalURL) | 39 : m_hasSyntacticallyValidCSSHeader(true) |
| 53 , m_hasSyntacticallyValidCSSHeader(true) | |
| 54 , m_didLoadErrorOccur(false) | |
| 55 , m_usesRemUnits(false) | 40 , m_usesRemUnits(false) |
| 56 , m_isMutable(false) | |
| 57 , m_isInMemoryCache(false) | |
| 58 , m_hasFontFaceRule(false) | |
| 59 , m_hasMediaQueries(false) | 41 , m_hasMediaQueries(false) |
| 60 , m_hasSingleOwnerDocument(true) | 42 , m_hasSingleOwnerDocument(true) |
| 43 , m_originalURL(originalURL) |
| 61 , m_parserContext(context) | 44 , m_parserContext(context) |
| 62 { | 45 { |
| 63 } | 46 } |
| 64 | 47 |
| 65 StyleSheetContents::StyleSheetContents(const StyleSheetContents& o) | |
| 66 : m_originalURL(o.m_originalURL) | |
| 67 , m_childRules(o.m_childRules.size()) | |
| 68 , m_namespaces(o.m_namespaces) | |
| 69 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) | |
| 70 , m_didLoadErrorOccur(false) | |
| 71 , m_usesRemUnits(o.m_usesRemUnits) | |
| 72 , m_isMutable(false) | |
| 73 , m_isInMemoryCache(false) | |
| 74 , m_hasFontFaceRule(o.m_hasFontFaceRule) | |
| 75 , m_hasMediaQueries(o.m_hasMediaQueries) | |
| 76 , m_hasSingleOwnerDocument(true) | |
| 77 , m_parserContext(o.m_parserContext) | |
| 78 { | |
| 79 ASSERT(o.isCacheable()); | |
| 80 | |
| 81 for (unsigned i = 0; i < m_childRules.size(); ++i) | |
| 82 m_childRules[i] = o.m_childRules[i]->copy(); | |
| 83 } | |
| 84 | |
| 85 StyleSheetContents::~StyleSheetContents() | 48 StyleSheetContents::~StyleSheetContents() |
| 86 { | 49 { |
| 87 #if !ENABLE(OILPAN) | 50 #if !ENABLE(OILPAN) |
| 88 clearRules(); | 51 clearRules(); |
| 89 #endif | 52 #endif |
| 90 } | 53 } |
| 91 | 54 |
| 92 void StyleSheetContents::setHasSyntacticallyValidCSSHeader(bool isValidCss) | 55 void StyleSheetContents::setHasSyntacticallyValidCSSHeader(bool isValidCss) |
| 93 { | 56 { |
| 94 if (!isValidCss) { | 57 if (!isValidCss) { |
| 95 if (Document* document = clientSingleOwnerDocument()) | 58 if (Document* document = clientSingleOwnerDocument()) |
| 96 removeSheetFromCache(document); | 59 removeSheetFromCache(document); |
| 97 } | 60 } |
| 98 m_hasSyntacticallyValidCSSHeader = isValidCss; | 61 m_hasSyntacticallyValidCSSHeader = isValidCss; |
| 99 } | 62 } |
| 100 | 63 |
| 101 bool StyleSheetContents::isCacheable() const | 64 bool StyleSheetContents::isCacheable() const |
| 102 { | 65 { |
| 103 // FIXME: StyleSheets with media queries can't be cached because their RuleS
et | 66 // FIXME: StyleSheets with media queries can't be cached because their RuleS
et |
| 104 // is processed differently based off the media queries, which might resolve | 67 // is processed differently based off the media queries, which might resolve |
| 105 // differently depending on the context of the parent CSSStyleSheet (e.g. | 68 // differently depending on the context of the parent CSSStyleSheet (e.g. |
| 106 // if they are in differently sized iframes). Once RuleSets are media query | 69 // if they are in differently sized iframes). Once RuleSets are media query |
| 107 // agnostic, we can restore sharing of StyleSheetContents with medea queries
. | 70 // agnostic, we can restore sharing of StyleSheetContents with medea queries
. |
| 108 if (m_hasMediaQueries) | 71 if (m_hasMediaQueries) |
| 109 return false; | 72 return false; |
| 110 if (m_didLoadErrorOccur) | |
| 111 return false; | |
| 112 // It is not the original sheet anymore. | |
| 113 if (m_isMutable) | |
| 114 return false; | |
| 115 // If the header is valid we are not going to need to check the SecurityOrig
in. | 73 // If the header is valid we are not going to need to check the SecurityOrig
in. |
| 116 // FIXME: Valid mime type avoids the check too. | 74 // FIXME: Valid mime type avoids the check too. |
| 117 if (!m_hasSyntacticallyValidCSSHeader) | 75 if (!m_hasSyntacticallyValidCSSHeader) |
| 118 return false; | 76 return false; |
| 119 return true; | 77 return true; |
| 120 } | 78 } |
| 121 | 79 |
| 122 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) | 80 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) |
| 123 { | 81 { |
| 124 // Add warning message to inspector if dpi/dpcm values are used for screen m
edia. | 82 // Add warning message to inspector if dpi/dpcm values are used for screen m
edia. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 unsigned StyleSheetContents::ruleCount() const | 102 unsigned StyleSheetContents::ruleCount() const |
| 145 { | 103 { |
| 146 return m_childRules.size(); | 104 return m_childRules.size(); |
| 147 } | 105 } |
| 148 | 106 |
| 149 void StyleSheetContents::clearRules() | 107 void StyleSheetContents::clearRules() |
| 150 { | 108 { |
| 151 m_childRules.clear(); | 109 m_childRules.clear(); |
| 152 } | 110 } |
| 153 | 111 |
| 154 bool StyleSheetContents::wrapperInsertRule(PassRefPtr<StyleRuleBase> rule, unsig
ned index) | |
| 155 { | |
| 156 ASSERT(m_isMutable); | |
| 157 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); | |
| 158 | |
| 159 if (rule->isMediaRule()) | |
| 160 setHasMediaQueries(); | |
| 161 | |
| 162 if (rule->isFontFaceRule()) | |
| 163 setHasFontFaceRule(true); | |
| 164 m_childRules.insert(index, rule); | |
| 165 return true; | |
| 166 } | |
| 167 | |
| 168 void StyleSheetContents::wrapperDeleteRule(unsigned index) | |
| 169 { | |
| 170 ASSERT(m_isMutable); | |
| 171 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | |
| 172 | |
| 173 if (m_childRules[index]->isFontFaceRule()) | |
| 174 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get()))
; | |
| 175 m_childRules.remove(index); | |
| 176 } | |
| 177 | |
| 178 bool StyleSheetContents::parseString(const String& sheetText) | 112 bool StyleSheetContents::parseString(const String& sheetText) |
| 179 { | 113 { |
| 180 return parseStringAtPosition(sheetText, TextPosition::minimumPosition(), fal
se); | 114 return parseStringAtPosition(sheetText, TextPosition::minimumPosition(), fal
se); |
| 181 } | 115 } |
| 182 | 116 |
| 183 bool StyleSheetContents::parseStringAtPosition(const String& sheetText, const Te
xtPosition& startPosition, bool createdByParser) | 117 bool StyleSheetContents::parseStringAtPosition(const String& sheetText, const Te
xtPosition& startPosition, bool createdByParser) |
| 184 { | 118 { |
| 185 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); | 119 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); |
| 186 BisonCSSParser p(context); | 120 BisonCSSParser p(context); |
| 187 p.parseSheet(this, sheetText, startPosition, 0, createdByParser); | 121 p.parseSheet(this, sheetText, startPosition, 0, createdByParser); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 removeSheetFromCache(sheet->ownerDocument()); | 219 removeSheetFromCache(sheet->ownerDocument()); |
| 286 m_hasSingleOwnerDocument = true; | 220 m_hasSingleOwnerDocument = true; |
| 287 } | 221 } |
| 288 | 222 |
| 289 void StyleSheetContents::removeSheetFromCache(Document* document) | 223 void StyleSheetContents::removeSheetFromCache(Document* document) |
| 290 { | 224 { |
| 291 ASSERT(document); | 225 ASSERT(document); |
| 292 document->styleEngine()->removeSheet(this); | 226 document->styleEngine()->removeSheet(this); |
| 293 } | 227 } |
| 294 | 228 |
| 295 void StyleSheetContents::addedToMemoryCache() | |
| 296 { | |
| 297 ASSERT(!m_isInMemoryCache); | |
| 298 ASSERT(isCacheable()); | |
| 299 m_isInMemoryCache = true; | |
| 300 } | |
| 301 | |
| 302 void StyleSheetContents::removedFromMemoryCache() | |
| 303 { | |
| 304 ASSERT(m_isInMemoryCache); | |
| 305 ASSERT(isCacheable()); | |
| 306 m_isInMemoryCache = false; | |
| 307 } | |
| 308 | |
| 309 void StyleSheetContents::shrinkToFit() | 229 void StyleSheetContents::shrinkToFit() |
| 310 { | 230 { |
| 311 m_childRules.shrinkToFit(); | 231 m_childRules.shrinkToFit(); |
| 312 } | 232 } |
| 313 | 233 |
| 314 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad
dRuleFlags addRuleFlags) | 234 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad
dRuleFlags addRuleFlags) |
| 315 { | 235 { |
| 316 if (!m_ruleSet) { | 236 if (!m_ruleSet) { |
| 317 m_ruleSet = RuleSet::create(); | 237 m_ruleSet = RuleSet::create(); |
| 318 m_ruleSet->addRulesFromSheet(this, medium, addRuleFlags); | 238 m_ruleSet->addRulesFromSheet(this, medium, addRuleFlags); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 ownerNode->document().styleEngine()->removeFontFaceRules(Vector<RawP
tr<const StyleRuleFontFace> >(1, fontFaceRule)); | 270 ownerNode->document().styleEngine()->removeFontFaceRules(Vector<RawP
tr<const StyleRuleFontFace> >(1, fontFaceRule)); |
| 351 } | 271 } |
| 352 } | 272 } |
| 353 | 273 |
| 354 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF
aceRule) | 274 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF
aceRule) |
| 355 { | 275 { |
| 356 removeFontFaceRules(m_loadingClients, fontFaceRule); | 276 removeFontFaceRules(m_loadingClients, fontFaceRule); |
| 357 removeFontFaceRules(m_completedClients, fontFaceRule); | 277 removeFontFaceRules(m_completedClients, fontFaceRule); |
| 358 } | 278 } |
| 359 | 279 |
| 360 static void findFontFaceRulesFromRules(const Vector<RefPtr<StyleRuleBase> >& rul
es, Vector<RawPtr<const StyleRuleFontFace> >& fontFaceRules) | |
| 361 { | |
| 362 for (unsigned i = 0; i < rules.size(); ++i) { | |
| 363 StyleRuleBase* rule = rules[i].get(); | |
| 364 | |
| 365 if (rule->isFontFaceRule()) { | |
| 366 fontFaceRules.append(toStyleRuleFontFace(rule)); | |
| 367 } else if (rule->isMediaRule()) { | |
| 368 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); | |
| 369 // We cannot know whether the media rule matches or not, but | |
| 370 // for safety, remove @font-face in the media rule (if exists). | |
| 371 findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules); | |
| 372 } | |
| 373 } | |
| 374 } | 280 } |
| 375 | |
| 376 void StyleSheetContents::findFontFaceRules(Vector<RawPtr<const StyleRuleFontFace
> >& fontFaceRules) | |
| 377 { | |
| 378 findFontFaceRulesFromRules(childRules(), fontFaceRules); | |
| 379 } | |
| 380 | |
| 381 } | |
| OLD | NEW |