Title: [128598] trunk/Source/WebCore
Revision
128598
Author
[email protected]
Date
2012-09-14 06:07:26 -0700 (Fri, 14 Sep 2012)

Log Message

Web Inspector: reuse WebInspector.ProgressIndicator in Audits panel
https://bugs.webkit.org/show_bug.cgi?id=96755

Reviewed by Alexander Pavlov.

- remove AuditProgressMonitor, use WebInspector.ProgressIndicator instead;
- add annotations for a bunch of audit methods;
- simplify control flow -- remove callbacks where possible.

* English.lproj/localizedStrings.js:
* inspector/front-end/AuditLauncherView.js:
(WebInspector.AuditLauncherView):
(WebInspector.AuditLauncherView.prototype._setAuditRunning):
(WebInspector.AuditLauncherView.prototype._launchButtonClicked.onAuditStarted):
(WebInspector.AuditLauncherView.prototype._launchButtonClicked):
(WebInspector.AuditLauncherView.prototype._createLauncherUI):
(WebInspector.AuditLauncherView.prototype._updateResourceProgress):
(WebInspector.AuditLauncherView.prototype._updateButton):
* inspector/front-end/AuditRules.js:
(WebInspector.AuditRules.GzipRule.prototype.doRun):
(WebInspector.AuditRules.CombineExternalResourcesRule.prototype.doRun):
(WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype.doRun):
(WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.selectorsCallback):
(WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.documentLoaded):
(WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback):
(WebInspector.AuditRules.UnusedCssRule.prototype.doRun.styleSheetCallback):
(WebInspector.AuditRules.UnusedCssRule.prototype.doRun.allStylesCallback):
(WebInspector.AuditRules.UnusedCssRule.prototype.doRun):
(WebInspector.AuditRules.CacheControlRule.prototype.doRun):
(WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
(WebInspector.AuditRules.CssInHeadRule.prototype.doRun):
(WebInspector.AuditRules.CssInHeadRule.prototype.doRun.externalStylesheetsReceived):
(WebInspector.AuditRules.CssInHeadRule.prototype.doRun.inlineStylesReceived):
(WebInspector.AuditRules.CssInHeadRule.prototype.doRun.onDocumentAvailable):
(WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun):
(WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.cssBeforeInlineReceived):
(WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.lateStylesReceived):
(WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.onDocumentAvailable):
(WebInspector.AuditRules.CSSRuleBase.prototype.doRun.sheetsCallback):
(WebInspector.AuditRules.CSSRuleBase.prototype._visitStyleSheet.sheetCallback):
(WebInspector.AuditRules.CSSRuleBase.prototype._visitStyleSheet):
(WebInspector.AuditRules.CookieRuleBase.prototype.doRun.resultCallback):
(WebInspector.AuditRules.CookieRuleBase.prototype.doRun):
* inspector/front-end/AuditsPanel.js:
(WebInspector.AuditsPanel):
(WebInspector.AuditsPanel.prototype._executeAudit.ruleResultReadyCallback):
(WebInspector.AuditsPanel.prototype._executeAudit):
(WebInspector.AuditsPanel.prototype._auditFinishedCallback):
(WebInspector.AuditsPanel.prototype.initiateAudit.else.onReload):
(WebInspector.AuditsPanel.prototype.initiateAudit):
(WebInspector.AuditCategory.prototype.run):
(WebInspector.AuditRule.prototype.run):
(WebInspector.AuditRule.prototype.doRun):
* inspector/front-end/ProgressBar.js:
(WebInspector.Progress.prototype.worked):
(WebInspector.ProgressIndicator):
(WebInspector.ProgressIndicator.prototype.cancel):
(WebInspector.ProgressIndicator.prototype.setWorked):
(WebInspector.ProgressIndicator.prototype.worked):
(WebInspector.SubProgress.prototype.setWorked):
(WebInspector.SubProgress.prototype.worked):
* inspector/front-end/auditsPanel.css:
(.audit-launcher-view .progress-bar-container):
(.audit-launcher-view .progress-bar-container .progress-bar-stop-button):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (128597 => 128598)


--- trunk/Source/WebCore/ChangeLog	2012-09-14 12:45:29 UTC (rev 128597)
+++ trunk/Source/WebCore/ChangeLog	2012-09-14 13:07:26 UTC (rev 128598)
@@ -1,3 +1,70 @@
+2012-09-14  Andrey Kosyakov  <[email protected]>
+
+        Web Inspector: reuse WebInspector.ProgressIndicator in Audits panel
+        https://bugs.webkit.org/show_bug.cgi?id=96755
+
+        Reviewed by Alexander Pavlov.
+
+        - remove AuditProgressMonitor, use WebInspector.ProgressIndicator instead;
+        - add annotations for a bunch of audit methods;
+        - simplify control flow -- remove callbacks where possible.
+
+        * English.lproj/localizedStrings.js:
+        * inspector/front-end/AuditLauncherView.js:
+        (WebInspector.AuditLauncherView):
+        (WebInspector.AuditLauncherView.prototype._setAuditRunning):
+        (WebInspector.AuditLauncherView.prototype._launchButtonClicked.onAuditStarted):
+        (WebInspector.AuditLauncherView.prototype._launchButtonClicked):
+        (WebInspector.AuditLauncherView.prototype._createLauncherUI):
+        (WebInspector.AuditLauncherView.prototype._updateResourceProgress):
+        (WebInspector.AuditLauncherView.prototype._updateButton):
+        * inspector/front-end/AuditRules.js:
+        (WebInspector.AuditRules.GzipRule.prototype.doRun):
+        (WebInspector.AuditRules.CombineExternalResourcesRule.prototype.doRun):
+        (WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype.doRun):
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.selectorsCallback):
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.documentLoaded):
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback):
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.styleSheetCallback):
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.allStylesCallback):
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun):
+        (WebInspector.AuditRules.CacheControlRule.prototype.doRun):
+        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
+        (WebInspector.AuditRules.CssInHeadRule.prototype.doRun):
+        (WebInspector.AuditRules.CssInHeadRule.prototype.doRun.externalStylesheetsReceived):
+        (WebInspector.AuditRules.CssInHeadRule.prototype.doRun.inlineStylesReceived):
+        (WebInspector.AuditRules.CssInHeadRule.prototype.doRun.onDocumentAvailable):
+        (WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun):
+        (WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.cssBeforeInlineReceived):
+        (WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.lateStylesReceived):
+        (WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.onDocumentAvailable):
+        (WebInspector.AuditRules.CSSRuleBase.prototype.doRun.sheetsCallback):
+        (WebInspector.AuditRules.CSSRuleBase.prototype._visitStyleSheet.sheetCallback):
+        (WebInspector.AuditRules.CSSRuleBase.prototype._visitStyleSheet):
+        (WebInspector.AuditRules.CookieRuleBase.prototype.doRun.resultCallback):
+        (WebInspector.AuditRules.CookieRuleBase.prototype.doRun):
+        * inspector/front-end/AuditsPanel.js:
+        (WebInspector.AuditsPanel):
+        (WebInspector.AuditsPanel.prototype._executeAudit.ruleResultReadyCallback):
+        (WebInspector.AuditsPanel.prototype._executeAudit):
+        (WebInspector.AuditsPanel.prototype._auditFinishedCallback):
+        (WebInspector.AuditsPanel.prototype.initiateAudit.else.onReload):
+        (WebInspector.AuditsPanel.prototype.initiateAudit):
+        (WebInspector.AuditCategory.prototype.run):
+        (WebInspector.AuditRule.prototype.run):
+        (WebInspector.AuditRule.prototype.doRun):
+        * inspector/front-end/ProgressBar.js:
+        (WebInspector.Progress.prototype.worked):
+        (WebInspector.ProgressIndicator):
+        (WebInspector.ProgressIndicator.prototype.cancel):
+        (WebInspector.ProgressIndicator.prototype.setWorked):
+        (WebInspector.ProgressIndicator.prototype.worked):
+        (WebInspector.SubProgress.prototype.setWorked):
+        (WebInspector.SubProgress.prototype.worked):
+        * inspector/front-end/auditsPanel.css:
+        (.audit-launcher-view .progress-bar-container):
+        (.audit-launcher-view .progress-bar-container .progress-bar-stop-button):
+
 2012-09-14  Vsevolod Vlasov  <[email protected]>
 
         Unreviewed inspector ui polish.

