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

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

Issue 28553005: Avoid parsing css text if there are identical inline style blocks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased 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/StyleSheetContents.h" 22 #include "core/css/StyleSheetContents.h"
23 23
24 #include "core/css/CSSParser.h" 24 #include "core/css/CSSParser.h"
25 #include "core/css/CSSStyleSheet.h" 25 #include "core/css/CSSStyleSheet.h"
26 #include "core/css/MediaList.h" 26 #include "core/css/MediaList.h"
27 #include "core/css/StylePropertySet.h" 27 #include "core/css/StylePropertySet.h"
28 #include "core/css/StyleRule.h" 28 #include "core/css/StyleRule.h"
29 #include "core/css/StyleRuleImport.h" 29 #include "core/css/StyleRuleImport.h"
30 #include "core/dom/Node.h" 30 #include "core/dom/Node.h"
31 #include "core/dom/StyleEngine.h"
31 #include "core/fetch/CSSStyleSheetResource.h" 32 #include "core/fetch/CSSStyleSheetResource.h"
32 #include "platform/TraceEvent.h" 33 #include "platform/TraceEvent.h"
33 #include "weborigin/SecurityOrigin.h" 34 #include "weborigin/SecurityOrigin.h"
34 #include "wtf/Deque.h" 35 #include "wtf/Deque.h"
35 36
36 namespace WebCore { 37 namespace WebCore {
37 38
38 // Rough size estimate for the memory cache. 39 // Rough size estimate for the memory cache.
39 unsigned StyleSheetContents::estimatedSizeInBytes() const 40 unsigned StyleSheetContents::estimatedSizeInBytes() const
40 { 41 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 87
87 // FIXME: Copy import rules. 88 // FIXME: Copy import rules.
88 ASSERT(o.m_importRules.isEmpty()); 89 ASSERT(o.m_importRules.isEmpty());
89 90
90 for (unsigned i = 0; i < m_childRules.size(); ++i) 91 for (unsigned i = 0; i < m_childRules.size(); ++i)
91 m_childRules[i] = o.m_childRules[i]->copy(); 92 m_childRules[i] = o.m_childRules[i]->copy();
92 } 93 }
93 94
94 StyleSheetContents::~StyleSheetContents() 95 StyleSheetContents::~StyleSheetContents()
95 { 96 {
97 StyleEngine::removeSheet(this);
96 clearRules(); 98 clearRules();
97 } 99 }
98 100
99 bool StyleSheetContents::isCacheable() const 101 void StyleSheetContents::setMutable()
102 {
103 // If the contents is changed to be mutable, it is safe not to share the con tents with others.
104 if (maybeCacheable())
105 StyleEngine::removeSheet(this);
106 m_isMutable = true;
esprehn 2013/11/15 10:27:37 You can't make yourself mutable like this, you hav
tasak 2014/01/09 09:24:50 I see. I moved the logic to CSSStyleSheet::willMut
107 }
108
109 void StyleSheetContents::setHasSyntacticallyValidCSSHeader(bool isValidCss)
110 {
111 if (maybeCacheable() && !isValidCss)
112 StyleEngine::removeSheet(this);
113 m_hasSyntacticallyValidCSSHeader = isValidCss;
114 }
115
116 bool StyleSheetContents::maybeCacheable() const
100 { 117 {
101 // FIXME: Support copying import rules. 118 // FIXME: Support copying import rules.
102 if (!m_importRules.isEmpty()) 119 if (!m_importRules.isEmpty())
103 return false; 120 return false;
104 // FIXME: Support cached stylesheets in import rules. 121 // FIXME: Support cached stylesheets in import rules.
105 if (m_ownerRule) 122 if (m_ownerRule)
106 return false; 123 return false;
107 // This would require dealing with multiple clients for load callbacks.
108 if (!m_loadCompleted)
109 return false;
110 if (m_didLoadErrorOccur) 124 if (m_didLoadErrorOccur)
111 return false; 125 return false;
112 // It is not the original sheet anymore. 126 // It is not the original sheet anymore.
113 if (m_isMutable) 127 if (m_isMutable)
114 return false; 128 return false;
115 // If the header is valid we are not going to need to check the SecurityOrig in. 129 // If the header is valid we are not going to need to check the SecurityOrig in.
116 // FIXME: Valid mime type avoids the check too. 130 // FIXME: Valid mime type avoids the check too.
117 if (!m_hasSyntacticallyValidCSSHeader) 131 if (!m_hasSyntacticallyValidCSSHeader)
118 return false; 132 return false;
119 return true; 133 return true;
120 } 134 }
121 135
136 bool StyleSheetContents::isCacheable() const
137 {
138 // This would require dealing with multiple clients for load callbacks.
139 if (!m_loadCompleted)
140 return false;
141 return maybeCacheable();
142 }
143
122 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) 144 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
123 { 145 {
124 ASSERT(!rule->isCharsetRule()); 146 ASSERT(!rule->isCharsetRule());
125 if (rule->isImportRule()) { 147 if (rule->isImportRule()) {
126 // Parser enforces that @import rules come before anything else except @ charset. 148 // Parser enforces that @import rules come before anything else except @ charset.
127 ASSERT(m_childRules.isEmpty()); 149 ASSERT(m_childRules.isEmpty());
128 m_importRules.append(static_cast<StyleRuleImport*>(rule.get())); 150 m_importRules.append(static_cast<StyleRuleImport*>(rule.get()));
129 m_importRules.last()->setParentStyleSheet(this); 151 m_importRules.last()->setParentStyleSheet(this);
130 m_importRules.last()->requestStyleSheet(); 152 m_importRules.last()->requestStyleSheet();
131 return; 153 return;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 330
309 bool StyleSheetContents::isLoading() const 331 bool StyleSheetContents::isLoading() const
310 { 332 {
311 for (unsigned i = 0; i < m_importRules.size(); ++i) { 333 for (unsigned i = 0; i < m_importRules.size(); ++i) {
312 if (m_importRules[i]->isLoading()) 334 if (m_importRules[i]->isLoading())
313 return true; 335 return true;
314 } 336 }
315 return false; 337 return false;
316 } 338 }
317 339
318 void StyleSheetContents::checkLoaded() 340 void StyleSheetContents::checkLoadedFor(PassRefPtr<Node> ownerNode)
319 { 341 {
320 if (isLoading()) 342 if (isLoading())
321 return; 343 return;
322 344
323 // Avoid |this| being deleted by scripts that run via 345 // Avoid |this| being deleted by scripts that run via
324 // ScriptableDocumentParser::executeScriptsWaitingForResources(). 346 // ScriptableDocumentParser::executeScriptsWaitingForResources().
325 // See https://bugs.webkit.org/show_bug.cgi?id=95106 347 // See https://bugs.webkit.org/show_bug.cgi?id=95106
326 RefPtr<StyleSheetContents> protect(this); 348 RefPtr<StyleSheetContents> protect(this);
327 349
328 StyleSheetContents* parentSheet = parentStyleSheet(); 350 StyleSheetContents* parentSheet = parentStyleSheet();
329 if (parentSheet) { 351 if (parentSheet) {
330 parentSheet->checkLoaded(); 352 parentSheet->checkLoadedFor(ownerNode);
331 m_loadCompleted = true; 353 m_loadCompleted = true;
332 return; 354 return;
333 } 355 }
334 RefPtr<Node> ownerNode = singleOwnerNode();
335 if (!ownerNode) { 356 if (!ownerNode) {
336 m_loadCompleted = true; 357 m_loadCompleted = true;
337 return; 358 return;
338 } 359 }
339 m_loadCompleted = ownerNode->sheetLoaded(); 360 m_loadCompleted = ownerNode->sheetLoaded();
340 if (m_loadCompleted) 361 if (m_loadCompleted)
341 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoadErrorOcc ur); 362 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoadErrorOcc ur);
342 } 363 }
343 364
365 void StyleSheetContents::checkLoaded()
366 {
367 if (isLoading())
368 return;
369
370 // Avoid |this| being deleted by scripts that run via
371 // ScriptableDocumentParser::executeScriptsWaitingForResources().
372 // See https://bugs.webkit.org/show_bug.cgi?id=95106
373 RefPtr<StyleSheetContents> protect(this);
374
375 StyleSheetContents* parentSheet = parentStyleSheet();
376 if (parentSheet) {
377 parentSheet->checkLoaded();
378 m_loadCompleted = true;
379 return;
380 }
381
382 StyleSheetContents* root = rootStyleSheet();
383 if (root->m_clients.isEmpty()) {
384 m_loadCompleted = true;
385 return;
386 }
387
388 for (unsigned i = 0; i < root->m_clients.size(); ++i) {
389 RefPtr<Node> ownerNode = m_clients[i]->ownerNode();
390 ASSERT(ownerNode);
391 bool loadCompleted = ownerNode->sheetLoaded();
esprehn 2013/11/15 10:27:37 How could the sheet have loaded for one node but n
tasak 2014/01/09 09:24:50 I see. I moved loadCompleted to CSSStyleSheet. If
392 ASSERT(i <= 0 || m_loadCompleted == loadCompleted);
393 m_loadCompleted = loadCompleted;
394 if (loadCompleted)
395 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoadErro rOccur);
396 }
397 }
398
344 void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet) 399 void StyleSheetContents::notifyLoadedSheet(const CSSStyleSheetResource* sheet)
345 { 400 {
346 ASSERT(sheet); 401 ASSERT(sheet);
347 m_didLoadErrorOccur |= sheet->errorOccurred(); 402 m_didLoadErrorOccur |= sheet->errorOccurred();
348 } 403 }
349 404
350 void StyleSheetContents::startLoadingDynamicSheet() 405 void StyleSheetContents::startLoadingDynamicSheet()
351 { 406 {
352 if (Node* owner = singleOwnerNode()) 407 if (Node* owner = singleOwnerNode())
353 owner->startLoadingDynamicSheet(); 408 owner->startLoadingDynamicSheet();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 m_isInMemoryCache = false; 548 m_isInMemoryCache = false;
494 } 549 }
495 550
496 void StyleSheetContents::shrinkToFit() 551 void StyleSheetContents::shrinkToFit()
497 { 552 {
498 m_importRules.shrinkToFit(); 553 m_importRules.shrinkToFit();
499 m_childRules.shrinkToFit(); 554 m_childRules.shrinkToFit();
500 } 555 }
501 556
502 } 557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698