Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: Source/devtools/front_end/audits/AuditRules.js

Issue 667743002: DevTools: remove "type" getters in Resource and NetworkRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 * @param {!Array.<!WebInspector.NetworkRequest>} requests 46 * @param {!Array.<!WebInspector.NetworkRequest>} requests
47 * @param {?Array.<!WebInspector.resourceTypes>} types 47 * @param {?Array.<!WebInspector.resourceTypes>} types
48 * @param {boolean} needFullResources 48 * @param {boolean} needFullResources
49 * @return {!Object.<string, !Array.<!WebInspector.NetworkRequest|string>>} 49 * @return {!Object.<string, !Array.<!WebInspector.NetworkRequest|string>>}
50 */ 50 */
51 WebInspector.AuditRules.getDomainToResourcesMap = function(requests, types, need FullResources) 51 WebInspector.AuditRules.getDomainToResourcesMap = function(requests, types, need FullResources)
52 { 52 {
53 var domainToResourcesMap = {}; 53 var domainToResourcesMap = {};
54 for (var i = 0, size = requests.length; i < size; ++i) { 54 for (var i = 0, size = requests.length; i < size; ++i) {
55 var request = requests[i]; 55 var request = requests[i];
56 if (types && types.indexOf(request.type) === -1) 56 if (types && types.indexOf(request.resourceType()) === -1)
57 continue; 57 continue;
58 var parsedURL = request.url.asParsedURL(); 58 var parsedURL = request.url.asParsedURL();
59 if (!parsedURL) 59 if (!parsedURL)
60 continue; 60 continue;
61 var domain = parsedURL.host; 61 var domain = parsedURL.host;
62 var domainResources = domainToResourcesMap[domain]; 62 var domainResources = domainToResourcesMap[domain];
63 if (domainResources === undefined) { 63 if (domainResources === undefined) {
64 domainResources = []; 64 domainResources = [];
65 domainToResourcesMap[domain] = domainResources; 65 domainToResourcesMap[domain] = domainResources;
66 } 66 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return false; 127 return false;
128 128
129 return /\b(?:gzip|deflate)\b/.test(encodingHeader); 129 return /\b(?:gzip|deflate)\b/.test(encodingHeader);
130 }, 130 },
131 131
132 /** 132 /**
133 * @param {!WebInspector.NetworkRequest} request 133 * @param {!WebInspector.NetworkRequest} request
134 */ 134 */
135 _shouldCompress: function(request) 135 _shouldCompress: function(request)
136 { 136 {
137 return request.type.isTextType() && request.parsedURL.host && request.re sourceSize !== undefined && request.resourceSize > 150; 137 return request.resourceType().isTextType() && request.parsedURL.host && request.resourceSize !== undefined && request.resourceSize > 150;
138 }, 138 },
139 139
140 __proto__: WebInspector.AuditRule.prototype 140 __proto__: WebInspector.AuditRule.prototype
141 } 141 }
142 142
143 /** 143 /**
144 * @constructor 144 * @constructor
145 * @extends {WebInspector.AuditRule} 145 * @extends {WebInspector.AuditRule}
146 */ 146 */
147 WebInspector.AuditRules.CombineExternalResourcesRule = function(id, name, type, resourceTypeName, allowedPerDomain) 147 WebInspector.AuditRules.CombineExternalResourcesRule = function(id, name, type, resourceTypeName, allowedPerDomain)
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 continue; 407 continue;
408 unusedRules.push(rule.selectorText); 408 unusedRules.push(rule.selectorText);
409 } 409 }
410 totalStylesheetSize += styleSheet.rules.length; 410 totalStylesheetSize += styleSheet.rules.length;
411 totalUnusedStylesheetSize += unusedRules.length; 411 totalUnusedStylesheetSize += unusedRules.length;
412 412
413 if (!unusedRules.length) 413 if (!unusedRules.length)
414 continue; 414 continue;
415 415
416 var resource = WebInspector.resourceForURL(styleSheet.source URL); 416 var resource = WebInspector.resourceForURL(styleSheet.source URL);
417 var isInlineBlock = resource && resource.request && resource .request.type === WebInspector.resourceTypes.Document; 417 var isInlineBlock = resource && resource.request && resource .request.resourceType() === WebInspector.resourceTypes.Document;
418 var url = !isInlineBlock ? WebInspector.AuditRuleResult.link ifyDisplayName(styleSheet.sourceURL) : WebInspector.UIString("Inline block #%d", ++inlineBlockOrdinal); 418 var url = !isInlineBlock ? WebInspector.AuditRuleResult.link ifyDisplayName(styleSheet.sourceURL) : WebInspector.UIString("Inline block #%d", ++inlineBlockOrdinal);
419 var pctUnused = Math.round(100 * unusedRules.length / styleS heet.rules.length); 419 var pctUnused = Math.round(100 * unusedRules.length / styleS heet.rules.length);
420 if (!summary) 420 if (!summary)
421 summary = result.addChild("", true); 421 summary = result.addChild("", true);
422 var entry = summary.addFormatted("%s: %d% is not used by the current page.", url, pctUnused); 422 var entry = summary.addFormatted("%s: %d% is not used by the current page.", url, pctUnused);
423 423
424 for (var j = 0; j < unusedRules.length; ++j) 424 for (var j = 0; j < unusedRules.length; ++j)
425 entry.addSnippet(unusedRules[j]); 425 entry.addSnippet(unusedRules[j]);
426 426
427 result.violationCount += unusedRules.length; 427 result.violationCount += unusedRules.length;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 { 670 {
671 return request.responseHeaderValue(header) !== undefined; 671 return request.responseHeaderValue(header) !== undefined;
672 }, 672 },
673 673
674 /** 674 /**
675 * @param {!WebInspector.NetworkRequest} request 675 * @param {!WebInspector.NetworkRequest} request
676 * @return {boolean} 676 * @return {boolean}
677 */ 677 */
678 isCompressible: function(request) 678 isCompressible: function(request)
679 { 679 {
680 return request.type.isTextType(); 680 return request.resourceType().isTextType();
681 }, 681 },
682 682
683 /** 683 /**
684 * @param {!WebInspector.NetworkRequest} request 684 * @param {!WebInspector.NetworkRequest} request
685 * @return {boolean} 685 * @return {boolean}
686 */ 686 */
687 isPubliclyCacheable: function(request) 687 isPubliclyCacheable: function(request)
688 { 688 {
689 if (this._isExplicitlyNonCacheable(request)) 689 if (this._isExplicitlyNonCacheable(request))
690 return false; 690 return false;
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 result.violationCount = badUrls.length; 1592 result.violationCount = badUrls.length;
1593 }, 1593 },
1594 1594
1595 _collectorCallback: function(matchingResourceData, request, cookie) 1595 _collectorCallback: function(matchingResourceData, request, cookie)
1596 { 1596 {
1597 matchingResourceData[request.url] = (matchingResourceData[request.url] | | 0) + cookie.size(); 1597 matchingResourceData[request.url] = (matchingResourceData[request.url] | | 0) + cookie.size();
1598 }, 1598 },
1599 1599
1600 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype 1600 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype
1601 } 1601 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698