Title: [279847] trunk/Source
Revision
279847
Author
[email protected]
Date
2021-07-12 13:45:20 -0700 (Mon, 12 Jul 2021)

Log Message

Add a StyleSheets log channel and some logging
https://bugs.webkit.org/show_bug.cgi?id=227880

Reviewed by Alan Bujtas.

Source/WebCore:

Add some logging to help debug issues when pages dynamically build style sheets.

Also make Document loggable.

* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::insertRule):
(WebCore::CSSStyleSheet::deleteRule):
(WebCore::CSSStyleSheet::addRule):
(WebCore::CSSStyleSheet::debugDescription const):
* css/CSSStyleSheet.h:
* css/StyleSheet.cpp:
(WebCore::operator<<):
* css/StyleSheet.h:
* dom/Document.cpp:
(WebCore::Document::debugDescription const):
(WebCore::operator<<):
* dom/Document.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::process):
(WebCore::HTMLLinkElement::debugDescription const):
* html/HTMLLinkElement.h:
* platform/Logging.h:
* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::dumpProperties const):
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::imageBufferResult):
* style/StyleScope.cpp:
(WebCore::Style::Scope::addPendingSheet):
(WebCore::Style::Scope::addStyleSheetCandidateNode):
(WebCore::Style::Scope::collectActiveStyleSheets):
(WebCore::Style::Scope::updateActiveStyleSheets):
* xml/XSLStyleSheet.h:
* xml/XSLStyleSheetLibxslt.cpp:
(WebCore::XSLStyleSheet::debugDescription const):

Source/WTF:

Make it possible to feed Ref<> and RefPtr<> into TextStream.

* wtf/text/TextStream.h:
(WTF::operator<<):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (279846 => 279847)


--- trunk/Source/WTF/ChangeLog	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WTF/ChangeLog	2021-07-12 20:45:20 UTC (rev 279847)
@@ -1,3 +1,15 @@
+2021-07-12  Simon Fraser  <[email protected]>
+
+        Add a StyleSheets log channel and some logging
+        https://bugs.webkit.org/show_bug.cgi?id=227880
+
+        Reviewed by Alan Bujtas.
+
+        Make it possible to feed Ref<> and RefPtr<> into TextStream.
+
+        * wtf/text/TextStream.h:
+        (WTF::operator<<):
+
 2021-07-09  Jer Noble  <[email protected]>
 
         [Cocoa] Make Coordinator playback commands more precise

Modified: trunk/Source/WTF/wtf/text/TextStream.h (279846 => 279847)


--- trunk/Source/WTF/wtf/text/TextStream.h	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WTF/wtf/text/TextStream.h	2021-07-12 20:45:20 UTC (rev 279847)
@@ -28,6 +28,8 @@
 #include <wtf/Forward.h>
 #include <wtf/Markable.h>
 #include <wtf/OptionSet.h>
+#include <wtf/Ref.h>
+#include <wtf/RefPtr.h>
 #include <wtf/WeakPtr.h>
 #include <wtf/text/StringBuilder.h>
 
@@ -237,6 +239,21 @@
     return ts << "null";
 }
 
