Changeset 117293 in webkit


Ignore:
Timestamp:
May 16, 2012 8:41:08 AM (12 years ago)
Author:
caseq@chromium.org
Message:

Web Inspector: [Extensions API] expose evaluateOptions in audit formatters
https://bugs.webkit.org/show_bug.cgi?id=86617

Reviewed by Pavel Feldman.

Source/WebCore:

Test: inspector/extensions/extensions-audits-content-script.html

  • apply extension-specific audit formatters earlier (in ExtensionAduitCategory, not along with the rest in AuditFormatters);
  • use ExtensionServer.evaluate() to handle evaluateOptions instead of PageAgent.evaluate();
  • inspector/front-end/AuditFormatters.js: Move node and object formatters to ExtensionAuditCategory.

(WebInspector.partiallyApplyFormatters): Added a method to traverse formatters tree and apply formatters that are passed as input.

  • inspector/front-end/ExtensionAuditCategory.js:

(WebInspector.ExtensionAuditCategory): Pass extensionOrigin.
(WebInspector.ExtensionAuditCategoryResults.prototype._addNode): Apply extensions formatters before adding the result.
(WebInspector.ExtensionAuditCategoryResults.prototype._addResult):
(WebInspector.ExtensionAuditCategoryResults.prototype.evaluate): moved from AuditFormatters.
(WebInspector.ExtensionAuditFormatters.object.onEvaluate):
(WebInspector.ExtensionAuditFormatters.object):
(WebInspector.ExtensionAuditFormatters.node.onNodeAvailable):
(WebInspector.ExtensionAuditFormatters.node.onEvaluate):
(WebInspector.ExtensionAuditFormatters.node):

  • inspector/front-end/ExtensionServer.js:

(WebInspector.ExtensionServer.prototype._onAddAuditCategory): Plumb extensionOrigin through to audit category.

