| 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #include "core/css/StyleSheetContents.h" | 21 #include "core/css/StyleSheetContents.h" |
| 22 | 22 |
| 23 #include "core/css/CSSStyleSheet.h" | 23 #include "core/css/CSSStyleSheet.h" |
| 24 #include "core/css/StylePropertySet.h" | 24 #include "core/css/StylePropertySet.h" |
| 25 #include "core/css/StyleRule.h" | 25 #include "core/css/StyleRule.h" |
| 26 #include "core/css/StyleRuleImport.h" | 26 #include "core/css/StyleRuleImport.h" |
| 27 #include "core/css/StyleRuleNamespace.h" | 27 #include "core/css/StyleRuleNamespace.h" |
| 28 #include "core/css/parser/CSSParser.h" | 28 #include "core/css/parser/CSSParser.h" |
| 29 #include "core/css/serializer/CSSDeserializeStream.h" |
| 30 #include "core/css/serializer/CSSSerializeStream.h" |
| 29 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 30 #include "core/dom/Node.h" | 32 #include "core/dom/Node.h" |
| 31 #include "core/dom/StyleEngine.h" | 33 #include "core/dom/StyleEngine.h" |
| 32 #include "core/fetch/CSSStyleSheetResource.h" | 34 #include "core/fetch/CSSStyleSheetResource.h" |
| 33 #include "core/frame/UseCounter.h" | 35 #include "core/frame/UseCounter.h" |
| 34 #include "core/inspector/InspectorTraceEvents.h" | 36 #include "core/inspector/InspectorTraceEvents.h" |
| 35 #include "platform/TraceEvent.h" | 37 #include "platform/TraceEvent.h" |
| 36 #include "platform/weborigin/SecurityOrigin.h" | 38 #include "platform/weborigin/SecurityOrigin.h" |
| 37 #include "wtf/Deque.h" | 39 #include "wtf/Deque.h" |
| 38 | 40 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 bool StyleSheetContents::isCacheable() const | 118 bool StyleSheetContents::isCacheable() const |
| 117 { | 119 { |
| 118 // This would require dealing with multiple clients for load callbacks. | 120 // This would require dealing with multiple clients for load callbacks. |
| 119 if (!loadCompleted()) | 121 if (!loadCompleted()) |
| 120 return false; | 122 return false; |
| 121 // FIXME: StyleSheets with media queries can't be cached because their RuleS
et | 123 // FIXME: StyleSheets with media queries can't be cached because their RuleS
et |
| 122 // is processed differently based off the media queries, which might resolve | 124 // is processed differently based off the media queries, which might resolve |
| 123 // differently depending on the context of the parent CSSStyleSheet (e.g. | 125 // differently depending on the context of the parent CSSStyleSheet (e.g. |
| 124 // if they are in differently sized iframes). Once RuleSets are media query | 126 // if they are in differently sized iframes). Once RuleSets are media query |
| 125 // agnostic, we can restore sharing of StyleSheetContents with medea queries
. | 127 // agnostic, we can restore sharing of StyleSheetContents with medea queries
. |
| 126 if (m_hasMediaQueries) | 128 CSDEBUG("hasMediaQueries: %d, m_importRules not empty %d, m_ownerRule %d\n", |
| 127 return false; | 129 m_hasMediaQueries, !m_importRules.isEmpty(), (bool)m_ownerRule); |
| 130 CSDEBUG("loaderr: %d, mutable: %d, css h invalid: %d\n", m_didLoadErrorOccur
, m_isMutable, !m_hasSyntacticallyValidCSSHeader); |
| 131 //if (m_hasMediaQueries) |
| 132 // return false; |
| 128 // FIXME: Support copying import rules. | 133 // FIXME: Support copying import rules. |
| 129 if (!m_importRules.isEmpty()) | 134 if (!m_importRules.isEmpty()) |
| 130 return false; | 135 return false; |
| 131 // FIXME: Support cached stylesheets in import rules. | 136 // FIXME: Support cached stylesheets in import rules. |
| 132 if (m_ownerRule) | 137 if (m_ownerRule) |
| 133 return false; | 138 return false; |
| 134 if (m_didLoadErrorOccur) | 139 if (m_didLoadErrorOccur) |
| 135 return false; | 140 return false; |
| 136 // It is not the original sheet anymore. | 141 // It is not the original sheet anymore. |
| 137 if (m_isMutable) | 142 if (m_isMutable) |
| 138 return false; | 143 return false; |
| 139 // If the header is valid we are not going to need to check the SecurityOrig
in. | 144 // If the header is valid we are not going to need to check the SecurityOrig
in. |
| 140 // FIXME: Valid mime type avoids the check too. | 145 // FIXME: Valid mime type avoids the check too. |
| 141 if (!m_hasSyntacticallyValidCSSHeader) | 146 if (!m_hasSyntacticallyValidCSSHeader) |
| 142 return false; | 147 return false; |
| 143 return true; | 148 return true; |
| 144 } | 149 } |
| 145 | 150 |
| 151 void StyleSheetContents::deserialize(CSSDeserializeStream* stream) |
| 152 { |
| 153 CSDEBUG("StyleSheetContents::deserialize\n"); |
| 154 |
| 155 unsigned numChildRules = stream->readUnsigned(); |
| 156 for (unsigned i = 0; i < numChildRules; ++i) { |
| 157 parserAppendRule(StyleRuleBase::deserialize(stream)); |
| 158 } |
| 159 } |
| 160 |
| 161 void StyleSheetContents::serialize(CSSSerializeStream* stream) |
| 162 { |
| 163 CSDEBUG("StyleSheetContents::serialize isCacheable: %d\n", isCacheable()); |
| 164 |
| 165 stream->writeUnsigned(m_childRules.size()); |
| 166 for (auto childRule : m_childRules) { |
| 167 childRule->serialize(stream); |
| 168 } |
| 169 } |
| 170 |
| 146 void StyleSheetContents::parserAppendRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule) | 171 void StyleSheetContents::parserAppendRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule) |
| 147 { | 172 { |
| 148 if (rule->isImportRule()) { | 173 if (rule->isImportRule()) { |
| 149 // Parser enforces that @import rules come before anything else | 174 // Parser enforces that @import rules come before anything else |
| 150 ASSERT(m_childRules.isEmpty()); | 175 ASSERT(m_childRules.isEmpty()); |
| 151 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); | 176 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); |
| 152 if (importRule->mediaQueries()) | 177 if (importRule->mediaQueries()) |
| 153 setHasMediaQueries(); | 178 setHasMediaQueries(); |
| 154 m_importRules.append(importRule); | 179 m_importRules.append(importRule); |
| 155 m_importRules.last()->setParentStyleSheet(this); | 180 m_importRules.last()->setParentStyleSheet(this); |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 visitor->trace(m_importRules); | 700 visitor->trace(m_importRules); |
| 676 visitor->trace(m_namespaceRules); | 701 visitor->trace(m_namespaceRules); |
| 677 visitor->trace(m_childRules); | 702 visitor->trace(m_childRules); |
| 678 visitor->trace(m_loadingClients); | 703 visitor->trace(m_loadingClients); |
| 679 visitor->trace(m_completedClients); | 704 visitor->trace(m_completedClients); |
| 680 visitor->trace(m_ruleSet); | 705 visitor->trace(m_ruleSet); |
| 681 #endif | 706 #endif |
| 682 } | 707 } |
| 683 | 708 |
| 684 } | 709 } |
| OLD | NEW |