Modified: trunk/Source/WebCore/English.lproj/localizedStrings.js (128597 => 128598)


--- trunk/Source/WebCore/English.lproj/localizedStrings.js	2012-09-14 12:45:29 UTC (rev 128597)
+++ trunk/Source/WebCore/English.lproj/localizedStrings.js	2012-09-14 13:07:26 UTC (rev 128598)
@@ -742,3 +742,4 @@
 localizedStrings["Layout forced"] = "Layout forced";
 localizedStrings["Paused on assertion."] = "Paused on assertion.";
 localizedStrings["%s (%s%s)"] = "%s (%s%s)";
+localizedStrings["Running audit"] = "Running audit";

Modified: trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js (128597 => 128598)


--- trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js	2012-09-14 12:45:29 UTC (rev 128597)
+++ trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js	2012-09-14 13:07:26 UTC (rev 128598)
@@ -30,14 +30,14 @@
 
 /**
  * @constructor
+ * @param {function(Array.<string>, WebInspector.Progress, boolean, function(), function()):undefined} runnerCallback
  * @extends {WebInspector.View}
  */
-WebInspector.AuditLauncherView = function(runnerCallback, stopCallback)
+WebInspector.AuditLauncherView = function(runnerCallback)
 {
     WebInspector.View.call(this);
 
     this._runnerCallback = runnerCallback;
-    this._stopCallback = stopCallback;
     this._categoryIdPrefix = "audit-category-item-";
     this._auditRunning = false;
 
@@ -118,29 +118,46 @@
         if (this._auditRunning === auditRunning)
             return;
         this._auditRunning = auditRunning;
-        delete this._stopRequested;
         this._updateButton();
-        this._updateResourceProgress();
+        if (this._auditRunning)
+            this._startAudit();
+        else
+            this._stopAudit();
     },
 
