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

Side by Side Diff: third_party/WebKit/Source/core/css/StyleSheetContents.cpp

Issue 1858753003: Remove RawPtr from core/css (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // It is not the original sheet anymore. 135 // It is not the original sheet anymore.
136 if (m_isMutable) 136 if (m_isMutable)
137 return false; 137 return false;
138 // If the header is valid we are not going to need to check the SecurityOrig in. 138 // If the header is valid we are not going to need to check the SecurityOrig in.
139 // FIXME: Valid mime type avoids the check too. 139 // FIXME: Valid mime type avoids the check too.
140 if (!m_hasSyntacticallyValidCSSHeader) 140 if (!m_hasSyntacticallyValidCSSHeader)
141 return false; 141 return false;
142 return true; 142 return true;
143 } 143 }
144 144
145 void StyleSheetContents::parserAppendRule(RawPtr<StyleRuleBase> rule) 145 void StyleSheetContents::parserAppendRule(StyleRuleBase* rule)
146 { 146 {
147 if (rule->isImportRule()) { 147 if (rule->isImportRule()) {
148 // Parser enforces that @import rules come before anything else 148 // Parser enforces that @import rules come before anything else
149 ASSERT(m_childRules.isEmpty()); 149 ASSERT(m_childRules.isEmpty());
150 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); 150 StyleRuleImport* importRule = toStyleRuleImport(rule);
151 if (importRule->mediaQueries()) 151 if (importRule->mediaQueries())
152 setHasMediaQueries(); 152 setHasMediaQueries();
153 m_importRules.append(importRule); 153 m_importRules.append(importRule);
154 m_importRules.last()->setParentStyleSheet(this); 154 m_importRules.last()->setParentStyleSheet(this);
155 m_importRules.last()->requestStyleSheet(); 155 m_importRules.last()->requestStyleSheet();
156 return; 156 return;
157 } 157 }
158 158
159 if (rule->isNamespaceRule()) { 159 if (rule->isNamespaceRule()) {
160 // Parser enforces that @namespace rules come before all rules other tha n 160 // Parser enforces that @namespace rules come before all rules other tha n
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 { 205 {
206 for (unsigned i = 0; i < m_importRules.size(); ++i) { 206 for (unsigned i = 0; i < m_importRules.size(); ++i) {
207 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); 207 ASSERT(m_importRules.at(i)->parentStyleSheet() == this);
208 m_importRules[i]->clearParentStyleSheet(); 208 m_importRules[i]->clearParentStyleSheet();
209 } 209 }
210 m_importRules.clear(); 210 m_importRules.clear();
211 m_namespaceRules.clear(); 211 m_namespaceRules.clear();
212 m_childRules.clear(); 212 m_childRules.clear();
213 } 213 }
214 214
215 bool StyleSheetContents::wrapperInsertRule(RawPtr<StyleRuleBase> rule, unsigned index) 215 bool StyleSheetContents::wrapperInsertRule(StyleRuleBase* rule, unsigned index)
216 { 216 {
217 ASSERT(m_isMutable); 217 ASSERT(m_isMutable);
218 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); 218 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount());
219 219
220 if (index < m_importRules.size() || (index == m_importRules.size() && rule-> isImportRule())) { 220 if (index < m_importRules.size() || (index == m_importRules.size() && rule-> isImportRule())) {
221 // Inserting non-import rule before @import is not allowed. 221 // Inserting non-import rule before @import is not allowed.
222 if (!rule->isImportRule()) 222 if (!rule->isImportRule())
223 return false; 223 return false;
224 224
225 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); 225 StyleRuleImport* importRule = toStyleRuleImport(rule);
226 if (importRule->mediaQueries()) 226 if (importRule->mediaQueries())
227 setHasMediaQueries(); 227 setHasMediaQueries();
228 228
229 m_importRules.insert(index, importRule); 229 m_importRules.insert(index, importRule);
230 m_importRules[index]->setParentStyleSheet(this); 230 m_importRules[index]->setParentStyleSheet(this);
231 m_importRules[index]->requestStyleSheet(); 231 m_importRules[index]->requestStyleSheet();
232 // FIXME: Stylesheet doesn't actually change meaningfully before the imp orted sheets are loaded. 232 // FIXME: Stylesheet doesn't actually change meaningfully before the imp orted sheets are loaded.
233 return true; 233 return true;
234 } 234 }
235 // Inserting @import rule after a non-import rule is not allowed. 235 // Inserting @import rule after a non-import rule is not allowed.
236 if (rule->isImportRule()) 236 if (rule->isImportRule())
237 return false; 237 return false;
238 238
239 index -= m_importRules.size(); 239 index -= m_importRules.size();
240 240
241 if (index < m_namespaceRules.size() || (index == m_namespaceRules.size() && rule->isNamespaceRule())) { 241 if (index < m_namespaceRules.size() || (index == m_namespaceRules.size() && rule->isNamespaceRule())) {
242 // Inserting non-namespace rules other than import rule before @namespac e is not allowed. 242 // Inserting non-namespace rules other than import rule before @namespac e is not allowed.
243 if (!rule->isNamespaceRule()) 243 if (!rule->isNamespaceRule())
244 return false; 244 return false;
245 // Inserting @namespace rule when rules other than import/namespace/char set are present is not allowed. 245 // Inserting @namespace rule when rules other than import/namespace/char set are present is not allowed.
246 if (!m_childRules.isEmpty()) 246 if (!m_childRules.isEmpty())
247 return false; 247 return false;
248 248
249 StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule.get()); 249 StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule);
250 m_namespaceRules.insert(index, namespaceRule); 250 m_namespaceRules.insert(index, namespaceRule);
251 // For now to be compatible with IE and Firefox if namespace rule with s ame prefix is added 251 // For now to be compatible with IE and Firefox if namespace rule with s ame prefix is added
252 // irrespective of adding the rule at any index, last added rule's value is considered. 252 // irrespective of adding the rule at any index, last added rule's value is considered.
253 // TODO (ramya.v@samsung.com): As per spec last valid rule should be con sidered, 253 // TODO (ramya.v@samsung.com): As per spec last valid rule should be con sidered,
254 // which means if namespace rule is added in the middle of existing name space rules, 254 // which means if namespace rule is added in the middle of existing name space rules,
255 // rule which comes later in rule list with same prefix needs to be cons idered. 255 // rule which comes later in rule list with same prefix needs to be cons idered.
256 parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri()); 256 parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri());
257 return true; 257 return true;
258 } 258 }
259 259
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 364
365 StyleSheetContents* root = rootStyleSheet(); 365 StyleSheetContents* root = rootStyleSheet();
366 return root->m_loadingClients.isEmpty(); 366 return root->m_loadingClients.isEmpty();
367 } 367 }
368 368
369 void StyleSheetContents::checkLoaded() 369 void StyleSheetContents::checkLoaded()
370 { 370 {
371 if (isLoading()) 371 if (isLoading())
372 return; 372 return;
373 373
374 // Avoid |this| being deleted by scripts that run via
375 // ScriptableDocumentParser::executeScriptsWaitingForResources().
376 // See https://bugs.webkit.org/show_bug.cgi?id=95106
377 RawPtr<StyleSheetContents> protect(this);
378
379 StyleSheetContents* parentSheet = parentStyleSheet(); 374 StyleSheetContents* parentSheet = parentStyleSheet();
380 if (parentSheet) { 375 if (parentSheet) {
381 parentSheet->checkLoaded(); 376 parentSheet->checkLoaded();
382 return; 377 return;
383 } 378 }
384 379
385 ASSERT(this == rootStyleSheet()); 380 ASSERT(this == rootStyleSheet());
386 if (m_loadingClients.isEmpty()) 381 if (m_loadingClients.isEmpty())
387 return; 382 return;
388 383
389 // Avoid |CSSSStyleSheet| and |ownerNode| being deleted by scripts that run via 384 // Avoid |CSSSStyleSheet| and |ownerNode| being deleted by scripts that run via
390 // ScriptableDocumentParser::executeScriptsWaitingForResources(). Also prote ct 385 // ScriptableDocumentParser::executeScriptsWaitingForResources(). Also prote ct
391 // the |CSSStyleSheet| from being deleted during iteration via the |sheetLoa ded| 386 // the |CSSStyleSheet| from being deleted during iteration via the |sheetLoa ded|
392 // method. 387 // method.
393 // 388 //
394 // When a sheet is loaded it is moved from the set of loading clients 389 // When a sheet is loaded it is moved from the set of loading clients
395 // to the set of completed clients. We therefore need the copy in order to 390 // to the set of completed clients. We therefore need the copy in order to
396 // not modify the set while iterating it. 391 // not modify the set while iterating it.
397 HeapVector<Member<CSSStyleSheet>> loadingClients; 392 HeapVector<Member<CSSStyleSheet>> loadingClients;
398 copyToVector(m_loadingClients, loadingClients); 393 copyToVector(m_loadingClients, loadingClients);
399 394
400 for (unsigned i = 0; i < loadingClients.size(); ++i) { 395 for (unsigned i = 0; i < loadingClients.size(); ++i) {
401 if (loadingClients[i]->loadCompleted()) 396 if (loadingClients[i]->loadCompleted())
402 continue; 397 continue;
403 398
404 // sheetLoaded might be invoked after its owner node is removed from doc ument. 399 // sheetLoaded might be invoked after its owner node is removed from doc ument.
405 if (RawPtr<Node> ownerNode = loadingClients[i]->ownerNode()) { 400 if (Node* ownerNode = loadingClients[i]->ownerNode()) {
406 if (loadingClients[i]->sheetLoaded()) 401 if (loadingClients[i]->sheetLoaded())
407 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoad ErrorOccur ? Node::ErrorOccurredLoadingSubresource : Node::NoErrorLoadingSubreso urce); 402 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoad ErrorOccur ? Node::ErrorOccurredLoadingSubresource : Node::NoErrorLoadingSubreso urce);
408 } 403 }
409 } 404 }
410 } 405 }
411 406
412 void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet) 407 void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet)
413 { 408 {
414 ASSERT(sheet); 409 ASSERT(sheet);
415 m_didLoadErrorOccur |= sheet->errorOccurred(); 410 m_didLoadErrorOccur |= sheet->errorOccurred();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 visitor->trace(m_importRules); 662 visitor->trace(m_importRules);
668 visitor->trace(m_namespaceRules); 663 visitor->trace(m_namespaceRules);
669 visitor->trace(m_childRules); 664 visitor->trace(m_childRules);
670 visitor->trace(m_loadingClients); 665 visitor->trace(m_loadingClients);
671 visitor->trace(m_completedClients); 666 visitor->trace(m_completedClients);
672 visitor->trace(m_ruleSet); 667 visitor->trace(m_ruleSet);
673 #endif 668 #endif
674 } 669 }
675 670
676 } // namespace blink 671 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698