Changeset 147538 in webkit


Ignore:
Timestamp:
Apr 3, 2013 4:06:49 AM (11 years ago)
Author:
Antoine Quint
Message:

Web Inspector: crash in WebCore::InspectorLayerTreeAgent::buildObjectForLayer if a layer is created for an anonymous RenderObject (:first-letter)
https://bugs.webkit.org/show_bug.cgi?id=113768

Source/WebCore:

The InspectorLayerTreeAgent now knows how to deal with anonymous RenderObjects
for the :first-letter and :first-line pseudo-elements.

Reviewed by Timothy Hatcher.

Test: inspector-protocol/layers/layers-anonymous.html

  • inspector/Inspector.json:

Change the Layer type in the LayerTree domain to have more accurate terminology
(pseudo-element vs. pseudo-class) and a new optional isAnonymous flag for layers
associated to anonymous RenderObjects.

  • inspector/InspectorLayerTreeAgent.cpp:

(WebCore::InspectorLayerTreeAgent::buildObjectForLayer):
Check for anonymous RenderObjects and set the parent renderer's node as the node
for this layer since anonymous renderers have the Document as their node and this
would not be satisfactory to show in a front-end. We also check for anonymous
RenderObjects for the :first-letter and :first-line pseudo-elements and set them
in the pseudoElement property of the Layer object created such that a front-end
could correctly identify what type of pseudo-element for the associated node
yielded this layer.

(WebCore::InspectorLayerTreeAgent::idForNode):
Here we fix the actual crash by first checking if the node provided is null and
returning 0 if there's no such node. This ensures that any scenario where there
is no node associated with the RenderObject simply informs of the front-end that
no such node exists and we do not crash.

LayoutTests:

Reviewed by Timothy Hatcher.

  • inspector-protocol/layers/layers-anonymous-expected.txt: Added.
  • inspector-protocol/layers/layers-anonymous.html: Added.

New test for layers created for CSS anonymous boxes or blocks.

  • inspector-protocol/layers/layers-generated-content.html:

Update test to use the "pseudoElement" property instead of "pseudoClass"
which was the previous, less accurate name.