-    _launchButtonClicked: function(event)
+    _startAudit: function()
     {
-        if (!this._auditRunning) {
-            var catIds = [];
-            for (var category = 0; category < this._sortedCategories.length; ++category) {
-                if (this._sortedCategories[category]._checkboxElement.checked)
-                    catIds.push(this._sortedCategories[category].id);
-            }
+        var catIds = [];
+        for (var category = 0; category < this._sortedCategories.length; ++category) {
+            if (this._sortedCategories[category]._checkboxElement.checked)
+                catIds.push(this._sortedCategories[category].id);
+        }
 
-            this._setAuditRunning(true);
-            this._runnerCallback(catIds, this._resourceProgressElement, this._auditPresentStateElement.checked, this._setAuditRunning.bind(this, false));
-        } else {
-            this._stopRequested = true;
-            this._stopCallback(this._setAuditRunning.bind(this, false));
-            this._updateButton();
+        this._resetResourceCount();
+        this._progressIndicator = new WebInspector.ProgressIndicator();
+        this._buttonContainerElement.appendChild(this._progressIndicator.element);
+        this._displayResourceLoadingProgress = true;
+
+        function onAuditStarted()
+        {
+            this._displayResourceLoadingProgress = false;
         }
+        this._runnerCallback(catIds, this._progressIndicator, this._auditPresentStateElement.checked, onAuditStarted.bind(this), this._setAuditRunning.bind(this, false));
     },
 
+    _stopAudit: function()
+    {
+        this._displayResourceLoadingProgress = false;
+        this._progressIndicator.cancel();
+        this._progressIndicator.done();
+        delete this._progressIndicator;
+    },
+
+    _launchButtonClicked: function(event)
+    {
+        this._setAuditRunning(!this._auditRunning);
+    },
+
     _selectAllClicked: function(checkCategories)
     {
         var childNodes = this._categoriesElement.childNodes;
@@ -218,37 +235,20 @@
         this._launchButton.textContent = WebInspector.UIString("Run");
         this._launchButton.addEventListener("click", this._launchButtonClicked.bind(this), false);
 
-        this._resourceProgressContainer = this._buttonContainerElement.createChild("span", "resource-progress");
-        this._resourceProgressElement = this._resourceProgressContainer.createChild("progress");
-        this._resourceProgressContainer.appendChild(document.createTextNode(" "));
-        this._resourceProgressTextElement = this._resourceProgressContainer.createChild("span");
-
-
         this._selectAllClicked(this._selectAllCheckboxElement.checked);
         this._updateButton();
-        this._updateResourceProgress();
     },
 
     _updateResourceProgress: function()
     {
-        if (!this._resourceProgressContainer)
-            return;
-
-        if (!this._auditRunning || this._stopRequested) {
-            this._resetResourceCount();
-            this._resourceProgressContainer.addStyleClass("hidden");
-        } else
-            this._resourceProgressContainer.removeStyleClass("hidden");
-        if (this._loadedResources)
-            this._resourceProgressTextElement.textContent = WebInspector.UIString("Loading (%d of %d)", this._loadedResources, this._totalResources);
-        else
-            this._resourceProgressTextElement.textContent = "";
+        if (this._displayResourceLoadingProgress)
+            this._progressIndicator.setTitle(WebInspector.UIString("Loading (%d of %d)", this._loadedResources, this._totalResources));
     },
 
     _updateButton: function()
     {
         this._launchButton.textContent = this._auditRunning ? WebInspector.UIString("Stop") : WebInspector.UIString("Run");
-        this._launchButton.disabled = !this._currentCategoriesCount || (this._auditRunning && this._stopRequested);
+        this._launchButton.disabled = !this._currentCategoriesCount;
     }
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/AuditRules.js (128597 => 128598)


--- trunk/Source/WebCore/inspector/front-end/AuditRules.js	2012-09-14 12:45:29 UTC (rev 128597)
+++ trunk/Source/WebCore/inspector/front-end/AuditRules.js	2012-09-14 13:07:26 UTC (rev 128598)
@@ -75,8 +75,11 @@
 WebInspector.AuditRules.GzipRule.prototype = {
     /**
      * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
      */
-    doRun: function(requests, result, callback, progressMonitor)
+    doRun: function(requests, result, callback, progress)
     {
         var totalSavings = 0;
         var compressedSize = 0;
@@ -135,7 +138,13 @@
 }
 
 WebInspector.AuditRules.CombineExternalResourcesRule.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(requests, [this._type], false);
         var penalizedResourceCount = 0;
@@ -190,7 +199,13 @@
 }
 
 WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         var summary = result.addChild("");
         var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(requests, undefined, false);
@@ -228,7 +243,13 @@
 }
 
 WebInspector.AuditRules.ParallelizeDownloadRule.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         function hostSorter(a, b)
         {
@@ -297,12 +318,18 @@
 }
 
 WebInspector.AuditRules.UnusedCssRule.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         var self = this;
 
         function evalCallback(styleSheets) {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!styleSheets.length)
