Modified: trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js (102108 => 102109)
--- trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js 2011-12-06 08:38:54 UTC (rev 102108)
+++ trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js 2011-12-06 10:05:07 UTC (rev 102109)
@@ -32,10 +32,11 @@
* @constructor
* @extends {WebInspector.View}
*/
-WebInspector.AuditLauncherView = function(runnerCallback)
+WebInspector.AuditLauncherView = function(runnerCallback, stopCallback)
{
WebInspector.View.call(this);
this._runnerCallback = runnerCallback;
+ this._stopCallback = stopCallback;
this._categoryIdPrefix = "audit-category-item-";
this._auditRunning = false;
@@ -115,21 +116,27 @@
if (this._auditRunning === auditRunning)
return;
this._auditRunning = auditRunning;
+ delete this._stopRequested;
this._updateButton();
this._updateResourceProgress();
},
_launchButtonClicked: function(event)
{
- var catIds = [];
- var childNodes = this._categoriesElement.childNodes;
- for (var category = 0; category < this._sortedCategories.length; ++category) {
- if (this._sortedCategories[category]._checkboxElement.checked)
- catIds.push(this._sortedCategories[category].id);
- }
+ 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);
+ }
- this._setAuditRunning(true);
- this._runnerCallback(catIds, this._auditPresentStateElement.checked, this._setAuditRunning.bind(this, false));
+ 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();
+ }
},
_selectAllClicked: function(checkCategories)
@@ -184,52 +191,36 @@
this._selectAllCheckboxElement.addEventListener("click", handleSelectAllClick.bind(this), false);
this._contentElement.appendChild(categoryElement);
- this._categoriesElement = document.createElement("div");
- this._categoriesElement.className = "audit-categories-container";
- this._contentElement.appendChild(this._categoriesElement);
-
+ this._categoriesElement = this._contentElement.createChild("div", "audit-categories-container");
this._currentCategoriesCount = 0;
- var flexibleSpaceElement = document.createElement("div");
- flexibleSpaceElement.className = "flexible-space";
- this._contentElement.appendChild(flexibleSpaceElement);
+ this._contentElement.createChild("div", "flexible-space");
- this._buttonContainerElement = document.createElement("div");
- this._buttonContainerElement.className = "button-container";
+ this._buttonContainerElement = this._contentElement.createChild("div", "button-container");
- var labelElement = document.createElement("label");
- this._auditPresentStateElement = document.createElement("input");
+ var labelElement = this._buttonContainerElement.createChild("label");
+ this._auditPresentStateElement = labelElement.createChild("input");
this._auditPresentStateElement.name = "audit-mode";
this._auditPresentStateElement.type = "radio";
this._auditPresentStateElement.checked = true;
this._auditPresentStateLabelElement = document.createTextNode(WebInspector.UIString("Audit Present State"));
- labelElement.appendChild(this._auditPresentStateElement);
labelElement.appendChild(this._auditPresentStateLabelElement);
- this._buttonContainerElement.appendChild(labelElement);
- labelElement = document.createElement("label");
- this.auditReloadedStateElement = document.createElement("input");
+ labelElement = this._buttonContainerElement.createChild("label");
+ this.auditReloadedStateElement = labelElement.createChild("input");
this.auditReloadedStateElement.name = "audit-mode";
this.auditReloadedStateElement.type = "radio";
- labelElement.appendChild(this.auditReloadedStateElement);
labelElement.appendChild(document.createTextNode("Reload Page and Audit on Load"));
- this._buttonContainerElement.appendChild(labelElement);
- this._launchButton = document.createElement("button");
- this._launchButton.type = "button";
+ this._launchButton = this._buttonContainerElement.createChild("button");
this._launchButton.textContent = WebInspector.UIString("Run");
this._launchButton.addEventListener("click", this._launchButtonClicked.bind(this), false);
- this._buttonContainerElement.appendChild(this._launchButton);
- this._resourceProgressContainer = document.createElement("span");
- this._resourceProgressContainer.className = "resource-progress";
- var resourceProgressImage = document.createElement("img");
- this._resourceProgressContainer.appendChild(resourceProgressImage);
- this._resourceProgressTextElement = document.createElement("span");
- this._resourceProgressContainer.appendChild(this._resourceProgressTextElement);
- this._buttonContainerElement.appendChild(this._resourceProgressContainer);
+ 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._contentElement.appendChild(this._buttonContainerElement);
this._selectAllClicked(this._selectAllCheckboxElement.checked);
this._updateButton();
@@ -241,17 +232,21 @@
if (!this._resourceProgressContainer)
return;
- if (!this._auditRunning) {
+ if (!this._auditRunning || this._stopRequested) {
this._resetResourceCount();
this._resourceProgressContainer.addStyleClass("hidden");
} else
this._resourceProgressContainer.removeStyleClass("hidden");
- this._resourceProgressTextElement.textContent = WebInspector.UIString("Loading (%d of %d)", this._loadedResources, this._totalResources);
+ if (this._loadedResources)
+ this._resourceProgressTextElement.textContent = WebInspector.UIString("Loading (%d of %d)", this._loadedResources, this._totalResources);
+ else
+ this._resourceProgressTextElement.textContent = "";
},
_updateButton: function()
{
- this._launchButton.disabled = !this._currentCategoriesCount || this._auditRunning;
+ this._launchButton.textContent = this._auditRunning ? WebInspector.UIString("Stop") : WebInspector.UIString("Run");
+ this._launchButton.disabled = !this._currentCategoriesCount || (this._auditRunning && this._stopRequested);
}
}
Modified: trunk/Source/WebCore/inspector/front-end/AuditRules.js (102108 => 102109)
--- trunk/Source/WebCore/inspector/front-end/AuditRules.js 2011-12-06 08:38:54 UTC (rev 102108)
+++ trunk/Source/WebCore/inspector/front-end/AuditRules.js 2011-12-06 10:05:07 UTC (rev 102109)
@@ -73,7 +73,7 @@
}
WebInspector.AuditRules.GzipRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
var totalSavings = 0;
var compressedSize = 0;
@@ -132,7 +132,7 @@
}
WebInspector.AuditRules.CombineExternalResourcesRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, [this._type], false);
var penalizedResourceCount = 0;
@@ -187,7 +187,7 @@
}
WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
var summary = result.addChild("");
var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, undefined, false);
@@ -225,7 +225,7 @@
}
WebInspector.AuditRules.ParallelizeDownloadRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
function hostSorter(a, b)
{
@@ -294,11 +294,14 @@
}
WebInspector.AuditRules.UnusedCssRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
var self = this;
function evalCallback(styleSheets) {
+ if (progressMonitor.canceled)
+ return;
+
if (!styleSheets.length)
return callback(null);
@@ -318,6 +321,9 @@
function selectorsCallback(callback, styleSheets, testedSelectors, foundSelectors)
{
+ if (progressMonitor.canceled)
+ return;
+
var inlineBlockOrdinal = 0;
var totalStylesheetSize = 0;
var totalUnusedStylesheetSize = 0;
@@ -379,8 +385,11 @@
}
function documentLoaded(selectors, document) {
- for (var i = 0; i < selectors.length; ++i)
+ for (var i = 0; i < selectors.length; ++i) {
+ if (progressMonitor.canceled)
+ 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));
+ }
}
WebInspector.domAgent.requestDocument(documentLoaded.bind(null, selectors));
@@ -388,6 +397,9 @@
function styleSheetCallback(styleSheets, sourceURL, continuation, styleSheet)
{
+ if (progressMonitor.canceled)
+ return;
+
if (styleSheet) {
styleSheet.sourceURL = sourceURL;
styleSheets.push(styleSheet);
@@ -398,6 +410,9 @@
function allStylesCallback(error, styleSheetInfos)
{
+ if (progressMonitor.canceled)
+ return;
+
if (error || !styleSheetInfos || !styleSheetInfos.length)
return evalCallback([]);
var styleSheets = [];
@@ -426,7 +441,7 @@
WebInspector.AuditRules.CacheControlRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
var cacheableAndNonCacheableResources = this._cacheableAndNonCacheableResources(resources);
if (cacheableAndNonCacheableResources[0].length)
@@ -673,7 +688,7 @@
}
WebInspector.AuditRules.ImageDimensionsRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
var urlToNoDimensionCount = {};
@@ -692,6 +707,9 @@
function imageStylesReady(imageId, styles, isLastStyle, computedStyle)
{
+ if (progressMonitor.canceled)
+ return;
+
const node = WebInspector.domAgent.nodeForId(imageId);
var src = ""
if (!src.asParsedURL()) {
@@ -743,6 +761,8 @@
function getStyles(nodeIds)
{
+ if (progressMonitor.canceled)
+ return;
var targetResult = {};
function inlineCallback(inlineStyle, styleAttributes)
@@ -769,9 +789,13 @@
function onDocumentAvailable(root)
{
+ if (progressMonitor.canceled)
+ return;
WebInspector.domAgent.querySelectorAll(root.id, "img[src]", getStyles);
}
+ if (progressMonitor.canceled)
+ return;
WebInspector.domAgent.requestDocument(onDocumentAvailable);
}
}
@@ -788,10 +812,13 @@
}
WebInspector.AuditRules.CssInHeadRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
function evalCallback(evalResult)
{
+ if (progressMonitor.canceled)
+ return;
+
if (!evalResult)
return callback(null);
@@ -814,6 +841,9 @@
function externalStylesheetsReceived(root, inlineStyleNodeIds, nodeIds)
{
+ if (progressMonitor.canceled)
+ return;
+
if (!nodeIds)
return;
var externalStylesheetNodeIds = nodeIds;
@@ -834,6 +864,9 @@
function inlineStylesReceived(root, nodeIds)
{
+ if (progressMonitor.canceled)
+ return;
+
if (!nodeIds)
return;
WebInspector.domAgent.querySelectorAll(root.id, "body link[rel~='stylesheet'][href]", externalStylesheetsReceived.bind(null, root, nodeIds));
@@ -841,6 +874,9 @@
function onDocumentAvailable(root)
{
+ if (progressMonitor.canceled)
+ return;
+
WebInspector.domAgent.querySelectorAll(root.id, "body style", inlineStylesReceived.bind(null, root));
}
@@ -860,10 +896,13 @@
}
WebInspector.AuditRules.StylesScriptsOrderRule.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
function evalCallback(resultValue)
{
+ if (progressMonitor.canceled)
+ return;
+
if (!resultValue)
return callback(null);
@@ -883,6 +922,9 @@
function cssBeforeInlineReceived(lateStyleIds, nodeIds)
{
+ if (progressMonitor.canceled)
+ return;
+
if (!nodeIds)
return;
@@ -903,6 +945,9 @@
function lateStylesReceived(root, nodeIds)
{
+ if (progressMonitor.canceled)
+ return;
+
if (!nodeIds)
return;
@@ -911,6 +956,9 @@
function onDocumentAvailable(root)
{
+ if (progressMonitor.canceled)
+ return;
+
WebInspector.domAgent.querySelectorAll(root.id, "head script[src] ~ link[rel~='stylesheet'][href]", lateStylesReceived.bind(null, root));
}
@@ -930,13 +978,17 @@
}
WebInspector.AuditRules.CookieRuleBase.prototype = {
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
var self = this;
function resultCallback(receivedCookies, isAdvanced) {
+ if (progressMonitor.canceled)
+ return;
+
self.processCookies(isAdvanced ? receivedCookies : [], resources, result);
callback(result);
}
+
WebInspector.Cookies.getCookiesAsync(resultCallback);
},
Modified: trunk/Source/WebCore/inspector/front-end/AuditsPanel.js (102108 => 102109)
--- trunk/Source/WebCore/inspector/front-end/AuditsPanel.js 2011-12-06 08:38:54 UTC (rev 102108)
+++ trunk/Source/WebCore/inspector/front-end/AuditsPanel.js 2011-12-06 10:05:07 UTC (rev 102109)
@@ -57,7 +57,7 @@
this._constructCategories();
- this._launcherView = new WebInspector.AuditLauncherView(this.initiateAudit.bind(this));
+ this._launcherView = new WebInspector.AuditLauncherView(this.initiateAudit.bind(this), this.terminateAudit.bind(this));
for (var id in this.categoriesById)
this._launcherView.addCategory(this.categoriesById[id]);
@@ -131,21 +131,27 @@
for (var i = 0; i < categories.length; ++i)
rulesRemaining += categories[i].ruleCount;
+ this._progressMonitor.setTotalWork(rulesRemaining);
+
var results = [];
var mainResourceURL = WebInspector.inspectedPageURL;
function ruleResultReadyCallback(categoryResult, ruleResult)
{
+ if (this._progressMonitor.canceled)
+ return;
+
if (ruleResult && ruleResult.children)
categoryResult.addRuleResult(ruleResult);
--rulesRemaining;
+ this._progressMonitor.worked(1);
- if (!rulesRemaining && resultCallback)
+ if (this._progressMonitor.done() && resultCallback)
resultCallback(mainResourceURL, results);
}
- if (!rulesRemaining) {
+ if (this._progressMonitor.done()) {
resultCallback(mainResourceURL, results);
return;
}
@@ -154,7 +160,7 @@
var category = categories[i];
var result = new WebInspector.AuditCategoryResult(category);
results.push(result);
- category.run(resources, ruleResultReadyCallback.bind(null, result));
+ category.run(resources, ruleResultReadyCallback.bind(this, result), this._progressMonitor);
}
},
@@ -170,15 +176,17 @@
var resultTreeElement = new WebInspector.AuditResultSidebarTreeElement(results, mainResourceURL, ordinal);
this.auditResultsTreeElement.appendChild(resultTreeElement);
resultTreeElement.revealAndSelect();
- if (launcherCallback)
+ if (!this._progressMonitor.canceled && launcherCallback)
launcherCallback();
},
- initiateAudit: function(categoryIds, runImmediately, launcherCallback)
+ initiateAudit: function(categoryIds, progressElement, runImmediately, launcherCallback)
{
if (!categoryIds || !categoryIds.length)
return;
+ this._progressMonitor = new WebInspector.AuditProgressMonitor(progressElement);
+
var categories = [];
for (var i = 0; i < categoryIds.length; ++i)
categories.push(this.categoriesById[categoryIds[i]]);
@@ -196,6 +204,12 @@
WebInspector.userMetrics.AuditsStarted.record();
},
+ terminateAudit: function(launcherCallback)
+ {
+ this._progressMonitor.canceled = true;
+ launcherCallback();
+ },
+
_reloadResources: function(callback)
{
this._pageReloadCallback = callback;
@@ -292,11 +306,11 @@
this._rules.push(rule);
},
- run: function(resources, callback)
+ run: function(resources, callback, progressMonitor)
{
this._ensureInitialized();
for (var i = 0; i < this._rules.length; ++i)
- this._rules[i].run(resources, callback);
+ this._rules[i].run(resources, callback, progressMonitor);
},
_ensureInitialized: function()
@@ -346,14 +360,17 @@
this._severity = severity;
},
- run: function(resources, callback)
+ run: function(resources, callback, progressMonitor)
{
+ if (progressMonitor.canceled)
+ return;
+
var result = new WebInspector.AuditRuleResult(this.displayName);
result.severity = this._severity;
- this.doRun(resources, result, callback);
+ this.doRun(resources, result, callback, progressMonitor);
},
- doRun: function(resources, result, callback)
+ doRun: function(resources, result, callback, progressMonitor)
{
throw new Error("doRun() not implemented");
}
@@ -460,6 +477,67 @@
/**
* @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}
*/
WebInspector.AuditsSidebarTreeElement = function()