Web Inspector: Implement tracking of active stylesheets in the frontend
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Aug 2015 23:48:49 +0000 (23:48 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Aug 2015 23:48:49 +0000 (23:48 +0000)
commitb9a79291c646a8c7fe89b741bd817614c558157e
treed3942efd709aa402a531eba2c60e37755dd1a555
parent1edbe8eb5d12088414c3f3be6d45ef10c22d2e16
Web Inspector: Implement tracking of active stylesheets in the frontend
https://bugs.webkit.org/show_bug.cgi?id=105828

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/protocol/CSS.json:
Add new events for when a StyleSheet is added or removed.

Source/WebCore:

Tests: inspector/css/stylesheet-events-basic.html
       inspector/css/stylesheet-events-imports.html
       inspector/css/stylesheet-events-inspector-stylesheet.html

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::documentDetachedImpl):
(WebCore::InspectorInstrumentation::activeStyleSheetsUpdatedImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::documentDetached):
(WebCore::InspectorInstrumentation::activeStyleSheetsUpdated):
New hooks for when a document is detached or a document's style sheets are updated.

* dom/Document.cpp:
(WebCore::Document::prepareForDestruction):
Inform the inspector so the CSSAgent can remove document related data.

* dom/DocumentStyleSheetCollection.h:
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
Inform the inspector so the CSSAgent can push stylesheet related events.

(WebCore::DocumentStyleSheetCollection::activeStyleSheetsForInspector): Added.
CSSStyleSheets for the inspector include non-disabled author stylesheets
even if they are empty.

* inspector/InspectorCSSAgent.h:
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::reset):
(WebCore::InspectorCSSAgent::documentDetached):
Handling for the new list of known document to CSSStyleSheets map.

(WebCore::InspectorCSSAgent::enable):
When the CSS domain is enabled, tell the frontend about known stylesheets.

(WebCore::InspectorCSSAgent::activeStyleSheetsUpdated):
(WebCore::InspectorCSSAgent::setActiveStyleSheetsForDocument):
Diff the old list of known stylesheets to the new list of stylesheets
for an individual document. Then send appropriate added/removed events.

(WebCore::InspectorCSSAgent::collectAllStyleSheets):
(WebCore::InspectorCSSAgent::collectAllDocumentStyleSheets):
(WebCore::InspectorCSSAgent::collectStyleSheets):
Collect stylesheets recursively. A stylesheet may link to other stylesheets
through @import statements.

(WebCore::InspectorCSSAgent::getAllStyleSheets):
Use the new methods, this command should go away as it will no longer be useful.

(WebCore::InspectorCSSAgent::unbindStyleSheet):
(WebCore::InspectorCSSAgent::bindStyleSheet):
Create an InspectorStyleSheet from a CSSStyleSheet and add to the appropriate lists.
Likewise, unbinding will remove from the appropriate lists.

(WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
(WebCore::InspectorCSSAgent::detectOrigin):
When creating the inspector stylesheet, which is a <style> element,
it will push a StyleSheetAdded event. In the process of binding this
new stylesheet use the m_creatingViaInspectorStyleSheet to add it to
out list of Inspector Stylesheets.

Source/WebInspectorUI:

* UserInterface/Models/CSSStyleSheet.js:
(WebInspector.CSSStyleSheet):
(WebInspector.CSSStyleSheet.prototype.get origin):
(WebInspector.CSSStyleSheet.prototype.updateInfo):
Add a new origin attribute that has been sent from the backend for a while.

* UserInterface/Controllers/CSSStyleManager.js:
(WebInspector.CSSStyleManager.prototype.styleSheetAdded):
(WebInspector.CSSStyleManager.prototype.styleSheetRemoved):
Handle the new events by managing the new CSSStyleSheets.

(WebInspector.CSSStyleManager):
(WebInspector.CSSStyleManager.prototype._mainResourceDidChange):
Reset the legacy fetching flag. Fetching is only needed for legacy backends.

(WebInspector.CSSStyleManager.prototype._fetchInfoForAllStyleSheets):
Include the new origin property in the legacy updateInfo path.

* UserInterface/Protocol/CSSObserver.js:
(WebInspector.CSSObserver.prototype.styleSheetAdded):
(WebInspector.CSSObserver.prototype.styleSheetRemoved):
Forward to the manager.

* UserInterface/Views/CSSStyleDetailsSidebarPanel.js:
(WebInspector.CSSStyleDetailsSidebarPanel):
Refresh the sidebar when stylesheets are added / removed, as that
may affect the style of the select element.

LayoutTests:

* inspector/css/resources/import-level-1.css: Added.
* inspector/css/resources/import-level-2.css: Added.
* inspector/css/resources/stylesheet-events-subframe.html: Added.
* inspector/css/stylesheet-events-basic-expected.txt: Added.
* inspector/css/stylesheet-events-basic.html: Added.
* inspector/css/stylesheet-events-imports-expected.txt: Added.
* inspector/css/stylesheet-events-imports.html: Added.
* inspector/css/stylesheet-events-inspector-stylesheet-expected.txt: Added.
* inspector/css/stylesheet-events-inspector-stylesheet.html: Added.
* inspector/css/stylesheet-events-multiple-documents-expected.txt: Added.
* inspector/css/stylesheet-events-multiple-documents.html: Added.
Tests for different ways that StyleSheets can be added / removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189002 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/css/resources/import-level-1.css [new file with mode: 0644]
LayoutTests/inspector/css/resources/import-level-2.css [new file with mode: 0644]
LayoutTests/inspector/css/resources/stylesheet-events-subframe.html [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-basic-expected.txt [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-basic.html [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-imports-expected.txt [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-imports.html [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet-expected.txt [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet.html [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-multiple-documents-expected.txt [new file with mode: 0644]
LayoutTests/inspector/css/stylesheet-events-multiple-documents.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/protocol/CSS.json
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/dom/DocumentStyleSheetCollection.h
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorCSSAgent.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js
Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js
Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js
Source/WebInspectorUI/UserInterface/Protocol/CSSObserver.js
Source/WebInspectorUI/UserInterface/Views/CSSStyleDetailsSidebarPanel.js