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

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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 StyleSheetContents* root = rootStyleSheet(); 375 StyleSheetContents* root = rootStyleSheet();
376 return root->m_loadingClients.isEmpty(); 376 return root->m_loadingClients.isEmpty();
377 } 377 }
378 378
379 void StyleSheetContents::checkLoaded() 379 void StyleSheetContents::checkLoaded()
380 { 380 {
381 if (isLoading()) 381 if (isLoading())
382 return; 382 return;
383 383
384 // Avoid |this| being deleted by scripts that run via
385 // ScriptableDocumentParser::executeScriptsWaitingForResources().
386 // See https://bugs.webkit.org/show_bug.cgi?id=95106
387 RawPtr<StyleSheetContents> protect(this);
388
389 StyleSheetContents* parentSheet = parentStyleSheet(); 384 StyleSheetContents* parentSheet = parentStyleSheet();
390 if (parentSheet) { 385 if (parentSheet) {
391 parentSheet->checkLoaded(); 386 parentSheet->checkLoaded();
392 return; 387 return;
393 } 388 }
394 389
395 ASSERT(this == rootStyleSheet()); 390 ASSERT(this == rootStyleSheet());
396 if (m_loadingClients.isEmpty()) 391 if (m_loadingClients.isEmpty())
397 return; 392 return;
398 393
399 // Avoid |CSSSStyleSheet| and |ownerNode| being deleted by scripts that run via 394 // Avoid |CSSSStyleSheet| and |ownerNode| being deleted by scripts that run via
400 // ScriptableDocumentParser::executeScriptsWaitingForResources(). Also prote ct 395 // ScriptableDocumentParser::executeScriptsWaitingForResources(). Also prote ct
401 // the |CSSStyleSheet| from being deleted during iteration via the |sheetLoa ded| 396 // the |CSSStyleSheet| from being deleted during iteration via the |sheetLoa ded|
402 // method. 397 // method.
403 // 398 //
404 // When a sheet is loaded it is moved from the set of loading clients 399 // When a sheet is loaded it is moved from the set of loading clients
405 // to the set of completed clients. We therefore need the copy in order to 400 // to the set of completed clients. We therefore need the copy in order to
406 // not modify the set while iterating it. 401 // not modify the set while iterating it.
407 HeapVector<Member<CSSStyleSheet>> loadingClients; 402 HeapVector<Member<CSSStyleSheet>> loadingClients;
408 copyToVector(m_loadingClients, loadingClients); 403 copyToVector(m_loadingClients, loadingClients);
409 404
410 for (unsigned i = 0; i < loadingClients.size(); ++i) { 405 for (unsigned i = 0; i < loadingClients.size(); ++i) {
411 if (loadingClients[i]->loadCompleted()) 406 if (loadingClients[i]->loadCompleted())
412 continue; 407 continue;
413 408
414 // sheetLoaded might be invoked after its owner node is removed from doc ument. 409 // sheetLoaded might be invoked after its owner node is removed from doc ument.
415 if (RawPtr<Node> ownerNode = loadingClients[i]->ownerNode()) { 410 if (Node* ownerNode = loadingClients[i]->ownerNode()) {
416 if (loadingClients[i]->sheetLoaded()) 411 if (loadingClients[i]->sheetLoaded())
417 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoad ErrorOccur ? Node::ErrorOccurredLoadingSubresource : Node::NoErrorLoadingSubreso urce); 412 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoad ErrorOccur ? Node::ErrorOccurredLoadingSubresource : Node::NoErrorLoadingSubreso urce);
418 } 413 }
419 } 414 }
420 } 415 }
421 416
422 void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet) 417 void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet)
423 { 418 {
424 ASSERT(sheet); 419 ASSERT(sheet);
425 m_didLoadErrorOccur |= sheet->errorOccurred(); 420 m_didLoadErrorOccur |= sheet->errorOccurred();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 visitor->trace(m_ownerRule); 670 visitor->trace(m_ownerRule);
676 visitor->trace(m_importRules); 671 visitor->trace(m_importRules);
677 visitor->trace(m_namespaceRules); 672 visitor->trace(m_namespaceRules);
678 visitor->trace(m_childRules); 673 visitor->trace(m_childRules);
679 visitor->trace(m_loadingClients); 674 visitor->trace(m_loadingClients);
680 visitor->trace(m_completedClients); 675 visitor->trace(m_completedClients);
681 visitor->trace(m_ruleSet); 676 visitor->trace(m_ruleSet);
682 } 677 }
683 678
684 } // namespace blink 679 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/StyleSheetContents.h ('k') | third_party/WebKit/Source/core/css/StyleSheetContentsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698