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

Unified Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 202893003: Reapply 169371 "DevTools: defer styles delta calculation to until the end of the task" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Lint Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorController.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp
index 82645d6e39cda700e3ea22d76bc96274e50e3fab..3ac48a43dbb299569f5943737a485acf9c8df568 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -431,11 +431,22 @@ void InspectorCSSAgent::restore()
wasEnabled(nullptr);
}
+void InspectorCSSAgent::flushPendingFrontendMessages()
+{
+ if (!m_invalidatedDocuments.size())
+ return;
+ HashSet<Document*> invalidatedDocuments;
+ m_invalidatedDocuments.swap(&invalidatedDocuments);
+ for (HashSet<Document*>::iterator it = invalidatedDocuments.begin(); it != invalidatedDocuments.end(); ++it)
+ updateActiveStyleSheets(*it, ExistingFrontendRefresh);
+}
+
void InspectorCSSAgent::reset()
{
m_idToInspectorStyleSheet.clear();
m_cssStyleSheetToInspectorStyleSheet.clear();
- m_frameToCSSStyleSheets.clear();
+ m_documentToCSSStyleSheets.clear();
+ m_invalidatedDocuments.clear();
m_nodeToInspectorStyleSheet.clear();
m_documentToViaInspectorStyleSheet.clear();
resetNonPersistentData();
@@ -490,10 +501,8 @@ void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback)
m_instrumentingAgents->setInspectorCSSAgent(this);
Vector<Document*> documents = m_domAgent->documents();
- for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) {
- Document* document = *it;
- updateActiveStyleSheetsForDocument(document, InitialFrontendLoad);
- }
+ for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it)
+ updateActiveStyleSheets(*it, InitialFrontendLoad);
if (callback)
callback->sendSuccess();
@@ -512,13 +521,20 @@ void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader)
return;
}
- updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
+ Vector<Document*> toDispose;
+ for (DocumentStyleSheets::iterator it = m_documentToCSSStyleSheets.begin(); it != m_documentToCSSStyleSheets.end(); ++it) {
+ Document* document = it->key;
+ if (!document->frame() || document->frame() == frame)
+ toDispose.append(document);
+ }
+ for (Vector<Document*>::iterator it = toDispose.begin(); it != toDispose.end(); ++it)
+ documentDetached(*it);
}
void InspectorCSSAgent::mediaQueryResultChanged()
{
- if (m_frontend)
- m_frontend->mediaQueryResultChanged();
+ flushPendingFrontendMessages();
+ m_frontend->mediaQueryResultChanged();
}
void InspectorCSSAgent::willMutateRules()
@@ -559,33 +575,30 @@ void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document)
{
if (styleSheetEditInProgress())
return;
- updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh);
+ m_invalidatedDocuments.add(document);
+ if (m_creatingViaInspectorStyleSheet)
+ flushPendingFrontendMessages();
}
-void InspectorCSSAgent::updateActiveStyleSheetsForDocument(Document* document, StyleSheetsUpdateType styleSheetsUpdateType)
+void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsUpdateType styleSheetsUpdateType)
{
- LocalFrame* frame = document->frame();
- if (!frame)
- return;
Vector<CSSStyleSheet*> newSheetsVector;
collectAllDocumentStyleSheets(document, newSheetsVector);
- updateActiveStyleSheets(frame, newSheetsVector, styleSheetsUpdateType);
+ setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType);
}
-void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType)
+void InspectorCSSAgent::setActiveStyleSheets(Document* document, const Vector<CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType)
{
bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad;
- HashSet<CSSStyleSheet*>* frameCSSStyleSheets = m_frameToCSSStyleSheets.get(frame);
- if (!frameCSSStyleSheets) {
- frameCSSStyleSheets = new HashSet<CSSStyleSheet*>();
- OwnPtr<HashSet<CSSStyleSheet*> > frameCSSStyleSheetsPtr = adoptPtr(frameCSSStyleSheets);
- m_frameToCSSStyleSheets.set(frame, frameCSSStyleSheetsPtr.release());
+ HashSet<CSSStyleSheet*>* documentCSSStyleSheets = m_documentToCSSStyleSheets.get(document);
+ if (!documentCSSStyleSheets) {
+ documentCSSStyleSheets = new HashSet<CSSStyleSheet*>();
+ OwnPtr<HashSet<CSSStyleSheet*> > documentCSSStyleSheetsPtr = adoptPtr(documentCSSStyleSheets);
+ m_documentToCSSStyleSheets.set(document, documentCSSStyleSheetsPtr.release());
}
- HashSet<CSSStyleSheet*> removedSheets;
- for (HashSet<CSSStyleSheet*>::iterator it = frameCSSStyleSheets->begin(); it != frameCSSStyleSheets->end(); ++it)
- removedSheets.add(*it);
+ HashSet<CSSStyleSheet*> removedSheets(*documentCSSStyleSheets);
HashSet<CSSStyleSheet*> addedSheets;
for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it != allSheetsVector.end(); ++it) {
@@ -604,9 +617,9 @@ void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<
RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspectorStyleSheet.get(cssStyleSheet);
ASSERT(inspectorStyleSheet);
+ documentCSSStyleSheets->remove(cssStyleSheet);
if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) {
String id = unbindStyleSheet(inspectorStyleSheet.get());
- frameCSSStyleSheets->remove(cssStyleSheet);
if (m_frontend && !isInitialFrontendLoad)
m_frontend->styleSheetRemoved(id);
}
@@ -617,19 +630,25 @@ void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<
bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSheet.contains(cssStyleSheet);
if (isNew) {
InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet);
- frameCSSStyleSheets->add(cssStyleSheet);
+ documentCSSStyleSheets->add(cssStyleSheet);
if (m_frontend)
m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSheetInfo());
}
}
- if (frameCSSStyleSheets->isEmpty())
- m_frameToCSSStyleSheets.remove(frame);
+ if (documentCSSStyleSheets->isEmpty())
+ m_documentToCSSStyleSheets.remove(document);
+}
+
+void InspectorCSSAgent::documentDetached(Document* document)
+{
+ m_invalidatedDocuments.remove(document);
+ setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
}
void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame)
{
- updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
+ documentDetached(frame->document());
}
bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoType pseudoType)
@@ -892,6 +911,8 @@ void InspectorCSSAgent::createStyleSheet(ErrorString* errorString, const String&
return;
}
+ updateActiveStyleSheets(document, ExistingFrontendRefresh);
+
*outStyleSheetId = inspectorStyleSheet->id();
}
@@ -1312,8 +1333,8 @@ void InspectorCSSAgent::didModifyDOMAttr(Element* element)
void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet)
{
- if (m_frontend)
- m_frontend->styleSheetChanged(styleSheet->id());
+ flushPendingFrontendMessages();
+ m_frontend->styleSheetChanged(styleSheet->id());
}
void InspectorCSSAgent::willReparseStyleSheet()
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698