Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: Source/core/css/ElementRuleCollector.h

Issue 49093005: Fix memory error during selector matching due to getMatchedCSSRules. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 21
22 #ifndef ElementRuleCollector_h 22 #ifndef ElementRuleCollector_h
23 #define ElementRuleCollector_h 23 #define ElementRuleCollector_h
24 24
25 #include "core/css/PseudoStyleRequest.h" 25 #include "core/css/PseudoStyleRequest.h"
26 #include "core/css/SelectorChecker.h" 26 #include "core/css/SelectorChecker.h"
27 #include "core/css/resolver/ElementResolveContext.h" 27 #include "core/css/resolver/ElementResolveContext.h"
28 #include "core/css/resolver/MatchRequest.h" 28 #include "core/css/resolver/MatchRequest.h"
29 #include "core/css/resolver/MatchResult.h" 29 #include "core/css/resolver/MatchResult.h"
30 #include "core/css/resolver/StyleResolverIncludes.h"
30 #include "wtf/RefPtr.h" 31 #include "wtf/RefPtr.h"
31 #include "wtf/Vector.h" 32 #include "wtf/Vector.h"
32 33
33 namespace WebCore { 34 namespace WebCore {
34 35
35 class CSSRuleList; 36 class CSSRuleList;
36 class DocumentRuleSets; 37 class DocumentRuleSets;
37 class RenderRegion; 38 class RenderRegion;
38 class RuleData; 39 class RuleData;
39 class RuleSet; 40 class RuleSet;
(...skipping 29 matching lines...) Expand all
69 uint32_t m_position; 70 uint32_t m_position;
70 }; 71 };
71 72
72 // ElementRuleCollector is designed to be used as a stack object. 73 // ElementRuleCollector is designed to be used as a stack object.
73 // Create one, ask what rules the ElementResolveContext matches 74 // Create one, ask what rules the ElementResolveContext matches
74 // and then let it go out of scope. 75 // and then let it go out of scope.
75 // FIXME: Currently it modifies the RenderStyle but should not! 76 // FIXME: Currently it modifies the RenderStyle but should not!
76 class ElementRuleCollector { 77 class ElementRuleCollector {
77 WTF_MAKE_NONCOPYABLE(ElementRuleCollector); 78 WTF_MAKE_NONCOPYABLE(ElementRuleCollector);
78 public: 79 public:
79 ElementRuleCollector(const ElementResolveContext&, const SelectorFilter&, Re nderStyle* = 0); 80 ElementRuleCollector(const ElementResolveContext&, const SelectorFilter&, Re nderStyle* = 0, ShouldIncludeStyleSheetInCSSOMWrapper = IncludeStyleSheetInCSSOM Wrapper);
80 ~ElementRuleCollector(); 81 ~ElementRuleCollector();
81 82
82 void setCanUseFastReject(bool canUseFastReject) { m_canUseFastReject = canUs eFastReject; } 83 void setCanUseFastReject(bool canUseFastReject) { m_canUseFastReject = canUs eFastReject; }
83 bool canUseFastReject() const { return m_canUseFastReject; } 84 bool canUseFastReject() const { return m_canUseFastReject; }
84 85
85 void setMode(SelectorChecker::Mode mode) { m_mode = mode; } 86 void setMode(SelectorChecker::Mode mode) { m_mode = mode; }
86 void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyl eRequest = request; } 87 void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyl eRequest = request; }
87 void setSameOriginOnly(bool f) { m_sameOriginOnly = f; } 88 void setSameOriginOnly(bool f) { m_sameOriginOnly = f; }
88 void setRegionForStyling(const RenderRegion* regionForStyling) { m_regionFor Styling = regionForStyling; } 89 void setRegionForStyling(const RenderRegion* regionForStyling) { m_regionFor Styling = regionForStyling; }
89 90
(...skipping 12 matching lines...) Expand all
102 unsigned lastMatchedRulesPosition() const { return m_matchedRules ? m_matche dRules->size() : 0; } 103 unsigned lastMatchedRulesPosition() const { return m_matchedRules ? m_matche dRules->size() : 0; }
103 void sortMatchedRulesFrom(unsigned position); 104 void sortMatchedRulesFrom(unsigned position);
104 void sortAndTransferMatchedRulesWithOnlySortBySpecificity(); 105 void sortAndTransferMatchedRulesWithOnlySortBySpecificity();
105 106
106 private: 107 private:
107 void collectRuleIfMatches(const RuleData&, SelectorChecker::BehaviorAtBounda ry, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&); 108 void collectRuleIfMatches(const RuleData&, SelectorChecker::BehaviorAtBounda ry, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&);
108 void collectMatchingRulesForList(const Vector<RuleData>*, SelectorChecker::B ehaviorAtBoundary, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&); 109 void collectMatchingRulesForList(const Vector<RuleData>*, SelectorChecker::B ehaviorAtBoundary, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&);
109 void collectMatchingRulesForList(const RuleData*, SelectorChecker::BehaviorA tBoundary, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&); 110 void collectMatchingRulesForList(const RuleData*, SelectorChecker::BehaviorA tBoundary, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&);
110 bool ruleMatches(const RuleData&, const ContainerNode* scope, PseudoId&, Sel ectorChecker::BehaviorAtBoundary); 111 bool ruleMatches(const RuleData&, const ContainerNode* scope, PseudoId&, Sel ectorChecker::BehaviorAtBoundary);
111 112
113 void appendCSSOMWrapperForRule(StyleRule*);
114
112 void sortMatchedRules(); 115 void sortMatchedRules();
113 void addMatchedRule(const RuleData*, CascadeScope, CascadeOrder); 116 void addMatchedRule(const RuleData*, CascadeScope, CascadeOrder);
114 117
115 StaticCSSRuleList* ensureRuleList(); 118 StaticCSSRuleList* ensureRuleList();
116 119
117 private: 120 private:
118 const ElementResolveContext& m_context; 121 const ElementResolveContext& m_context;
119 const SelectorFilter& m_selectorFilter; 122 const SelectorFilter& m_selectorFilter;
120 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching! 123 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching!
121 124
122 const RenderRegion* m_regionForStyling; 125 const RenderRegion* m_regionForStyling;
123 PseudoStyleRequest m_pseudoStyleRequest; 126 PseudoStyleRequest m_pseudoStyleRequest;
124 SelectorChecker::Mode m_mode; 127 SelectorChecker::Mode m_mode;
125 bool m_canUseFastReject; 128 bool m_canUseFastReject;
126 bool m_sameOriginOnly; 129 bool m_sameOriginOnly;
127 bool m_matchingUARules; 130 bool m_matchingUARules;
131 bool m_includeStyleSheet;
128 132
129 OwnPtr<Vector<MatchedRule, 32> > m_matchedRules; 133 OwnPtr<Vector<MatchedRule, 32> > m_matchedRules;
130 134
131 // Output. 135 // Output.
132 RefPtr<StaticCSSRuleList> m_ruleList; 136 RefPtr<StaticCSSRuleList> m_ruleList;
133 MatchResult m_result; 137 MatchResult m_result;
134 }; 138 };
135 139
136 } // namespace WebCore 140 } // namespace WebCore
137 141
138 #endif // ElementRuleCollector_h 142 #endif // ElementRuleCollector_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698