Changeset 128875 in webkit


Ignore:
Timestamp:
Sep 18, 2012 4:41:16 AM (12 years ago)
Author:
caseq@chromium.org
Message:

Web Inspector: [Extensions API] explicitly manage extension audit progress
https://bugs.webkit.org/show_bug.cgi?id=96803

Reviewed by Alexander Pavlov.

Source/WebCore:

  • create a sub-progress per audit category;
  • manage audit category progress within the category, not in the panel logic;
  • consider audit is done when all categories are done;
  • expose AuditResults.updateProgress(worked, totalWork) in the extensions API;
  • retain old magic for computing audit progress if extension specifies extension results count.
  • inspector/front-end/AuditsPanel.js:

(WebInspector.AuditsPanel.prototype._executeAudit.ruleResultReadyCallback):
(WebInspector.AuditsPanel.prototype._executeAudit):
(WebInspector.AuditCategory.prototype.run.callbackWrapper):
(WebInspector.AuditCategory.prototype.run):

  • inspector/front-end/ExtensionAPI.js:

(defineCommonExtensionSymbols):
(injectedExtensionAPI.Audits.prototype.addCategory):
(injectedExtensionAPI.AuditResultImpl.prototype.updateProgress):

  • inspector/front-end/ExtensionAuditCategory.js:

(WebInspector.ExtensionAuditCategory.prototype.run):
(WebInspector.ExtensionAuditCategoryResults):
(WebInspector.ExtensionAuditCategoryResults.prototype.done):
(WebInspector.ExtensionAuditCategoryResults.prototype._addResult):
(WebInspector.ExtensionAuditCategoryResults.prototype.updateProgress):

  • inspector/front-end/ExtensionServer.js:

(WebInspector.ExtensionServer):
(WebInspector.ExtensionServer.prototype._onUpdateAuditProgress):
(WebInspector.ExtensionServer.prototype._onStopAuditCategoryRun):

  • inspector/front-end/ProgressBar.js:

(WebInspector.ProgressIndicator.prototype.done): Assure only first call to done() has effect.