+template<typename T>
+TextStream& operator<<(TextStream& ts, const RefPtr<T>& item)
+{
+    if (item)
+        return ts << *item;
+    
+    return ts << "null";
+}
+
+template<typename T>
+TextStream& operator<<(TextStream& ts, const Ref<T>& item)
+{
+    return ts << item.get();
+}
+
 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
 TextStream& operator<<(TextStream& ts, const HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>& map)
 {

Modified: trunk/Source/WebCore/ChangeLog (279846 => 279847)


--- trunk/Source/WebCore/ChangeLog	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/ChangeLog	2021-07-12 20:45:20 UTC (rev 279847)
@@ -1,3 +1,45 @@
+2021-07-12  Simon Fraser  <[email protected]>
+
+        Add a StyleSheets log channel and some logging
+        https://bugs.webkit.org/show_bug.cgi?id=227880
+
+        Reviewed by Alan Bujtas.
+
+        Add some logging to help debug issues when pages dynamically build style sheets.
+
+        Also make Document loggable.
+
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::insertRule):
+        (WebCore::CSSStyleSheet::deleteRule):
+        (WebCore::CSSStyleSheet::addRule):
+        (WebCore::CSSStyleSheet::debugDescription const):
+        * css/CSSStyleSheet.h:
+        * css/StyleSheet.cpp:
+        (WebCore::operator<<):
+        * css/StyleSheet.h:
+        * dom/Document.cpp:
+        (WebCore::Document::debugDescription const):
+        (WebCore::operator<<):
+        * dom/Document.h:
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::process):
+        (WebCore::HTMLLinkElement::debugDescription const):
+        * html/HTMLLinkElement.h:
+        * platform/Logging.h:
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::dumpProperties const):
+        * platform/graphics/filters/FilterEffect.cpp:
+        (WebCore::FilterEffect::imageBufferResult):
+        * style/StyleScope.cpp:
+        (WebCore::Style::Scope::addPendingSheet):
+        (WebCore::Style::Scope::addStyleSheetCandidateNode):
+        (WebCore::Style::Scope::collectActiveStyleSheets):
+        (WebCore::Style::Scope::updateActiveStyleSheets):
+        * xml/XSLStyleSheet.h:
+        * xml/XSLStyleSheetLibxslt.cpp:
+        (WebCore::XSLStyleSheet::debugDescription const):
+
 2021-07-12  Chris Dumez  <[email protected]>
 
         Unreviewed, partial revert of r279661 to address crashes on iOS Debug.

Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (279846 => 279847)


--- trunk/Source/WebCore/css/CSSStyleSheet.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -28,6 +28,7 @@
 #include "Document.h"
 #include "HTMLLinkElement.h"
 #include "HTMLStyleElement.h"
+#include "Logging.h"
 #include "MediaList.h"
 #include "Node.h"
 #include "SVGStyleElement.h"
@@ -37,6 +38,9 @@
 #include "StyleScope.h"
 #include "StyleSheetContents.h"
 
