| Differences between
and this patch
- a/LayoutTests/ChangeLog +12 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2015-02-10  Joseph Pecoraro  <pecoraro@apple.com>
2
3
        Web Inspector: Crash inspecting styles of element with mutated stylesheet
4
        https://bugs.webkit.org/show_bug.cgi?id=141451
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * inspector/css/stylesheet-with-mutations-expected.txt: Added.
9
        * inspector/css/stylesheet-with-mutations.html: Added.
10
        Previously this test would crash, or in debug builds show one
11
        of the two selectors in the rule.
12
1
2015-02-09  Brent Fulgham  <bfulgham@apple.com>
13
2015-02-09  Brent Fulgham  <bfulgham@apple.com>
2
14
3
        [Win] Activate media tests. (Unreviewed)
15
        [Win] Activate media tests. (Unreviewed)
- a/LayoutTests/inspector/css/stylesheet-with-mutations-expected.txt +5 lines
Line 0 a/LayoutTests/inspector/css/stylesheet-with-mutations-expected.txt_sec1
1
Testing that we get expected values for selectors after CSSOM stylesheet modifications.
2
3
.foo
4
.bar
5
- a/LayoutTests/inspector/css/stylesheet-with-mutations.html +58 lines
Line 0 a/LayoutTests/inspector/css/stylesheet-with-mutations.html_sec1
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<style>
5
.foo, .bar { color: red; }
6
</style>
7
<script type="text/javascript" src="../../http/tests/inspector/inspector-test.js"></script>
8
<script>
9
// Insert a rule at the beginning of the inline stylesheet above that would shift all rule ordinals down.
10
document.styleSheets[0].insertRule("body { padding: 10px; }", 0);
11
12
function test() {
13
    var nodeStyles;
14
15
    function validateSelectors()
16
    {
17
        for (var i = 0; i < nodeStyles.matchedRules.length; ++i) {
18
            var rule = nodeStyles.matchedRules[i];
19
            if (rule.type !== WebInspector.CSSRule.Type.Author)
20
                continue;
21
22
            for (var selector of rule.selectors)
23
                InspectorTest.log(selector.text);
24
        }
25
26
        InspectorTest.completeTest();
27
    }
28
29
    function onStylesRefreshed()
30
    {
31
        nodeStyles.removeEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, onStylesRefreshed, this);
32
        validateSelectors();
33
    }
34
35
    WebInspector.domTreeManager.requestDocument(function(documentNode) {
36
        WebInspector.domTreeManager.querySelector(documentNode.id, ".bar", function(contentNodeId) {
37
            if (contentNodeId) {
38
                var domNode = WebInspector.domTreeManager.nodeForId(contentNodeId);
39
                nodeStyles = WebInspector.cssStyleManager.stylesForNode(domNode);
40
41
                if (nodeStyles.needsRefresh)
42
                    nodeStyles.addEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, onStylesRefreshed, this);
43
                else
44
                    validateSelectors();
45
            } else {
46
                InspectorTest.log("DOM node not found.");
47
                InspectorTest.completeTest();
48
            }
49
        });
50
    });
51
}
52
</script>
53
</head>
54
<body onload="runTest()">
55
    <p>Testing that we get expected values for selectors after a stylesheet has mutations.</p>
56
    <div class="bar"></div>
57
</body>
58
</html>
- a/Source/WebCore/ChangeLog +37 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2015-02-10  Joseph Pecoraro  <pecoraro@apple.com>
2
3
        Web Inspector: Crash inspecting styles of element with mutated stylesheet
4
        https://bugs.webkit.org/show_bug.cgi?id=141451
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Test: inspector/css/stylesheet-with-mutations.html
9
10
        * css/CSSStyleSheet.h:
11
        * css/CSSStyleSheet.cpp:
12
        (WebCore::CSSStyleSheet::CSSStyleSheet):
13
        (WebCore::CSSStyleSheet::didMutateRules):
14
        Keep a flag on the CSSStyleSheet to know when it has had a rule
15
        mutation from the contents.
16
17
        * inspector/InspectorStyleSheet.h:
18
        * inspector/InspectorStyleSheet.cpp:
19
        (WebCore::InspectorStyleSheet::reparseStyleSheet):
20
        When completely replacing the stylesheet's contents, we will have
21
        destroyed any previous rules, so clear the has mutations flag.
