| 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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 * @param {function(!Array.<!Audits.AuditRules.ParsedStyleSheet>)} styleSheets
ParsedCallback | 503 * @param {function(!Array.<!Audits.AuditRules.ParsedStyleSheet>)} styleSheets
ParsedCallback |
| 504 */ | 504 */ |
| 505 constructor(styleSheetHeaders, progress, styleSheetsParsedCallback) { | 505 constructor(styleSheetHeaders, progress, styleSheetsParsedCallback) { |
| 506 this._styleSheetHeaders = styleSheetHeaders; | 506 this._styleSheetHeaders = styleSheetHeaders; |
| 507 this._progress = progress; | 507 this._progress = progress; |
| 508 this._styleSheets = []; | 508 this._styleSheets = []; |
| 509 this._styleSheetsParsedCallback = styleSheetsParsedCallback; | 509 this._styleSheetsParsedCallback = styleSheetsParsedCallback; |
| 510 } | 510 } |
| 511 | 511 |
| 512 run() { | 512 run() { |
| 513 this._parser = new SDK.CSSParser(); | |
| 514 this._processNextStyleSheet(); | 513 this._processNextStyleSheet(); |
| 515 } | 514 } |
| 516 | 515 |
| 517 _terminateWorker() { | |
| 518 if (this._parser) { | |
| 519 this._parser.dispose(); | |
| 520 delete this._parser; | |
| 521 } | |
| 522 } | |
| 523 | |
| 524 _finish() { | |
| 525 this._terminateWorker(); | |
| 526 this._styleSheetsParsedCallback(this._styleSheets); | |
| 527 } | |
| 528 | |
| 529 _processNextStyleSheet() { | 516 _processNextStyleSheet() { |
| 530 if (!this._styleSheetHeaders.length) { | 517 if (!this._styleSheetHeaders.length) { |
| 531 this._finish(); | 518 this._styleSheetsParsedCallback(this._styleSheets); |
| 532 return; | 519 return; |
| 533 } | 520 } |
| 534 this._currentStyleSheetHeader = this._styleSheetHeaders.shift(); | 521 this._currentStyleSheetHeader = this._styleSheetHeaders.shift(); |
| 535 this._parser.fetchAndParse(this._currentStyleSheetHeader, this._onStyleSheet
Parsed.bind(this)); | 522 |
| 523 var allRules = []; |
| 524 this._currentStyleSheetHeader.requestContent().then( |
| 525 content => Common.formatterWorkerPool.parseCSS(content || '', onRulesPar
sed.bind(this))); |
| 526 |
| 527 /** |
| 528 * @param {boolean} isLastChunk |
| 529 * @param {!Array<!Common.FormatterWorkerPool.CSSRule>} rules |
| 530 * @this {Audits.AuditRules.StyleSheetProcessor} |
| 531 */ |
| 532 function onRulesParsed(isLastChunk, rules) { |
| 533 allRules.push(...rules); |
| 534 if (isLastChunk) |
| 535 this._onStyleSheetParsed(allRules); |
| 536 } |
| 536 } | 537 } |
| 537 | 538 |
| 538 /** | 539 /** |
| 539 * @param {!Array.<!Common.FormatterWorkerPool.CSSRule>} rules | 540 * @param {!Array.<!Common.FormatterWorkerPool.CSSRule>} rules |
| 540 */ | 541 */ |
| 541 _onStyleSheetParsed(rules) { | 542 _onStyleSheetParsed(rules) { |
| 542 if (this._progress.isCanceled()) { | 543 if (this._progress.isCanceled()) { |
| 543 this._finish(); | 544 this._styleSheetsParsedCallback(this._styleSheets); |
| 544 return; | 545 return; |
| 545 } | 546 } |
| 546 | 547 |
| 547 var styleRules = []; | 548 var styleRules = []; |
| 548 for (var i = 0; i < rules.length; ++i) { | 549 for (var i = 0; i < rules.length; ++i) { |
| 549 var rule = rules[i]; | 550 var rule = rules[i]; |
| 550 if (rule.selectorText) | 551 if (rule.selectorText) |
| 551 styleRules.push(rule); | 552 styleRules.push(rule); |
| 552 } | 553 } |
| 553 this._styleSheets.push({sourceURL: this._currentStyleSheetHeader.sourceURL,
rules: styleRules}); | 554 this._styleSheets.push({sourceURL: this._currentStyleSheetHeader.sourceURL,
rules: styleRules}); |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 Number.bytesToString(cookieBytes)), | 1479 Number.bytesToString(cookieBytes)), |
| 1479 true); | 1480 true); |
| 1480 entry.addURLs(badUrls); | 1481 entry.addURLs(badUrls); |
| 1481 result.violationCount = badUrls.length; | 1482 result.violationCount = badUrls.length; |
| 1482 } | 1483 } |
| 1483 | 1484 |
| 1484 _collectorCallback(matchingResourceData, request, cookie) { | 1485 _collectorCallback(matchingResourceData, request, cookie) { |
| 1485 matchingResourceData[request.url] = (matchingResourceData[request.url] || 0)
+ cookie.size(); | 1486 matchingResourceData[request.url] = (matchingResourceData[request.url] || 0)
+ cookie.size(); |
| 1486 } | 1487 } |
| 1487 }; | 1488 }; |
| OLD | NEW |