Location:
trunk
Files:
1 added
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r147536 r147538  
     12013-04-03  Antoine Quint  <graouts@apple.com>
     2
     3        Web Inspector: crash in WebCore::InspectorLayerTreeAgent::buildObjectForLayer if a layer is created for an anonymous RenderObject (:first-letter)
     4        https://bugs.webkit.org/show_bug.cgi?id=113768
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * inspector-protocol/layers/layers-anonymous-expected.txt: Added.
     9        * inspector-protocol/layers/layers-anonymous.html: Added.
     10        New test for layers created for CSS anonymous boxes or blocks.
     11
     12        * inspector-protocol/layers/layers-generated-content.html:
     13        Update test to use the "pseudoElement" property instead of "pseudoClass"
     14        which was the previous, less accurate name.
     15
    1162013-04-03  Zoltan Arvai  <zarvai@inf.u-szeged.hu>
    217
  • trunk/LayoutTests/inspector-protocol/layers/layers-anonymous.html

    r147536 r147538  
    4646    function gotLayerTree(result)
    4747    {
    48         var beforeLayers = [];
    49         var afterLayers = [];
    50         result.layers.forEach(function (layer) {
    51             if (!layer.isGeneratedContent)
    52                 return;
    53 
    54             if (layer.pseudoClass === "before")
    55                 beforeLayers.push(layer);
    56             if (layer.pseudoClass === "after")
    57                 afterLayers.push(layer);
     48        var anonymousLayers = result.layers.filter(function (layer) {
     49            return layer.isAnonymous;
    5850        });
    5951
    6052        logTestName("Check layers");
    6153
    62         assert("Expected number of ::before layers", beforeLayers.length, 1);
    63         assert("The sole ::before layer has a pseudo element", beforeLayers[0].pseudoElementId !== "", true);
    64 
    65         assert("Expected number of ::after layers", afterLayers.length, 2);
    66         assert("The first ::after layer has a pseudo element", afterLayers[0].pseudoElementId !== "", true);
    67         assert("The second ::after layer has a pseudo element", afterLayers[1].pseudoElementId !== "", true);
    68         assert("The second ::after layer is a reflection", afterLayers[1].isReflection, true);
    69         assert("The two ::after layers have the same node id", afterLayers[0].nodeId, afterLayers[1].nodeId);
    70         assert("The two ::after layers have the same pseudo element id", afterLayers[0].pseudoElementId, afterLayers[1].pseudoElementId);
    71 
    72         assert("The non-reflection generated generated layers have the same node id", beforeLayers[0].nodeId, afterLayers[0].nodeId);
    73         assert("The non-reflection generated layers have different pseudo element ids", beforeLayers[0].pseudoElementId !== afterLayers[0].pseudoElementId, true);
     54        assert("Expected number of anonymous layers", anonymousLayers.length, 1);
     55        assert("The sole anonymous layer has a non-zero node id", anonymousLayers[0].nodeId !== 0, true);
     56        assert("The sole anonymous layer has a :first-letter pseudo-element", anonymousLayers[0].pseudoElement === "first-letter", true);
    7457
    7558        var node;
    76         var nodeId = beforeLayers[0].nodeId;
     59        var nodeId = anonymousLayers[0].nodeId;
    7760        for (var i = 0, count = nodes.length; i < count; ++i) {
    7861            if (nodes[i].nodeId === nodeId) {
     
    8265        }
    8366
    84         logTestName("Check generating node");
     67        logTestName("Check node");
    8568       
    86         assert("Generating node was found", !!node, true);
    87         assert("Generating node has expected localName", node.localName, "div");
    88         assert("Generating node has id", node.attributes[0], "id");
    89         assert("Generating node has expected id", node.attributes[1], "generator");
     69        assert("Node was found", !!node, true);
     70        assert("Node has expected localName", node.localName, "p");
     71        assert("Node has id", node.attributes[0], "id");
     72        assert("Node has expected id", node.attributes[1], "first-letter");
    9073       
    9174        InspectorTest.completeTest();
     
    142125</script>
    143126<style type="text/css">
    144      
    145     #generator::before,
    146     #generator::after {
    147         position: absolute;
    148         width: 100px;
    149         height: 100px;
    150         background-color: black;
    151         -webkit-transform: translateZ(0);
    152         content: "";
    153     }
    154127
    155     #generator::after {
    156         -webkit-box-reflect:below 1px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0.5, transparent), to(white));
     128    #first-letter::first-letter {
     129        float: left;
     130        -webkit-backface-visibility: hidden;
    157131    }
    158132
     
    161135<body>
    162136
    163     <div id="generator"></div>
     137    <p id="first-letter">This is a test</p>
    164138
    165139</body>
  • trunk/LayoutTests/inspector-protocol/layers/layers-generated-content.html

    r145057 r147538  
    5252                return;
    5353
    54             if (layer.pseudoClass === "before")
     54            if (layer.pseudoElement === "before")
    5555                beforeLayers.push(layer);
    56             if (layer.pseudoClass === "after")
     56            if (layer.pseudoElement === "after")
    5757                afterLayers.push(layer);
    5858        });
  • trunk/Source/WebCore/ChangeLog

    r147535 r147538  
     12013-04-03  Antoine Quint  <graouts@apple.com>
     2
     3        Web Inspector: crash in WebCore::InspectorLayerTreeAgent::buildObjectForLayer if a layer is created for an anonymous RenderObject (:first-letter)
     4        https://bugs.webkit.org/show_bug.cgi?id=113768
     5
     6        The InspectorLayerTreeAgent now knows how to deal with anonymous RenderObjects
     7        for the :first-letter and :first-line pseudo-elements.
     8
     9        Reviewed by Timothy Hatcher.
     10
     11        Test: inspector-protocol/layers/layers-anonymous.html
     12
     13        * inspector/Inspector.json:
     14        Change the Layer type in the LayerTree domain to have more accurate terminology
     15        (pseudo-element vs. pseudo-class) and a new optional isAnonymous flag for layers
     16        associated to anonymous RenderObjects.
     17
     18        * inspector/InspectorLayerTreeAgent.cpp:
     19        (WebCore::InspectorLayerTreeAgent::buildObjectForLayer):
     20        Check for anonymous RenderObjects and set the parent renderer's node as the node
     21        for this layer since anonymous renderers have the Document as their node and this
     22        would not be satisfactory to show in a front-end. We also check for anonymous
     23        RenderObjects for the :first-letter and :first-line pseudo-elements and set them
     24        in the pseudoElement property of the Layer object created such that a front-end
     25        could correctly identify what type of pseudo-element for the associated node
     26        yielded this layer.
     27
     28        (WebCore::InspectorLayerTreeAgent::idForNode):
     29        Here we fix the actual crash by first checking if the node provided is null and
     30        returning 0 if there's no such node. This ensures that any scenario where there
     31        is no node associated with the RenderObject simply informs of the front-end that
     32        no such node exists and we do not crash.
     33
    1342013-04-03  Alexander Pavlov  <apavlov@chromium.org>
    235
  • trunk/Source/WebCore/inspector/Inspector.json

    r147428 r147538  
    37403740                    { "name": "isReflection", "type": "boolean", "optional": true, "description": "Indicates whether this layer was used to provide a reflection for the element." },
    37413741                    { "name": "isGeneratedContent", "type": "boolean", "optional": true, "description": "Indicates whether the layer is attached to a pseudo element that is CSS generated content." },
     3742                    { "name": "isAnonymous", "type": "boolean", "optional": true, "description": "Indicates whether the layer was created for a CSS anonymous block or box." },
    37423743                    { "name": "pseudoElementId", "$ref": "PseudoElementId", "optional": true, "description": "The id for the pseudo element associated with this layer." },
    3743                     { "name": "pseudoClass", "type": "string", "optional": true, "description": "The name of the CSS pseudo-class that prompted the layer's content to be generated." }
     3744                    { "name": "pseudoElement", "type": "string", "optional": true, "description": "The name of the CSS pseudo-element that prompted the layer to be generated." }
    37443745                ]
    37453746            },
  • trunk/Source/WebCore/inspector/InspectorLayerTreeAgent.cpp

    r145136 r147538  
    166166    bool isReflection = renderLayer->isReflection();
    167167    bool isGenerated = (isReflection ? renderer->parent() : renderer)->isBeforeOrAfterContent();
     168    bool isAnonymous = renderer->isAnonymous();
    168169
    169170    if (isReflection && isGenerated)
     
    171172    else if (isGenerated)
    172173        node = renderer->generatingNode();
    173     else if (isReflection)
     174    else if (isReflection || isAnonymous)
    174175        node = renderer->parent()->node();
    175176
     
    195196        layerObject->setPseudoElementId(bindPseudoElement(static_cast<PseudoElement*>(renderer->node())));
    196197        if (renderer->isBeforeContent())
    197             layerObject->setPseudoClass("before");
     198            layerObject->setPseudoElement("before");
    198199        else if (renderer->isAfterContent())
    199             layerObject->setPseudoClass("after");
     200            layerObject->setPseudoElement("after");
     201    }
     202
     203    if (isAnonymous) {
     204        layerObject->setIsAnonymous(true);
     205        if (RenderStyle* style = renderer->style()) {
     206            if (style->styleType() == FIRST_LETTER)
     207                layerObject->setPseudoElement("first-letter");
     208            else if (style->styleType() == FIRST_LINE)
     209                layerObject->setPseudoElement("first-line");
     210        }
    200211    }
    201212
     
    205216int InspectorLayerTreeAgent::idForNode(ErrorString* errorString, Node* node)
    206217{
     218    if (!node)
     219        return 0;
     220
    207221    InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent();
    208222   
Note: See TracChangeset for help on using the changeset viewer.