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

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

Issue 202623003: Reapply 169354 "DevTools: track stylesheets by document, not local frame" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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/InspectorInstrumentation.idl » ('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..1601e47d11bab6a57b314dba8fda55459fe6f698 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -435,7 +435,7 @@ void InspectorCSSAgent::reset()
{
m_idToInspectorStyleSheet.clear();
m_cssStyleSheetToInspectorStyleSheet.clear();
- m_frameToCSSStyleSheets.clear();
+ m_documentToCSSStyleSheets.clear();
m_nodeToInspectorStyleSheet.clear();
m_documentToViaInspectorStyleSheet.clear();
resetNonPersistentData();
@@ -490,10 +490,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,7 +510,14 @@ 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)
+ documentDisposed(*it);
}
void InspectorCSSAgent::mediaQueryResultChanged()
@@ -559,33 +564,28 @@ void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document)
{
if (styleSheetEditInProgress())
return;
- updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh);
+ updateActiveStyleSheets(document, ExistingFrontendRefresh);
}
-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 +604,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 +617,24 @@ 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::documentDisposed(Document* document)
+{
+ setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
}
void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame)
{
- updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
+ documentDisposed(frame->document());
}
bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoType pseudoType)
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorInstrumentation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698