@@ -324,7 +351,7 @@
 
             function selectorsCallback(callback, styleSheets, testedSelectors, foundSelectors)
             {
-                if (progressMonitor.canceled)
+                if (progress.isCanceled())
                     return;
 
                 var inlineBlockOrdinal = 0;
@@ -389,7 +416,7 @@
 
             function documentLoaded(selectors, document) {
                 for (var i = 0; i < selectors.length; ++i) {
-                    if (progressMonitor.canceled)
+                    if (progress.isCanceled())
                         return;
                     WebInspector.domAgent.querySelector(document.id, selectors[i], queryCallback.bind(null, i === selectors.length - 1 ? selectorsCallback.bind(null, callback, styleSheets, testedSelectors) : null, selectors[i], styleSheets, testedSelectors));
                 }
@@ -400,7 +427,7 @@
 
         function styleSheetCallback(styleSheets, sourceURL, continuation, styleSheet)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (styleSheet) {
@@ -413,7 +440,7 @@
 
         function allStylesCallback(error, styleSheetInfos)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (error || !styleSheetInfos || !styleSheetInfos.length)
@@ -443,8 +470,13 @@
 WebInspector.AuditRules.CacheControlRule.MillisPerMonth = 1000 * 60 * 60 * 24 * 30;
 
 WebInspector.AuditRules.CacheControlRule.prototype = {
-
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         var cacheableAndNonCacheableResources = this._cacheableAndNonCacheableResources(requests);
         if (cacheableAndNonCacheableResources[0].length)
@@ -691,7 +723,13 @@
 }
 
 WebInspector.AuditRules.ImageDimensionsRule.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         var urlToNoDimensionCount = {};
 
@@ -710,7 +748,7 @@
 
         function imageStylesReady(imageId, styles, isLastStyle, computedStyle)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             const node = WebInspector.domAgent.nodeForId(imageId);
@@ -766,7 +804,7 @@
 
         function getStyles(nodeIds)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
             var targetResult = {};
 
@@ -794,12 +832,12 @@
 
         function onDocumentAvailable(root)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
             WebInspector.domAgent.querySelectorAll(root.id, "img[src]", getStyles);
         }
 
-        if (progressMonitor.canceled)
+        if (progress.isCanceled())
             return;
         WebInspector.domAgent.requestDocument(onDocumentAvailable);
     }
@@ -817,11 +855,17 @@
 }
 
 WebInspector.AuditRules.CssInHeadRule.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         function evalCallback(evalResult)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!evalResult)