22
23
        (WebCore::selectorsFromSource):
24
        Previously there was a mismatch between the rules the parsed
25
        SourceData had, and the actual CSSSelectors we were iterating.
26
        We use the SourceData so we can get the exact user authored
27
        text instead of generated longhands from actualy selector objects.
28
        Add an ASSERT and bail to catch and more gracefully handle
29
        any possible mismatches in the future.
30
31
        (WebCore::InspectorStyleSheet::styleSheetMutated):
32
        (WebCore::InspectorStyleSheet::ensureParsedDataReady):
33
        When a CSSStyleSheet has been mutated beyond the inspector's
34
        knowledge right now, fall back to readonly generated selectors.
35
        We should better handle this in the future:
36
        <https://webkit.org/b/141450> Web Inspector: Better support for CSSOM StyleSheet mutations (insertRule/deleteRule)
37
1
2015-02-10  Carlos Garcia Campos  <cgarcia@igalia.com>
38
2015-02-10  Carlos Garcia Campos  <cgarcia@igalia.com>
2
39
3
        [GTK] GMutexLocker build issue
40
        [GTK] GMutexLocker build issue
- a/Source/WebCore/css/CSSStyleSheet.cpp +4 lines
Lines 95-100 CSSStyleSheet::CSSStyleSheet(Ref<StyleSheetContents>&& contents, CSSImportRule* a/Source/WebCore/css/CSSStyleSheet.cpp_sec1
95
    : m_contents(WTF::move(contents))
95
    : m_contents(WTF::move(contents))
96
    , m_isInlineStylesheet(false)
96
    , m_isInlineStylesheet(false)
97
    , m_isDisabled(false)
97
    , m_isDisabled(false)
98
    , m_mutatedRules(false)
98
    , m_ownerNode(0)
99
    , m_ownerNode(0)
99
    , m_ownerRule(ownerRule)
100
    , m_ownerRule(ownerRule)
100
{
101
{
Lines 105-110 CSSStyleSheet::CSSStyleSheet(Ref<StyleSheetContents>&& contents, Node* ownerNode a/Source/WebCore/css/CSSStyleSheet.cpp_sec2
105
    : m_contents(WTF::move(contents))
106
    : m_contents(WTF::move(contents))
106
    , m_isInlineStylesheet(isInlineStylesheet)
107
    , m_isInlineStylesheet(isInlineStylesheet)
107
    , m_isDisabled(false)
108
    , m_isDisabled(false)
109
    , m_mutatedRules(false)
108
    , m_ownerNode(ownerNode)
110
    , m_ownerNode(ownerNode)
109
    , m_ownerRule(0)
111
    , m_ownerRule(0)
110
{
112
{
Lines 177-182 void CSSStyleSheet::didMutateRules(RuleMutationType mutationType, WhetherContent a/Source/WebCore/css/CSSStyleSheet.cpp_sec3
177
    }
179
    }
178
180
179
    owner->styleResolverChanged(DeferRecalcStyle);
181
    owner->styleResolverChanged(DeferRecalcStyle);
182
183
    m_mutatedRules = true;
180
}
184
}
181
185
182
void CSSStyleSheet::didMutate()
186
void CSSStyleSheet::didMutate()
- a/Source/WebCore/css/CSSStyleSheet.h +4 lines
Lines 88-93 public: a/Source/WebCore/css/CSSStyleSheet.h_sec1
88
    void setMediaQueries(PassRefPtr<MediaQuerySet>);
88
    void setMediaQueries(PassRefPtr<MediaQuerySet>);
89
    void setTitle(const String& title) { m_title = title; }
89
    void setTitle(const String& title) { m_title = title; }
90
90
91
    bool hadRulesMutation() const { return m_mutatedRules; }
92
    void clearHadRulesMutation() { m_mutatedRules = false; }
93
91
    enum RuleMutationType { OtherMutation, RuleInsertion };
94
    enum RuleMutationType { OtherMutation, RuleInsertion };
92
    enum WhetherContentsWereClonedForMutation { ContentsWereNotClonedForMutation = 0, ContentsWereClonedForMutation };
95
    enum WhetherContentsWereClonedForMutation { ContentsWereNotClonedForMutation = 0, ContentsWereClonedForMutation };
93
96
Lines 129-134 private: a/Source/WebCore/css/CSSStyleSheet.h_sec2
129
    Ref<StyleSheetContents> m_contents;
132
    Ref<StyleSheetContents> m_contents;
130
    bool m_isInlineStylesheet;
133
    bool m_isInlineStylesheet;
131
    bool m_isDisabled;
134
    bool m_isDisabled;
135
    bool m_mutatedRules;
132
    String m_title;
136
    String m_title;
133
    RefPtr<MediaQuerySet> m_mediaQueries;
137
    RefPtr<MediaQuerySet> m_mediaQueries;
134
138
- a/Source/WebCore/inspector/InspectorStyleSheet.cpp -1 / +15 lines
Lines 609-614 void InspectorStyleSheet::reparseStyleSheet(const String& text) a/Source/WebCore/inspector/InspectorStyleSheet.cpp_sec1
609
        m_pageStyleSheet->clearChildRuleCSSOMWrappers();
609
        m_pageStyleSheet->clearChildRuleCSSOMWrappers();
610
        fireStyleSheetChanged();
610
        fireStyleSheetChanged();
611
    }
611
    }
612
613
    // We just wiped the entire contents of the stylesheet. Clear the mutation flag.
614
    m_pageStyleSheet->clearHadRulesMutation();
612
}
615
}
613
616
614
bool InspectorStyleSheet::setText(const String& text, ExceptionCode& ec)
617
bool InspectorStyleSheet::setText(const String& text, ExceptionCode& ec)
Lines 860-865 static Ref<Inspector::Protocol::Array<Inspector::Protocol::CSS::CSSSelector>> se a/Source/WebCore/inspector/InspectorStyleSheet.cpp_sec2
860
    const SelectorRangeList& ranges = sourceData->selectorRanges;
