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

Side by Side Diff: Source/core/dom/StyleEngine.cpp

Issue 1050783003: Remove stylesheet injection from Blink. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revert devtool removals Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | Source/core/page/InjectedStyleSheets.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 26 matching lines...) Expand all
37 #include "core/dom/DocumentStyleSheetCollector.h" 37 #include "core/dom/DocumentStyleSheetCollector.h"
38 #include "core/dom/Element.h" 38 #include "core/dom/Element.h"
39 #include "core/dom/ProcessingInstruction.h" 39 #include "core/dom/ProcessingInstruction.h"
40 #include "core/dom/ShadowTreeStyleSheetCollection.h" 40 #include "core/dom/ShadowTreeStyleSheetCollection.h"
41 #include "core/dom/shadow/ShadowRoot.h" 41 #include "core/dom/shadow/ShadowRoot.h"
42 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
43 #include "core/html/HTMLIFrameElement.h" 43 #include "core/html/HTMLIFrameElement.h"
44 #include "core/html/HTMLLinkElement.h" 44 #include "core/html/HTMLLinkElement.h"
45 #include "core/html/imports/HTMLImportsController.h" 45 #include "core/html/imports/HTMLImportsController.h"
46 #include "core/inspector/InspectorInstrumentation.h" 46 #include "core/inspector/InspectorInstrumentation.h"
47 #include "core/page/InjectedStyleSheets.h"
48 #include "core/page/Page.h" 47 #include "core/page/Page.h"
49 #include "core/svg/SVGStyleElement.h" 48 #include "core/svg/SVGStyleElement.h"
50 #include "platform/URLPatternMatcher.h"
51 49
52 namespace blink { 50 namespace blink {
53 51
54 using namespace HTMLNames; 52 using namespace HTMLNames;
55 53
56 StyleEngine::StyleEngine(Document& document) 54 StyleEngine::StyleEngine(Document& document)
57 : m_document(&document) 55 : m_document(&document)
58 , m_isMaster(!document.importsController() || document.importsController()-> master() == &document) 56 , m_isMaster(!document.importsController() || document.importsController()-> master() == &document)
59 , m_pendingStylesheets(0) 57 , m_pendingStylesheets(0)
60 , m_injectedStyleSheetCacheValid(false)
61 , m_documentStyleSheetCollection(DocumentStyleSheetCollection::create(docume nt)) 58 , m_documentStyleSheetCollection(DocumentStyleSheetCollection::create(docume nt))
62 , m_documentScopeDirty(true) 59 , m_documentScopeDirty(true)
63 , m_usesSiblingRules(false) 60 , m_usesSiblingRules(false)
64 , m_usesFirstLineRules(false) 61 , m_usesFirstLineRules(false)
65 , m_usesWindowInactiveSelector(false) 62 , m_usesWindowInactiveSelector(false)
66 , m_usesFirstLetterRules(false) 63 , m_usesFirstLetterRules(false)
67 , m_usesRemUnits(false) 64 , m_usesRemUnits(false)
68 , m_maxDirectAdjacentSelectors(0) 65 , m_maxDirectAdjacentSelectors(0)
69 , m_ignorePendingStylesheets(false) 66 , m_ignorePendingStylesheets(false)
70 , m_didCalculateResolver(false) 67 , m_didCalculateResolver(false)
(...skipping 13 matching lines...) Expand all
84 { 81 {
85 return isHTMLStyleElement(node) || isSVGStyleElement(node); 82 return isHTMLStyleElement(node) || isSVGStyleElement(node);
86 } 83 }
87 84
88 #if !ENABLE(OILPAN) 85 #if !ENABLE(OILPAN)
89 void StyleEngine::detachFromDocument() 86 void StyleEngine::detachFromDocument()
90 { 87 {
91 // Cleanup is performed eagerly when the StyleEngine is removed from the 88 // Cleanup is performed eagerly when the StyleEngine is removed from the
92 // document. The StyleEngine is unreachable after this, since only the 89 // document. The StyleEngine is unreachable after this, since only the
93 // document has a reference to it. 90 // document has a reference to it.
94 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i)
95 m_injectedAuthorStyleSheets[i]->clearOwnerNode();
96 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) 91 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i)
97 m_authorStyleSheets[i]->clearOwnerNode(); 92 m_authorStyleSheets[i]->clearOwnerNode();
98 93
99 if (m_fontSelector) { 94 if (m_fontSelector) {
100 m_fontSelector->clearDocument(); 95 m_fontSelector->clearDocument();
101 m_fontSelector->unregisterForInvalidationCallbacks(this); 96 m_fontSelector->unregisterForInvalidationCallbacks(this);
102 } 97 }
103 98
104 // Decrement reference counts for things we could be keeping alive. 99 // Decrement reference counts for things we could be keeping alive.
105 m_fontSelector.clear(); 100 m_fontSelector.clear();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 219 }
225 220
226 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) 221 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features)
227 { 222 {
228 m_usesSiblingRules = features.usesSiblingRules(); 223 m_usesSiblingRules = features.usesSiblingRules();
229 m_usesFirstLineRules = features.usesFirstLineRules(); 224 m_usesFirstLineRules = features.usesFirstLineRules();
230 m_usesWindowInactiveSelector = features.usesWindowInactiveSelector(); 225 m_usesWindowInactiveSelector = features.usesWindowInactiveSelector();
231 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); 226 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors();
232 } 227 }
233 228
234 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>>& StyleEngine::injected AuthorStyleSheets() const
235 {
236 updateInjectedStyleSheetCache();
237 return m_injectedAuthorStyleSheets;
238 }
239
240 void StyleEngine::updateInjectedStyleSheetCache() const
241 {
242 if (m_injectedStyleSheetCacheValid)
243 return;
244 m_injectedStyleSheetCacheValid = true;
245 m_injectedAuthorStyleSheets.clear();
246
247 Page* owningPage = document().page();
248 if (!owningPage)
249 return;
250
251 const InjectedStyleSheetEntryVector& entries = InjectedStyleSheets::instance ().entries();
252 for (unsigned i = 0; i < entries.size(); ++i) {
253 const InjectedStyleSheetEntry* entry = entries[i].get();
254 if (entry->injectedFrames() == InjectStyleInTopFrameOnly && document().o wnerElement())
255 continue;
256 if (!URLPatternMatcher::matchesPatterns(document().url(), entry->whiteli st()))
257 continue;
258 RefPtrWillBeRawPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInli ne(m_document, KURL());
259 m_injectedAuthorStyleSheets.append(groupSheet);
260 groupSheet->contents()->parseString(entry->source());
261 }
262 }
263
264 void StyleEngine::invalidateInjectedStyleSheetCache()
265 {
266 m_injectedStyleSheetCacheValid = false;
267 markDocumentDirty();
268 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio n::updateActiveStyleSheets
269 // and batch updates lots of sheets so we can't call addedStyleSheet() or re movedStyleSheet().
270 document().styleResolverChanged();
271 }
272
273 void StyleEngine::compatibilityModeChanged()
274 {
275 if (!m_injectedAuthorStyleSheets.isEmpty())
276 invalidateInjectedStyleSheetCache();
277 }
278
279 void StyleEngine::addAuthorSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> auth orSheet) 229 void StyleEngine::addAuthorSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> auth orSheet)
280 { 230 {
281 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_document)); 231 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_document));
282 document().addedStyleSheet(m_authorStyleSheets.last().get()); 232 document().addedStyleSheet(m_authorStyleSheets.last().get());
283 markDocumentDirty(); 233 markDocumentDirty();
284 } 234 }
285 235
286 void StyleEngine::addPendingSheet() 236 void StyleEngine::addPendingSheet()
287 { 237 {
288 m_pendingStylesheets++; 238 m_pendingStylesheets++;
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 visitor->trace(m_dirtyTreeScopes); 706 visitor->trace(m_dirtyTreeScopes);
757 visitor->trace(m_activeTreeScopes); 707 visitor->trace(m_activeTreeScopes);
758 visitor->trace(m_fontSelector); 708 visitor->trace(m_fontSelector);
759 visitor->trace(m_textToSheetCache); 709 visitor->trace(m_textToSheetCache);
760 visitor->trace(m_sheetToTextCache); 710 visitor->trace(m_sheetToTextCache);
761 #endif 711 #endif
762 CSSFontSelectorClient::trace(visitor); 712 CSSFontSelectorClient::trace(visitor);
763 } 713 }
764 714
765 } 715 }
OLDNEW
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | Source/core/page/InjectedStyleSheets.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698