@@ -846,7 +890,7 @@
 
         function externalStylesheetsReceived(root, inlineStyleNodeIds, nodeIds)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!nodeIds)
@@ -869,7 +913,7 @@
 
         function inlineStylesReceived(root, nodeIds)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!nodeIds)
@@ -879,7 +923,7 @@
 
         function onDocumentAvailable(root)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             WebInspector.domAgent.querySelectorAll(root.id, "body style", inlineStylesReceived.bind(null, root));
@@ -901,11 +945,17 @@
 }
 
 WebInspector.AuditRules.StylesScriptsOrderRule.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         function evalCallback(resultValue)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!resultValue)
@@ -927,7 +977,7 @@
 
         function cssBeforeInlineReceived(lateStyleIds, nodeIds)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!nodeIds)
@@ -950,7 +1000,7 @@
 
         function lateStylesReceived(root, nodeIds)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!nodeIds)
@@ -961,7 +1011,7 @@
 
         function onDocumentAvailable(root)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             WebInspector.domAgent.querySelectorAll(root.id, "head script[src] ~ link[rel~='stylesheet'][href]", lateStylesReceived.bind(null, root));
@@ -983,7 +1033,13 @@
 }
 
 WebInspector.AuditRules.CSSRuleBase.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         CSSAgent.getAllStyleSheets(sheetsCallback.bind(this));
 
@@ -997,7 +1053,7 @@
                 if (header.disabled)
                     continue; // Do not check disabled stylesheets.
 
-                this._visitStyleSheet(header.styleSheetId, i === headers.length - 1 ? finishedCallback : null, result, progressMonitor);
+                this._visitStyleSheet(header.styleSheetId, i === headers.length - 1 ? finishedCallback : null, result, progress);
             }
         }
 
