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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 function documentLoaded(selectors, document) { | 451 function documentLoaded(selectors, document) { |
452 var pseudoSelectorRegexp = /::?(?:[\w-]+)(?:\(.*?\))?/g; | 452 var pseudoSelectorRegexp = /::?(?:[\w-]+)(?:\(.*?\))?/g; |
453 if (!selectors.length) { | 453 if (!selectors.length) { |
454 selectorsCallback([]); | 454 selectorsCallback([]); |
455 return; | 455 return; |
456 } | 456 } |
457 for (var i = 0; i < selectors.length; ++i) { | 457 for (var i = 0; i < selectors.length; ++i) { |
458 if (progress.isCanceled()) | 458 if (progress.isCanceled()) |
459 return; | 459 return; |
460 var effectiveSelector = selectors[i].replace(pseudoSelectorR
egexp, ""); | 460 var effectiveSelector = selectors[i].replace(pseudoSelectorR
egexp, ""); |
461 WebInspector.domAgent.querySelector(document.id, effectiveSe
lector, queryCallback.bind(null, i === selectors.length - 1 ? selectorsCallback.
bind(null, styleSheets) : null, selectors[i])); | 461 WebInspector.domModel.querySelector(document.id, effectiveSe
lector, queryCallback.bind(null, i === selectors.length - 1 ? selectorsCallback.
bind(null, styleSheets) : null, selectors[i])); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 WebInspector.domAgent.requestDocument(documentLoaded.bind(null, sele
ctors)); | 465 WebInspector.domModel.requestDocument(documentLoaded.bind(null, sele
ctors)); |
466 } | 466 } |
467 | 467 |
468 var styleSheetInfos = WebInspector.cssModel.allStyleSheets(); | 468 var styleSheetInfos = WebInspector.cssModel.allStyleSheets(); |
469 if (!styleSheetInfos || !styleSheetInfos.length) { | 469 if (!styleSheetInfos || !styleSheetInfos.length) { |
470 evalCallback([]); | 470 evalCallback([]); |
471 return; | 471 return; |
472 } | 472 } |
473 var styleSheetProcessor = new WebInspector.AuditRules.StyleSheetProcesso
r(styleSheetInfos, progress, evalCallback); | 473 var styleSheetProcessor = new WebInspector.AuditRules.StyleSheetProcesso
r(styleSheetInfos, progress, evalCallback); |
474 styleSheetProcessor.run(); | 474 styleSheetProcessor.run(); |
475 }, | 475 }, |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 result.violationCount++; | 878 result.violationCount++; |
879 } | 879 } |
880 callback(entry ? result : null); | 880 callback(entry ? result : null); |
881 } | 881 } |
882 | 882 |
883 function imageStylesReady(imageId, styles, isLastStyle, computedStyle) | 883 function imageStylesReady(imageId, styles, isLastStyle, computedStyle) |
884 { | 884 { |
885 if (progress.isCanceled()) | 885 if (progress.isCanceled()) |
886 return; | 886 return; |
887 | 887 |
888 const node = WebInspector.domAgent.nodeForId(imageId); | 888 const node = WebInspector.domModel.nodeForId(imageId); |
889 var src = node.getAttribute("src"); | 889 var src = node.getAttribute("src"); |
890 if (!src.asParsedURL()) { | 890 if (!src.asParsedURL()) { |
891 for (var frameOwnerCandidate = node; frameOwnerCandidate; frameO
wnerCandidate = frameOwnerCandidate.parentNode) { | 891 for (var frameOwnerCandidate = node; frameOwnerCandidate; frameO
wnerCandidate = frameOwnerCandidate.parentNode) { |
892 if (frameOwnerCandidate.baseURL) { | 892 if (frameOwnerCandidate.baseURL) { |
893 var completeSrc = WebInspector.ParsedURL.completeURL(fra
meOwnerCandidate.baseURL, src); | 893 var completeSrc = WebInspector.ParsedURL.completeURL(fra
meOwnerCandidate.baseURL, src); |
894 break; | 894 break; |
895 } | 895 } |
896 } | 896 } |
897 } | 897 } |
898 if (completeSrc) | 898 if (completeSrc) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 WebInspector.cssModel.getMatchedStylesAsync(nodeIds[i], false, f
alse, matchedCallback); | 964 WebInspector.cssModel.getMatchedStylesAsync(nodeIds[i], false, f
alse, matchedCallback); |
965 WebInspector.cssModel.getInlineStylesAsync(nodeIds[i], inlineCal
lback); | 965 WebInspector.cssModel.getInlineStylesAsync(nodeIds[i], inlineCal
lback); |
966 WebInspector.cssModel.getComputedStyleAsync(nodeIds[i], imageSty
lesReady.bind(null, nodeIds[i], targetResult, i === nodeIds.length - 1)); | 966 WebInspector.cssModel.getComputedStyleAsync(nodeIds[i], imageSty
lesReady.bind(null, nodeIds[i], targetResult, i === nodeIds.length - 1)); |
967 } | 967 } |
968 } | 968 } |
969 | 969 |
970 function onDocumentAvailable(root) | 970 function onDocumentAvailable(root) |
971 { | 971 { |
972 if (progress.isCanceled()) | 972 if (progress.isCanceled()) |
973 return; | 973 return; |
974 WebInspector.domAgent.querySelectorAll(root.id, "img[src]", getStyle
s); | 974 WebInspector.domModel.querySelectorAll(root.id, "img[src]", getStyle
s); |
975 } | 975 } |
976 | 976 |
977 if (progress.isCanceled()) | 977 if (progress.isCanceled()) |
978 return; | 978 return; |
979 WebInspector.domAgent.requestDocument(onDocumentAvailable); | 979 WebInspector.domModel.requestDocument(onDocumentAvailable); |
980 }, | 980 }, |
981 | 981 |
982 __proto__: WebInspector.AuditRule.prototype | 982 __proto__: WebInspector.AuditRule.prototype |
983 } | 983 } |
984 | 984 |
985 /** | 985 /** |
986 * @constructor | 986 * @constructor |
987 * @extends {WebInspector.AuditRule} | 987 * @extends {WebInspector.AuditRule} |
988 */ | 988 */ |
989 WebInspector.AuditRules.CssInHeadRule = function() | 989 WebInspector.AuditRules.CssInHeadRule = function() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 return; | 1034 return; |
1035 | 1035 |
1036 if (!nodeIds) | 1036 if (!nodeIds) |
1037 return; | 1037 return; |
1038 var externalStylesheetNodeIds = nodeIds; | 1038 var externalStylesheetNodeIds = nodeIds; |
1039 var result = null; | 1039 var result = null; |
1040 if (inlineStyleNodeIds.length || externalStylesheetNodeIds.length) { | 1040 if (inlineStyleNodeIds.length || externalStylesheetNodeIds.length) { |
1041 var urlToViolationsArray = {}; | 1041 var urlToViolationsArray = {}; |
1042 var externalStylesheetHrefs = []; | 1042 var externalStylesheetHrefs = []; |
1043 for (var j = 0; j < externalStylesheetNodeIds.length; ++j) { | 1043 for (var j = 0; j < externalStylesheetNodeIds.length; ++j) { |
1044 var linkNode = WebInspector.domAgent.nodeForId(externalStyle
sheetNodeIds[j]); | 1044 var linkNode = WebInspector.domModel.nodeForId(externalStyle
sheetNodeIds[j]); |
1045 var completeHref = WebInspector.ParsedURL.completeURL(linkNo
de.ownerDocument.baseURL, linkNode.getAttribute("href")); | 1045 var completeHref = WebInspector.ParsedURL.completeURL(linkNo
de.ownerDocument.baseURL, linkNode.getAttribute("href")); |
1046 externalStylesheetHrefs.push(completeHref || "<empty>"); | 1046 externalStylesheetHrefs.push(completeHref || "<empty>"); |
1047 } | 1047 } |
1048 urlToViolationsArray[root.documentURL] = [inlineStyleNodeIds.len
gth, externalStylesheetHrefs]; | 1048 urlToViolationsArray[root.documentURL] = [inlineStyleNodeIds.len
gth, externalStylesheetHrefs]; |
1049 result = urlToViolationsArray; | 1049 result = urlToViolationsArray; |
1050 } | 1050 } |
1051 evalCallback(result); | 1051 evalCallback(result); |
1052 } | 1052 } |
1053 | 1053 |
1054 /** | 1054 /** |
1055 * @param {!Array.<!DOMAgent.NodeId>=} nodeIds | 1055 * @param {!Array.<!DOMAgent.NodeId>=} nodeIds |
1056 */ | 1056 */ |
1057 function inlineStylesReceived(root, nodeIds) | 1057 function inlineStylesReceived(root, nodeIds) |
1058 { | 1058 { |
1059 if (progress.isCanceled()) | 1059 if (progress.isCanceled()) |
1060 return; | 1060 return; |
1061 | 1061 |
1062 if (!nodeIds) | 1062 if (!nodeIds) |
1063 return; | 1063 return; |
1064 WebInspector.domAgent.querySelectorAll(root.id, "body link[rel~='sty
lesheet'][href]", externalStylesheetsReceived.bind(null, root, nodeIds)); | 1064 WebInspector.domModel.querySelectorAll(root.id, "body link[rel~='sty
lesheet'][href]", externalStylesheetsReceived.bind(null, root, nodeIds)); |
1065 } | 1065 } |
1066 | 1066 |
1067 function onDocumentAvailable(root) | 1067 function onDocumentAvailable(root) |
1068 { | 1068 { |
1069 if (progress.isCanceled()) | 1069 if (progress.isCanceled()) |
1070 return; | 1070 return; |
1071 | 1071 |
1072 WebInspector.domAgent.querySelectorAll(root.id, "body style", inline
StylesReceived.bind(null, root)); | 1072 WebInspector.domModel.querySelectorAll(root.id, "body style", inline
StylesReceived.bind(null, root)); |
1073 } | 1073 } |
1074 | 1074 |
1075 WebInspector.domAgent.requestDocument(onDocumentAvailable); | 1075 WebInspector.domModel.requestDocument(onDocumentAvailable); |
1076 }, | 1076 }, |
1077 | 1077 |
1078 __proto__: WebInspector.AuditRule.prototype | 1078 __proto__: WebInspector.AuditRule.prototype |
1079 } | 1079 } |
1080 | 1080 |
1081 /** | 1081 /** |
1082 * @constructor | 1082 * @constructor |
1083 * @extends {WebInspector.AuditRule} | 1083 * @extends {WebInspector.AuditRule} |
1084 */ | 1084 */ |
1085 WebInspector.AuditRules.StylesScriptsOrderRule = function() | 1085 WebInspector.AuditRules.StylesScriptsOrderRule = function() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 return; | 1130 return; |
1131 | 1131 |
1132 if (!nodeIds) | 1132 if (!nodeIds) |
1133 return; | 1133 return; |
1134 | 1134 |
1135 var cssBeforeInlineCount = nodeIds.length; | 1135 var cssBeforeInlineCount = nodeIds.length; |
1136 var result = null; | 1136 var result = null; |
1137 if (lateStyleIds.length || cssBeforeInlineCount) { | 1137 if (lateStyleIds.length || cssBeforeInlineCount) { |
1138 var lateStyleUrls = []; | 1138 var lateStyleUrls = []; |
1139 for (var i = 0; i < lateStyleIds.length; ++i) { | 1139 for (var i = 0; i < lateStyleIds.length; ++i) { |
1140 var lateStyleNode = WebInspector.domAgent.nodeForId(lateStyl
eIds[i]); | 1140 var lateStyleNode = WebInspector.domModel.nodeForId(lateStyl
eIds[i]); |
1141 var completeHref = WebInspector.ParsedURL.completeURL(lateSt
yleNode.ownerDocument.baseURL, lateStyleNode.getAttribute("href")); | 1141 var completeHref = WebInspector.ParsedURL.completeURL(lateSt
yleNode.ownerDocument.baseURL, lateStyleNode.getAttribute("href")); |
1142 lateStyleUrls.push(completeHref || "<empty>"); | 1142 lateStyleUrls.push(completeHref || "<empty>"); |
1143 } | 1143 } |
1144 result = [ lateStyleUrls, cssBeforeInlineCount ]; | 1144 result = [ lateStyleUrls, cssBeforeInlineCount ]; |
1145 } | 1145 } |
1146 | 1146 |
1147 evalCallback(result); | 1147 evalCallback(result); |
1148 } | 1148 } |
1149 | 1149 |
1150 /** | 1150 /** |
1151 * @param {!WebInspector.DOMDocument} root | 1151 * @param {!WebInspector.DOMDocument} root |
1152 * @param {!Array.<!DOMAgent.NodeId>=} nodeIds | 1152 * @param {!Array.<!DOMAgent.NodeId>=} nodeIds |
1153 */ | 1153 */ |
1154 function lateStylesReceived(root, nodeIds) | 1154 function lateStylesReceived(root, nodeIds) |
1155 { | 1155 { |
1156 if (progress.isCanceled()) | 1156 if (progress.isCanceled()) |
1157 return; | 1157 return; |
1158 | 1158 |
1159 if (!nodeIds) | 1159 if (!nodeIds) |
1160 return; | 1160 return; |
1161 | 1161 |
1162 WebInspector.domAgent.querySelectorAll(root.id, "head link[rel~='sty
lesheet'][href] ~ script:not([src])", cssBeforeInlineReceived.bind(null, nodeIds
)); | 1162 WebInspector.domModel.querySelectorAll(root.id, "head link[rel~='sty
lesheet'][href] ~ script:not([src])", cssBeforeInlineReceived.bind(null, nodeIds
)); |
1163 } | 1163 } |
1164 | 1164 |
1165 /** | 1165 /** |
1166 * @param {!WebInspector.DOMDocument} root | 1166 * @param {!WebInspector.DOMDocument} root |
1167 */ | 1167 */ |
1168 function onDocumentAvailable(root) | 1168 function onDocumentAvailable(root) |
1169 { | 1169 { |
1170 if (progress.isCanceled()) | 1170 if (progress.isCanceled()) |
1171 return; | 1171 return; |
1172 | 1172 |
1173 WebInspector.domAgent.querySelectorAll(root.id, "head script[src] ~
link[rel~='stylesheet'][href]", lateStylesReceived.bind(null, root)); | 1173 WebInspector.domModel.querySelectorAll(root.id, "head script[src] ~
link[rel~='stylesheet'][href]", lateStylesReceived.bind(null, root)); |
1174 } | 1174 } |
1175 | 1175 |
1176 WebInspector.domAgent.requestDocument(onDocumentAvailable); | 1176 WebInspector.domModel.requestDocument(onDocumentAvailable); |
1177 }, | 1177 }, |
1178 | 1178 |
1179 __proto__: WebInspector.AuditRule.prototype | 1179 __proto__: WebInspector.AuditRule.prototype |
1180 } | 1180 } |
1181 | 1181 |
1182 /** | 1182 /** |
1183 * @constructor | 1183 * @constructor |
1184 * @extends {WebInspector.AuditRule} | 1184 * @extends {WebInspector.AuditRule} |
1185 */ | 1185 */ |
1186 WebInspector.AuditRules.CSSRuleBase = function(id, name) | 1186 WebInspector.AuditRules.CSSRuleBase = function(id, name) |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 result.violationCount = badUrls.length; | 1575 result.violationCount = badUrls.length; |
1576 }, | 1576 }, |
1577 | 1577 |
1578 _collectorCallback: function(matchingResourceData, request, cookie) | 1578 _collectorCallback: function(matchingResourceData, request, cookie) |
1579 { | 1579 { |
1580 matchingResourceData[request.url] = (matchingResourceData[request.url] |
| 0) + cookie.size(); | 1580 matchingResourceData[request.url] = (matchingResourceData[request.url] |
| 0) + cookie.size(); |
1581 }, | 1581 }, |
1582 | 1582 |
1583 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype | 1583 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype |
1584 } | 1584 } |
OLD | NEW |