Diff
Modified: trunk/Source/WebCore/ChangeLog (254185 => 254186)
--- trunk/Source/WebCore/ChangeLog 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebCore/ChangeLog 2020-01-08 05:02:02 UTC (rev 254186)
@@ -1,3 +1,37 @@
+2020-01-07 Devin Rousso <drou...@apple.com>
+
+ Web Inspector: unable to edit or view the source of style sheets injected by safari app extensions
+ https://bugs.webkit.org/show_bug.cgi?id=205900
+ <rdar://problem/57898773>
+
+ Reviewed by Timothy Hatcher.
+
+ Remove the restrictions around `CSS.StyleSheetOrigin.User` style sheets, thereby allowing
+ Web Inspector to get the source information that is necessary to show the "resource" in the
+ Sources Tab.
+
+ * dom/ExtensionStyleSheets.h:
+ * dom/ExtensionStyleSheets.cpp:
+ (WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
+ (WebCore::ExtensionStyleSheets::contentForInjectedStyleSheet const): Added.
+ Save a copy of the string source of any injected style sheet and provide a way to get it for
+ any given `CSSStyleSheet`.
+
+ * style/StyleScope.cpp:
+ (WebCore::Style::Scope::activeStyleSheetsForInspector):
+ * style/InspectorCSSOMWrappers.cpp:
+ (WebCore::Style::InspectorCSSOMWrappers::collectDocumentWrappers):
+ Include all types of extension style sheets when collecting active rules and style sheets
+ for Web Inspector to instrument.
+
+ * inspector/InspectorStyleSheet.cpp:
+ * inspector/InspectorStyleSheet.h:
+ (WebCore::InspectorStyleSheet::buildObjectForRule):
+ (WebCore::InspectorStyleSheet::originalStyleSheetText const):
+ (WebCore::InspectorStyleSheet::resourceStyleSheetText const):
+ (WebCore::InspectorStyleSheet::inlineStyleSheetText const):
+ (WebCore::InspectorStyleSheet::extensionStyleSheetText const): Added.
+
2020-01-07 Alex Christensen <achristen...@webkit.org>
Introduce _WKResourceLoadDelegate
Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp (254185 => 254186)
--- trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp 2020-01-08 05:02:02 UTC (rev 254186)
@@ -117,9 +117,11 @@
{
if (m_injectedStyleSheetCacheValid)
return;
+
m_injectedStyleSheetCacheValid = true;
m_injectedUserStyleSheets.clear();
m_injectedAuthorStyleSheets.clear();
+ m_injectedStyleSheetToSource.clear();
Page* owningPage = m_document.page();
if (!owningPage)
@@ -134,6 +136,8 @@
auto sheet = createExtensionsStyleSheet(const_cast<Document&>(m_document), userStyleSheet.url(), userStyleSheet.source(), userStyleSheet.level());
+ m_injectedStyleSheetToSource.set(sheet.copyRef(), userStyleSheet.source());
+
if (userStyleSheet.level() == UserStyleUserLevel)
m_injectedUserStyleSheets.append(WTFMove(sheet));
else
@@ -189,6 +193,11 @@
}
#endif // ENABLE(CONTENT_EXTENSIONS)
+String ExtensionStyleSheets::contentForInjectedStyleSheet(const RefPtr<CSSStyleSheet>& styleSheet) const
+{
+ return m_injectedStyleSheetToSource.get(styleSheet);
+}
+
void ExtensionStyleSheets::detachFromDocument()
{
if (m_pageUserSheet)
Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.h (254185 => 254186)
--- trunk/Source/WebCore/dom/ExtensionStyleSheets.h 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.h 2020-01-08 05:02:02 UTC (rev 254186)
@@ -72,6 +72,8 @@
void maybeAddContentExtensionSheet(const String& identifier, StyleSheetContents&);
#endif
+ String contentForInjectedStyleSheet(const RefPtr<CSSStyleSheet>&) const;
+
void detachFromDocument();
private:
@@ -81,6 +83,7 @@
mutable Vector<RefPtr<CSSStyleSheet>> m_injectedUserStyleSheets;
mutable Vector<RefPtr<CSSStyleSheet>> m_injectedAuthorStyleSheets;
+ mutable HashMap<RefPtr<CSSStyleSheet>, String> m_injectedStyleSheetToSource;
mutable bool m_injectedStyleSheetCacheValid { false };
Vector<RefPtr<CSSStyleSheet>> m_userStyleSheets;
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (254185 => 254186)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2020-01-08 05:02:02 UTC (rev 254186)
@@ -41,6 +41,7 @@
#include "ContentSecurityPolicy.h"
#include "Document.h"
#include "Element.h"
+#include "ExtensionStyleSheets.h"
#include "HTMLHeadElement.h"
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
@@ -1167,8 +1168,7 @@
.setStyle(buildObjectForStyle(&rule->style()))
.release();
- // "sourceURL" is present only for regular rules, otherwise "origin" should be used in the frontend.
- if (m_origin == Inspector::Protocol::CSS::StyleSheetOrigin::Regular)
+ if (m_origin == Inspector::Protocol::CSS::StyleSheetOrigin::Regular || m_origin == Inspector::Protocol::CSS::StyleSheetOrigin::User)
result->setSourceURL(finalURL());
if (canBind()) {
@@ -1404,15 +1404,12 @@
bool InspectorStyleSheet::originalStyleSheetText(String* result) const
{
- bool success = inlineStyleSheetText(result);
- if (!success)
- success = resourceStyleSheetText(result);
- return success;
+ return inlineStyleSheetText(result) || resourceStyleSheetText(result) || extensionStyleSheetText(result);
}
bool InspectorStyleSheet::resourceStyleSheetText(String* result) const
{
- if (m_origin == Inspector::Protocol::CSS::StyleSheetOrigin::User || m_origin == Inspector::Protocol::CSS::StyleSheetOrigin::UserAgent)
+ if (m_origin != Inspector::Protocol::CSS::StyleSheetOrigin::Regular && m_origin != Inspector::Protocol::CSS::StyleSheetOrigin::Inspector)
return false;
if (!m_pageStyleSheet || !ownerDocument() || !ownerDocument()->frame())
@@ -1426,20 +1423,40 @@
bool InspectorStyleSheet::inlineStyleSheetText(String* result) const
{
+ if (m_origin != Inspector::Protocol::CSS::StyleSheetOrigin::Regular)
+ return false;
+
if (!m_pageStyleSheet)
return false;
- Node* ownerNode = m_pageStyleSheet->ownerNode();
+ auto* ownerNode = m_pageStyleSheet->ownerNode();
if (!is<Element>(ownerNode))
return false;
- Element& ownerElement = downcast<Element>(*ownerNode);
+ auto& ownerElement = downcast<Element>(*ownerNode);
if (!is<HTMLStyleElement>(ownerElement) && !is<SVGStyleElement>(ownerElement))
return false;
+
*result = ownerElement.textContent();
return true;
}
+bool InspectorStyleSheet::extensionStyleSheetText(String* result) const
+{
+ if (m_origin != Inspector::Protocol::CSS::StyleSheetOrigin::User)
+ return false;
+
+ if (!m_pageStyleSheet || !ownerDocument())
+ return false;
+
+ auto content = ownerDocument()->extensionStyleSheets().contentForInjectedStyleSheet(m_pageStyleSheet);
+ if (content.isEmpty())
+ return false;
+
+ *result = content;
+ return true;
+}
+
Ref<JSON::ArrayOf<Inspector::Protocol::CSS::CSSRule>> InspectorStyleSheet::buildArrayForRuleList(CSSRuleList* ruleList)
{
auto result = JSON::ArrayOf<Inspector::Protocol::CSS::CSSRule>::create();
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.h (254185 => 254186)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2020-01-08 05:02:02 UTC (rev 254186)
@@ -213,6 +213,7 @@
bool originalStyleSheetText(String* result) const;
bool resourceStyleSheetText(String* result) const;
bool inlineStyleSheetText(String* result) const;
+ bool extensionStyleSheetText(String* result) const;
Ref<JSON::ArrayOf<Inspector::Protocol::CSS::CSSRule>> buildArrayForRuleList(CSSRuleList*);
Ref<Inspector::Protocol::CSS::CSSSelector> buildObjectForSelector(const CSSSelector*, Element*);
Ref<Inspector::Protocol::CSS::SelectorList> buildObjectForSelectorList(CSSStyleRule*, Element*, int& endingLine);
Modified: trunk/Source/WebCore/style/InspectorCSSOMWrappers.cpp (254185 => 254186)
--- trunk/Source/WebCore/style/InspectorCSSOMWrappers.cpp 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebCore/style/InspectorCSSOMWrappers.cpp 2020-01-08 05:02:02 UTC (rev 254186)
@@ -124,6 +124,8 @@
collect(extensionStyleSheets.pageUserSheet());
collectFromStyleSheets(extensionStyleSheets.injectedUserStyleSheets());
collectFromStyleSheets(extensionStyleSheets.documentUserStyleSheets());
+ collectFromStyleSheets(extensionStyleSheets.injectedAuthorStyleSheets());
+ collectFromStyleSheets(extensionStyleSheets.authorStyleSheetsForTesting());
}
}
Modified: trunk/Source/WebCore/style/StyleScope.cpp (254185 => 254186)
--- trunk/Source/WebCore/style/StyleScope.cpp 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebCore/style/StyleScope.cpp 2020-01-08 05:02:02 UTC (rev 254186)
@@ -517,6 +517,10 @@
{
Vector<RefPtr<CSSStyleSheet>> result;
+ if (auto* pageUserSheet = m_document.extensionStyleSheets().pageUserSheet())
+ result.append(pageUserSheet);
+ result.appendVector(m_document.extensionStyleSheets().documentUserStyleSheets());
+ result.appendVector(m_document.extensionStyleSheets().injectedUserStyleSheets());
result.appendVector(m_document.extensionStyleSheets().injectedAuthorStyleSheets());
result.appendVector(m_document.extensionStyleSheets().authorStyleSheetsForTesting());
Modified: trunk/Source/WebInspectorUI/ChangeLog (254185 => 254186)
--- trunk/Source/WebInspectorUI/ChangeLog 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/ChangeLog 2020-01-08 05:02:02 UTC (rev 254186)
@@ -1,5 +1,77 @@
2020-01-07 Devin Rousso <drou...@apple.com>
+ Web Inspector: unable to edit or view the source of style sheets injected by safari app extensions
+ https://bugs.webkit.org/show_bug.cgi?id=205900
+ <rdar://problem/57898773>
+
+ Reviewed by Timothy Hatcher.
+
+ Remove the restrictions around `CSS.StyleSheetOrigin.User` style sheets, thereby allowing
+ Web Inspector to get the source information that is necessary to show the "resource" in the
+ Sources Tab.
+
+ * UserInterface/Models/CSSStyleSheet.js:
+ (WI.CSSStyleSheet.prototype.get displayName):
+ (WI.CSSStyleSheet.prototype.get injected): Added.
+ (WI.CSSStyleSheet.prototype.get anonymous): Added.
+
+ * UserInterface/Models/DOMNodeStyles.js:
+ (WI.DOMNodeStyles.prototype._parseRulePayload):
+ * UserInterface/Models/CSSRule.js:
+ (WI.CSSRule):
+ (WI.CSSRule.prototype.get editable):
+ (WI.CSSRule.prototype._selectorResolved):
+ Attempt to create a source code location for any style sheet with a source range, not just
+ for the Inspector Style Sheet.
+
+ * UserInterface/Views/CSSStyleSheetTreeElement.js:
+ (WI.CSSStyleSheetTreeElement):
+ Instead of hardcoding "Inspector Style Sheet", use the associated `WI.CSSStyleSheet`'s info.
+
+ * UserInterface/Views/FrameTreeElement.js:
+ (WI.FrameTreeElement):
+ (WI.FrameTreeElement.prototype.onattach):
+ (WI.FrameTreeElement.prototype.ondetach):
+ (WI.FrameTreeElement.prototype._styleSheetAdded):
+ (WI.FrameTreeElement.prototype._styleSheetRemoved): Added.
+ Ensure that only non-injected non-anonymous style sheets are shown under frames.
+
+ * UserInterface/Views/SourcesNavigationSidebarPanel.js:
+ (WI.SourcesNavigationSidebarPanel):
+ (WI.SourcesNavigationSidebarPanel.prototype._compareTreeElements):
+ (WI.SourcesNavigationSidebarPanel.prototype._addResource):
+ (WI.SourcesNavigationSidebarPanel.prototype._addStyleSheet): Added.
+ (WI.SourcesNavigationSidebarPanel.prototype._handleResourceGroupingModeChanged):
+ (WI.SourcesNavigationSidebarPanel.prototype._handleCSSStyleSheetAdded): Added.
+ (WI.SourcesNavigationSidebarPanel.prototype._handleCSSStyleSheetRemoved): Added.
+ Add "Extension Style Sheets", "Extra Style Sheets", and "Anonymous Style Sheets" folders,
+ just like for scripts, with a similar logic as to when style sheets are added to each.
+
+ * UserInterface/Views/OpenResourceDialog.js:
+ (WI.OpenResourceDialog):
+ (WI.OpenResourceDialog.prototype.representedObjectIsValid): Added.
+ (WI.OpenResourceDialog.prototype._populateResourceTreeOutline):
+ (WI.OpenResourceDialog.prototype._populateResourceTreeOutline.createTreeElement):
+ (WI.OpenResourceDialog.prototype.didDismissDialog):
+ (WI.OpenResourceDialog.prototype.didPresentDialog):
+ (WI.OpenResourceDialog.prototype._removeResource): Added.
+ (WI.OpenResourceDialog.prototype._resourceWasRemoved): Added.
+ (WI.OpenResourceDialog.prototype._scriptAdded):
+ (WI.OpenResourceDialog.prototype._scriptRemoved): Added.
+ (WI.OpenResourceDialog.prototype._handleStyleSheetAdded): Added.
+ (WI.OpenResourceDialog.prototype._handleStyleSheetRemoved): Added.
+ Add any non-injected non-anonymous style sheets when populating the list of resources.
+ Drive-by: remove listings for any resources that are removed from the inspected page.
+
+ * UserInterface/Views/ResourceTreeElement.js:
+ (WI.ResourceTreeElement.compareResourceTreeElements):
+ (WI.ResourceTreeElement.compareResourceTreeElements.resolvedType): Added.
+ Support comparisons against non-resource tree elements.
+
+ * Localizations/en.lproj/localizedStrings.js:
+
+2020-01-07 Devin Rousso <drou...@apple.com>
+
REGRESSION: [ Mac Debug ] inspector/page/setBootstrapScript-main-frame.html is a flaky failure
https://bugs.webkit.org/show_bug.cgi?id=205807
<rdar://problem/58344669>
Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -526,8 +526,10 @@
localizedStrings["Export result (%s)"] = "Export result (%s)";
localizedStrings["_expression_"] = "_expression_";
localizedStrings["Extension Scripts"] = "Extension Scripts";
+localizedStrings["Extension Style Sheets"] = "Extension Style Sheets";
localizedStrings["Extensions"] = "Extensions";
localizedStrings["Extra Scripts"] = "Extra Scripts";
+localizedStrings["Extra Style Sheets"] = "Extra Style Sheets";
localizedStrings["Fade unexecuted code"] = "Fade unexecuted code";
localizedStrings["Failed to upgrade"] = "Failed to upgrade";
localizedStrings["Failure status code"] = "Failure status code";
Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSRule.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSRule.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSRule.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -54,7 +54,7 @@
get editable()
{
- return !!this._id && (this._type === WI.CSSStyleSheet.Type.Author || this._type === WI.CSSStyleSheet.Type.Inspector);
+ return !!this._id && this._type !== WI.CSSStyleSheet.Type.UserAgent;
}
get selectorText()
@@ -135,9 +135,8 @@
}
if (this._ownerStyleSheet) {
- if (!sourceCodeLocation && this._ownerStyleSheet.isInspectorStyleSheet())
+ if (!sourceCodeLocation && sourceRange)
sourceCodeLocation = this._ownerStyleSheet.createSourceCodeLocation(sourceRange.startLine, sourceRange.startColumn);
-
sourceCodeLocation = this._ownerStyleSheet.offsetSourceCodeLocation(sourceCodeLocation);
}
Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -68,6 +68,16 @@
return this._origin;
}
+ get injected()
+ {
+ return this.urlComponents && this.urlComponents.scheme.endsWith("extension");
+ }
+
+ get anonymous()
+ {
+ return !this.isInspectorStyleSheet() && !this._url;
+ }
+
get url()
{
return this._url;
@@ -87,6 +97,9 @@
get displayName()
{
+ if (this.isInspectorStyleSheet())
+ return WI.UIString("Inspector Style Sheet");
+
if (this._url)
return WI.displayNameForURL(this._url, this.urlComponents);
Modified: trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -689,9 +689,8 @@
}
if (styleSheet) {
- if (!sourceCodeLocation && styleSheet.isInspectorStyleSheet())
+ if (!sourceCodeLocation && sourceRange)
sourceCodeLocation = styleSheet.createSourceCodeLocation(sourceRange.startLine, sourceRange.startColumn);
-
sourceCodeLocation = styleSheet.offsetSourceCodeLocation(sourceCodeLocation);
}
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleSheetTreeElement.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleSheetTreeElement.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleSheetTreeElement.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -28,8 +28,23 @@
constructor(styleSheet)
{
console.assert(styleSheet instanceof WI.CSSStyleSheet);
- console.assert(styleSheet.isInspectorStyleSheet());
- super(styleSheet, ["style-sheet", "style-sheet-icon"], WI.UIString("Inspector Style Sheet"));
+ const title = null;
+ const subtitle = null;
+ super(styleSheet, ["style-sheet", "style-sheet-icon"], title, subtitle);
+
+ this.mainTitle = styleSheet.displayName;
+
+ if (styleSheet.url) {
+ if (styleSheet.urlComponents.scheme === "web-inspector")
+ this.tooltip = this.mainTitle;
+ else {
+ // Show the host as the subtitle if it is different from the main title.
+ let host = WI.displayNameForHost(styleSheet.urlComponents.host);
+ this.subtitle = this.mainTitle !== host ? host : null;
+
+ this.tooltip = styleSheet.url;
+ }
+ }
}
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -116,11 +116,13 @@
WI.GeneralTreeElement.prototype.onattach.call(this);
WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetAdded, this._styleSheetAdded, this);
+ WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetRemoved, this._styleSheetRemoved, this);
}
ondetach()
{
WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetAdded, this._styleSheetAdded, this);
+ WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetRemoved, this._styleSheetRemoved, this);
super.ondetach();
}
@@ -259,9 +261,19 @@
_styleSheetAdded(event)
{
- if (!event.data.styleSheet.isInspectorStyleSheet())
+ let {styleSheet} = event.data;
+ if (styleSheet.origin === WI.CSSStyleSheet.Type.Author || styleSheet.injected || styleSheet.anonymous)
return;
- this.addRepresentedObjectToNewChildQueue(event.data.styleSheet);
+ this.addRepresentedObjectToNewChildQueue(styleSheet);
}
+
+ _styleSheetRemoved(event)
+ {
+ let {styleSheet} = event.data;
+ if (styleSheet.origin === WI.CSSStyleSheet.Type.Author || styleSheet.injected || styleSheet.anonymous)
+ return;
+
+ this.removeChildForRepresentedObject(styleSheet);
+ }
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -63,6 +63,17 @@
// Protected
+ representedObjectIsValid(value)
+ {
+ if (value instanceof WI.Script && value.anonymous)
+ return false;
+
+ if (value instanceof WI.CSSStyleSheet && value.anonymous)
+ return false;
+
+ return super.representedObjectIsValid(value);
+ }
+
_populateResourceTreeOutline()
{
function createHighlightedTitleFragment(title, highlightTextRanges)
@@ -96,6 +107,8 @@
treeElement = new WI.ResourceTreeElement(representedObject);
else if (representedObject instanceof WI.Script)
treeElement = new WI.ScriptTreeElement(representedObject);
+ else if (representedObject instanceof WI.CSSStyleSheet)
+ treeElement = new WI.CSSStyleSheetTreeElement(representedObject);
return treeElement;
}
@@ -134,8 +147,12 @@
{
WI.Frame.removeEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
WI.Frame.removeEventListener(WI.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
+ WI.Frame.removeEventListener(WI.Frame.Event.ResourceWasRemoved, this._resourceWasRemoved, this);
WI.Target.removeEventListener(WI.Target.Event.ResourceAdded, this._resourceWasAdded, this);
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.ScriptAdded, this._scriptAdded, this);
+ WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.ScriptRemoved, this._scriptRemoved, this);
+ WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetAdded, this._handleStyleSheetAdded, this);
+ WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetRemoved, this._handleStyleSheetRemoved, this);
this._queryController.reset();
}
@@ -144,8 +161,12 @@
{
WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
WI.Frame.addEventListener(WI.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
+ WI.Frame.addEventListener(WI.Frame.Event.ResourceWasRemoved, this._resourceWasRemoved, this);
WI.Target.addEventListener(WI.Target.Event.ResourceAdded, this._resourceWasAdded, this);
WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ScriptAdded, this._scriptAdded, this);
+ WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ScriptRemoved, this._scriptRemoved, this);
+ WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetAdded, this._handleStyleSheetAdded, this);
+ WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetRemoved, this._handleStyleSheetRemoved, this);
if (WI.networkManager.mainFrame)
this._addResourcesForFrame(WI.networkManager.mainFrame);
@@ -167,6 +188,11 @@
}
}
+ for (let styleSheet of WI.cssManager.styleSheets) {
+ if (styleSheet.origin !== WI.CSSStyleSheet.Type.Author)
+ this._addResource(styleSheet);
+ }
+
this._updateFilter();
this._inputElement.focus();
@@ -303,6 +329,16 @@
this._updateFilter();
}
+ _removeResource(resource)
+ {
+ if (!this.representedObjectIsValid(resource))
+ return;
+
+ this._queryController.removeResource(resource);
+
+ this._updateFilter();
+ }
+
_addResourcesForFrame(frame)
{
const suppressFilterUpdate = true;
@@ -378,17 +414,46 @@
this._addResource(event.data.resource);
}
+ _resourceWasRemoved(event)
+ {
+ this._removeResource(event.data.resource);
+ }
+
_scriptAdded(event)
{
- let script = event.data.script;
- if (script.resource)
+ let {script} = event.data;
+ if (script.resource || script.target === WI.mainTarget)
return;
- if (script.target === WI.mainTarget)
+ this._addResource(script);
+ }
+
+ _scriptRemoved(event)
+ {
+ let {script} = event.data;
+ if (script.resource || script.target === WI.mainTarget)
return;
- this._addResource(script);
+ this._removeResource(script);
}
+
+ _handleStyleSheetAdded(event)
+ {
+ let {styleSheet} = event.data;
+ if (styleSheet.origin === WI.CSSStyleSheet.Type.Author || styleSheet.injected || styleSheet.anonymous)
+ return;
+
+ this._addResource(styleSheet);
+ }
+
+ _handleStyleSheetRemoved(event)
+ {
+ let {styleSheet} = event.data;
+ if (styleSheet.origin === WI.CSSStyleSheet.Type.Author || styleSheet.injected || styleSheet.anonymous)
+ return;
+
+ this._removeResource(styleSheet);
+ }
};
WI.OpenResourceDialog.ResourceMatchCookieDataSymbol = Symbol("open-resource-dialog-resource-match-cookie-data");
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -46,16 +46,35 @@
static compareResourceTreeElements(a, b)
{
+ console.assert(a instanceof WI.SourceCodeTreeElement);
+ console.assert(b instanceof WI.SourceCodeTreeElement);
+
+ let resourceA = a.resource || a.representedObject;
+ let resourceB = b.resource || b.representedObject;
+
+ function resolvedType(resource) {
+ if (resource instanceof WI.Resource)
+ return resource.type;
+ if (resource instanceof WI.CSSStyleSheet)
+ return WI.Resource.Type.StyleSheet;
+ if (resource instanceof WI.Script)
+ return WI.Resource.Type.Script;
+ return WI.Resource.Type.Other;
+ }
+
+ let typeA = resolvedType(resourceA);
+ let typeB = resolvedType(resourceB);
+
// Compare by type first to keep resources grouped by type when not sorted into folders.
- var comparisonResult = a.resource.type.extendedLocaleCompare(b.resource.type);
+ var comparisonResult = typeA.extendedLocaleCompare(typeB);
if (comparisonResult !== 0)
return comparisonResult;
// Compare async resource types by their first timestamp so they are in chronological order.
- if (a.resource.type === WI.Resource.Type.XHR
- || a.resource.type === WI.Resource.Type.Fetch
- || a.resource.type === WI.Resource.Type.WebSocket)
- return a.resource.firstTimestamp - b.resource.firstTimestamp || 0;
+ if (typeA === WI.Resource.Type.XHR
+ || typeA === WI.Resource.Type.Fetch
+ || typeA === WI.Resource.Type.WebSocket)
+ return resourceA.firstTimestamp - resourceB.firstTimestamp || 0;
// Compare by subtitle when the types are the same. The subtitle is used to show the
// domain of the resource. This causes resources to group by domain. If the resource
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js (254185 => 254186)
--- trunk/Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js 2020-01-08 04:03:38 UTC (rev 254185)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js 2020-01-08 05:02:02 UTC (rev 254186)
@@ -33,8 +33,11 @@
this._workerTargetTreeElementMap = new Map;
this._mainFrameTreeElement = null;
this._extensionScriptsFolderTreeElement = null;
+ this._extensionStyleSheetsFolderTreeElement = null;
this._extraScriptsFolderTreeElement = null;
+ this._extraStyleSheetsFolderTreeElement = null;
this._anonymousScriptsFolderTreeElement = null;
+ this._anonymousStyleSheetsFolderTreeElement = null;
this._originTreeElementMap = new Map;
@@ -314,6 +317,7 @@
WI.auditManager.addEventListener(WI.AuditManager.Event.TestCompleted, this._handleAuditManagerTestCompleted, this);
WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetAdded, this._handleCSSStyleSheetAdded, this);
+ WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetRemoved, this._handleCSSStyleSheetRemoved, this);
WI.targetManager.addEventListener(WI.TargetManager.Event.TargetAdded, this._handleTargetAdded, this);
WI.targetManager.addEventListener(WI.TargetManager.Event.TargetRemoved, this._handleTargetRemoved, this);
@@ -744,12 +748,18 @@
(treeElement) => treeElement instanceof WI.OriginTreeElement,
(treeElement) => {
return treeElement !== this._extensionScriptsFolderTreeElement
+ && treeElement !== this._extensionStyleSheetsFolderTreeElement
&& treeElement !== this._extraScriptsFolderTreeElement
- && treeElement !== this._anonymousScriptsFolderTreeElement;
+ && treeElement !== this._extraStyleSheetsFolderTreeElement
+ && treeElement !== this._anonymousScriptsFolderTreeElement
+ && treeElement !== this._anonymousStyleSheetsFolderTreeElement;
},
(treeElement) => treeElement === this._extensionScriptsFolderTreeElement,
+ (treeElement) => treeElement === this._extensionStyleSheetsFolderTreeElement,
(treeElement) => treeElement === this._extraScriptsFolderTreeElement,
+ (treeElement) => treeElement === this._extraStyleSheetsFolderTreeElement,
(treeElement) => treeElement === this._anonymousScriptsFolderTreeElement,
+ (treeElement) => treeElement === this._anonymousStyleSheetsFolderTreeElement,
];
let aRank = rankFunctions.findIndex((rankFunction) => rankFunction(a));
@@ -861,8 +871,10 @@
let parentTreeElement = null;
- if (resource instanceof WI.CSSStyleSheet && resource.isInspectorStyleSheet())
+ if (resource instanceof WI.CSSStyleSheet) {
+ console.assert(resource.isInspectorStyleSheet());
parentTreeElement = this._resourcesTreeOutline.findTreeElement(resource.parentFrame.mainResource);
+ }
if (!parentTreeElement) {
let origin = resource.urlComponents.origin;
@@ -917,6 +929,38 @@
}
}
+ _addStyleSheet(styleSheet)
+ {
+ console.assert(styleSheet instanceof WI.CSSStyleSheet);
+ console.assert(!styleSheet.isInspectorStyleSheet());
+
+ let parentTreeElement = null;
+
+ if (styleSheet.injected) {
+ if (!this._extensionStyleSheetsFolderTreeElement)
+ this._extensionStyleSheetsFolderTreeElement = new WI.FolderTreeElement(WI.UIString("Extension Style Sheets"), new WI.CSSStyleSheetCollection);
+ parentTreeElement = this._extensionStyleSheetsFolderTreeElement;
+ } else if (!styleSheet.anonymous) {
+ if (!this._extraStyleSheetsFolderTreeElement)
+ this._extraStyleSheetsFolderTreeElement = new WI.FolderTreeElement(WI.UIString("Extra Style Sheets"), new WI.CSSStyleSheetCollection);
+ parentTreeElement = this._extraStyleSheetsFolderTreeElement;
+ } else {
+ if (!this._anonymousStyleSheetsFolderTreeElement)
+ this._anonymousStyleSheetsFolderTreeElement = new WI.FolderTreeElement(WI.UIString("Anonymous Style Sheets"), new WI.CSSStyleSheetCollection);
+ parentTreeElement = this._anonymousStyleSheetsFolderTreeElement;
+ }
+
+ if (!parentTreeElement.parent) {
+ let index = insertionIndexForObjectInListSortedByFunction(parentTreeElement, this._resourcesTreeOutline.children, this._boundCompareTreeElements);
+ this._resourcesTreeOutline.insertChild(parentTreeElement, index);
+ }
+
+ let treeElement = new WI.CSSStyleSheetTreeElement(styleSheet);
+
+ let index = insertionIndexForObjectInListSortedByFunction(treeElement, parentTreeElement.children, this._boundCompareTreeElements);
+ parentTreeElement.insertChild(treeElement, index);
+ }
+
_addScript(script)
{
// We don't add scripts without URLs here. Those scripts can quickly clutter the interface and
@@ -1987,8 +2031,11 @@
this._workerTargetTreeElementMap.clear();
this._mainFrameTreeElement = null;
this._extensionScriptsFolderTreeElement = null;
+ this._extensionStyleSheetsFolderTreeElement = null;
this._extraScriptsFolderTreeElement = null;
+ this._extraStyleSheetsFolderTreeElement = null;
this._anonymousScriptsFolderTreeElement = null;
+ this._anonymousStyleSheetsFolderTreeElement = null;
this._originTreeElementMap.clear();
@@ -2016,6 +2063,11 @@
if (script.sourceMaps.length && WI.SourcesNavigationSidebarPanel.shouldPlaceResourcesAtTopLevel())
this._resourcesTreeOutline.disclosureButtons = true;
}
+
+ for (let styleSheet of WI.cssManager.styleSheets) {
+ if (styleSheet.origin !== WI.CSSStyleSheet.Type.Author && !styleSheet.isInspectorStyleSheet())
+ this._addStyleSheet(styleSheet);
+ }
}
_handleFrameMainResourceDidChange(event)
@@ -2362,21 +2414,55 @@
_handleCSSStyleSheetAdded(event)
{
- let styleSheet = event.data.styleSheet;
- if (!styleSheet.isInspectorStyleSheet())
+ let {styleSheet} = event.data;
+ if (styleSheet.origin === WI.CSSStyleSheet.Type.Author)
return;
- if (WI.settings.resourceGroupingMode.value === WI.Resource.GroupingMode.Type) {
- let frameTreeElement = this.treeElementForRepresentedObject(styleSheet.parentFrame);
- if (frameTreeElement) {
- frameTreeElement.addRepresentedObjectToNewChildQueue(styleSheet);
- return;
+ if (styleSheet.isInspectorStyleSheet()) {
+ if (WI.settings.resourceGroupingMode.value === WI.Resource.GroupingMode.Type) {
+ let frameTreeElement = this.treeElementForRepresentedObject(styleSheet.parentFrame);
+ if (frameTreeElement) {
+ frameTreeElement.addRepresentedObjectToNewChildQueue(styleSheet);
+ return;
+ }
}
- }
- this._addResource(styleSheet);
+ this._addResource(styleSheet);
+ } else
+ this._addStyleSheet(styleSheet);
}
+ _handleCSSStyleSheetRemoved(event)
+ {
+ let {styleSheet} = event.data;
+ if (styleSheet.origin === WI.CSSStyleSheet.Type.Author)
+ return;
+
+ let treeElement = this._resourcesTreeOutline.findTreeElement(styleSheet);
+ if (!treeElement)
+ return;
+
+ let parent = treeElement.parent;
+ treeElement.parent.removeChild(treeElement);
+
+ if (!parent.children.length)
+ parent.parent.removeChild(parent);
+
+ switch (parent) {
+ case this._extensionStyleSheetsFolderTreeElement:
+ this._extensionStyleSheetsFolderTreeElement = null;
+ break;
+
+ case this._extraStyleSheetsFolderTreeElement:
+ this._extraStyleSheetsFolderTreeElement = null;
+ break;
+
+ case this._anonymousStyleSheetsFolderTreeElement:
+ this._anonymousStyleSheetsFolderTreeElement = null;
+ break;
+ }
+ }
+
_handleTargetAdded(event)
{
this._addTarget(event.data.target);