863
    const SelectorRangeList& ranges = sourceData->selectorRanges;
861
    const CSSSelector* selector = selectorList.first();
864
    const CSSSelector* selector = selectorList.first();
862
    for (size_t i = 0, size = ranges.size(); i < size; ++i) {
865
    for (size_t i = 0, size = ranges.size(); i < size; ++i) {
866
        // If we don't have a selector, that means the SourceData for this CSSStyleSheet
867
        // no longer matches up with the actual rules in the CSSStyleSheet.
868
        ASSERT(selector);
869
        if (!selector)
870
            break;
871
863
        const SourceRange& range = ranges.at(i);
872
        const SourceRange& range = ranges.at(i);
864
        String selectorText = sheetText.substring(range.start, range.length());
873
        String selectorText = sheetText.substring(range.start, range.length());
865
874
Lines 1061-1069 bool InspectorStyleSheet::checkPageStyleSheet(ExceptionCode& ec) const a/Source/WebCore/inspector/InspectorStyleSheet.cpp_sec3
1061
    return true;
1070
    return true;
1062
}
1071
}
1063
1072
1073
bool InspectorStyleSheet::styleSheetMutated() const
1074
{
1075
    return m_pageStyleSheet && m_pageStyleSheet->hadRulesMutation();
1076
}
1077
1064
bool InspectorStyleSheet::ensureParsedDataReady()
1078
bool InspectorStyleSheet::ensureParsedDataReady()
1065
{
1079
{
1066
    return ensureText() && ensureSourceData();
1080
    return !styleSheetMutated() && ensureText() && ensureSourceData();
1067
}
1081
}
1068
1082
1069
bool InspectorStyleSheet::ensureText() const
1083
bool InspectorStyleSheet::ensureText() const
- a/Source/WebCore/inspector/InspectorStyleSheet.h +1 lines
Lines 215-220 private: a/Source/WebCore/inspector/InspectorStyleSheet.h_sec1
215
215
216
    static void collectFlatRules(RefPtr<CSSRuleList>&&, CSSStyleRuleVector* result);
216
    static void collectFlatRules(RefPtr<CSSRuleList>&&, CSSStyleRuleVector* result);
217
    bool checkPageStyleSheet(ExceptionCode&) const;
217
    bool checkPageStyleSheet(ExceptionCode&) const;
218
    bool styleSheetMutated() const;
218
    bool ensureText() const;
219
    bool ensureText() const;
219
    bool ensureSourceData();
220
    bool ensureSourceData();
220
    void ensureFlatRules() const;
221
    void ensureFlatRules() const;

Return to Bug 141451