@@ -1007,13 +1063,13 @@
         }
     },
 
-    _visitStyleSheet: function(styleSheetId, callback, result, progressMonitor)
+    _visitStyleSheet: function(styleSheetId, callback, result, progress)
     {
         WebInspector.CSSStyleSheet.createForId(styleSheetId, sheetCallback.bind(this));
 
         function sheetCallback(styleSheet)
         {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             if (!styleSheet) {
@@ -1144,11 +1200,17 @@
 }
 
 WebInspector.AuditRules.CookieRuleBase.prototype = {
-    doRun: function(requests, result, callback, progressMonitor)
+    /**
+     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
+     */
+    doRun: function(requests, result, callback, progress)
     {
         var self = this;
         function resultCallback(receivedCookies, isAdvanced) {
-            if (progressMonitor.canceled)
+            if (progress.isCanceled())
                 return;
 
             self.processCookies(isAdvanced ? receivedCookies : [], requests, result);

Modified: trunk/Source/WebCore/inspector/front-end/AuditsPanel.js (128597 => 128598)


--- trunk/Source/WebCore/inspector/front-end/AuditsPanel.js	2012-09-14 12:45:29 UTC (rev 128597)
+++ trunk/Source/WebCore/inspector/front-end/AuditsPanel.js	2012-09-14 13:07:26 UTC (rev 128598)
@@ -57,7 +57,7 @@
 
     this._constructCategories();
 
-    this._launcherView = new WebInspector.AuditLauncherView(this.initiateAudit.bind(this), this.terminateAudit.bind(this));
+    this._launcherView = new WebInspector.AuditLauncherView(this.initiateAudit.bind(this));
     for (var id in this.categoriesById)
         this._launcherView.addCategory(this.categoriesById[id]);
 
@@ -104,27 +104,28 @@
         for (var i = 0; i < categories.length; ++i)
             rulesRemaining += categories[i].ruleCount;
 
-        this._progressMonitor.setTotalWork(rulesRemaining);
+        this._progress.setTotalWork(rulesRemaining);
+        this._progress.setTitle(WebInspector.UIString("Running audit"));
 
         var results = [];
         var mainResourceURL = WebInspector.inspectedPageURL;
 
         function ruleResultReadyCallback(categoryResult, ruleResult)
         {
-            if (this._progressMonitor.canceled)
+            if (this._progress.isCanceled())
                 return;
 
             if (ruleResult && ruleResult.children)
                 categoryResult.addRuleResult(ruleResult);
 
             --rulesRemaining;
-            this._progressMonitor.worked(1);
+            this._progress.worked();
 
-            if (this._progressMonitor.done() && resultCallback)
+            if (!rulesRemaining || this._progress.isCanceled())
                 resultCallback(mainResourceURL, results);
         }
 
-        if (this._progressMonitor.done()) {
+        if (!rulesRemaining || this._progress.isCanceled()) {
             resultCallback(mainResourceURL, results);
             return;
         }
@@ -133,7 +134,7 @@
             var category = categories[i];
             var result = new WebInspector.AuditCategoryResult(category);
             results.push(result);
-            category.run(requests, ruleResultReadyCallback.bind(this, result), this._progressMonitor);
+            category.run(requests, ruleResultReadyCallback.bind(this, result), this._progress);
         }
     },
 
@@ -149,40 +150,42 @@
         var resultTreeElement = new WebInspector.AuditResultSidebarTreeElement(this, results, mainResourceURL, ordinal);
         this.auditResultsTreeElement.appendChild(resultTreeElement);
         resultTreeElement.revealAndSelect();
-        if (!this._progressMonitor.canceled && launcherCallback)
+        if (!this._progress.isCanceled())
             launcherCallback();
     },
 
-    initiateAudit: function(categoryIds, progressElement, runImmediately, launcherCallback)
+    /**
+     * @param {Array.<string>} categoryIds
+     * @param {WebInspector.Progress} progress
+     * @param {boolean} runImmediately
+     * @param {function()} startedCallback
+     * @param {function()} finishedCallback
+     */
+    initiateAudit: function(categoryIds, progress, runImmediately, startedCallback, finishedCallback)
     {
         if (!categoryIds || !categoryIds.length)
             return;
 
-        this._progressMonitor = new WebInspector.AuditProgressMonitor(progressElement);
+        this._progress = progress;
 
         var categories = [];
         for (var i = 0; i < categoryIds.length; ++i)
             categories.push(this.categoriesById[categoryIds[i]]);
 
-        function initiateAuditCallback(categories, launcherCallback)
+        function startAuditWhenResourcesReady()
         {
-            this._executeAudit(categories, this._auditFinishedCallback.bind(this, launcherCallback));
+            startedCallback();
+            this._executeAudit(categories, this._auditFinishedCallback.bind(this, finishedCallback));
         }
 
         if (runImmediately)
-            initiateAuditCallback.call(this, categories, launcherCallback);
+            startAuditWhenResourcesReady.call(this);
         else
-            this._reloadResources(initiateAuditCallback.bind(this, categories, launcherCallback));
+            this._reloadResources(startAuditWhenResourcesReady.bind(this));
 
         WebInspector.userMetrics.AuditsStarted.record();
     },
 
-    terminateAudit: function(launcherCallback)
-    {
-        this._progressMonitor.canceled = true;
-        launcherCallback();
-    },
-
     _reloadResources: function(callback)
     {
         this._pageReloadCallback = callback;
@@ -281,12 +284,14 @@
 
     /**
      * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {function()} callback
+     * @param {WebInspector.Progress} progress
      */
-    run: function(requests, callback, progressMonitor)
+    run: function(requests, callback, progress)
     {
         this._ensureInitialized();
         for (var i = 0; i < this._rules.length; ++i)
-            this._rules[i].run(requests, callback, progressMonitor);
+            this._rules[i].run(requests, callback, progress);
     },
 
     _ensureInitialized: function()
@@ -338,21 +343,26 @@
 
     /**
      * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
      */
-    run: function(requests, callback, progressMonitor)
+    run: function(requests, callback, progress)
     {
-        if (progressMonitor.canceled)
+        if (progress.isCanceled())
             return;
 
         var result = new WebInspector.AuditRuleResult(this.displayName);
         result.severity = this._severity;
-        this.doRun(requests, result, callback, progressMonitor);
+        this.doRun(requests, result, callback, progress);
     },
 
     /**
      * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {WebInspector.AuditRuleResult} result
+     * @param {function(WebInspector.AuditRuleResult)} callback
+     * @param {WebInspector.Progress} progress
      */
-    doRun: function(requests, result, callback, progressMonitor)
+    doRun: function(requests, result, callback, progress)
     {
         throw new Error("doRun() not implemented");
     }
@@ -459,67 +469,6 @@
 
 /**
  * @constructor
- * @param {Element} progressElement
- */
-WebInspector.AuditProgressMonitor = function(progressElement)
-{
-    this._element = progressElement;
-    this.setTotalWork(WebInspector.AuditProgressMonitor.INDETERMINATE);
-}
-
-WebInspector.AuditProgressMonitor.INDETERMINATE = -1;
-
-WebInspector.AuditProgressMonitor.prototype = {
-    setTotalWork: function(total)
-    {
-        if (this.canceled || this._total === total)
-            return;
-        this._total = total;
-        this._value = 0;
-        this._element.max = total;
-        if (total === WebInspector.AuditProgressMonitor.INDETERMINATE)
-            this._element.removeAttribute("value");
-        else
-            this._element.value = 0;
-    },
-
-    worked: function(items)
-    {
-        if (this.canceled || this.indeterminate || this.done())
-            return;
-        this._value += items;
-        if (this._value > this._total)
-            this._value = this._total;
-        this._element.value = this._value;
-    },
-
-    get indeterminate()
-    {
-        return this._total === WebInspector.AuditProgressMonitor.INDETERMINATE;
-    },
-
-    done: function()
-    {
-        return !this.indeterminate && (this.canceled || this._value === this._total);
-    },
-
-    get canceled()
-    {
-        return !!this._canceled;
-    },
-
-    set canceled(x)
-    {
-        if (this._canceled === x)
-            return;
-        if (x)
-            this.setTotalWork(WebInspector.AuditProgressMonitor.INDETERMINATE);
-        this._canceled = x;
-    }
-}
-
-/**
- * @constructor
  * @extends {WebInspector.SidebarTreeElement}
  * @param {WebInspector.AuditsPanel} panel
  */

Modified: trunk/Source/WebCore/inspector/front-end/ProgressBar.js (128597 => 128598)


--- trunk/Source/WebCore/inspector/front-end/ProgressBar.js	2012-09-14 12:45:29 UTC (rev 128597)
+++ trunk/Source/WebCore/inspector/front-end/ProgressBar.js	2012-09-14 13:07:26 UTC (rev 128598)
@@ -52,6 +52,11 @@
      */
     setWorked: function(worked, title) { },
 
+    /**
+     * @param {number=} worked
+     */
+    worked: function(worked) { },
+
     done: function() { },
 
     /**
@@ -72,9 +77,10 @@
     this._labelElement = this.element.createChild("span");
     this._progressElement = this.element.createChild("progress");
     this._stopButton = new WebInspector.StatusBarButton(WebInspector.UIString("Cancel"), "progress-bar-stop-button");
-    this._stopButton.addEventListener("click", this._cancel, this);
+    this._stopButton.addEventListener("click", this.cancel, this);
     this.element.appendChild(this._stopButton.element);
     this._isCanceled = false;
+    this._worked = 0;
 }
 
 WebInspector.ProgressIndicator.Events = {
@@ -103,7 +109,7 @@
         this.dispatchEventToListeners(WebInspector.ProgressIndicator.Events.Done);
     },
 
-    _cancel: function()
+    cancel: function()
     {
         this._isCanceled = true;
     },
@@ -135,9 +141,18 @@
      */
     setWorked: function(worked, title)
     {
+        this._worked = worked;
         this._progressElement.value = worked;
         if (title)
             this.setTitle(title);
+    },
+
+    /**
+     * @param {number=} worked
+     */
+    worked: function(worked)
+    {
+        this.setWorked(this._worked + (worked || 1));
     }
 }
 
@@ -243,5 +258,13 @@
         if (typeof title !== "undefined")
             this.setTitle(title);
         this._composite._update();
+    },
+
+    /**
+     * @param {number=} worked
+     */
+    worked: function(worked)
+    {
+        this.setWorked(this._worked + (worked || 1));
     }
 }

Modified: trunk/Source/WebCore/inspector/front-end/auditsPanel.css (128597 => 128598)


--- trunk/Source/WebCore/inspector/front-end/auditsPanel.css	2012-09-14 12:45:29 UTC (rev 128597)
+++ trunk/Source/WebCore/inspector/front-end/auditsPanel.css	2012-09-14 13:07:26 UTC (rev 128598)
@@ -116,12 +116,6 @@
     margin-left: 0;
 }
 
-.audit-launcher-view .resource-progress > img {
-    content: url(Images/spinner.gif);
-    vertical-align: text-top;
-    margin: 0 4px 0 8px;
-}
-
 .audit-result-view {
     overflow: auto;
     position: absolute;
@@ -233,3 +227,11 @@
     margin-left: -28px;
     margin-top: -1px;
 }
+
+.audit-launcher-view .progress-bar-container {
+    display: inline-block;
+}
+
+.audit-launcher-view .progress-bar-container .progress-bar-stop-button {
+    display: none;
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to