Chromium Code Reviews| Index: Source/core/inspector/InspectorCSSAgent.cpp |
| diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp |
| index ae9418a15a0a7335583068b20701750f93e56d5c..f14e1bd262e6d2475a6a6232c05e430c53a428f2 100644 |
| --- a/Source/core/inspector/InspectorCSSAgent.cpp |
| +++ b/Source/core/inspector/InspectorCSSAgent.cpp |
| @@ -435,7 +435,8 @@ 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 +491,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 +511,11 @@ void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader) |
| return; |
| } |
| - updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh); |
| + for (HashSet<Document*>::iterator it = m_invalidatedDocuments.begin(); it != m_invalidatedDocuments.end(); ++it) { |
| + Document* document = *it; |
| + if (!document->frame() || document->frame() == frame) |
| + documentDisposed(document); |
| + } |
| } |
| void InspectorCSSAgent::mediaQueryResultChanged() |
| @@ -555,36 +558,47 @@ void InspectorCSSAgent::didMutateStyle(CSSStyleDeclaration* style, bool isInline |
| } |
| } |
| +void InspectorCSSAgent::didProcessTask() |
| +{ |
| + if (!m_invalidatedDocuments.size()) |
| + return; |
| + HashSet<Document*> invalidatedDocuments; |
| + m_invalidatedDocuments.swap(&invalidatedDocuments); |
|
lushnikov
2014/03/17 08:46:43
This is nifty; but why not simply clear m_invalida
pfeldman
2014/03/17 12:32:58
For re-entrance.
|
| + for (HashSet<Document*>::iterator it = invalidatedDocuments.begin(); it != invalidatedDocuments.end(); ++it) |
| + updateActiveStyleSheets(*it, ExistingFrontendRefresh); |
| +} |
| + |
| void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) |
| { |
| if (styleSheetEditInProgress()) |
| return; |
| - updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh); |
| + if (m_creatingViaInspectorStyleSheet) |
|
lushnikov
2014/03/17 08:37:32
I don't see where you set this to true
pfeldman
2014/03/17 12:32:58
It was there.
|
| + updateActiveStyleSheets(document, ExistingFrontendRefresh); |
| + else |
| + m_invalidatedDocuments.add(document); |
| } |
| -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) |
| + for (HashSet<CSSStyleSheet*>::iterator it = documentCSSStyleSheets->begin(); it != documentCSSStyleSheets->end(); ++it) |
| removedSheets.add(*it); |
| HashSet<CSSStyleSheet*> addedSheets; |
| @@ -606,7 +620,7 @@ void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector< |
| if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { |
| String id = unbindStyleSheet(inspectorStyleSheet.get()); |
| - frameCSSStyleSheets->remove(cssStyleSheet); |
| + documentCSSStyleSheets->remove(cssStyleSheet); |
| if (m_frontend && !isInitialFrontendLoad) |
| m_frontend->styleSheetRemoved(id); |
| } |
| @@ -617,19 +631,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::documentDisposed(Document* document) |
| +{ |
| + m_invalidatedDocuments.remove(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) |