Skip to content

Commit

Permalink
updated webkit front-end
Browse files Browse the repository at this point in the history
- strip function wrapper from node sources
  • Loading branch information
dannycoates committed Nov 28, 2010
1 parent 635ff93 commit 23812b3
Show file tree
Hide file tree
Showing 76 changed files with 5,825 additions and 4,959 deletions.
2 changes: 1 addition & 1 deletion front-end/ApplicationCacheItemsView.js
Expand Up @@ -64,7 +64,7 @@ WebInspector.ApplicationCacheItemsView = function(treeElement, appcacheDomain)
this._appcacheDomain = appcacheDomain; this._appcacheDomain = appcacheDomain;


this._emptyMsgElement = document.createElement("div"); this._emptyMsgElement = document.createElement("div");
this._emptyMsgElement.className = "storage-table-empty"; this._emptyMsgElement.className = "storage-empty-view";
this._emptyMsgElement.textContent = WebInspector.UIString("No Application Cache information available."); this._emptyMsgElement.textContent = WebInspector.UIString("No Application Cache information available.");
this.element.appendChild(this._emptyMsgElement); this.element.appendChild(this._emptyMsgElement);


Expand Down
1 change: 1 addition & 0 deletions front-end/AuditLauncherView.js
Expand Up @@ -269,6 +269,7 @@ WebInspector.AuditLauncherView.prototype = {
this._selectAllClicked(this._selectAllCheckboxElement.checked); this._selectAllClicked(this._selectAllCheckboxElement.checked);
this.updateResourceTrackingState(); this.updateResourceTrackingState();
this._updateButton(); this._updateButton();
this._updateResourceProgress();
}, },


_updateResourceProgress: function() _updateResourceProgress: function()
Expand Down
3 changes: 2 additions & 1 deletion front-end/AuditResultView.js
Expand Up @@ -89,7 +89,8 @@ WebInspector.AuditCategoryResultPane.prototype = {
title = String.sprintf("%s (%d)", title, result.violationCount); title = String.sprintf("%s (%d)", title, result.violationCount);
} }


var treeElement = new TreeElement(title, null, !!result.children); var treeElement = new TreeElement(null, null, !!result.children);
treeElement.titleHTML = title;
parentTreeElement.appendChild(treeElement); parentTreeElement.appendChild(treeElement);


if (result.className) if (result.className)
Expand Down
82 changes: 46 additions & 36 deletions front-end/AuditRules.js
Expand Up @@ -42,17 +42,17 @@ WebInspector.AuditRules.CacheableResponseCodes =
304: true // Underlying resource is cacheable 304: true // Underlying resource is cacheable
} }


