| Index: chrome_linux64/resources/inspector/AuditsPanel.js
|
| ===================================================================
|
| --- chrome_linux64/resources/inspector/AuditsPanel.js (revision 273864)
|
| +++ chrome_linux64/resources/inspector/AuditsPanel.js (working copy)
|
| @@ -1,5 +1,5 @@
|
| WebInspector.AuditsPanel=function()
|
| -{WebInspector.Panel.call(this,"audits");this.registerRequiredCSS("panelEnablerView.css");this.registerRequiredCSS("auditsPanel.css");this.createSidebarViewWithTree();this.splitView.mainElement().classList.add("vbox");this.auditsTreeElement=new WebInspector.SidebarSectionTreeElement("",{},true);this.sidebarTree.appendChild(this.auditsTreeElement);this.auditsTreeElement.listItemElement.classList.add("hidden");this.auditsItemTreeElement=new WebInspector.AuditsSidebarTreeElement(this);this.auditsTreeElement.appendChild(this.auditsItemTreeElement);this.auditResultsTreeElement=new WebInspector.SidebarSectionTreeElement(WebInspector.UIString("RESULTS"),{},true);this.sidebarTree.appendChild(this.auditResultsTreeElement);this.auditResultsTreeElement.expand();this._constructCategories();this._auditController=new WebInspector.AuditController(this);this._launcherView=new WebInspector.AuditLauncherView(this._auditController);for(var id in this.categoriesById)
|
| +{WebInspector.PanelWithSidebarTree.call(this,"audits");this.registerRequiredCSS("panelEnablerView.css");this.registerRequiredCSS("auditsPanel.css");this.auditsTreeElement=new WebInspector.SidebarSectionTreeElement("",{},true);this.sidebarTree.appendChild(this.auditsTreeElement);this.auditsTreeElement.listItemElement.classList.add("hidden");this.auditsItemTreeElement=new WebInspector.AuditsSidebarTreeElement(this);this.auditsTreeElement.appendChild(this.auditsItemTreeElement);this.auditResultsTreeElement=new WebInspector.SidebarSectionTreeElement(WebInspector.UIString("RESULTS"),{},true);this.sidebarTree.appendChild(this.auditResultsTreeElement);this.auditResultsTreeElement.expand();this._constructCategories();this._auditController=new WebInspector.AuditController(this);this._launcherView=new WebInspector.AuditLauncherView(this._auditController);for(var id in this.categoriesById)
|
| this._launcherView.addCategory(this.categoriesById[id]);}
|
| WebInspector.AuditsPanel.prototype={canSearch:function()
|
| {return false;},get categoriesById()
|
| @@ -17,10 +17,10 @@
|
| {if(this._visibleView===x)
|
| return;if(this._visibleView)
|
| this._visibleView.detach();this._visibleView=x;if(x)
|
| -this.splitView.setMainView(x);},wasShown:function()
|
| +x.show(this.mainElement());},wasShown:function()
|
| {WebInspector.Panel.prototype.wasShown.call(this);if(!this._visibleView)
|
| this.auditsItemTreeElement.select();},clearResults:function()
|
| -{this.auditsItemTreeElement.revealAndSelect();this.auditResultsTreeElement.removeChildren();},__proto__:WebInspector.Panel.prototype}
|
| +{this.auditsItemTreeElement.revealAndSelect();this.auditResultsTreeElement.removeChildren();},__proto__:WebInspector.PanelWithSidebarTree.prototype}
|
| WebInspector.AuditCategoryImpl=function(displayName)
|
| {this._displayName=displayName;this._rules=[];}
|
| WebInspector.AuditCategoryImpl.prototype={get id()
|
| @@ -97,7 +97,7 @@
|
| {if(ruleResult&&ruleResult.children)
|
| categoryResult.addRuleResult(ruleResult);if(this._progress.isCanceled())
|
| this._progress.done();}
|
| -var results=[];var mainResourceURL=WebInspector.inspectedPageURL;var categoriesDone=0;function categoryDoneCallback()
|
| +var results=[];var mainResourceURL=WebInspector.resourceTreeModel.inspectedPageURL();var categoriesDone=0;function categoryDoneCallback()
|
| {if(++categoriesDone!==categories.length)
|
| return;this._progress.done();resultCallback(mainResourceURL,results)}
|
| var requests=WebInspector.networkLog.requests.slice();var compositeProgress=new WebInspector.CompositeProgress(this._progress);var subprogresses=[];for(var i=0;i<categories.length;++i)
|
| @@ -131,7 +131,7 @@
|
| return value.map(this.partiallyApply.bind(this,formatters,thisArgument));if(typeof value==="object"&&typeof formatters[value.type]==="function"&&value.arguments)
|
| return formatters[value.type].apply(thisArgument,value.arguments);return value;}}
|
| WebInspector.auditFormatters=new WebInspector.AuditFormatters();;WebInspector.AuditLauncherView=function(auditController)
|
| -{WebInspector.View.call(this);this._auditController=auditController;this._categoryIdPrefix="audit-category-item-";this._auditRunning=false;this.element.classList.add("audit-launcher-view");this.element.classList.add("panel-enabler-view");this._contentElement=document.createElement("div");this._contentElement.className="audit-launcher-view-content";this.element.appendChild(this._contentElement);this._boundCategoryClickListener=this._categoryClicked.bind(this);this._resetResourceCount();this._sortedCategories=[];this._headerElement=document.createElement("h1");this._headerElement.className="no-audits";this._headerElement.textContent=WebInspector.UIString("No audits to run");this._contentElement.appendChild(this._headerElement);WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestStarted,this._onRequestStarted,this);WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished,this._onRequestFinished,this);var defaultSelectedAuditCategory={};defaultSelectedAuditCategory[WebInspector.AuditLauncherView.AllCategoriesKey]=true;this._selectedCategoriesSetting=WebInspector.settings.createSetting("selectedAuditCategories",defaultSelectedAuditCategory);}
|
| +{WebInspector.VBox.call(this);this.setMinimumSize(100,25);this._auditController=auditController;this._categoryIdPrefix="audit-category-item-";this._auditRunning=false;this.element.classList.add("audit-launcher-view");this.element.classList.add("panel-enabler-view");this._contentElement=document.createElement("div");this._contentElement.className="audit-launcher-view-content";this.element.appendChild(this._contentElement);this._boundCategoryClickListener=this._categoryClicked.bind(this);this._resetResourceCount();this._sortedCategories=[];this._headerElement=document.createElement("h1");this._headerElement.className="no-audits";this._headerElement.textContent=WebInspector.UIString("No audits to run");this._contentElement.appendChild(this._headerElement);WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestStarted,this._onRequestStarted,this);WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished,this._onRequestFinished,this);var defaultSelectedAuditCategory={};defaultSelectedAuditCategory[WebInspector.AuditLauncherView.AllCategoriesKey]=true;this._selectedCategoriesSetting=WebInspector.settings.createSetting("selectedAuditCategories",defaultSelectedAuditCategory);}
|
| WebInspector.AuditLauncherView.AllCategoriesKey="__AllCategories";WebInspector.AuditLauncherView.prototype={_resetResourceCount:function()
|
| {this._loadedResources=0;this._totalResources=0;},_onRequestStarted:function(event)
|
| {var request=(event.data);if(request.type===WebInspector.resourceTypes.WebSocket)
|
| @@ -169,8 +169,8 @@
|
| this._progressIndicator.setTitle(WebInspector.UIString("Loading (%d of %d)",this._loadedResources,this._totalResources));},_selectedCategoriesUpdated:function(userGesture)
|
| {var selectedCategories=userGesture?{}:this._selectedCategoriesSetting.get();var childNodes=this._categoriesElement.childNodes;for(var i=0,length=childNodes.length;i<length;++i)
|
| selectedCategories[childNodes[i].__displayName]=childNodes[i].firstChild.checked;selectedCategories[WebInspector.AuditLauncherView.AllCategoriesKey]=this._selectAllCheckboxElement.checked;this._selectedCategoriesSetting.set(selectedCategories);this._updateButton();},_updateButton:function()
|
| -{this._launchButton.textContent=this._auditRunning?WebInspector.UIString("Stop"):WebInspector.UIString("Run");this._launchButton.disabled=!this._currentCategoriesCount;},__proto__:WebInspector.View.prototype};WebInspector.AuditResultView=function(categoryResults)
|
| -{WebInspector.SidebarPaneStack.call(this);this.element.classList.add("audit-result-view");function categorySorter(a,b){return(a.title||"").localeCompare(b.title||"");}
|
| +{this._launchButton.textContent=this._auditRunning?WebInspector.UIString("Stop"):WebInspector.UIString("Run");this._launchButton.disabled=!this._currentCategoriesCount;},__proto__:WebInspector.VBox.prototype};WebInspector.AuditResultView=function(categoryResults)
|
| +{WebInspector.SidebarPaneStack.call(this);this.setMinimumSize(100,25);this.element.classList.add("audit-result-view","fill");function categorySorter(a,b){return(a.title||"").localeCompare(b.title||"");}
|
| categoryResults.sort(categorySorter);for(var i=0;i<categoryResults.length;++i)
|
| this.addPane(new WebInspector.AuditCategoryResultPane(categoryResults[i]));}
|
| WebInspector.AuditResultView.prototype={__proto__:WebInspector.SidebarPaneStack.prototype}
|
| @@ -178,12 +178,13 @@
|
| {WebInspector.SidebarPane.call(this,categoryResult.title);var treeOutlineElement=document.createElement("ol");this.bodyElement.classList.add("audit-result-tree");this.bodyElement.appendChild(treeOutlineElement);this._treeOutline=new TreeOutline(treeOutlineElement);this._treeOutline.expandTreeElementsWhenArrowing=true;function ruleSorter(a,b)
|
| {var result=WebInspector.AuditRule.SeverityOrder[a.severity||0]-WebInspector.AuditRule.SeverityOrder[b.severity||0];if(!result)
|
| result=(a.value||"").localeCompare(b.value||"");return result;}
|
| -categoryResult.ruleResults.sort(ruleSorter);for(var i=0;i<categoryResult.ruleResults.length;++i){var ruleResult=categoryResult.ruleResults[i];var treeElement=this._appendResult(this._treeOutline,ruleResult);treeElement.listItemElement.classList.add("audit-result");if(ruleResult.severity){var severityElement=document.createElement("div");severityElement.className="severity-"+ruleResult.severity;treeElement.listItemElement.appendChild(severityElement);}}
|
| +categoryResult.ruleResults.sort(ruleSorter);for(var i=0;i<categoryResult.ruleResults.length;++i){var ruleResult=categoryResult.ruleResults[i];var treeElement=this._appendResult(this._treeOutline,ruleResult,ruleResult.severity);treeElement.listItemElement.classList.add("audit-result");}
|
| this.expand();}
|
| -WebInspector.AuditCategoryResultPane.prototype={_appendResult:function(parentTreeElement,result)
|
| +WebInspector.AuditCategoryResultPane.prototype={_appendResult:function(parentTreeElement,result,severity)
|
| {var title="";if(typeof result.value==="string"){title=result.value;if(result.violationCount)
|
| title=String.sprintf("%s (%d)",title,result.violationCount);}
|
| -var treeElement=new TreeElement(title,null,!!result.children);parentTreeElement.appendChild(treeElement);if(result.className)
|
| +var titleFragment=document.createDocumentFragment();if(severity){var severityElement=document.createElement("div");severityElement.className="severity-"+severity;titleFragment.appendChild(severityElement);}
|
| +titleFragment.appendChild(document.createTextNode(title));var treeElement=new TreeElement(titleFragment,null,!!result.children);parentTreeElement.appendChild(treeElement);if(result.className)
|
| treeElement.listItemElement.classList.add(result.className);if(typeof result.value!=="string")
|
| treeElement.listItemElement.appendChild(WebInspector.auditFormatters.apply(result.value));if(result.children){for(var i=0;i<result.children.length;++i)
|
| this._appendResult(treeElement,result.children[i]);}
|
| @@ -229,7 +230,7 @@
|
| {WebInspector.AuditRule.call(this,"network-parallelizehosts",WebInspector.UIString("Parallelize downloads across hostnames"));this._optimalHostnameCount=optimalHostnameCount;this._minRequestThreshold=minRequestThreshold;this._minBalanceThreshold=minBalanceThreshold;}
|
| WebInspector.AuditRules.ParallelizeDownloadRule.prototype={doRun:function(requests,result,callback,progress)
|
| {function hostSorter(a,b)
|
| -{var aCount=domainToResourcesMap[a].length;var bCount=domainToResourcesMap[b].length;return(aCount<bCount)?1:(aCount==bCount)?0:-1;}
|
| +{var aCount=domainToResourcesMap[a].length;var bCount=domainToResourcesMap[b].length;return(aCount<bCount)?1:(aCount===bCount)?0:-1;}
|
| var domainToResourcesMap=WebInspector.AuditRules.getDomainToResourcesMap(requests,[WebInspector.resourceTypes.Stylesheet,WebInspector.resourceTypes.Image],true);var hosts=[];for(var url in domainToResourcesMap)
|
| hosts.push(url);if(!hosts.length){callback(null);return;}
|
| hosts.sort(hostSorter);var optimalHostnameCount=this._optimalHostnameCount;if(hosts.length>optimalHostnameCount)
|
| @@ -241,8 +242,7 @@
|
| WebInspector.AuditRules.UnusedCssRule=function()
|
| {WebInspector.AuditRule.call(this,"page-unusedcss",WebInspector.UIString("Remove unused CSS rules"));}
|
| WebInspector.AuditRules.UnusedCssRule.prototype={doRun:function(requests,result,callback,progress)
|
| -{var self=this;function evalCallback(styleSheets){if(progress.isCanceled())
|
| -return;if(!styleSheets.length)
|
| +{function evalCallback(styleSheets){if(!styleSheets.length)
|
| return callback(null);var selectors=[];var testedSelectors={};for(var i=0;i<styleSheets.length;++i){var styleSheet=styleSheets[i];for(var curRule=0;curRule<styleSheet.rules.length;++curRule){var selectorText=styleSheet.rules[curRule].selectorText;if(testedSelectors[selectorText])
|
| continue;selectors.push(selectorText);testedSelectors[selectorText]=1;}}
|
| var foundSelectors={};function selectorsCallback(styleSheets)
|
| @@ -250,7 +250,7 @@
|
| return;var inlineBlockOrdinal=0;var totalStylesheetSize=0;var totalUnusedStylesheetSize=0;var summary;for(var i=0;i<styleSheets.length;++i){var styleSheet=styleSheets[i];var unusedRules=[];for(var curRule=0;curRule<styleSheet.rules.length;++curRule){var rule=styleSheet.rules[curRule];if(!testedSelectors[rule.selectorText]||foundSelectors[rule.selectorText])
|
| continue;unusedRules.push(rule.selectorText);}
|
| totalStylesheetSize+=styleSheet.rules.length;totalUnusedStylesheetSize+=unusedRules.length;if(!unusedRules.length)
|
| -continue;var resource=WebInspector.resourceForURL(styleSheet.sourceURL);var isInlineBlock=resource&&resource.request&&resource.request.type==WebInspector.resourceTypes.Document;var url=!isInlineBlock?WebInspector.AuditRuleResult.linkifyDisplayName(styleSheet.sourceURL):WebInspector.UIString("Inline block #%d",++inlineBlockOrdinal);var pctUnused=Math.round(100*unusedRules.length/styleSheet.rules.length);if(!summary)
|
| +continue;var resource=WebInspector.resourceForURL(styleSheet.sourceURL);var isInlineBlock=resource&&resource.request&&resource.request.type===WebInspector.resourceTypes.Document;var url=!isInlineBlock?WebInspector.AuditRuleResult.linkifyDisplayName(styleSheet.sourceURL):WebInspector.UIString("Inline block #%d",++inlineBlockOrdinal);var pctUnused=Math.round(100*unusedRules.length/styleSheet.rules.length);if(!summary)
|
| summary=result.addChild("",true);var entry=summary.addFormatted("%s: %d% is not used by the current page.",url,pctUnused);for(var j=0;j<unusedRules.length;++j)
|
| entry.addSnippet(unusedRules[j]);result.violationCount+=unusedRules.length;}
|
| if(!totalUnusedStylesheetSize)
|
| @@ -261,18 +261,22 @@
|
| boundSelectorsCallback();}
|
| function documentLoaded(selectors,document){var pseudoSelectorRegexp=/::?(?:[\w-]+)(?:\(.*?\))?/g;if(!selectors.length){selectorsCallback([]);return;}
|
| for(var i=0;i<selectors.length;++i){if(progress.isCanceled())
|
| -return;var effectiveSelector=selectors[i].replace(pseudoSelectorRegexp,"");WebInspector.domAgent.querySelector(document.id,effectiveSelector,queryCallback.bind(null,i===selectors.length-1?selectorsCallback.bind(null,styleSheets):null,selectors[i]));}}
|
| -WebInspector.domAgent.requestDocument(documentLoaded.bind(null,selectors));}
|
| -function styleSheetCallback(styleSheets,sourceURL,continuation,styleSheet)
|
| -{if(progress.isCanceled())
|
| -return;if(styleSheet){styleSheet.sourceURL=sourceURL;styleSheets.push(styleSheet);}
|
| -if(continuation)
|
| -continuation(styleSheets);}
|
| -function allStylesCallback(error,styleSheetInfos)
|
| -{if(progress.isCanceled())
|
| -return;if(error||!styleSheetInfos||!styleSheetInfos.length)
|
| -return evalCallback([]);var styleSheets=[];for(var i=0;i<styleSheetInfos.length;++i){var info=styleSheetInfos[i];WebInspector.CSSStyleSheet.createForId(info.styleSheetId,styleSheetCallback.bind(null,styleSheets,info.sourceURL,i==styleSheetInfos.length-1?evalCallback:null));}}
|
| -CSSAgent.getAllStyleSheets(allStylesCallback);},__proto__:WebInspector.AuditRule.prototype}
|
| +return;var effectiveSelector=selectors[i].replace(pseudoSelectorRegexp,"");WebInspector.domModel.querySelector(document.id,effectiveSelector,queryCallback.bind(null,i===selectors.length-1?selectorsCallback.bind(null,styleSheets):null,selectors[i]));}}
|
| +WebInspector.domModel.requestDocument(documentLoaded.bind(null,selectors));}
|
| +var styleSheetInfos=WebInspector.cssModel.allStyleSheets();if(!styleSheetInfos||!styleSheetInfos.length){evalCallback([]);return;}
|
| +var styleSheetProcessor=new WebInspector.AuditRules.StyleSheetProcessor(styleSheetInfos,progress,evalCallback);styleSheetProcessor.run();},__proto__:WebInspector.AuditRule.prototype}
|
| +WebInspector.AuditRules.ParsedStyleSheet;WebInspector.AuditRules.StyleSheetProcessor=function(styleSheetHeaders,progress,styleSheetsParsedCallback)
|
| +{this._styleSheetHeaders=styleSheetHeaders;this._progress=progress;this._styleSheets=[];this._styleSheetsParsedCallback=styleSheetsParsedCallback;}
|
| +WebInspector.AuditRules.StyleSheetProcessor.prototype={run:function()
|
| +{this._parser=new WebInspector.CSSParser();this._processNextStyleSheet();},_terminateWorker:function()
|
| +{if(this._parser){this._parser.dispose();delete this._parser;}},_finish:function()
|
| +{this._terminateWorker();this._styleSheetsParsedCallback(this._styleSheets);},_processNextStyleSheet:function()
|
| +{if(!this._styleSheetHeaders.length){this._finish();return;}
|
| +this._currentStyleSheetHeader=this._styleSheetHeaders.shift();this._parser.fetchAndParse(this._currentStyleSheetHeader,this._onStyleSheetParsed.bind(this));},_onStyleSheetParsed:function(rules)
|
| +{if(this._progress.isCanceled()){this._terminateWorker();return;}
|
| +var styleRules=[];for(var i=0;i<rules.length;++i){var rule=rules[i];if(rule.selectorText)
|
| +styleRules.push(rule);}
|
| +this._styleSheets.push({sourceURL:this._currentStyleSheetHeader.sourceURL,rules:styleRules});this._processNextStyleSheet();},}
|
| WebInspector.AuditRules.CacheControlRule=function(id,name)
|
| {WebInspector.AuditRule.call(this,id,name);}
|
| WebInspector.AuditRules.CacheControlRule.MillisPerMonth=1000*60*60*24*30;WebInspector.AuditRules.CacheControlRule.prototype={doRun:function(requests,result,callback,progress)
|
| @@ -298,7 +302,7 @@
|
| {return request.type.isTextType();},isPubliclyCacheable:function(request)
|
| {if(this._isExplicitlyNonCacheable(request))
|
| return false;if(this.responseHeaderMatch(request,"Cache-Control","public"))
|
| -return true;return request.url.indexOf("?")==-1&&!this.responseHeaderMatch(request,"Cache-Control","private");},responseHeaderMatch:function(request,header,regexp)
|
| +return true;return request.url.indexOf("?")===-1&&!this.responseHeaderMatch(request,"Cache-Control","private");},responseHeaderMatch:function(request,header,regexp)
|
| {return request.responseHeaderValue(header)?request.responseHeaderValue(header).match(new RegExp(regexp,"im")):null;},hasExplicitExpiration:function(request)
|
| {return this.hasResponseHeader(request,"Date")&&(this.hasResponseHeader(request,"Expires")||!!this.responseHeaderMatch(request,"Cache-Control","max-age"));},_isExplicitlyNonCacheable:function(request)
|
| {var hasExplicitExp=this.hasExplicitExpiration(request);return!!this.responseHeaderMatch(request,"Cache-Control","(no-cache|no-store|must-revalidate)")||!!this.responseHeaderMatch(request,"Pragma","no-cache")||(hasExplicitExp&&!this.freshnessLifetimeGreaterThan(request,0))||(!hasExplicitExp&&!!request.url&&request.url.indexOf("?")>=0)||(!hasExplicitExp&&!this.isCacheableResource(request));},isCacheableResource:function(request)
|
| @@ -329,7 +333,7 @@
|
| callback(entry?result:null);}
|
| function imageStylesReady(imageId,styles,isLastStyle,computedStyle)
|
| {if(progress.isCanceled())
|
| -return;const node=WebInspector.domAgent.nodeForId(imageId);var src=node.getAttribute("src");if(!src.asParsedURL()){for(var frameOwnerCandidate=node;frameOwnerCandidate;frameOwnerCandidate=frameOwnerCandidate.parentNode){if(frameOwnerCandidate.baseURL){var completeSrc=WebInspector.ParsedURL.completeURL(frameOwnerCandidate.baseURL,src);break;}}}
|
| +return;const node=WebInspector.domModel.nodeForId(imageId);var src=node.getAttribute("src");if(!src.asParsedURL()){for(var frameOwnerCandidate=node;frameOwnerCandidate;frameOwnerCandidate=frameOwnerCandidate.parentNode){if(frameOwnerCandidate.baseURL){var completeSrc=WebInspector.ParsedURL.completeURL(frameOwnerCandidate.baseURL,src);break;}}}
|
| if(completeSrc)
|
| src=completeSrc;if(computedStyle.getPropertyValue("position")==="absolute"){if(isLastStyle)
|
| doneCallback();return;}
|
| @@ -356,9 +360,9 @@
|
| doneCallback();for(var i=0;nodeIds&&i<nodeIds.length;++i){WebInspector.cssModel.getMatchedStylesAsync(nodeIds[i],false,false,matchedCallback);WebInspector.cssModel.getInlineStylesAsync(nodeIds[i],inlineCallback);WebInspector.cssModel.getComputedStyleAsync(nodeIds[i],imageStylesReady.bind(null,nodeIds[i],targetResult,i===nodeIds.length-1));}}
|
| function onDocumentAvailable(root)
|
| {if(progress.isCanceled())
|
| -return;WebInspector.domAgent.querySelectorAll(root.id,"img[src]",getStyles);}
|
| +return;WebInspector.domModel.querySelectorAll(root.id,"img[src]",getStyles);}
|
| if(progress.isCanceled())
|
| -return;WebInspector.domAgent.requestDocument(onDocumentAvailable);},__proto__:WebInspector.AuditRule.prototype}
|
| +return;WebInspector.domModel.requestDocument(onDocumentAvailable);},__proto__:WebInspector.AuditRule.prototype}
|
| WebInspector.AuditRules.CssInHeadRule=function()
|
| {WebInspector.AuditRule.call(this,"page-cssinhead",WebInspector.UIString("Put CSS in the document head"));}
|
| WebInspector.AuditRules.CssInHeadRule.prototype={doRun:function(requests,result,callback,progress)
|
| @@ -372,17 +376,17 @@
|
| function externalStylesheetsReceived(root,inlineStyleNodeIds,nodeIds)
|
| {if(progress.isCanceled())
|
| return;if(!nodeIds)
|
| -return;var externalStylesheetNodeIds=nodeIds;var result=null;if(inlineStyleNodeIds.length||externalStylesheetNodeIds.length){var urlToViolationsArray={};var externalStylesheetHrefs=[];for(var j=0;j<externalStylesheetNodeIds.length;++j){var linkNode=WebInspector.domAgent.nodeForId(externalStylesheetNodeIds[j]);var completeHref=WebInspector.ParsedURL.completeURL(linkNode.ownerDocument.baseURL,linkNode.getAttribute("href"));externalStylesheetHrefs.push(completeHref||"<empty>");}
|
| +return;var externalStylesheetNodeIds=nodeIds;var result=null;if(inlineStyleNodeIds.length||externalStylesheetNodeIds.length){var urlToViolationsArray={};var externalStylesheetHrefs=[];for(var j=0;j<externalStylesheetNodeIds.length;++j){var linkNode=WebInspector.domModel.nodeForId(externalStylesheetNodeIds[j]);var completeHref=WebInspector.ParsedURL.completeURL(linkNode.ownerDocument.baseURL,linkNode.getAttribute("href"));externalStylesheetHrefs.push(completeHref||"<empty>");}
|
| urlToViolationsArray[root.documentURL]=[inlineStyleNodeIds.length,externalStylesheetHrefs];result=urlToViolationsArray;}
|
| evalCallback(result);}
|
| function inlineStylesReceived(root,nodeIds)
|
| {if(progress.isCanceled())
|
| return;if(!nodeIds)
|
| -return;WebInspector.domAgent.querySelectorAll(root.id,"body link[rel~='stylesheet'][href]",externalStylesheetsReceived.bind(null,root,nodeIds));}
|
| +return;WebInspector.domModel.querySelectorAll(root.id,"body link[rel~='stylesheet'][href]",externalStylesheetsReceived.bind(null,root,nodeIds));}
|
| function onDocumentAvailable(root)
|
| {if(progress.isCanceled())
|
| -return;WebInspector.domAgent.querySelectorAll(root.id,"body style",inlineStylesReceived.bind(null,root));}
|
| -WebInspector.domAgent.requestDocument(onDocumentAvailable);},__proto__:WebInspector.AuditRule.prototype}
|
| +return;WebInspector.domModel.querySelectorAll(root.id,"body style",inlineStylesReceived.bind(null,root));}
|
| +WebInspector.domModel.requestDocument(onDocumentAvailable);},__proto__:WebInspector.AuditRule.prototype}
|
| WebInspector.AuditRules.StylesScriptsOrderRule=function()
|
| {WebInspector.AuditRule.call(this,"page-stylescriptorder",WebInspector.UIString("Optimize the order of styles and scripts"));}
|
| WebInspector.AuditRules.StylesScriptsOrderRule.prototype={doRun:function(requests,result,callback,progress)
|
| @@ -395,51 +399,45 @@
|
| function cssBeforeInlineReceived(lateStyleIds,nodeIds)
|
| {if(progress.isCanceled())
|
| return;if(!nodeIds)
|
| -return;var cssBeforeInlineCount=nodeIds.length;var result=null;if(lateStyleIds.length||cssBeforeInlineCount){var lateStyleUrls=[];for(var i=0;i<lateStyleIds.length;++i){var lateStyleNode=WebInspector.domAgent.nodeForId(lateStyleIds[i]);var completeHref=WebInspector.ParsedURL.completeURL(lateStyleNode.ownerDocument.baseURL,lateStyleNode.getAttribute("href"));lateStyleUrls.push(completeHref||"<empty>");}
|
| +return;var cssBeforeInlineCount=nodeIds.length;var result=null;if(lateStyleIds.length||cssBeforeInlineCount){var lateStyleUrls=[];for(var i=0;i<lateStyleIds.length;++i){var lateStyleNode=WebInspector.domModel.nodeForId(lateStyleIds[i]);var completeHref=WebInspector.ParsedURL.completeURL(lateStyleNode.ownerDocument.baseURL,lateStyleNode.getAttribute("href"));lateStyleUrls.push(completeHref||"<empty>");}
|
| result=[lateStyleUrls,cssBeforeInlineCount];}
|
| evalCallback(result);}
|
| function lateStylesReceived(root,nodeIds)
|
| {if(progress.isCanceled())
|
| return;if(!nodeIds)
|
| -return;WebInspector.domAgent.querySelectorAll(root.id,"head link[rel~='stylesheet'][href] ~ script:not([src])",cssBeforeInlineReceived.bind(null,nodeIds));}
|
| +return;WebInspector.domModel.querySelectorAll(root.id,"head link[rel~='stylesheet'][href] ~ script:not([src])",cssBeforeInlineReceived.bind(null,nodeIds));}
|
| function onDocumentAvailable(root)
|
| {if(progress.isCanceled())
|
| -return;WebInspector.domAgent.querySelectorAll(root.id,"head script[src] ~ link[rel~='stylesheet'][href]",lateStylesReceived.bind(null,root));}
|
| -WebInspector.domAgent.requestDocument(onDocumentAvailable);},__proto__:WebInspector.AuditRule.prototype}
|
| +return;WebInspector.domModel.querySelectorAll(root.id,"head script[src] ~ link[rel~='stylesheet'][href]",lateStylesReceived.bind(null,root));}
|
| +WebInspector.domModel.requestDocument(onDocumentAvailable);},__proto__:WebInspector.AuditRule.prototype}
|
| WebInspector.AuditRules.CSSRuleBase=function(id,name)
|
| {WebInspector.AuditRule.call(this,id,name);}
|
| WebInspector.AuditRules.CSSRuleBase.prototype={doRun:function(requests,result,callback,progress)
|
| -{CSSAgent.getAllStyleSheets(sheetsCallback.bind(this));function sheetsCallback(error,headers)
|
| -{if(error)
|
| -return callback(null);if(!headers.length)
|
| -return callback(null);for(var i=0;i<headers.length;++i){var header=headers[i];if(header.disabled)
|
| -continue;this._visitStyleSheet(header.styleSheetId,i===headers.length-1?finishedCallback:null,result,progress);}}
|
| -function finishedCallback()
|
| -{callback(result);}},_visitStyleSheet:function(styleSheetId,callback,result,progress)
|
| -{WebInspector.CSSStyleSheet.createForId(styleSheetId,sheetCallback.bind(this));function sheetCallback(styleSheet)
|
| -{if(progress.isCanceled())
|
| -return;if(!styleSheet){if(callback)
|
| -callback();return;}
|
| -this.visitStyleSheet(styleSheet,result);for(var i=0;i<styleSheet.rules.length;++i)
|
| -this._visitRule(styleSheet,styleSheet.rules[i],result);this.didVisitStyleSheet(styleSheet,result);if(callback)
|
| -callback();}},_visitRule:function(styleSheet,rule,result)
|
| -{this.visitRule(styleSheet,rule,result);var allProperties=rule.style.allProperties;for(var i=0;i<allProperties.length;++i)
|
| -this.visitProperty(styleSheet,allProperties[i],result);this.didVisitRule(styleSheet,rule,result);},visitStyleSheet:function(styleSheet,result)
|
| +{var headers=WebInspector.cssModel.allStyleSheets();if(!headers.length){callback(null);return;}
|
| +var activeHeaders=[]
|
| +for(var i=0;i<headers.length;++i){if(!headers[i].disabled)
|
| +activeHeaders.push(headers[i]);}
|
| +var styleSheetProcessor=new WebInspector.AuditRules.StyleSheetProcessor(activeHeaders,progress,this._styleSheetsLoaded.bind(this,result,callback,progress));styleSheetProcessor.run();},_styleSheetsLoaded:function(result,callback,progress,styleSheets)
|
| +{for(var i=0;i<styleSheets.length;++i)
|
| +this._visitStyleSheet(styleSheets[i],result);callback(result);},_visitStyleSheet:function(styleSheet,result)
|
| +{this.visitStyleSheet(styleSheet,result);for(var i=0;i<styleSheet.rules.length;++i)
|
| +this._visitRule(styleSheet,styleSheet.rules[i],result);this.didVisitStyleSheet(styleSheet,result);},_visitRule:function(styleSheet,rule,result)
|
| +{this.visitRule(styleSheet,rule,result);var allProperties=rule.properties;for(var i=0;i<allProperties.length;++i)
|
| +this.visitProperty(styleSheet,rule,allProperties[i],result);this.didVisitRule(styleSheet,rule,result);},visitStyleSheet:function(styleSheet,result)
|
| {},didVisitStyleSheet:function(styleSheet,result)
|
| {},visitRule:function(styleSheet,rule,result)
|
| {},didVisitRule:function(styleSheet,rule,result)
|
| -{},visitProperty:function(styleSheet,property,result)
|
| +{},visitProperty:function(styleSheet,rule,property,result)
|
| {},__proto__:WebInspector.AuditRule.prototype}
|
| WebInspector.AuditRules.VendorPrefixedCSSProperties=function()
|
| {WebInspector.AuditRules.CSSRuleBase.call(this,"page-vendorprefixedcss",WebInspector.UIString("Use normal CSS property names instead of vendor-prefixed ones"));this._webkitPrefix="-webkit-";}
|
| WebInspector.AuditRules.VendorPrefixedCSSProperties.supportedProperties=["background-clip","background-origin","background-size","border-radius","border-bottom-left-radius","border-bottom-right-radius","border-top-left-radius","border-top-right-radius","box-shadow","box-sizing","opacity","text-shadow"].keySet();WebInspector.AuditRules.VendorPrefixedCSSProperties.prototype={didVisitStyleSheet:function(styleSheet)
|
| {delete this._styleSheetResult;},visitRule:function(rule)
|
| {this._mentionedProperties={};},didVisitRule:function()
|
| -{delete this._ruleResult;delete this._mentionedProperties;},visitProperty:function(styleSheet,property,result)
|
| +{delete this._ruleResult;delete this._mentionedProperties;},visitProperty:function(styleSheet,rule,property,result)
|
| {if(!property.name.startsWith(this._webkitPrefix))
|
| -return;var normalPropertyName=property.name.substring(this._webkitPrefix.length).toLowerCase();if(WebInspector.AuditRules.VendorPrefixedCSSProperties.supportedProperties[normalPropertyName]&&!this._mentionedProperties[normalPropertyName]){var style=property.ownerStyle;var liveProperty=style.getLiveProperty(normalPropertyName);if(liveProperty&&!liveProperty.styleBased)
|
| -return;var rule=style.parentRule;this._mentionedProperties[normalPropertyName]=true;if(!this._styleSheetResult)
|
| -this._styleSheetResult=result.addChild(rule.sourceURL?WebInspector.linkifyResourceAsNode(rule.sourceURL):WebInspector.UIString("<unknown>"));if(!this._ruleResult){var anchor=WebInspector.linkifyURLAsNode(rule.sourceURL,rule.selectorText);anchor.preferredPanel="resources";anchor.lineNumber=rule.lineNumberInSource();this._ruleResult=this._styleSheetResult.addChild(anchor);}
|
| +return;var normalPropertyName=property.name.substring(this._webkitPrefix.length).toLowerCase();if(WebInspector.AuditRules.VendorPrefixedCSSProperties.supportedProperties[normalPropertyName]&&!this._mentionedProperties[normalPropertyName]){this._mentionedProperties[normalPropertyName]=true;if(!this._styleSheetResult)
|
| +this._styleSheetResult=result.addChild(styleSheet.sourceURL?WebInspector.linkifyResourceAsNode(styleSheet.sourceURL):WebInspector.UIString("<unknown>"));if(!this._ruleResult){var anchor=WebInspector.linkifyURLAsNode(styleSheet.sourceURL,rule.selectorText);anchor.lineNumber=rule.lineNumber;this._ruleResult=this._styleSheetResult.addChild(anchor);}
|
| ++result.violationCount;this._ruleResult.addSnippet(WebInspector.UIString("\"%s%s\" is used, but \"%s\" is supported.",this._webkitPrefix,normalPropertyName,normalPropertyName));}},__proto__:WebInspector.AuditRules.CSSRuleBase.prototype}
|
| WebInspector.AuditRules.CookieRuleBase=function(id,name)
|
| {WebInspector.AuditRule.call(this,id,name);}
|
| @@ -467,7 +465,7 @@
|
| {var cookies=cookiesPerResourceDomain[request.parsedURL.host];if(!cookies){cookies=[];cookiesPerResourceDomain[request.parsedURL.host]=cookies;}
|
| cookies.push(cookie);}
|
| if(!allCookies.length)
|
| -return;var sortedCookieSizes=[];var domainToResourcesMap=WebInspector.AuditRules.getDomainToResourcesMap(requests,null,true);var matchingResourceData={};this.mapResourceCookies(domainToResourcesMap,allCookies,collectorCallback.bind(this));for(var requestDomain in cookiesPerResourceDomain){var cookies=cookiesPerResourceDomain[requestDomain];sortedCookieSizes.push({domain:requestDomain,avgCookieSize:this._average(cookies),maxCookieSize:this._max(cookies)});}
|
| +return;var sortedCookieSizes=[];var domainToResourcesMap=WebInspector.AuditRules.getDomainToResourcesMap(requests,null,true);var matchingResourceData={};this.mapResourceCookies(domainToResourcesMap,allCookies,collectorCallback);for(var requestDomain in cookiesPerResourceDomain){var cookies=cookiesPerResourceDomain[requestDomain];sortedCookieSizes.push({domain:requestDomain,avgCookieSize:this._average(cookies),maxCookieSize:this._max(cookies)});}
|
| var avgAllCookiesSize=this._average(allCookies);var hugeCookieDomains=[];sortedCookieSizes.sort(maxSizeSorter);for(var i=0,len=sortedCookieSizes.length;i<len;++i){var maxCookieSize=sortedCookieSizes[i].maxCookieSize;if(maxCookieSize>this._maxBytesThreshold)
|
| hugeCookieDomains.push(WebInspector.AuditRuleResult.resourceDomain(sortedCookieSizes[i].domain)+": "+Number.bytesToString(maxCookieSize));}
|
| var bigAvgCookieDomains=[];sortedCookieSizes.sort(avgSizeSorter);for(var i=0,len=sortedCookieSizes.length;i<len;++i){var domain=sortedCookieSizes[i].domain;var avgCookieSize=sortedCookieSizes[i].avgCookieSize;if(avgCookieSize>this._avgBytesThreshold&&avgCookieSize<this._maxBytesThreshold)
|
|
|