| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 WebInspector.AuditRules.CacheableResponseCodes = | 33 WebInspector.AuditRules.CacheableResponseCodes = |
| 34 { | 34 { |
| 35 200: true, | 35 200: true, |
| 36 203: true, | 36 203: true, |
| 37 206: true, | 37 206: true, |
| 38 300: true, | 38 300: true, |
| 39 301: true, | 39 301: true, |
| 40 410: true, | 40 410: true, |
| 41 | 41 |
| 42 304: true // Underlying request is cacheable | 42 304: true // Underlying request is cacheable |
| 43 } | 43 }; |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 46 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 47 * @param {?Array.<!WebInspector.ResourceType>} types | 47 * @param {?Array.<!WebInspector.ResourceType>} 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.resourceType()) === -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 } |
| 67 domainResources.push(needFullResources ? request : request.url); | 67 domainResources.push(needFullResources ? request : request.url); |
| 68 } | 68 } |
| 69 return domainToResourcesMap; | 69 return domainToResourcesMap; |
| 70 } | 70 }; |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * @constructor | 73 * @constructor |
| 74 * @extends {WebInspector.AuditRule} | 74 * @extends {WebInspector.AuditRule} |
| 75 */ | 75 */ |
| 76 WebInspector.AuditRules.GzipRule = function() | 76 WebInspector.AuditRules.GzipRule = function() |
| 77 { | 77 { |
| 78 WebInspector.AuditRule.call(this, "network-gzip", WebInspector.UIString("Ena
ble gzip compression")); | 78 WebInspector.AuditRule.call(this, "network-gzip", WebInspector.UIString("Ena
ble gzip compression")); |
| 79 } | 79 }; |
| 80 | 80 |
| 81 WebInspector.AuditRules.GzipRule.prototype = { | 81 WebInspector.AuditRules.GzipRule.prototype = { |
| 82 /** | 82 /** |
| 83 * @override | 83 * @override |
| 84 * @param {!WebInspector.Target} target | 84 * @param {!WebInspector.Target} target |
| 85 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 85 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 86 * @param {!WebInspector.AuditRuleResult} result | 86 * @param {!WebInspector.AuditRuleResult} result |
| 87 * @param {function(?WebInspector.AuditRuleResult)} callback | 87 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 88 * @param {!WebInspector.Progress} progress | 88 * @param {!WebInspector.Progress} progress |
| 89 */ | 89 */ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * @param {!WebInspector.NetworkRequest} request | 134 * @param {!WebInspector.NetworkRequest} request |
| 135 */ | 135 */ |
| 136 _shouldCompress: function(request) | 136 _shouldCompress: function(request) |
| 137 { | 137 { |
| 138 return request.resourceType().isTextType() && request.parsedURL.host &&
request.resourceSize !== undefined && request.resourceSize > 150; | 138 return request.resourceType().isTextType() && request.parsedURL.host &&
request.resourceSize !== undefined && request.resourceSize > 150; |
| 139 }, | 139 }, |
| 140 | 140 |
| 141 __proto__: WebInspector.AuditRule.prototype | 141 __proto__: WebInspector.AuditRule.prototype |
| 142 } | 142 }; |
| 143 | 143 |
| 144 /** | 144 /** |
| 145 * @constructor | 145 * @constructor |
| 146 * @extends {WebInspector.AuditRule} | 146 * @extends {WebInspector.AuditRule} |
| 147 * @param {string} id | 147 * @param {string} id |
| 148 * @param {string} name | 148 * @param {string} name |
| 149 * @param {!WebInspector.ResourceType} type | 149 * @param {!WebInspector.ResourceType} type |
| 150 * @param {string} resourceTypeName | 150 * @param {string} resourceTypeName |
| 151 * @param {boolean} allowedPerDomain | 151 * @param {boolean} allowedPerDomain |
| 152 */ | 152 */ |
| 153 WebInspector.AuditRules.CombineExternalResourcesRule = function(id, name, type,
resourceTypeName, allowedPerDomain) | 153 WebInspector.AuditRules.CombineExternalResourcesRule = function(id, name, type,
resourceTypeName, allowedPerDomain) |
| 154 { | 154 { |
| 155 WebInspector.AuditRule.call(this, id, name); | 155 WebInspector.AuditRule.call(this, id, name); |
| 156 this._type = type; | 156 this._type = type; |
| 157 this._resourceTypeName = resourceTypeName; | 157 this._resourceTypeName = resourceTypeName; |
| 158 this._allowedPerDomain = allowedPerDomain; | 158 this._allowedPerDomain = allowedPerDomain; |
| 159 } | 159 }; |
| 160 | 160 |
| 161 WebInspector.AuditRules.CombineExternalResourcesRule.prototype = { | 161 WebInspector.AuditRules.CombineExternalResourcesRule.prototype = { |
| 162 /** | 162 /** |
| 163 * @override | 163 * @override |
| 164 * @param {!WebInspector.Target} target | 164 * @param {!WebInspector.Target} target |
| 165 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 165 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 166 * @param {!WebInspector.AuditRuleResult} result | 166 * @param {!WebInspector.AuditRuleResult} result |
| 167 * @param {function(?WebInspector.AuditRuleResult)} callback | 167 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 168 * @param {!WebInspector.Progress} progress | 168 * @param {!WebInspector.Progress} progress |
| 169 */ | 169 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 185 if (!penalizedResourceCount) { | 185 if (!penalizedResourceCount) { |
| 186 callback(null); | 186 callback(null); |
| 187 return; | 187 return; |
| 188 } | 188 } |
| 189 | 189 |
| 190 summary.value = WebInspector.UIString("There are multiple resources serv
ed from same domain. Consider combining them into as few files as possible."); | 190 summary.value = WebInspector.UIString("There are multiple resources serv
ed from same domain. Consider combining them into as few files as possible."); |
| 191 callback(result); | 191 callback(result); |
| 192 }, | 192 }, |
| 193 | 193 |
| 194 __proto__: WebInspector.AuditRule.prototype | 194 __proto__: WebInspector.AuditRule.prototype |
| 195 } | 195 }; |
| 196 | 196 |
| 197 /** | 197 /** |
| 198 * @constructor | 198 * @constructor |
| 199 * @extends {WebInspector.AuditRules.CombineExternalResourcesRule} | 199 * @extends {WebInspector.AuditRules.CombineExternalResourcesRule} |
| 200 */ | 200 */ |
| 201 WebInspector.AuditRules.CombineJsResourcesRule = function(allowedPerDomain) { | 201 WebInspector.AuditRules.CombineJsResourcesRule = function(allowedPerDomain) { |
| 202 WebInspector.AuditRules.CombineExternalResourcesRule.call(this, "page-extern
aljs", WebInspector.UIString("Combine external JavaScript"), WebInspector.resour
ceTypes.Script, "JavaScript", allowedPerDomain); | 202 WebInspector.AuditRules.CombineExternalResourcesRule.call(this, "page-extern
aljs", WebInspector.UIString("Combine external JavaScript"), WebInspector.resour
ceTypes.Script, "JavaScript", allowedPerDomain); |
| 203 } | 203 }; |
| 204 | 204 |
| 205 WebInspector.AuditRules.CombineJsResourcesRule.prototype = { | 205 WebInspector.AuditRules.CombineJsResourcesRule.prototype = { |
| 206 __proto__: WebInspector.AuditRules.CombineExternalResourcesRule.prototype | 206 __proto__: WebInspector.AuditRules.CombineExternalResourcesRule.prototype |
| 207 } | 207 }; |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * @constructor | 210 * @constructor |
| 211 * @extends {WebInspector.AuditRules.CombineExternalResourcesRule} | 211 * @extends {WebInspector.AuditRules.CombineExternalResourcesRule} |
| 212 */ | 212 */ |
| 213 WebInspector.AuditRules.CombineCssResourcesRule = function(allowedPerDomain) { | 213 WebInspector.AuditRules.CombineCssResourcesRule = function(allowedPerDomain) { |
| 214 WebInspector.AuditRules.CombineExternalResourcesRule.call(this, "page-extern
alcss", WebInspector.UIString("Combine external CSS"), WebInspector.resourceType
s.Stylesheet, "CSS", allowedPerDomain); | 214 WebInspector.AuditRules.CombineExternalResourcesRule.call(this, "page-extern
alcss", WebInspector.UIString("Combine external CSS"), WebInspector.resourceType
s.Stylesheet, "CSS", allowedPerDomain); |
| 215 } | 215 }; |
| 216 | 216 |
| 217 WebInspector.AuditRules.CombineCssResourcesRule.prototype = { | 217 WebInspector.AuditRules.CombineCssResourcesRule.prototype = { |
| 218 __proto__: WebInspector.AuditRules.CombineExternalResourcesRule.prototype | 218 __proto__: WebInspector.AuditRules.CombineExternalResourcesRule.prototype |
| 219 } | 219 }; |
| 220 | 220 |
| 221 /** | 221 /** |
| 222 * @constructor | 222 * @constructor |
| 223 * @extends {WebInspector.AuditRule} | 223 * @extends {WebInspector.AuditRule} |
| 224 */ | 224 */ |
| 225 WebInspector.AuditRules.MinimizeDnsLookupsRule = function(hostCountThreshold) { | 225 WebInspector.AuditRules.MinimizeDnsLookupsRule = function(hostCountThreshold) { |
| 226 WebInspector.AuditRule.call(this, "network-minimizelookups", WebInspector.UI
String("Minimize DNS lookups")); | 226 WebInspector.AuditRule.call(this, "network-minimizelookups", WebInspector.UI
String("Minimize DNS lookups")); |
| 227 this._hostCountThreshold = hostCountThreshold; | 227 this._hostCountThreshold = hostCountThreshold; |
| 228 } | 228 }; |
| 229 | 229 |
| 230 WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype = { | 230 WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype = { |
| 231 /** | 231 /** |
| 232 * @override | 232 * @override |
| 233 * @param {!WebInspector.Target} target | 233 * @param {!WebInspector.Target} target |
| 234 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 234 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 235 * @param {!WebInspector.AuditRuleResult} result | 235 * @param {!WebInspector.AuditRuleResult} result |
| 236 * @param {function(?WebInspector.AuditRuleResult)} callback | 236 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 237 * @param {!WebInspector.Progress} progress | 237 * @param {!WebInspector.Progress} progress |
| 238 */ | 238 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 254 if (!summary.children || summary.children.length <= this._hostCountThres
hold) { | 254 if (!summary.children || summary.children.length <= this._hostCountThres
hold) { |
| 255 callback(null); | 255 callback(null); |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 | 258 |
| 259 summary.value = WebInspector.UIString("The following domains only serve
one resource each. If possible, avoid the extra DNS lookups by serving these res
ources from existing domains."); | 259 summary.value = WebInspector.UIString("The following domains only serve
one resource each. If possible, avoid the extra DNS lookups by serving these res
ources from existing domains."); |
| 260 callback(result); | 260 callback(result); |
| 261 }, | 261 }, |
| 262 | 262 |
| 263 __proto__: WebInspector.AuditRule.prototype | 263 __proto__: WebInspector.AuditRule.prototype |
| 264 } | 264 }; |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * @constructor | 267 * @constructor |
| 268 * @extends {WebInspector.AuditRule} | 268 * @extends {WebInspector.AuditRule} |
| 269 */ | 269 */ |
| 270 WebInspector.AuditRules.ParallelizeDownloadRule = function(optimalHostnameCount,
minRequestThreshold, minBalanceThreshold) | 270 WebInspector.AuditRules.ParallelizeDownloadRule = function(optimalHostnameCount,
minRequestThreshold, minBalanceThreshold) |
| 271 { | 271 { |
| 272 WebInspector.AuditRule.call(this, "network-parallelizehosts", WebInspector.U
IString("Parallelize downloads across hostnames")); | 272 WebInspector.AuditRule.call(this, "network-parallelizehosts", WebInspector.U
IString("Parallelize downloads across hostnames")); |
| 273 this._optimalHostnameCount = optimalHostnameCount; | 273 this._optimalHostnameCount = optimalHostnameCount; |
| 274 this._minRequestThreshold = minRequestThreshold; | 274 this._minRequestThreshold = minRequestThreshold; |
| 275 this._minBalanceThreshold = minBalanceThreshold; | 275 this._minBalanceThreshold = minBalanceThreshold; |
| 276 } | 276 }; |
| 277 | 277 |
| 278 WebInspector.AuditRules.ParallelizeDownloadRule.prototype = { | 278 WebInspector.AuditRules.ParallelizeDownloadRule.prototype = { |
| 279 /** | 279 /** |
| 280 * @override | 280 * @override |
| 281 * @param {!WebInspector.Target} target | 281 * @param {!WebInspector.Target} target |
| 282 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 282 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 283 * @param {!WebInspector.AuditRuleResult} result | 283 * @param {!WebInspector.AuditRuleResult} result |
| 284 * @param {function(?WebInspector.AuditRuleResult)} callback | 284 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 285 * @param {!WebInspector.Progress} progress | 285 * @param {!WebInspector.Progress} progress |
| 286 */ | 286 */ |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 var requestsOnBusiestHost = domainToResourcesMap[hosts[0]]; | 342 var requestsOnBusiestHost = domainToResourcesMap[hosts[0]]; |
| 343 var entry = result.addChild(WebInspector.UIString("This page makes %d pa
rallelizable requests to %s. Increase download parallelization by distributing t
he following requests across multiple hostnames.", busiestHostResourceCount, hos
ts[0]), true); | 343 var entry = result.addChild(WebInspector.UIString("This page makes %d pa
rallelizable requests to %s. Increase download parallelization by distributing t
he following requests across multiple hostnames.", busiestHostResourceCount, hos
ts[0]), true); |
| 344 for (var i = 0; i < requestsOnBusiestHost.length; ++i) | 344 for (var i = 0; i < requestsOnBusiestHost.length; ++i) |
| 345 entry.addURL(requestsOnBusiestHost[i].url); | 345 entry.addURL(requestsOnBusiestHost[i].url); |
| 346 | 346 |
| 347 result.violationCount = requestsOnBusiestHost.length; | 347 result.violationCount = requestsOnBusiestHost.length; |
| 348 callback(result); | 348 callback(result); |
| 349 }, | 349 }, |
| 350 | 350 |
| 351 __proto__: WebInspector.AuditRule.prototype | 351 __proto__: WebInspector.AuditRule.prototype |
| 352 } | 352 }; |
| 353 | 353 |
| 354 /** | 354 /** |
| 355 * The reported CSS rule size is incorrect (parsed != original in WebKit), | 355 * The reported CSS rule size is incorrect (parsed != original in WebKit), |
| 356 * so use percentages instead, which gives a better approximation. | 356 * so use percentages instead, which gives a better approximation. |
| 357 * @constructor | 357 * @constructor |
| 358 * @extends {WebInspector.AuditRule} | 358 * @extends {WebInspector.AuditRule} |
| 359 */ | 359 */ |
| 360 WebInspector.AuditRules.UnusedCssRule = function() | 360 WebInspector.AuditRules.UnusedCssRule = function() |
| 361 { | 361 { |
| 362 WebInspector.AuditRule.call(this, "page-unusedcss", WebInspector.UIString("R
emove unused CSS rules")); | 362 WebInspector.AuditRule.call(this, "page-unusedcss", WebInspector.UIString("R
emove unused CSS rules")); |
| 363 } | 363 }; |
| 364 | 364 |
| 365 WebInspector.AuditRules.UnusedCssRule.prototype = { | 365 WebInspector.AuditRules.UnusedCssRule.prototype = { |
| 366 /** | 366 /** |
| 367 * @override | 367 * @override |
| 368 * @param {!WebInspector.Target} target | 368 * @param {!WebInspector.Target} target |
| 369 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 369 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 370 * @param {!WebInspector.AuditRuleResult} result | 370 * @param {!WebInspector.AuditRuleResult} result |
| 371 * @param {function(?WebInspector.AuditRuleResult)} callback | 371 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 372 * @param {!WebInspector.Progress} progress | 372 * @param {!WebInspector.Progress} progress |
| 373 */ | 373 */ |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 var styleSheetInfos = cssModel.allStyleSheets(); | 494 var styleSheetInfos = cssModel.allStyleSheets(); |
| 495 if (!styleSheetInfos || !styleSheetInfos.length) { | 495 if (!styleSheetInfos || !styleSheetInfos.length) { |
| 496 evalCallback([]); | 496 evalCallback([]); |
| 497 return; | 497 return; |
| 498 } | 498 } |
| 499 var styleSheetProcessor = new WebInspector.AuditRules.StyleSheetProcesso
r(styleSheetInfos, progress, evalCallback); | 499 var styleSheetProcessor = new WebInspector.AuditRules.StyleSheetProcesso
r(styleSheetInfos, progress, evalCallback); |
| 500 styleSheetProcessor.run(); | 500 styleSheetProcessor.run(); |
| 501 }, | 501 }, |
| 502 | 502 |
| 503 __proto__: WebInspector.AuditRule.prototype | 503 __proto__: WebInspector.AuditRule.prototype |
| 504 } | 504 }; |
| 505 | 505 |
| 506 /** | 506 /** |
| 507 * @typedef {!{sourceURL: string, rules: !Array.<!WebInspector.CSSParser.StyleRu
le>}} | 507 * @typedef {!{sourceURL: string, rules: !Array.<!WebInspector.CSSParser.StyleRu
le>}} |
| 508 */ | 508 */ |
| 509 WebInspector.AuditRules.ParsedStyleSheet; | 509 WebInspector.AuditRules.ParsedStyleSheet; |
| 510 | 510 |
| 511 /** | 511 /** |
| 512 * @constructor | 512 * @constructor |
| 513 * @param {!Array.<!WebInspector.CSSStyleSheetHeader>} styleSheetHeaders | 513 * @param {!Array.<!WebInspector.CSSStyleSheetHeader>} styleSheetHeaders |
| 514 * @param {!WebInspector.Progress} progress | 514 * @param {!WebInspector.Progress} progress |
| 515 * @param {function(!Array.<!WebInspector.AuditRules.ParsedStyleSheet>)} styleSh
eetsParsedCallback | 515 * @param {function(!Array.<!WebInspector.AuditRules.ParsedStyleSheet>)} styleSh
eetsParsedCallback |
| 516 */ | 516 */ |
| 517 WebInspector.AuditRules.StyleSheetProcessor = function(styleSheetHeaders, progre
ss, styleSheetsParsedCallback) | 517 WebInspector.AuditRules.StyleSheetProcessor = function(styleSheetHeaders, progre
ss, styleSheetsParsedCallback) |
| 518 { | 518 { |
| 519 this._styleSheetHeaders = styleSheetHeaders; | 519 this._styleSheetHeaders = styleSheetHeaders; |
| 520 this._progress = progress; | 520 this._progress = progress; |
| 521 this._styleSheets = []; | 521 this._styleSheets = []; |
| 522 this._styleSheetsParsedCallback = styleSheetsParsedCallback; | 522 this._styleSheetsParsedCallback = styleSheetsParsedCallback; |
| 523 } | 523 }; |
| 524 | 524 |
| 525 WebInspector.AuditRules.StyleSheetProcessor.prototype = { | 525 WebInspector.AuditRules.StyleSheetProcessor.prototype = { |
| 526 run: function() | 526 run: function() |
| 527 { | 527 { |
| 528 this._parser = new WebInspector.CSSParser(); | 528 this._parser = new WebInspector.CSSParser(); |
| 529 this._processNextStyleSheet(); | 529 this._processNextStyleSheet(); |
| 530 }, | 530 }, |
| 531 | 531 |
| 532 _terminateWorker: function() | 532 _terminateWorker: function() |
| 533 { | 533 { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 var rule = rules[i]; | 568 var rule = rules[i]; |
| 569 if (rule.selectorText) | 569 if (rule.selectorText) |
| 570 styleRules.push(rule); | 570 styleRules.push(rule); |
| 571 } | 571 } |
| 572 this._styleSheets.push({ | 572 this._styleSheets.push({ |
| 573 sourceURL: this._currentStyleSheetHeader.sourceURL, | 573 sourceURL: this._currentStyleSheetHeader.sourceURL, |
| 574 rules: styleRules | 574 rules: styleRules |
| 575 }); | 575 }); |
| 576 this._processNextStyleSheet(); | 576 this._processNextStyleSheet(); |
| 577 }, | 577 }, |
| 578 } | 578 }; |
| 579 | 579 |
| 580 /** | 580 /** |
| 581 * @constructor | 581 * @constructor |
| 582 * @extends {WebInspector.AuditRule} | 582 * @extends {WebInspector.AuditRule} |
| 583 */ | 583 */ |
| 584 WebInspector.AuditRules.CacheControlRule = function(id, name) | 584 WebInspector.AuditRules.CacheControlRule = function(id, name) |
| 585 { | 585 { |
| 586 WebInspector.AuditRule.call(this, id, name); | 586 WebInspector.AuditRule.call(this, id, name); |
| 587 } | 587 }; |
| 588 | 588 |
| 589 WebInspector.AuditRules.CacheControlRule.MillisPerMonth = 1000 * 60 * 60 * 24 *
30; | 589 WebInspector.AuditRules.CacheControlRule.MillisPerMonth = 1000 * 60 * 60 * 24 *
30; |
| 590 | 590 |
| 591 WebInspector.AuditRules.CacheControlRule.prototype = { | 591 WebInspector.AuditRules.CacheControlRule.prototype = { |
| 592 /** | 592 /** |
| 593 * @override | 593 * @override |
| 594 * @param {!WebInspector.Target} target | 594 * @param {!WebInspector.Target} target |
| 595 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 595 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 596 * @param {!WebInspector.AuditRuleResult} result | 596 * @param {!WebInspector.AuditRuleResult} result |
| 597 * @param {function(!WebInspector.AuditRuleResult)} callback | 597 * @param {function(!WebInspector.AuditRuleResult)} callback |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 /** | 757 /** |
| 758 * @param {!WebInspector.NetworkRequest} request | 758 * @param {!WebInspector.NetworkRequest} request |
| 759 * @return {boolean} | 759 * @return {boolean} |
| 760 */ | 760 */ |
| 761 isCacheableResource: function(request) | 761 isCacheableResource: function(request) |
| 762 { | 762 { |
| 763 return request.statusCode !== undefined && WebInspector.AuditRules.Cache
ableResponseCodes[request.statusCode]; | 763 return request.statusCode !== undefined && WebInspector.AuditRules.Cache
ableResponseCodes[request.statusCode]; |
| 764 }, | 764 }, |
| 765 | 765 |
| 766 __proto__: WebInspector.AuditRule.prototype | 766 __proto__: WebInspector.AuditRule.prototype |
| 767 } | 767 }; |
| 768 | 768 |
| 769 /** | 769 /** |
| 770 * @constructor | 770 * @constructor |
| 771 * @extends {WebInspector.AuditRules.CacheControlRule} | 771 * @extends {WebInspector.AuditRules.CacheControlRule} |
| 772 */ | 772 */ |
| 773 WebInspector.AuditRules.BrowserCacheControlRule = function() | 773 WebInspector.AuditRules.BrowserCacheControlRule = function() |
| 774 { | 774 { |
| 775 WebInspector.AuditRules.CacheControlRule.call(this, "http-browsercache", Web
Inspector.UIString("Leverage browser caching")); | 775 WebInspector.AuditRules.CacheControlRule.call(this, "http-browsercache", Web
Inspector.UIString("Leverage browser caching")); |
| 776 } | 776 }; |
| 777 | 777 |
| 778 WebInspector.AuditRules.BrowserCacheControlRule.prototype = { | 778 WebInspector.AuditRules.BrowserCacheControlRule.prototype = { |
| 779 handleNonCacheableResources: function(requests, result) | 779 handleNonCacheableResources: function(requests, result) |
| 780 { | 780 { |
| 781 if (requests.length) { | 781 if (requests.length) { |
| 782 var entry = result.addChild(WebInspector.UIString("The following res
ources are explicitly non-cacheable. Consider making them cacheable if possible:
"), true); | 782 var entry = result.addChild(WebInspector.UIString("The following res
ources are explicitly non-cacheable. Consider making them cacheable if possible:
"), true); |
| 783 result.violationCount += requests.length; | 783 result.violationCount += requests.length; |
| 784 for (var i = 0; i < requests.length; ++i) | 784 for (var i = 0; i < requests.length; ++i) |
| 785 entry.addURL(requests[i].url); | 785 entry.addURL(requests[i].url); |
| 786 } | 786 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 | 826 |
| 827 _oneYearExpirationCheck: function(request) | 827 _oneYearExpirationCheck: function(request) |
| 828 { | 828 { |
| 829 return this.isCacheableResource(request) && | 829 return this.isCacheableResource(request) && |
| 830 !this.hasResponseHeader(request, "Set-Cookie") && | 830 !this.hasResponseHeader(request, "Set-Cookie") && |
| 831 !this.freshnessLifetimeGreaterThan(request, 11 * WebInspector.AuditR
ules.CacheControlRule.MillisPerMonth) && | 831 !this.freshnessLifetimeGreaterThan(request, 11 * WebInspector.AuditR
ules.CacheControlRule.MillisPerMonth) && |
| 832 this.freshnessLifetimeGreaterThan(request, WebInspector.AuditRules.C
acheControlRule.MillisPerMonth); | 832 this.freshnessLifetimeGreaterThan(request, WebInspector.AuditRules.C
acheControlRule.MillisPerMonth); |
| 833 }, | 833 }, |
| 834 | 834 |
| 835 __proto__: WebInspector.AuditRules.CacheControlRule.prototype | 835 __proto__: WebInspector.AuditRules.CacheControlRule.prototype |
| 836 } | 836 }; |
| 837 | 837 |
| 838 /** | 838 /** |
| 839 * @constructor | 839 * @constructor |
| 840 * @extends {WebInspector.AuditRule} | 840 * @extends {WebInspector.AuditRule} |
| 841 */ | 841 */ |
| 842 WebInspector.AuditRules.ImageDimensionsRule = function() | 842 WebInspector.AuditRules.ImageDimensionsRule = function() |
| 843 { | 843 { |
| 844 WebInspector.AuditRule.call(this, "page-imagedims", WebInspector.UIString("S
pecify image dimensions")); | 844 WebInspector.AuditRule.call(this, "page-imagedims", WebInspector.UIString("S
pecify image dimensions")); |
| 845 } | 845 }; |
| 846 | 846 |
| 847 WebInspector.AuditRules.ImageDimensionsRule.prototype = { | 847 WebInspector.AuditRules.ImageDimensionsRule.prototype = { |
| 848 /** | 848 /** |
| 849 * @override | 849 * @override |
| 850 * @param {!WebInspector.Target} target | 850 * @param {!WebInspector.Target} target |
| 851 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 851 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 852 * @param {!WebInspector.AuditRuleResult} result | 852 * @param {!WebInspector.AuditRuleResult} result |
| 853 * @param {function(?WebInspector.AuditRuleResult)} callback | 853 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 854 * @param {!WebInspector.Progress} progress | 854 * @param {!WebInspector.Progress} progress |
| 855 */ | 855 */ |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 } | 974 } |
| 975 | 975 |
| 976 if (progress.isCanceled()) { | 976 if (progress.isCanceled()) { |
| 977 callback(null); | 977 callback(null); |
| 978 return; | 978 return; |
| 979 } | 979 } |
| 980 domModel.requestDocument(onDocumentAvailable); | 980 domModel.requestDocument(onDocumentAvailable); |
| 981 }, | 981 }, |
| 982 | 982 |
| 983 __proto__: WebInspector.AuditRule.prototype | 983 __proto__: WebInspector.AuditRule.prototype |
| 984 } | 984 }; |
| 985 | 985 |
| 986 /** | 986 /** |
| 987 * @constructor | 987 * @constructor |
| 988 * @extends {WebInspector.AuditRule} | 988 * @extends {WebInspector.AuditRule} |
| 989 */ | 989 */ |
| 990 WebInspector.AuditRules.CssInHeadRule = function() | 990 WebInspector.AuditRules.CssInHeadRule = function() |
| 991 { | 991 { |
| 992 WebInspector.AuditRule.call(this, "page-cssinhead", WebInspector.UIString("P
ut CSS in the document head")); | 992 WebInspector.AuditRule.call(this, "page-cssinhead", WebInspector.UIString("P
ut CSS in the document head")); |
| 993 } | 993 }; |
| 994 | 994 |
| 995 WebInspector.AuditRules.CssInHeadRule.prototype = { | 995 WebInspector.AuditRules.CssInHeadRule.prototype = { |
| 996 /** | 996 /** |
| 997 * @override | 997 * @override |
| 998 * @param {!WebInspector.Target} target | 998 * @param {!WebInspector.Target} target |
| 999 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 999 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 1000 * @param {!WebInspector.AuditRuleResult} result | 1000 * @param {!WebInspector.AuditRuleResult} result |
| 1001 * @param {function(?WebInspector.AuditRuleResult)} callback | 1001 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 1002 * @param {!WebInspector.Progress} progress | 1002 * @param {!WebInspector.Progress} progress |
| 1003 */ | 1003 */ |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 return; | 1091 return; |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 domModel.querySelectorAll(root.id, "body style", inlineStylesReceive
d.bind(null, root)); | 1094 domModel.querySelectorAll(root.id, "body style", inlineStylesReceive
d.bind(null, root)); |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 domModel.requestDocument(onDocumentAvailable); | 1097 domModel.requestDocument(onDocumentAvailable); |
| 1098 }, | 1098 }, |
| 1099 | 1099 |
| 1100 __proto__: WebInspector.AuditRule.prototype | 1100 __proto__: WebInspector.AuditRule.prototype |
| 1101 } | 1101 }; |
| 1102 | 1102 |
| 1103 /** | 1103 /** |
| 1104 * @constructor | 1104 * @constructor |
| 1105 * @extends {WebInspector.AuditRule} | 1105 * @extends {WebInspector.AuditRule} |
| 1106 */ | 1106 */ |
| 1107 WebInspector.AuditRules.StylesScriptsOrderRule = function() | 1107 WebInspector.AuditRules.StylesScriptsOrderRule = function() |
| 1108 { | 1108 { |
| 1109 WebInspector.AuditRule.call(this, "page-stylescriptorder", WebInspector.UISt
ring("Optimize the order of styles and scripts")); | 1109 WebInspector.AuditRule.call(this, "page-stylescriptorder", WebInspector.UISt
ring("Optimize the order of styles and scripts")); |
| 1110 } | 1110 }; |
| 1111 | 1111 |
| 1112 WebInspector.AuditRules.StylesScriptsOrderRule.prototype = { | 1112 WebInspector.AuditRules.StylesScriptsOrderRule.prototype = { |
| 1113 /** | 1113 /** |
| 1114 * @override | 1114 * @override |
| 1115 * @param {!WebInspector.Target} target | 1115 * @param {!WebInspector.Target} target |
| 1116 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 1116 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 1117 * @param {!WebInspector.AuditRuleResult} result | 1117 * @param {!WebInspector.AuditRuleResult} result |
| 1118 * @param {function(?WebInspector.AuditRuleResult)} callback | 1118 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 1119 * @param {!WebInspector.Progress} progress | 1119 * @param {!WebInspector.Progress} progress |
| 1120 */ | 1120 */ |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 return; | 1208 return; |
| 1209 } | 1209 } |
| 1210 | 1210 |
| 1211 domModel.querySelectorAll(root.id, "head script[src] ~ link[rel~='st
ylesheet'][href]", lateStylesReceived.bind(null, root)); | 1211 domModel.querySelectorAll(root.id, "head script[src] ~ link[rel~='st
ylesheet'][href]", lateStylesReceived.bind(null, root)); |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 domModel.requestDocument(onDocumentAvailable); | 1214 domModel.requestDocument(onDocumentAvailable); |
| 1215 }, | 1215 }, |
| 1216 | 1216 |
| 1217 __proto__: WebInspector.AuditRule.prototype | 1217 __proto__: WebInspector.AuditRule.prototype |
| 1218 } | 1218 }; |
| 1219 | 1219 |
| 1220 /** | 1220 /** |
| 1221 * @constructor | 1221 * @constructor |
| 1222 * @extends {WebInspector.AuditRule} | 1222 * @extends {WebInspector.AuditRule} |
| 1223 */ | 1223 */ |
| 1224 WebInspector.AuditRules.CSSRuleBase = function(id, name) | 1224 WebInspector.AuditRules.CSSRuleBase = function(id, name) |
| 1225 { | 1225 { |
| 1226 WebInspector.AuditRule.call(this, id, name); | 1226 WebInspector.AuditRule.call(this, id, name); |
| 1227 } | 1227 }; |
| 1228 | 1228 |
| 1229 WebInspector.AuditRules.CSSRuleBase.prototype = { | 1229 WebInspector.AuditRules.CSSRuleBase.prototype = { |
| 1230 /** | 1230 /** |
| 1231 * @override | 1231 * @override |
| 1232 * @param {!WebInspector.Target} target | 1232 * @param {!WebInspector.Target} target |
| 1233 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 1233 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 1234 * @param {!WebInspector.AuditRuleResult} result | 1234 * @param {!WebInspector.AuditRuleResult} result |
| 1235 * @param {function(?WebInspector.AuditRuleResult)} callback | 1235 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 1236 * @param {!WebInspector.Progress} progress | 1236 * @param {!WebInspector.Progress} progress |
| 1237 */ | 1237 */ |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 * @param {!WebInspector.CSSParser.StyleRule} rule | 1342 * @param {!WebInspector.CSSParser.StyleRule} rule |
| 1343 * @param {!WebInspector.CSSParser.Property} property | 1343 * @param {!WebInspector.CSSParser.Property} property |
| 1344 * @param {!WebInspector.AuditRuleResult} result | 1344 * @param {!WebInspector.AuditRuleResult} result |
| 1345 */ | 1345 */ |
| 1346 visitProperty: function(styleSheet, rule, property, result) | 1346 visitProperty: function(styleSheet, rule, property, result) |
| 1347 { | 1347 { |
| 1348 // Subclasses can implement. | 1348 // Subclasses can implement. |
| 1349 }, | 1349 }, |
| 1350 | 1350 |
| 1351 __proto__: WebInspector.AuditRule.prototype | 1351 __proto__: WebInspector.AuditRule.prototype |
| 1352 } | 1352 }; |
| 1353 | 1353 |
| 1354 /** | 1354 /** |
| 1355 * @constructor | 1355 * @constructor |
| 1356 * @extends {WebInspector.AuditRule} | 1356 * @extends {WebInspector.AuditRule} |
| 1357 */ | 1357 */ |
| 1358 WebInspector.AuditRules.CookieRuleBase = function(id, name) | 1358 WebInspector.AuditRules.CookieRuleBase = function(id, name) |
| 1359 { | 1359 { |
| 1360 WebInspector.AuditRule.call(this, id, name); | 1360 WebInspector.AuditRule.call(this, id, name); |
| 1361 } | 1361 }; |
| 1362 | 1362 |
| 1363 WebInspector.AuditRules.CookieRuleBase.prototype = { | 1363 WebInspector.AuditRules.CookieRuleBase.prototype = { |
| 1364 /** | 1364 /** |
| 1365 * @override | 1365 * @override |
| 1366 * @param {!WebInspector.Target} target | 1366 * @param {!WebInspector.Target} target |
| 1367 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 1367 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 1368 * @param {!WebInspector.AuditRuleResult} result | 1368 * @param {!WebInspector.AuditRuleResult} result |
| 1369 * @param {function(!WebInspector.AuditRuleResult)} callback | 1369 * @param {function(!WebInspector.AuditRuleResult)} callback |
| 1370 * @param {!WebInspector.Progress} progress | 1370 * @param {!WebInspector.Progress} progress |
| 1371 */ | 1371 */ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1400 { | 1400 { |
| 1401 if (!requests) | 1401 if (!requests) |
| 1402 return; | 1402 return; |
| 1403 for (var i = 0; i < requests.length; ++i) { | 1403 for (var i = 0; i < requests.length; ++i) { |
| 1404 if (WebInspector.Cookies.cookieMatchesResourceURL(cookie, requests[i
].url)) | 1404 if (WebInspector.Cookies.cookieMatchesResourceURL(cookie, requests[i
].url)) |
| 1405 callback(requests[i], cookie); | 1405 callback(requests[i], cookie); |
| 1406 } | 1406 } |
| 1407 }, | 1407 }, |
| 1408 | 1408 |
| 1409 __proto__: WebInspector.AuditRule.prototype | 1409 __proto__: WebInspector.AuditRule.prototype |
| 1410 } | 1410 }; |
| 1411 | 1411 |
| 1412 /** | 1412 /** |
| 1413 * @constructor | 1413 * @constructor |
| 1414 * @extends {WebInspector.AuditRules.CookieRuleBase} | 1414 * @extends {WebInspector.AuditRules.CookieRuleBase} |
| 1415 */ | 1415 */ |
| 1416 WebInspector.AuditRules.CookieSizeRule = function(avgBytesThreshold) | 1416 WebInspector.AuditRules.CookieSizeRule = function(avgBytesThreshold) |
| 1417 { | 1417 { |
| 1418 WebInspector.AuditRules.CookieRuleBase.call(this, "http-cookiesize", WebInsp
ector.UIString("Minimize cookie size")); | 1418 WebInspector.AuditRules.CookieRuleBase.call(this, "http-cookiesize", WebInsp
ector.UIString("Minimize cookie size")); |
| 1419 this._avgBytesThreshold = avgBytesThreshold; | 1419 this._avgBytesThreshold = avgBytesThreshold; |
| 1420 this._maxBytesThreshold = 1000; | 1420 this._maxBytesThreshold = 1000; |
| 1421 } | 1421 }; |
| 1422 | 1422 |
| 1423 WebInspector.AuditRules.CookieSizeRule.prototype = { | 1423 WebInspector.AuditRules.CookieSizeRule.prototype = { |
| 1424 _average: function(cookieArray) | 1424 _average: function(cookieArray) |
| 1425 { | 1425 { |
| 1426 var total = 0; | 1426 var total = 0; |
| 1427 for (var i = 0; i < cookieArray.length; ++i) | 1427 for (var i = 0; i < cookieArray.length; ++i) |
| 1428 total += cookieArray[i].size(); | 1428 total += cookieArray[i].size(); |
| 1429 return cookieArray.length ? Math.round(total / cookieArray.length) : 0; | 1429 return cookieArray.length ? Math.round(total / cookieArray.length) : 0; |
| 1430 }, | 1430 }, |
| 1431 | 1431 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 } | 1507 } |
| 1508 | 1508 |
| 1509 if (bigAvgCookieDomains.length) { | 1509 if (bigAvgCookieDomains.length) { |
| 1510 var entry = result.addChild(WebInspector.UIString("The following dom
ains have an average cookie size in excess of %d bytes. Reducing the size of coo
kies for these domains can reduce the time it takes to send requests.", this._av
gBytesThreshold), true); | 1510 var entry = result.addChild(WebInspector.UIString("The following dom
ains have an average cookie size in excess of %d bytes. Reducing the size of coo
kies for these domains can reduce the time it takes to send requests.", this._av
gBytesThreshold), true); |
| 1511 entry.addURLs(bigAvgCookieDomains); | 1511 entry.addURLs(bigAvgCookieDomains); |
| 1512 result.violationCount += bigAvgCookieDomains.length; | 1512 result.violationCount += bigAvgCookieDomains.length; |
| 1513 } | 1513 } |
| 1514 }, | 1514 }, |
| 1515 | 1515 |
| 1516 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype | 1516 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype |
| 1517 } | 1517 }; |
| 1518 | 1518 |
| 1519 /** | 1519 /** |
| 1520 * @constructor | 1520 * @constructor |
| 1521 * @extends {WebInspector.AuditRules.CookieRuleBase} | 1521 * @extends {WebInspector.AuditRules.CookieRuleBase} |
| 1522 */ | 1522 */ |
| 1523 WebInspector.AuditRules.StaticCookielessRule = function(minResources) | 1523 WebInspector.AuditRules.StaticCookielessRule = function(minResources) |
| 1524 { | 1524 { |
| 1525 WebInspector.AuditRules.CookieRuleBase.call(this, "http-staticcookieless", W
ebInspector.UIString("Serve static content from a cookieless domain")); | 1525 WebInspector.AuditRules.CookieRuleBase.call(this, "http-staticcookieless", W
ebInspector.UIString("Serve static content from a cookieless domain")); |
| 1526 this._minResources = minResources; | 1526 this._minResources = minResources; |
| 1527 } | 1527 }; |
| 1528 | 1528 |
| 1529 WebInspector.AuditRules.StaticCookielessRule.prototype = { | 1529 WebInspector.AuditRules.StaticCookielessRule.prototype = { |
| 1530 processCookies: function(allCookies, requests, result) | 1530 processCookies: function(allCookies, requests, result) |
| 1531 { | 1531 { |
| 1532 var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesM
ap(requests, | 1532 var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesM
ap(requests, |
| 1533 [WebInspector.resourceTypes.Stylesheet, | 1533 [WebInspector.resourceTypes.Stylesheet, |
| 1534 WebInspector.resourceTypes.Image], | 1534 WebInspector.resourceTypes.Image], |
| 1535 true); | 1535 true); |
| 1536 var totalStaticResources = 0; | 1536 var totalStaticResources = 0; |
| 1537 for (var domain in domainToResourcesMap) | 1537 for (var domain in domainToResourcesMap) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1554 entry.addURLs(badUrls); | 1554 entry.addURLs(badUrls); |
| 1555 result.violationCount = badUrls.length; | 1555 result.violationCount = badUrls.length; |
| 1556 }, | 1556 }, |
| 1557 | 1557 |
| 1558 _collectorCallback: function(matchingResourceData, request, cookie) | 1558 _collectorCallback: function(matchingResourceData, request, cookie) |
| 1559 { | 1559 { |
| 1560 matchingResourceData[request.url] = (matchingResourceData[request.url] |
| 0) + cookie.size(); | 1560 matchingResourceData[request.url] = (matchingResourceData[request.url] |
| 0) + cookie.size(); |
| 1561 }, | 1561 }, |
| 1562 | 1562 |
| 1563 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype | 1563 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype |
| 1564 } | 1564 }; |
| OLD | NEW |