WebInspector.AuditRules.getDomainToResourcesMap = function(resources, types, regexp, needFullResources) WebInspector.AuditRules.getDomainToResourcesMap = function(resources, types, needFullResources)
{ {
var domainToResourcesMap = {}; var domainToResourcesMap = {};
for (var i = 0, size = resources.length; i < size; ++i) { for (var i = 0, size = resources.length; i < size; ++i) {
var resource = resources[i]; var resource = resources[i];
if (types && types.indexOf(resource.type) === -1) if (types && types.indexOf(resource.type) === -1)
continue; continue;
var match = resource.url.match(regexp); var parsedURL = resource.url.asParsedURL();
if (!match) if (!parsedURL)
continue; continue;
var domain = match[2]; var domain = parsedURL.host;
var domainResources = domainToResourcesMap[domain]; var domainResources = domainToResourcesMap[domain];
if (domainResources === undefined) { if (domainResources === undefined) {
domainResources = []; domainResources = [];
Expand Down Expand Up @@ -128,7 +128,7 @@ WebInspector.AuditRules.CombineExternalResourcesRule = function(id, name, type,
WebInspector.AuditRules.CombineExternalResourcesRule.prototype = { WebInspector.AuditRules.CombineExternalResourcesRule.prototype = {
doRun: function(resources, result, callback) doRun: function(resources, result, callback)
{ {
var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, [this._type], WebInspector.URLRegExp); var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, [this._type]);
var penalizedResourceCount = 0; var penalizedResourceCount = 0;
// TODO: refactor according to the chosen i18n approach // TODO: refactor according to the chosen i18n approach
var summary = result.addChild("", true); var summary = result.addChild("", true);
Expand Down Expand Up @@ -175,14 +175,14 @@ WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype = {
doRun: function(resources, result, callback) doRun: function(resources, result, callback)
{ {
var summary = result.addChild(""); var summary = result.addChild("");
var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, undefined, WebInspector.URLRegExp); var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, undefined);
for (var domain in domainToResourcesMap) { for (var domain in domainToResourcesMap) {
if (domainToResourcesMap[domain].length > 1) if (domainToResourcesMap[domain].length > 1)
continue; continue;
var match = domain.match(WebInspector.URLRegExp); var parsedURL = domain.asParsedURL();
if (!match) if (!parsedURL)
continue; continue;
if (!match[2].search(WebInspector.AuditRules.IPAddressRegexp)) if (!parsedURL.host.search(WebInspector.AuditRules.IPAddressRegexp))
continue; // an IP address continue; // an IP address
summary.addSnippet(match[2]); summary.addSnippet(match[2]);
result.violationCount++; result.violationCount++;
Expand Down Expand Up @@ -220,7 +220,6 @@ WebInspector.AuditRules.ParallelizeDownloadRule.prototype = {
var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap( var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(
resources, resources,
[WebInspector.Resource.Type.Stylesheet, WebInspector.Resource.Type.Image], [WebInspector.Resource.Type.Stylesheet, WebInspector.Resource.Type.Image],
WebInspector.URLRegExp,
true); true);


var hosts = []; var hosts = [];
Expand Down Expand Up @@ -278,6 +277,7 @@ WebInspector.AuditRules.UnusedCssRule.prototype = {
doRun: function(resources, result, callback) doRun: function(resources, result, callback)
{ {
var self = this; var self = this;

function evalCallback(styleSheets) { function evalCallback(styleSheets) {
if (!styleSheets.length) if (!styleSheets.length)
return callback(null); return callback(null);
Expand All @@ -287,12 +287,12 @@ WebInspector.AuditRules.UnusedCssRule.prototype = {
var testedSelectors = {}; var testedSelectors = {};
for (var i = 0; i < styleSheets.length; ++i) { for (var i = 0; i < styleSheets.length; ++i) {
var styleSheet = styleSheets[i]; var styleSheet = styleSheets[i];
for (var curRule = 0; curRule < styleSheet.cssRules.length; ++curRule) { for (var curRule = 0; curRule < styleSheet.rules.length; ++curRule) {
var rule = styleSheet.cssRules[curRule]; var selectorText = styleSheet.rules[curRule].selectorText;
if (rule.selectorText.match(pseudoSelectorRegexp)) if (selectorText.match(pseudoSelectorRegexp) || testedSelectors[selectorText])
continue; continue;
selectors.push(rule.selectorText); selectors.push(selectorText);
testedSelectors[rule.selectorText] = 1; testedSelectors[selectorText] = 1;
} }
} }


Expand All @@ -308,9 +308,12 @@ WebInspector.AuditRules.UnusedCssRule.prototype = {
var stylesheetSize = 0; var stylesheetSize = 0;
var unusedStylesheetSize = 0; var unusedStylesheetSize = 0;
var unusedRules = []; var unusedRules = [];
for (var curRule = 0; curRule < styleSheet.cssRules.length; ++curRule) { for (var curRule = 0; curRule < styleSheet.rules.length; ++curRule) {
var rule = styleSheet.cssRules[curRule]; var rule = styleSheet.rules[curRule];
var textLength = rule.cssText ? rule.cssText.length : 0; // Exact computation whenever source ranges are available.
var textLength = (rule.selectorRange && rule.style.properties.endOffset) ? rule.style.properties.endOffset - rule.selectorRange.start + 1 : 0;
if (!textLength && rule.style.cssText)
textLength = rule.style.cssText.length + rule.selectorText.length;
stylesheetSize += textLength; stylesheetSize += textLength;
if (!testedSelectors[rule.selectorText] || foundSelectors[rule.selectorText]) if (!testedSelectors[rule.selectorText] || foundSelectors[rule.selectorText])
continue; continue;
Expand All @@ -323,11 +326,13 @@ WebInspector.AuditRules.UnusedCssRule.prototype = {
if (!unusedRules.length) if (!unusedRules.length)
continue; continue;


var url = styleSheet.href ? WebInspector.AuditRuleResult.linkifyDisplayName(styleSheet.href) : String.sprintf("Inline block #%d", ++inlineBlockOrdinal); var resource = WebInspector.resourceManager.resourceForURL(styleSheet.sourceURL);
var isInlineBlock = resource && resource.type == WebInspector.Resource.Type.Document;
var url = !isInlineBlock ? WebInspector.AuditRuleResult.linkifyDisplayName(styleSheet.sourceURL) : String.sprintf("Inline block #%d", ++inlineBlockOrdinal);
var pctUnused = Math.round(100 * unusedStylesheetSize / stylesheetSize); var pctUnused = Math.round(100 * unusedStylesheetSize / stylesheetSize);
if (!summary) if (!summary)
summary = result.addChild("", true); summary = result.addChild("", true);
var entry = summary.addChild(String.sprintf("%s: %d%% (estimated) is not used by the current page.", url, pctUnused)); var entry = summary.addChild(String.sprintf("%s: %s (%d%%) is not used by the current page.", url, Number.bytesToString(unusedStylesheetSize), pctUnused));


for (var j = 0; j < unusedRules.length; ++j) for (var j = 0; j < unusedRules.length; ++j)
entry.addSnippet(unusedRules[j]); entry.addSnippet(unusedRules[j]);
Expand All @@ -339,7 +344,7 @@ WebInspector.AuditRules.UnusedCssRule.prototype = {
return callback(null); return callback(null);


var totalUnusedPercent = Math.round(100 * totalUnusedStylesheetSize / totalStylesheetSize); var totalUnusedPercent = Math.round(100 * totalUnusedStylesheetSize / totalStylesheetSize);
summary.value = String.sprintf("%d%% of CSS (estimated) is not used by the current page.", totalUnusedPercent); summary.value = String.sprintf("%s (%d%%) of CSS is not used by the current page.", Number.bytesToString(totalUnusedStylesheetSize), totalUnusedPercent);


callback(result); callback(result);
} }
Expand All @@ -349,11 +354,10 @@ WebInspector.AuditRules.UnusedCssRule.prototype = {
var result = {}; var result = {};
for (var i = 0; i < selectorArray.length; ++i) { for (var i = 0; i < selectorArray.length; ++i) {
try { try {
var nodes = document.querySelectorAll(selectorArray[i]); if (document.querySelector(selectorArray[i]))
if (nodes && nodes.length)
result[selectorArray[i]] = true; result[selectorArray[i]] = true;
} catch(e) { } catch(e) {
// ignore and mark as unused // Ignore and mark as unused.
} }
} }
return result; return result;
Expand All @@ -362,16 +366,24 @@ WebInspector.AuditRules.UnusedCssRule.prototype = {
WebInspector.AuditRules.evaluateInTargetWindow(routine, [selectors], selectorsCallback.bind(null, callback, styleSheets, testedSelectors)); WebInspector.AuditRules.evaluateInTargetWindow(routine, [selectors], selectorsCallback.bind(null, callback, styleSheets, testedSelectors));
} }


function routine() function styleSheetCallback(styleSheets, continuation, styleSheet)
{ {
var styleSheets = document.styleSheets; if (styleSheet)
if (!styleSheets) styleSheets.push(styleSheet);
return false; if (continuation)
continuation(styleSheets);
}


return routineResult; function allStylesCallback(styleSheetIds)
{
if (!styleSheetIds || !styleSheetIds.length)
return evalCallback([]);
var styleSheets = [];
for (var i = 0; i < styleSheetIds.length; ++i)
WebInspector.CSSStyleSheet.createForId(styleSheetIds[i], styleSheetCallback.bind(null, styleSheets, i == styleSheetIds.length - 1 ? evalCallback : null));
} }


InspectorBackend.getAllStyles(evalCallback); InspectorBackend.getAllStyles2(allStylesCallback);
} }
} }


Expand Down Expand Up @@ -647,7 +659,7 @@ WebInspector.AuditRules.ImageDimensionsRule.prototype = {


const node = WebInspector.domAgent.nodeForId(imageId); const node = WebInspector.domAgent.nodeForId(imageId);
var src = node.getAttribute("src"); var src = node.getAttribute("src");
if (!WebInspector.URLRegExp.test(src)) { if (!src.asParsedURL()) {
for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) { for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
if (frameOwnerCandidate.documentURL) { if (frameOwnerCandidate.documentURL) {
var completeSrc = WebInspector.completeURL(frameOwnerCandidate.documentURL, src); var completeSrc = WebInspector.completeURL(frameOwnerCandidate.documentURL, src);
Expand All @@ -658,7 +670,7 @@ WebInspector.AuditRules.ImageDimensionsRule.prototype = {
if (completeSrc) if (completeSrc)
src = completeSrc; src = completeSrc;


const computedStyle = new WebInspector.CSSStyleDeclaration(styles.computedStyle); const computedStyle = styles.computedStyle;
if (computedStyle.getPropertyValue("position") === "absolute") { if (computedStyle.getPropertyValue("position") === "absolute") {
if (!context.imagesLeft) if (!context.imagesLeft)
doneCallback(context); doneCallback(context);
Expand All @@ -669,7 +681,7 @@ WebInspector.AuditRules.ImageDimensionsRule.prototype = {
var heightFound = "height" in styles.styleAttributes; var heightFound = "height" in styles.styleAttributes;


for (var i = styles.matchedCSSRules.length - 1; i >= 0 && !(widthFound && heightFound); --i) { for (var i = styles.matchedCSSRules.length - 1; i >= 0 && !(widthFound && heightFound); --i) {
var style = WebInspector.CSSStyleDeclaration.parseRule(styles.matchedCSSRules[i]).style; var style = styles.matchedCSSRules[i].style;
if (style.getPropertyValue("width") !== "") if (style.getPropertyValue("width") !== "")
widthFound = true; widthFound = true;
if (style.getPropertyValue("height") !== "") if (style.getPropertyValue("height") !== "")
Expand All @@ -693,7 +705,7 @@ WebInspector.AuditRules.ImageDimensionsRule.prototype = {
return callback(null); return callback(null);
var context = {imagesLeft: imageIds.length, urlToNoDimensionCount: {}}; var context = {imagesLeft: imageIds.length, urlToNoDimensionCount: {}};
for (var i = imageIds.length - 1; i >= 0; --i) for (var i = imageIds.length - 1; i >= 0; --i)
InspectorBackend.getStyles(imageIds[i], true, imageStylesReady.bind(this, imageIds[i], context)); WebInspector.cssModel.getStylesAsync(imageIds[i], imageStylesReady.bind(this, imageIds[i], context));
} }


function pushImageNodes() function pushImageNodes()
Expand Down Expand Up @@ -934,7 +946,6 @@ WebInspector.AuditRules.CookieSizeRule.prototype = {


var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources,
null, null,
WebInspector.URLRegExp,
true); true);
var matchingResourceData = {}; var matchingResourceData = {};
this.mapResourceCookies(domainToResourcesMap, allCookies, collectorCallback.bind(this)); this.mapResourceCookies(domainToResourcesMap, allCookies, collectorCallback.bind(this));
Expand Down Expand Up @@ -998,7 +1009,6 @@ WebInspector.AuditRules.StaticCookielessRule.prototype = {
var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources,
[WebInspector.Resource.Type.Stylesheet, [WebInspector.Resource.Type.Stylesheet,
WebInspector.Resource.Type.Image], WebInspector.Resource.Type.Image],
WebInspector.URLRegExp,
true); true);
var totalStaticResources = 0; var totalStaticResources = 0;
for (var domain in domainToResourcesMap) for (var domain in domainToResourcesMap)
Expand Down
21 changes: 8 additions & 13 deletions front-end/AuditsPanel.js
Expand Up @@ -130,8 +130,8 @@ WebInspector.AuditsPanel.prototype = {
_executeAudit: function(categories, resultCallback) _executeAudit: function(categories, resultCallback)
{ {
var resources = []; var resources = [];
for (var id in WebInspector.resources) for (var id in WebInspector.networkResources)
resources.push(WebInspector.resources[id]); resources.push(WebInspector.networkResources[id]);


var rulesRemaining = 0; var rulesRemaining = 0;
for (var i = 0; i < categories.length; ++i) for (var i = 0; i < categories.length; ++i)
Expand Down Expand Up @@ -203,20 +203,15 @@ WebInspector.AuditsPanel.prototype = {


_reloadResources: function(callback) _reloadResources: function(callback)
{ {
this._resourceTrackingCallback = callback; this._pageReloadCallback = callback;

InspectorBackend.reloadPage();
if (!WebInspector.panels.resources.resourceTrackingEnabled) {
InspectorBackend.enableResourceTracking(false);
this._updateLauncherViewControls(true);
} else
InspectorBackend.reloadPage();
}, },


_didMainResourceLoad: function() _didMainResourceLoad: function()
{ {
if (this._resourceTrackingCallback) { if (this._pageReloadCallback) {
var callback = this._resourceTrackingCallback; var callback = this._pageReloadCallback;
delete this._resourceTrackingCallback; delete this._pageReloadCallback;
callback(); callback();
} }
}, },
Expand Down Expand Up @@ -256,7 +251,7 @@ WebInspector.AuditsPanel.prototype = {
show: function() show: function()
{ {
WebInspector.Panel.prototype.show.call(this); WebInspector.Panel.prototype.show.call(this);
this._updateLauncherViewControls(WebInspector.panels.resources.resourceTrackingEnabled); this._updateLauncherViewControls(!WebInspector.panels.resources || WebInspector.panels.resources.resourceTrackingEnabled);
}, },


reset: function() reset: function()
Expand Down

0 comments on commit 23812b3

Please sign in to comment.