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

Side by Side Diff: Source/core/css/CSSStyleSheet.cpp

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 * (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 10 matching lines...) Expand all
21 #include "config.h" 21 #include "config.h"
22 #include "core/css/CSSStyleSheet.h" 22 #include "core/css/CSSStyleSheet.h"
23 23
24 #include "HTMLNames.h" 24 #include "HTMLNames.h"
25 #include "SVGNames.h" 25 #include "SVGNames.h"
26 #include "bindings/v8/ExceptionState.h" 26 #include "bindings/v8/ExceptionState.h"
27 #include "core/css/CSSCharsetRule.h" 27 #include "core/css/CSSCharsetRule.h"
28 #include "core/css/CSSImportRule.h" 28 #include "core/css/CSSImportRule.h"
29 #include "core/css/CSSParser.h" 29 #include "core/css/CSSParser.h"
30 #include "core/css/CSSRuleList.h" 30 #include "core/css/CSSRuleList.h"
31 #include "core/css/CSSStyleRule.h"
31 #include "core/css/MediaList.h" 32 #include "core/css/MediaList.h"
32 #include "core/css/StyleRule.h" 33 #include "core/css/StyleRule.h"
33 #include "core/css/StyleSheetContents.h" 34 #include "core/css/StyleSheetContents.h"
34 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
35 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
36 #include "core/dom/Node.h" 37 #include "core/dom/Node.h"
37 #include "weborigin/SecurityOrigin.h" 38 #include "weborigin/SecurityOrigin.h"
38 #include "wtf/text/StringBuilder.h" 39 #include "wtf/text/StringBuilder.h"
39 40
40 namespace WebCore { 41 namespace WebCore {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 CSSStyleSheet::~CSSStyleSheet() 112 CSSStyleSheet::~CSSStyleSheet()
112 { 113 {
113 // For style rules outside the document, .parentStyleSheet can become null e ven if the style rule 114 // For style rules outside the document, .parentStyleSheet can become null e ven if the style rule
114 // is still observable from JavaScript. This matches the behavior of .parent Node for nodes, but 115 // is still observable from JavaScript. This matches the behavior of .parent Node for nodes, but
115 // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection. 116 // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection.
116 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { 117 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
117 if (m_childRuleCSSOMWrappers[i]) 118 if (m_childRuleCSSOMWrappers[i])
118 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); 119 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0);
119 } 120 }
121 for (unsigned i = 0; i < m_extraChildRuleCSSOMWrappers.size(); ++i) {
122 m_extraChildRuleCSSOMWrappers[i]->setParentStyleSheet(0);
123 }
120 if (m_mediaCSSOMWrapper) 124 if (m_mediaCSSOMWrapper)
121 m_mediaCSSOMWrapper->clearParentStyleSheet(); 125 m_mediaCSSOMWrapper->clearParentStyleSheet();
122 126
123 m_contents->unregisterClient(this); 127 m_contents->unregisterClient(this);
124 } 128 }
125 129
126 void CSSStyleSheet::willMutateRules() 130 void CSSStyleSheet::willMutateRules()
127 { 131 {
128 // If we are the only client it is safe to mutate. 132 // If we are the only client it is safe to mutate.
129 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) { 133 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) {
(...skipping 27 matching lines...) Expand all
157 Document* owner = ownerDocument(); 161 Document* owner = ownerDocument();
158 if (!owner) 162 if (!owner)
159 return; 163 return;
160 164
161 // Need FullStyleUpdate when insertRule or deleteRule, 165 // Need FullStyleUpdate when insertRule or deleteRule,
162 // because StyleSheetCollection::analyzeStyleSheetChange cannot detect parti al rule update. 166 // because StyleSheetCollection::analyzeStyleSheetChange cannot detect parti al rule update.
163 StyleResolverUpdateMode updateMode = updateType != PartialRuleUpdate ? Analy zedStyleUpdate : FullStyleUpdate; 167 StyleResolverUpdateMode updateMode = updateType != PartialRuleUpdate ? Analy zedStyleUpdate : FullStyleUpdate;
164 owner->modifiedStyleSheet(this, RecalcStyleDeferred, updateMode); 168 owner->modifiedStyleSheet(this, RecalcStyleDeferred, updateMode);
165 } 169 }
166 170
171 void CSSStyleSheet::registerExtraChildRuleCSSOMWrapper(PassRefPtr<CSSRule> rule)
172 {
173 m_extraChildRuleCSSOMWrappers.append(rule);
174 }
175
167 void CSSStyleSheet::reattachChildRuleCSSOMWrappers() 176 void CSSStyleSheet::reattachChildRuleCSSOMWrappers()
168 { 177 {
169 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { 178 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
170 if (!m_childRuleCSSOMWrappers[i]) 179 if (!m_childRuleCSSOMWrappers[i])
171 continue; 180 continue;
172 m_childRuleCSSOMWrappers[i]->reattach(m_contents->ruleAt(i)); 181 m_childRuleCSSOMWrappers[i]->reattach(m_contents->ruleAt(i));
173 } 182 }
174 } 183 }
175 184
176 void CSSStyleSheet::setDisabled(bool disabled) 185 void CSSStyleSheet::setDisabled(bool disabled)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 root = root->parentStyleSheet(); 372 root = root->parentStyleSheet();
364 return root->ownerNode() ? &root->ownerNode()->document() : 0; 373 return root->ownerNode() ? &root->ownerNode()->document() : 0;
365 } 374 }
366 375
367 void CSSStyleSheet::clearChildRuleCSSOMWrappers() 376 void CSSStyleSheet::clearChildRuleCSSOMWrappers()
368 { 377 {
369 m_childRuleCSSOMWrappers.clear(); 378 m_childRuleCSSOMWrappers.clear();
370 } 379 }
371 380
372 } 381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698