+#include <wtf/HexNumber.h>
+#include <wtf/text/StringBuilder.h>
+
 namespace WebCore {
 
 class StyleSheetCSSRuleList final : public CSSRuleList {
@@ -247,6 +251,8 @@
 
 ExceptionOr<unsigned> CSSStyleSheet::insertRule(const String& ruleString, unsigned index)
 {
+    LOG_WITH_STREAM(StyleSheets, stream << "CSSStyleSheet " << this << " insertRule() " << ruleString << " at " << index);
+
     ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());
 
     if (index > length())
@@ -269,6 +275,8 @@
 
 ExceptionOr<void> CSSStyleSheet::deleteRule(unsigned index)
 {
+    LOG_WITH_STREAM(StyleSheets, stream << "CSSStyleSheet " << this << " deleteRule(" << index << ")");
+
     ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());
 
     if (index >= length())
@@ -288,6 +296,8 @@
 
 ExceptionOr<int> CSSStyleSheet::addRule(const String& selector, const String& style, std::optional<unsigned> index)
 {
+    LOG_WITH_STREAM(StyleSheets, stream << "CSSStyleSheet " << this << " addRule() selector " << selector << " style " << style << " at " << index);
+
     auto text = makeString(selector, " { ", style, !style.isEmpty() ? " " : "", '}');
     auto insertRuleResult = insertRule(text, index.value_or(length()));
     if (insertRuleResult.hasException())
@@ -374,6 +384,11 @@
     m_childRuleCSSOMWrappers.clear();
 }
 
+String CSSStyleSheet::debugDescription() const
+{
+    return makeString("CSSStyleSheet "_s, "0x"_s, hex(reinterpret_cast<uintptr_t>(this), Lowercase), ' ', href());
+}
+
 CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet, RuleMutationType mutationType, StyleRuleKeyframes* insertedKeyframesRule)
     : m_styleSheet(sheet)
     , m_mutationType(mutationType)

Modified: trunk/Source/WebCore/css/CSSStyleSheet.h (279846 => 279847)


--- trunk/Source/WebCore/css/CSSStyleSheet.h	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h	2021-07-12 20:45:20 UTC (rev 279847)
@@ -129,6 +129,8 @@
 
     bool canAccessRules() const;
 
+    String debugDescription() const final;
+
 private:
     CSSStyleSheet(Ref<StyleSheetContents>&&, CSSImportRule* ownerRule);
     CSSStyleSheet(Ref<StyleSheetContents>&&, Node* ownerNode, const TextPosition& startPosition, bool isInlineStylesheet);

Modified: trunk/Source/WebCore/css/StyleSheet.cpp (279846 => 279847)


--- trunk/Source/WebCore/css/StyleSheet.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/css/StyleSheet.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -20,8 +20,16 @@
 #include "config.h"
 #include "StyleSheet.h"
 
+#include <wtf/text/TextStream.h>
+
 namespace WebCore {
 
 StyleSheet::~StyleSheet() = default;
 
+TextStream& operator<<(TextStream& ts, const StyleSheet& styleSheet)
+{
+    ts << styleSheet.debugDescription();
+    return ts;
 }
+
+}

Modified: trunk/Source/WebCore/css/StyleSheet.h (279846 => 279847)


--- trunk/Source/WebCore/css/StyleSheet.h	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/css/StyleSheet.h	2021-07-12 20:45:20 UTC (rev 279847)
@@ -24,6 +24,10 @@
 #include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
 
+namespace WTF {
+class TextStream;
+}
+
 namespace WebCore {
 
 class CSSImportRule;
@@ -50,6 +54,10 @@
     virtual bool isLoading() const = 0;
     virtual bool isCSSStyleSheet() const { return false; }
     virtual bool isXSLStyleSheet() const { return false; }
+
+    virtual String debugDescription() const = 0;
 };
 
+TextStream& operator<<(TextStream&, const StyleSheet&);
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Document.cpp (279846 => 279847)


--- trunk/Source/WebCore/dom/Document.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -263,6 +263,7 @@
 #include <_javascript_Core/ScriptCallStack.h>
 #include <_javascript_Core/VM.h>
 #include <ctime>
+#include <wtf/HexNumber.h>
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/Language.h>
 #include <wtf/NeverDestroyed.h>
@@ -8888,6 +8889,24 @@
     return commonVM();
 }
 
+String Document::debugDescription() const
+{
+    StringBuilder builder;
+
+    builder.append("Document 0x"_s, hex(reinterpret_cast<uintptr_t>(this), Lowercase));
+    if (frame() && frame()->isMainFrame())
+        builder.append(" (main frame)"_s);
+
+    builder.append(' ', documentURI());
+    return builder.toString();
+}
+
+TextStream& operator<<(TextStream& ts, const Document& document)
+{
+    ts << document.debugDescription();
+    return ts;
+}
+
 } // namespace WebCore
 
 #undef DOCUMENT_RELEASE_LOG

Modified: trunk/Source/WebCore/dom/Document.h (279846 => 279847)


--- trunk/Source/WebCore/dom/Document.h	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/dom/Document.h	2021-07-12 20:45:20 UTC (rev 279847)
@@ -90,6 +90,10 @@
 class InputCursor;
 }
 
+namespace WTF {
+class TextStream;
+}
+
 namespace WebCore {
 
 class AXObjectCache;
@@ -1617,6 +1621,8 @@
 
     WEBCORE_EXPORT JSC::VM& vm() final;
 
+    String debugDescription() const;
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClassFlags = DefaultDocumentClass, unsigned constructionFlags = 0);
@@ -2237,6 +2243,8 @@
     return &document().contextDocument();
 }
 
+WTF::TextStream& operator<<(WTF::TextStream&, const Document&);
+
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Document)

Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (279846 => 279847)