LayoutTests:

  • inspector/extensions/extensions-audits-api-expected.txt: Added AuditResults.updateProgress()
  • inspector/extensions/extensions-audits.html: Added a call to updateProgress()
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r128873 r128875  
     12012-09-14  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Web Inspector: [Extensions API] explicitly manage extension audit progress
     4        https://bugs.webkit.org/show_bug.cgi?id=96803
     5
     6        Reviewed by Alexander Pavlov.
     7
     8        * inspector/extensions/extensions-audits-api-expected.txt: Added AuditResults.updateProgress()
     9        * inspector/extensions/extensions-audits.html: Added a call to updateProgress()
     10
    1112012-09-18  Raphael Kubo da Costa  <raphael.kubo.da.costa@intel.com>
    212
  • trunk/LayoutTests/inspector/extensions/extensions-audits-api-expected.txt

    r127147 r128875  
    2727    createURL : <function>
    2828    done : <function>
     29    updateProgress : <function>
    2930}
    3031{
  • trunk/LayoutTests/inspector/extensions/extensions-audits-expected.txt

    r116743 r128875  
    44Running tests...
    55RUNNING TEST: extension_testAudits
     6Progress: 50%
     7Progress: 75%
    68  Extension audits
    79    Failed rule (42)
  • trunk/LayoutTests/inspector/extensions/extensions-audits-tests.js

    r116739 r128875  
    3030        launcherView._launchButtonClicked();
    3131    }
     32
     33    InspectorTest.dumpAuditProgress = function()
     34    {
     35        var progress = document.querySelector(".panel.audits progress");
     36        InspectorTest.addResult("Progress: " + Math.round(100 * progress.value / progress.max) + "%");
     37    }
    3238}
  • trunk/LayoutTests/inspector/extensions/extensions-audits.html

    r116739 r128875  
    3030            nestedNode.addChild(results.createResourceLink(inspectedPageURL, 20));
    3131
    32             results.addResult("Rule with details subtree (1)", "This rule has a lot of details", results.Severity.Warning, node);
    33 
    34             // Audit normally terminates when number of added rule results is equal to
    35             // the rule count declared when adding a category. done() is only for
    36             // emergency cases, when we know we won't be able to run the rest of the rules.
    37             results.done();
     32            evaluateOnFrontend("InspectorTest.dumpAuditProgress(); reply();", function() {
     33                results.addResult("Rule with details subtree (1)", "This rule has a lot of details", results.Severity.Warning, node);
     34                results.updateProgress(10, 20);
     35                evaluateOnFrontend("InspectorTest.dumpAuditProgress(); reply();", results.done.bind(results));
     36            });
    3837        });
    3938    }
     
    4948    }
    5049
    51     var category = webInspector.audits.addCategory("Extension audits", 20);
     50    var category = webInspector.audits.addCategory("Extension audits");
    5251    category.onAuditStarted.addListener(onStartAuditCategory);
    5352
  • trunk/Source/WebCore/ChangeLog

    r128869 r128875  
     12012-09-14  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Web Inspector: [Extensions API] explicitly manage extension audit progress
     4        https://bugs.webkit.org/show_bug.cgi?id=96803
     5
     6        Reviewed by Alexander Pavlov.
     7
     8        - create a sub-progress per audit category;
     9        - manage audit category progress within the category, not in the panel logic;
     10        - consider audit is done when all categories are done;
     11        - expose AuditResults.updateProgress(worked, totalWork) in the extensions API;
     12        - retain old magic for computing audit progress if extension specifies extension results count.
     13
     14        * inspector/front-end/AuditsPanel.js:
     15        (WebInspector.AuditsPanel.prototype._executeAudit.ruleResultReadyCallback):
     16        (WebInspector.AuditsPanel.prototype._executeAudit):
     17        (WebInspector.AuditCategory.prototype.run.callbackWrapper):
     18        (WebInspector.AuditCategory.prototype.run):
     19        * inspector/front-end/ExtensionAPI.js:
     20        (defineCommonExtensionSymbols):
     21        (injectedExtensionAPI.Audits.prototype.addCategory):
     22        (injectedExtensionAPI.AuditResultImpl.prototype.updateProgress):
     23        * inspector/front-end/ExtensionAuditCategory.js:
     24        (WebInspector.ExtensionAuditCategory.prototype.run):
     25        (WebInspector.ExtensionAuditCategoryResults):
     26        (WebInspector.ExtensionAuditCategoryResults.prototype.done):
     27        (WebInspector.ExtensionAuditCategoryResults.prototype._addResult):
     28        (WebInspector.ExtensionAuditCategoryResults.prototype.updateProgress):
     29        * inspector/front-end/ExtensionServer.js:
     30        (WebInspector.ExtensionServer):
     31        (WebInspector.ExtensionServer.prototype._onUpdateAuditProgress):
     32        (WebInspector.ExtensionServer.prototype._onStopAuditCategoryRun):
     33        * inspector/front-end/ProgressBar.js:
     34        (WebInspector.ProgressIndicator.prototype.done): Assure only first call to done() has effect.
     35
    1362012-09-19  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
    237
  • trunk/Source/WebCore/inspector/front-end/AuditsPanel.js

    r128598 r128875  
    9999    _executeAudit: function(categories, resultCallback)
    100100    {
    101         var requests = WebInspector.networkLog.requests;
    102 
    103         var rulesRemaining = 0;
    104         for (var i = 0; i < categories.length; ++i)
    105             rulesRemaining += categories[i].ruleCount;
    106 
    107         this._progress.setTotalWork(rulesRemaining);
    108101        this._progress.setTitle(WebInspector.UIString("Running audit"));
     102
     103        function ruleResultReadyCallback(categoryResult, ruleResult)
     104        {
     105            if (ruleResult && ruleResult.children)
     106                categoryResult.addRuleResult(ruleResult);
     107
     108            if (this._progress.isCanceled())
     109                this._progress.done();
     110        }
    109111
    110112        var results = [];
    111113        var mainResourceURL = WebInspector.inspectedPageURL;
    112 
    113         function ruleResultReadyCallback(categoryResult, ruleResult)
     114        var categoriesDone = 0;
     115        function categoryDoneCallback()
    114116        {
    115             if (this._progress.isCanceled())
     117            if (++categoriesDone !== categories.length)
    116118                return;
    117 
    118             if (ruleResult && ruleResult.children)
    119                 categoryResult.addRuleResult(ruleResult);
    120 
    121             --rulesRemaining;
    122             this._progress.worked();
    123 
    124             if (!rulesRemaining || this._progress.isCanceled())
    125                 resultCallback(mainResourceURL, results);
    126         }
    127 
    128         if (!rulesRemaining || this._progress.isCanceled()) {
    129             resultCallback(mainResourceURL, results);
    130             return;
    131         }
    132 
     119            this._progress.done();
     120            resultCallback(mainResourceURL, results)
     121        }
     122
     123        var requests = WebInspector.networkLog.requests.slice();
     124        var compositeProgress = new WebInspector.CompositeProgress(this._progress);
     125        var subprogresses = [];
     126        for (var i = 0; i < categories.length; ++i)
     127            subprogresses.push(compositeProgress.createSubProgress());
    133128        for (var i = 0; i < categories.length; ++i) {
    134129            var category = categories[i];
    135130            var result = new WebInspector.AuditCategoryResult(category);
    136131            results.push(result);
    137             category.run(requests, ruleResultReadyCallback.bind(this, result), this._progress);
     132            category.run(requests, ruleResultReadyCallback.bind(this, result), categoryDoneCallback.bind(this), subprogresses[i]);
    138133        }
    139134    },
     
    271266    },
    272267
    273     get ruleCount()
    274     {
    275         this._ensureInitialized();
    276         return this._rules.length;
    277     },
    278 
    279268    addRule: function(rule, severity)
    280269    {
     
    285274    /**
    286275     * @param {Array.<WebInspector.NetworkRequest>} requests
    287      * @param {function()} callback
     276     * @param {function(WebInspector.AuditRuleResult)} ruleResultCallback
     277     * @param {function()} categoryDoneCallback
    288278     * @param {WebInspector.Progress} progress
    289279     */
    290     run: function(requests, callback, progress)
     280    run: function(requests, ruleResultCallback, categoryDoneCallback, progress)
    291281    {
    292282        this._ensureInitialized();
     283        var remainingRulesCount = this._rules.length;
     284        progress.setTotalWork(remainingRulesCount);
     285        function callbackWrapper()
     286        {
     287            ruleResultCallback.apply(this, arguments);
     288            progress.worked();
     289            if (!--remainingRulesCount)
     290                categoryDoneCallback();
     291        }
    293292        for (var i = 0; i < this._rules.length; ++i)
    294             this._rules[i].run(requests, callback, progress);
     293            this._rules[i].run(requests, callbackWrapper, progress);
    295294    },
    296295
  • trunk/Source/WebCore/inspector/front-end/ExtensionAPI.js

    r123902 r128875  
    9898        StopAuditCategoryRun: "stopAuditCategoryRun",
    9999        Unsubscribe: "unsubscribe",
     100        UpdateAuditProgress: "updateAuditProgress",
    100101        UpdateButton: "updateButton",
    101102        InspectedURLChanged: "inspectedURLChanged"
     
    510511    {
    511512        var id = "extension-audit-category-" + extensionServer.nextObjectId();
     513        if (typeof resultCount !== "undefined")
     514            console.warn("Passing resultCount to audits.addCategory() is deprecated. Use AuditResult.updateProgress() instead.");
    512515        extensionServer.sendRequest({ command: commands.AddAuditCategory, id: id, displayName: displayName, resultCount: resultCount });
    513516        return new AuditCategory(id);
     
    569572    {
    570573        return new AuditResultNode(Array.prototype.slice.call(arguments));
     574    },
     575
     576    updateProgress: function(worked, totalWork)
     577    {
     578        extensionServer.sendRequest({ command: commands.UpdateAuditProgress, resultId: this._id, progress: worked / totalWork });
    571579    },
    572580
  • trunk/Source/WebCore/inspector/front-end/ExtensionAuditCategory.js

    r117293 r128875  
    3131/**
    3232 * @constructor
     33 * @extends {WebInspector.AuditCategory}
    3334 * @param {string} extensionOrigin
    3435 * @param {string} id
    3536 * @param {string} displayName
    36  * @param {number} ruleCount
     37 * @param {number=} ruleCount
    3738 */
    3839WebInspector.ExtensionAuditCategory = function(extensionOrigin, id, displayName, ruleCount)
     
    5657    },
    5758
    58     get ruleCount()
    59     {
    60         return this._ruleCount;
    61     },
    62 
    63     run: function(resources, callback)
    64     {
    65         new WebInspector.ExtensionAuditCategoryResults(this, callback);
     59    /**
     60     * @param {Array.<WebInspector.NetworkRequest>} requests
     61     * @param {function(WebInspector.AuditRuleResult)} ruleResultCallback
     62     * @param {function()} categoryDoneCallback
     63     * @param {WebInspector.Progress} progress
     64     */
     65    run: function(requests, ruleResultCallback, categoryDoneCallback, progress)
     66    {
     67        var results = new WebInspector.ExtensionAuditCategoryResults(this, ruleResultCallback, categoryDoneCallback, progress);
     68        WebInspector.extensionServer.startAuditRun(this, results);
    6669    }
    6770}
     
    7073 * @constructor
    7174 * @param {WebInspector.ExtensionAuditCategory} category
    72  * @param {function(WebInspector.AuditRuleResult)} callback
     75 * @param {function(WebInspector.AuditRuleResult)} ruleResultCallback
     76 * @param {function()} categoryDoneCallback
     77 * @param {WebInspector.Progress} progress
    7378 */
    74 WebInspector.ExtensionAuditCategoryResults = function(category, callback)
     79WebInspector.ExtensionAuditCategoryResults = function(category, ruleResultCallback, categoryDoneCallback, progress)
    7580{
    7681    this._category = category;
    77     this._pendingRules = category.ruleCount;
    78     this._ruleCompletionCallback = callback;
     82    this._ruleResultCallback = ruleResultCallback;
     83    this._categoryDoneCallback = categoryDoneCallback;
     84    this._progress = progress;
     85    this._progress.setTotalWork(1);
     86    this._expectedResults = category._ruleCount;
     87    this._actualResults = 0;
    7988
    8089    this.id = category.id + "-" + ++WebInspector.ExtensionAuditCategoryResults._lastId;
    81     WebInspector.extensionServer.startAuditRun(category, this);
    8290}
    8391
    8492WebInspector.ExtensionAuditCategoryResults.prototype = {
    85     get complete()
    86     {
    87         return !this._pendingRules;
    88     },
    89 
    90     cancel: function()
    91     {
    92         while (!this.complete)
    93             this._addResult(null);
     93    done: function()
     94    {
     95        WebInspector.extensionServer.stopAuditRun(this);
     96        this._progress.done();
     97        this._categoryDoneCallback();
    9498    },
    9599
     
    116120    _addResult: function(result)
    117121    {
    118         this._ruleCompletionCallback(result);
    119         this._pendingRules--;
    120         if (!this._pendingRules)
    121             WebInspector.extensionServer.stopAuditRun(this);
     122        this._ruleResultCallback(result);
     123        ++this._actualResults;
     124        if (typeof this._expectedResults === "number") {
     125            this._progress.setWorked(this._actualResults / this._expectedResults);
     126            if (this._actualResults === this._expectedResults)
     127                this.done();
     128        }
     129    },
     130
     131    /**
     132     * @param {number} progress
     133     */
     134    updateProgress: function(progress)
     135    {
     136        this._progress.setWorked(progress);
    122137    },
    123138
  • trunk/Source/WebCore/inspector/front-end/ExtensionServer.js

    r127417 r128875  
    7272    this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this));
    7373    this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this));
     74    this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgress.bind(this));
    7475
    7576    window.addEventListener("message", this._onWindowMessage.bind(this), false);
     
    551552    },
    552553
     554    _onUpdateAuditProgress: function(message)
     555    {
     556        var auditResult = this._clientObjects[message.resultId];
     557        if (!auditResult)
     558            return this._status.E_NOTFOUND(message.resultId);
     559        auditResult.updateProgress(Math.min(Math.max(0, message.progress), 1));
     560    },
     561
    553562    _onStopAuditCategoryRun: function(message)
    554563    {
     
    556565        if (!auditRun)
    557566            return this._status.E_NOTFOUND(message.resultId);
    558         auditRun.cancel();
     567        auditRun.done();
    559568    },
    560569
  • trunk/Source/WebCore/inspector/front-end/ProgressBar.js

    r128598 r128875  
    106106    done: function()
    107107    {
     108        if (this._isDone)
     109            return;
     110        this._isDone = true;
    108111        this.hide();
    109112        this.dispatchEventToListeners(WebInspector.ProgressIndicator.Events.Done);
Note: See TracChangeset for help on using the changeset viewer.