LayoutTests:

  • inspector/extensions/extensions-audits-content-script-expected.txt: Added.
  • inspector/extensions/extensions-audits-content-script.html: Added.
  • platform/gtk/test_expectations.txt:
  • platform/mac/Skipped:
  • platform/qt/Skipped:
  • platform/win/Skipped:
  • platform/wk2/Skipped:
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r117289 r117293  
     12012-05-16  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Web Inspector: [Extensions API] expose evaluateOptions in audit formatters
     4        https://bugs.webkit.org/show_bug.cgi?id=86617
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/extensions/extensions-audits-content-script-expected.txt: Added.
     9        * inspector/extensions/extensions-audits-content-script.html: Added.
     10        * platform/gtk/test_expectations.txt:
     11        * platform/mac/Skipped:
     12        * platform/qt/Skipped:
     13        * platform/win/Skipped:
     14        * platform/wk2/Skipped:
     15
    1162012-05-16  Rob Buis  <rbuis@rim.com>
    217
  • trunk/LayoutTests/platform/gtk/test_expectations.txt

    r117250 r117293  
    783783BUGWK72434 SKIP : inspector/styles/svg-style.xhtml = FAIL
    784784BUGWK43034 SKIP : inspector/debugger/debugger-breakpoints-not-activated-on-reload.html = FAIL
    785 BUGWK81089 SKIP : inspector/debugger/snippets-model.html = FAIL
    786785BUGWK43332 SKIP : inspector/debugger/dom-breakpoints.html = FAIL
    787786BUGWK43332 SKIP : inspector/debugger/event-listener-breakpoints.html = FAIL
     
    792791BUGWK50868 SKIP : inspector/styles/styles-source-lines-inline.html = FAIL
    793792BUGWK85709 SKIP : inspector/extensions/extensions-eval-content-script.html = FAIL
     793BUGWK85709 SKIP : inspector/extensions/extensions-audits-content-script.html = FAIL
    794794
    795795// These inspector tests fell out of the radar after the transition to NRWT
  • trunk/LayoutTests/platform/mac/Skipped

    r117060 r117293  
    843843# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
    844844inspector/extensions/extensions-eval-content-script.html
     845inspector/extensions/extensions-audits-content-script.html
    845846
    846847# https://bugs.webkit.org/show_bug.cgi?id=86480
  • trunk/LayoutTests/platform/qt/Skipped

    r117275 r117293  
    24892489# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
    24902490inspector/extensions/extensions-eval-content-script.html
     2491inspector/extensions/extensions-audits-content-script.html
    24912492
    24922493# [Qt][GTK] New fast/multicol/split-in-top-margin.html fails
  • trunk/LayoutTests/platform/win/Skipped

    r117051 r117293  
    17481748# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
    17491749inspector/extensions/extensions-eval-content-script.html
    1750 
     1750inspector/extensions/extensions-audits-content-script.html
     1751
  • trunk/LayoutTests/platform/wk2/Skipped

    r117090 r117293  
    7474# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
    7575inspector/extensions/extensions-eval-content-script.html
     76inspector/extensions/extensions-audits-content-script.html
    7677
    7778# A bunch of inspector tests time out on Lion Intel Debug WebKit2 testers.
  • trunk/Source/WebCore/ChangeLog

    r117291 r117293  
     12012-05-16  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Web Inspector: [Extensions API] expose evaluateOptions in audit formatters
     4        https://bugs.webkit.org/show_bug.cgi?id=86617
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Test: inspector/extensions/extensions-audits-content-script.html
     9
     10        - apply extension-specific audit formatters earlier (in ExtensionAduitCategory, not along with the rest in AuditFormatters);
     11        - use ExtensionServer.evaluate() to handle evaluateOptions instead of PageAgent.evaluate();
     12
     13        * inspector/front-end/AuditFormatters.js: Move node and object formatters to ExtensionAuditCategory.
     14        (WebInspector.partiallyApplyFormatters): Added a method to traverse formatters tree and apply formatters that are passed as input.
     15        * inspector/front-end/ExtensionAuditCategory.js:
     16        (WebInspector.ExtensionAuditCategory): Pass extensionOrigin.
     17        (WebInspector.ExtensionAuditCategoryResults.prototype._addNode): Apply extensions formatters before adding the result.
     18        (WebInspector.ExtensionAuditCategoryResults.prototype._addResult):
     19        (WebInspector.ExtensionAuditCategoryResults.prototype.evaluate): moved from AuditFormatters.
     20        (WebInspector.ExtensionAuditFormatters.object.onEvaluate):
     21        (WebInspector.ExtensionAuditFormatters.object):
     22        (WebInspector.ExtensionAuditFormatters.node.onNodeAvailable):
     23        (WebInspector.ExtensionAuditFormatters.node.onEvaluate):
     24        (WebInspector.ExtensionAuditFormatters.node):
     25        * inspector/front-end/ExtensionServer.js:
     26        (WebInspector.ExtensionServer.prototype._onAddAuditCategory): Plumb extensionOrigin through to audit category.
     27
    1282012-05-16  Donald Carr  <donald.carr@nokia.com>
    229
  • trunk/Source/WebCore/inspector/front-end/AuditFormatters.js

    r117235 r117293  
    2929 */
    3030
    31 WebInspector.applyFormatters = function(value)
     31/**
     32 * @constructor
     33 */
     34WebInspector.AuditFormatters = function()
    3235{
    33     var formatter;
    34     var type = typeof value;
    35     var args;
    36 
    37     switch (type) {
    38         case "string":
    39         case "boolean":
    40         case "number":
    41             formatter = WebInspector.AuditFormatters.text;
    42             args = [ value.toString() ];
    43             break;
    44 
    45         case "object":
    46             if (value instanceof Node)
    47                 return value;
    48             if (value instanceof Array) {
    49                 formatter = WebInspector.AuditFormatters.concat;
    50                 args = value;
    51             } else if (value.type && value.arguments) {
    52                 formatter = WebInspector.AuditFormatters[value.type];
    53                 args = value.arguments;
    54             }
    55     }
    56     if (!formatter)
    57         throw "Invalid value or formatter: " + type + JSON.stringify(value);
    58 
    59     return formatter.apply(null, args);
    6036}
    6137
    62 WebInspector.AuditFormatters = {
     38WebInspector.AuditFormatters.Registry = {
    6339    text: function(text)
    6440    {
     
    7854        var parent = document.createElement("span");
    7955        for (var arg = 0; arg < arguments.length; ++arg)
    80             parent.appendChild(WebInspector.applyFormatters(arguments[arg]));
     56            parent.appendChild(WebInspector.auditFormatters.apply(arguments[arg]));
    8157        return parent;
    8258    },
     
    9773        // FIXME: use WebInspector.Linkifier
    9874        return WebInspector.linkifyResourceAsNode(url, line, "console-message-url webkit-html-resource-link");
     75    }
     76};
     77
     78WebInspector.AuditFormatters.prototype = {
     79    /**
     80     * @param {string|boolean|number|Object} value
     81     */
     82    apply: function(value)
     83    {
     84        var formatter;
     85        var type = typeof value;
     86        var args;
     87
     88        switch (type) {
     89        case "string":
     90        case "boolean":
     91        case "number":
     92            formatter = WebInspector.AuditFormatters.Registry.text;
     93        args = [ value.toString() ];
     94        break;
     95
     96        case "object":
     97            if (value instanceof Node)
     98                return value;
     99            if (value instanceof Array) {
     100                formatter = WebInspector.AuditFormatters.Registry.concat;
     101                args = value;
     102            } else if (value.type && value.arguments) {
     103                formatter = WebInspector.AuditFormatters.Registry[value.type];
     104                args = value.arguments;
     105            }
     106        }
     107        if (!formatter)
     108            throw "Invalid value or formatter: " + type + JSON.stringify(value);
     109
     110        return formatter.apply(null, args);
    99111    },
    100112
    101113    /**
    102      * @param {string} expression
    103      * @param {string} title
     114     * @param {Object} formatters
     115     * @param {Object} thisArgument
     116     * @param {string|boolean|number|Object} value
    104117     */
    105     object: function(expression, title)
     118    partiallyApply: function(formatters, thisArgument, value)
    106119    {
    107         var parentElement = document.createElement("div");
    108         function onEvaluate(remoteObject)
    109         {
    110             var section = new WebInspector.ObjectPropertiesSection(remoteObject, title);
    111             section.expanded = true;
    112             section.editable = false;
    113             parentElement.appendChild(section.element);
    114         }
    115         WebInspector.AuditFormatters.Utilities.evaluate(expression, onEvaluate);
    116         return parentElement;
    117     },
     120        if (value instanceof Array)
     121            return value.map(this.partiallyApply.bind(this, formatters, thisArgument));
     122        if (typeof value === "object" && typeof formatters[value.type] === "function" && value.arguments)
     123            return formatters[value.type].apply(thisArgument, value.arguments);
     124        return value;
     125    }
     126}
    118127
    119     /**
    120      * @param {string} expression
    121      */
    122     node: function(expression)
    123     {
    124         var parentElement = document.createElement("div");
    125         /**
    126          * @param {?number} nodeId
    127          */
    128         function onNodeAvailable(nodeId)
    129         {
    130             if (!nodeId)
    131                 return;
    132             var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
    133             treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(nodeId);
    134             treeOutline.element.addStyleClass("outline-disclosure");
    135             treeOutline.setVisible(true);
    136             parentElement.appendChild(treeOutline.element);
    137         }
    138         /**
    139          * @param {WebInspector.RemoteObject} remoteObject
    140          */
    141         function onEvaluate(remoteObject)
    142         {
    143             remoteObject.pushNodeToFrontend(onNodeAvailable);
    144         }
    145         WebInspector.AuditFormatters.Utilities.evaluate(expression, onEvaluate);
    146         return parentElement;
    147     }
    148 };
    149 
    150 WebInspector.AuditFormatters.Utilities = {
    151     /**
    152      * @param {string} expression
    153      * @param {function(WebInspector.RemoteObject)} callback
    154      */
    155     evaluate: function(expression, callback)
    156     {
    157         /**
    158          * @param {?string} error
    159          * @param {?RuntimeAgent.RemoteObject} result
    160          * @param {boolean=} wasThrown
    161          */
    162         function onEvaluate(error, result, wasThrown)
    163         {
    164             if (wasThrown)
    165                 return;
    166             var object = WebInspector.RemoteObject.fromPayload(result);
    167             callback(object);
    168         }
    169         RuntimeAgent.evaluate(expression, "extension-watch", true, undefined, undefined, undefined, onEvaluate);
    170     }
    171 };
    172 
     128WebInspector.auditFormatters = new WebInspector.AuditFormatters();
  • trunk/Source/WebCore/inspector/front-end/AuditResultView.js

    r101341 r117293  
    115115            treeElement.listItemElement.addStyleClass(result.className);
    116116        if (typeof result.value !== "string")
    117             treeElement.listItemElement.appendChild(WebInspector.applyFormatters(result.value));
     117            treeElement.listItemElement.appendChild(WebInspector.auditFormatters.apply(result.value));
    118118
    119119        if (result.children) {
  • trunk/Source/WebCore/inspector/front-end/ExtensionAuditCategory.js

    r97152 r117293  
    11/*
    2  * Copyright (C) 2010 Google Inc. All rights reserved.
     2 * Copyright (C) 2012 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131/**
    3232 * @constructor
     33 * @param {string} extensionOrigin
     34 * @param {string} id
     35 * @param {string} displayName
     36 * @param {number} ruleCount
    3337 */
    34 WebInspector.ExtensionAuditCategory = function(id, displayName, ruleCount)
     38WebInspector.ExtensionAuditCategory = function(extensionOrigin, id, displayName, ruleCount)
    3539{
     40    this._extensionOrigin = extensionOrigin;
    3641    this._id = id;
    3742    this._displayName = displayName;
     
    6469/**
    6570 * @constructor
     71 * @param {WebInspector.ExtensionAuditCategory} category
     72 * @param {function(WebInspector.AuditRuleResult)} callback
    6673 */
    6774WebInspector.ExtensionAuditCategoryResults = function(category, callback)
     
    99106    _addNode: function(parent, node)
    100107    {
    101         var addedNode = parent.addChild(node.contents, node.expanded);
     108        var contents = WebInspector.auditFormatters.partiallyApply(WebInspector.ExtensionAuditFormatters, this, node.contents);
     109        var addedNode = parent.addChild(contents, node.expanded);
    102110        if (node.children) {
    103111            for (var i = 0; i < node.children.length; ++i)
     
    112120        if (!this._pendingRules)
    113121            WebInspector.extensionServer.stopAuditRun(this);
     122    },
     123
     124    /**
     125     * @param {string} expression
     126     * @param {function(WebInspector.RemoteObject)} callback
     127     */
     128    evaluate: function(expression, evaluateOptions, callback)
     129    {
     130        /**
     131         * @param {?string} error
     132         * @param {?RuntimeAgent.RemoteObject} result
     133         * @param {boolean=} wasThrown
     134         */
     135        function onEvaluate(error, result, wasThrown)
     136        {
     137            if (wasThrown)
     138                return;
     139            var object = WebInspector.RemoteObject.fromPayload(result);
     140            callback(object);
     141        }
     142        WebInspector.extensionServer.evaluate(expression, false, false, evaluateOptions, this._category._extensionOrigin, onEvaluate);
    114143    }
    115144}
    116145
     146WebInspector.ExtensionAuditFormatters = {
     147    /**
     148     * @this {WebInspector.ExtensionAuditCategoryResults}
     149     * @param {string} expression
     150     * @param {string} title
     151     * @param {Object} evaluateOptions
     152     */
     153    object: function(expression, title, evaluateOptions)
     154    {
     155        var parentElement = document.createElement("div");
     156        function onEvaluate(remoteObject)
     157        {
     158            var section = new WebInspector.ObjectPropertiesSection(remoteObject, title);
     159            section.expanded = true;
     160            section.editable = false;
     161            parentElement.appendChild(section.element);
     162        }
     163        this.evaluate(expression, evaluateOptions, onEvaluate);
     164        return parentElement;
     165    },
     166
     167    /**
     168     * @this {WebInspector.ExtensionAuditCategoryResults}
     169     * @param {string} expression
     170     * @param {Object} evaluateOptions
     171     */
     172    node: function(expression, evaluateOptions)
     173    {
     174        var parentElement = document.createElement("div");
     175        /**
     176         * @param {?number} nodeId
     177         */
     178        function onNodeAvailable(nodeId)
     179        {
     180            if (!nodeId)
     181                return;
     182            var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
     183            treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(nodeId);
     184            treeOutline.element.addStyleClass("outline-disclosure");
     185            treeOutline.setVisible(true);
     186            parentElement.appendChild(treeOutline.element);
     187        }
     188        /**
     189         * @param {WebInspector.RemoteObject} remoteObject
     190         */
     191        function onEvaluate(remoteObject)
     192        {
     193            remoteObject.pushNodeToFrontend(onNodeAvailable);
     194        }
     195        this.evaluate(expression, evaluateOptions, onEvaluate);
     196        return parentElement;
     197    }
     198}
     199
    117200WebInspector.ExtensionAuditCategoryResults._lastId = 0;
  • trunk/Source/WebCore/inspector/front-end/ExtensionServer.js

    r116957 r117293  
    501501    },
    502502
    503     _onAddAuditCategory: function(message)
    504     {
    505         var category = new WebInspector.ExtensionAuditCategory(message.id, message.displayName, message.resultCount);
     503    _onAddAuditCategory: function(message, port)
     504    {
     505        var category = new WebInspector.ExtensionAuditCategory(port._extensionOrigin, message.id, message.displayName, message.resultCount);
    506506        if (WebInspector.panels.audits.getCategory(category.id))
    507507            return this._status.E_EXISTS(category.id);
Note: See TracChangeset for help on using the changeset viewer.