--- trunk/Source/WebCore/html/HTMLLinkElement.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -64,6 +64,7 @@
 #include <wtf/Ref.h>
 #include <wtf/Scope.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/text/TextStream.h>
 
 namespace WebCore {
 
@@ -281,6 +282,8 @@
     if (!treatAsStyleSheet)
         treatAsStyleSheet = document().settings().treatsAnyTextCSSLinkAsStylesheet() && m_type.containsIgnoringASCIICase("text/css");
 
+    LOG_WITH_STREAM(StyleSheets, stream << "HTMLLinkElement " << this << " process() - treatAsStyleSheet " << treatAsStyleSheet);
+
     if (m_disabledState != Disabled && treatAsStyleSheet && document().frame() && url.isValid()) {
         String charset = attributeWithoutSynchronization(charsetAttr);
         if (!TextEncoding { charset }.isValid())
@@ -677,4 +680,9 @@
     return ReferrerPolicy::EmptyString;
 }
 
+String HTMLLinkElement::debugDescription() const
+{
+    return makeString(HTMLElement::debugDescription(), ' ', type(), ' ', href().string());
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLLinkElement.h (279846 => 279847)


--- trunk/Source/WebCore/html/HTMLLinkElement.h	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/html/HTMLLinkElement.h	2021-07-12 20:45:20 UTC (rev 279847)
@@ -123,6 +123,8 @@
 
     void finishParsingChildren() final;
 
+    String debugDescription() const final;
+
     enum PendingSheetType : uint8_t { Unknown, ActiveSheet, InactiveSheet };
     void addPendingSheet(PendingSheetType);
 

Modified: trunk/Source/WebCore/platform/Logging.h (279846 => 279847)


--- trunk/Source/WebCore/platform/Logging.h	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/platform/Logging.h	2021-07-12 20:45:20 UTC (rev 279847)
@@ -111,6 +111,7 @@
     M(SQLDatabase) \
     M(Storage) \
     M(StorageAPI) \
+    M(StyleSheets) \
     M(SVG) \
     M(TextAutosizing) \
     M(Tiling) \

Modified: trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp (279846 => 279847)


--- trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -949,7 +949,7 @@
     if (m_maskLayer) {
         ts << indent << "(mask layer";
         if (behavior & LayerTreeAsTextDebug)
-            ts << " " << m_maskLayer;
+            ts << " " << m_maskLayer.get();
         ts << ")\n";
 
         TextStream::IndentScope indentScope(ts);
@@ -959,7 +959,7 @@
     if (m_replicaLayer) {
         ts << indent << "(replica layer";
         if (behavior & LayerTreeAsTextDebug)
-            ts << " " << m_replicaLayer;
+            ts << " " << m_replicaLayer.get();
         ts << ")\n";
 
         TextStream::IndentScope indentScope(ts);

Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp (279846 => 279847)


--- trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -265,7 +265,7 @@
 
 ImageBuffer* FilterEffect::imageBufferResult()
 {
-    LOG_WITH_STREAM(Filters, stream << "FilterEffect " << filterName() << " " << this << " imageBufferResult(). Existing image buffer " << m_imageBufferResult <<  " m_premultipliedImageResult " << m_premultipliedImageResult << " m_unmultipliedImageResult " << m_unmultipliedImageResult);
+    LOG_WITH_STREAM(Filters, stream << "FilterEffect " << filterName() << " " << this << " imageBufferResult(). Existing image buffer " << m_imageBufferResult.get() <<  " m_premultipliedImageResult " << m_premultipliedImageResult << " m_unmultipliedImageResult " << m_unmultipliedImageResult);
 
     if (!hasResult())
         return nullptr;

Modified: trunk/Source/WebCore/style/StyleScope.cpp (279846 => 279847)


--- trunk/Source/WebCore/style/StyleScope.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/style/StyleScope.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -39,6 +39,7 @@
 #include "HTMLSlotElement.h"
 #include "HTMLStyleElement.h"
 #include "InspectorInstrumentation.h"
+#include "Logging.h"
 #include "ProcessingInstruction.h"
 #include "SVGStyleElement.h"
 #include "Settings.h"
@@ -222,6 +223,9 @@
     ASSERT(!hasPendingSheet(element));
 
     bool isInHead = ancestorsOfType<HTMLHeadElement>(element).first();
+
+    LOG_WITH_STREAM(StyleSheets, stream << "Scope " << this << " addPendingSheet() " << element << " isInHead " << isInHead);
+
     if (isInHead)
         m_elementsInHeadWithPendingSheets.add(&element);
     else
@@ -310,7 +314,9 @@
         }
         followingNode = n;
     } while (it != begin);
-    
+
+    LOG_WITH_STREAM(StyleSheets, stream << "Scope " << this << " addStyleSheetCandidateNode() " << node);
+
     m_styleSheetCandidateNodes.insertBefore(followingNode, &node);
 }
 
@@ -338,6 +344,8 @@
     if (!m_document.settings().authorAndUserStylesEnabled())
         return;
 
+    LOG_WITH_STREAM(StyleSheets, stream << "Scope " << this << " collectActiveStyleSheets()");
+
     for (auto& node : m_styleSheetCandidateNodes) {
         RefPtr<StyleSheet> sheet;
         if (is<ProcessingInstruction>(*node)) {
@@ -345,6 +353,7 @@
                 continue;
             // We don't support linking to embedded CSS stylesheets, see <https://bugs.webkit.org/show_bug.cgi?id=49281> for discussion.
             sheet = downcast<ProcessingInstruction>(*node).sheet();
+            LOG_WITH_STREAM(StyleSheets, stream << " adding sheet " << sheet << " from ProcessingInstruction node " << *node);
         } else if (is<HTMLLinkElement>(*node) || is<HTMLStyleElement>(*node) || is<SVGStyleElement>(*node)) {
             Element& element = downcast<Element>(*node);
             AtomString title = element.isInShadowTree() ? nullAtom() : element.attributeWithoutSynchronization(titleAttr);
@@ -374,6 +383,7 @@
                 sheet = downcast<HTMLLinkElement>(element).sheet();
             else
                 sheet = downcast<HTMLStyleElement>(element).sheet();
+
             // Check to see if this sheet belongs to a styleset
             // (thus making it PREFERRED or ALTERNATE rather than
             // PERSISTENT).
@@ -394,6 +404,9 @@
 
             if (rel.contains("alternate") && title.isEmpty())
                 sheet = nullptr;
+
+            if (sheet)
+                LOG_WITH_STREAM(StyleSheets, stream << " adding sheet " << sheet << " from " << *node);
         }
         if (sheet)
             sheets.append(WTFMove(sheet));
@@ -485,6 +498,8 @@
 
     filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
 
+    LOG_WITH_STREAM(StyleSheets, stream << "Scope::updateActiveStyleSheets for document " << m_document << " sheets " << activeCSSStyleSheets);
+
     auto styleSheetChange = StyleSheetChange { ResolverUpdateType::Reconstruct };
     if (updateType == UpdateType::ActiveSet)
         styleSheetChange = analyzeStyleSheetChange(activeCSSStyleSheets);

Modified: trunk/Source/WebCore/xml/XSLStyleSheet.h (279846 => 279847)


--- trunk/Source/WebCore/xml/XSLStyleSheet.h	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/xml/XSLStyleSheet.h	2021-07-12 20:45:20 UTC (rev 279847)
@@ -100,6 +100,7 @@
     XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const URL& finalURL);
 
     bool isXSLStyleSheet() const override { return true; }
+    String debugDescription() const final;
 
     void clearXSLStylesheetDocument();
 

Modified: trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp (279846 => 279847)


--- trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp	2021-07-12 20:18:36 UTC (rev 279846)
+++ trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp	2021-07-12 20:45:20 UTC (rev 279847)
@@ -36,6 +36,7 @@
 #include <libxml/uri.h>
 #include <libxslt/xsltutils.h>
 #include <wtf/CheckedArithmetic.h>
+#include <wtf/HexNumber.h>
 #include <wtf/unicode/CharacterNames.h>
 
 #if OS(DARWIN) && !PLATFORM(GTK)
@@ -317,6 +318,11 @@
     m_stylesheetDocTaken = true;
 }
 
+String XSLStyleSheet::debugDescription() const
+{
+    return makeString("XSLStyleSheet "_s, "0x"_s, hex(reinterpret_cast<uintptr_t>(this), Lowercase), ' ', href());
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(XSLT)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to