| 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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 var entry = entry || result.addChild(WebInspector.UIString("A wi
dth and height should be specified for all images in order to speed up page disp
lay. The following image(s) are missing a width and/or height:"), true); | 910 var entry = entry || result.addChild(WebInspector.UIString("A wi
dth and height should be specified for all images in order to speed up page disp
lay. The following image(s) are missing a width and/or height:"), true); |
| 911 var format = "%r"; | 911 var format = "%r"; |
| 912 if (urlToNoDimensionCount[url] > 1) | 912 if (urlToNoDimensionCount[url] > 1) |
| 913 format += " (%d uses)"; | 913 format += " (%d uses)"; |
| 914 entry.addFormatted(format, url, urlToNoDimensionCount[url]); | 914 entry.addFormatted(format, url, urlToNoDimensionCount[url]); |
| 915 result.violationCount++; | 915 result.violationCount++; |
| 916 } | 916 } |
| 917 callback(entry ? result : null); | 917 callback(entry ? result : null); |
| 918 } | 918 } |
| 919 | 919 |
| 920 function imageStylesReady(imageId, styles, isLastStyle, computedStyle) | 920 function imageStylesReady(imageId, styles) |
| 921 { | 921 { |
| 922 if (progress.isCanceled()) { | 922 if (progress.isCanceled()) { |
| 923 callback(null); | 923 callback(null); |
| 924 return; | 924 return; |
| 925 } | 925 } |
| 926 | 926 |
| 927 const node = domModel.nodeForId(imageId); | 927 const node = domModel.nodeForId(imageId); |
| 928 var src = node.getAttribute("src"); | 928 var src = node.getAttribute("src"); |
| 929 if (!src.asParsedURL()) { | 929 if (!src.asParsedURL()) { |
| 930 for (var frameOwnerCandidate = node; frameOwnerCandidate; frameO
wnerCandidate = frameOwnerCandidate.parentNode) { | 930 for (var frameOwnerCandidate = node; frameOwnerCandidate; frameO
wnerCandidate = frameOwnerCandidate.parentNode) { |
| 931 if (frameOwnerCandidate.baseURL) { | 931 if (frameOwnerCandidate.baseURL) { |
| 932 var completeSrc = WebInspector.ParsedURL.completeURL(fra
meOwnerCandidate.baseURL, src); | 932 var completeSrc = WebInspector.ParsedURL.completeURL(fra
meOwnerCandidate.baseURL, src); |
| 933 break; | 933 break; |
| 934 } | 934 } |
| 935 } | 935 } |
| 936 } | 936 } |
| 937 if (completeSrc) | 937 if (completeSrc) |
| 938 src = completeSrc; | 938 src = completeSrc; |
| 939 | 939 |
| 940 if (computedStyle.getPropertyValue("position") === "absolute") { | 940 if (styles.computedStyle.getPropertyValue("position") === "absolute"
) |
| 941 if (isLastStyle) | |
| 942 doneCallback(); | |
| 943 return; | 941 return; |
| 944 } | |
| 945 | 942 |
| 946 if (styles.attributesStyle) { | 943 if (styles.attributesStyle) { |
| 947 var widthFound = !!styles.attributesStyle.getLiveProperty("width
"); | 944 var widthFound = !!styles.attributesStyle.getLiveProperty("width
"); |
| 948 var heightFound = !!styles.attributesStyle.getLiveProperty("heig
ht"); | 945 var heightFound = !!styles.attributesStyle.getLiveProperty("heig
ht"); |
| 949 } | 946 } |
| 950 | 947 |
| 951 var inlineStyle = styles.inlineStyle; | 948 var inlineStyle = styles.inlineStyle; |
| 952 if (inlineStyle) { | 949 if (inlineStyle) { |
| 953 if (inlineStyle.getPropertyValue("width") !== "") | 950 if (inlineStyle.getPropertyValue("width") !== "") |
| 954 widthFound = true; | 951 widthFound = true; |
| 955 if (inlineStyle.getPropertyValue("height") !== "") | 952 if (inlineStyle.getPropertyValue("height") !== "") |
| 956 heightFound = true; | 953 heightFound = true; |
| 957 } | 954 } |
| 958 | 955 |
| 959 for (var i = styles.matchedCSSRules.length - 1; i >= 0 && !(widthFou
nd && heightFound); --i) { | 956 for (var i = styles.matchedCSSRules.length - 1; i >= 0 && !(widthFou
nd && heightFound); --i) { |
| 960 var style = styles.matchedCSSRules[i].style; | 957 var style = styles.matchedCSSRules[i].style; |
| 961 if (style.getPropertyValue("width") !== "") | 958 if (style.getPropertyValue("width") !== "") |
| 962 widthFound = true; | 959 widthFound = true; |
| 963 if (style.getPropertyValue("height") !== "") | 960 if (style.getPropertyValue("height") !== "") |
| 964 heightFound = true; | 961 heightFound = true; |
| 965 } | 962 } |
| 966 | 963 |
| 967 if (!widthFound || !heightFound) { | 964 if (!widthFound || !heightFound) { |
| 968 if (src in urlToNoDimensionCount) | 965 if (src in urlToNoDimensionCount) |
| 969 ++urlToNoDimensionCount[src]; | 966 ++urlToNoDimensionCount[src]; |
| 970 else | 967 else |
| 971 urlToNoDimensionCount[src] = 1; | 968 urlToNoDimensionCount[src] = 1; |
| 972 } | 969 } |
| 973 | |
| 974 if (isLastStyle) | |
| 975 doneCallback(); | |
| 976 } | 970 } |
| 977 | 971 |
| 978 /** | 972 /** |
| 979 * @param {!Array.<!DOMAgent.NodeId>=} nodeIds | 973 * @param {!Array.<!DOMAgent.NodeId>=} nodeIds |
| 980 */ | 974 */ |
| 981 function getStyles(nodeIds) | 975 function getStyles(nodeIds) |
| 982 { | 976 { |
| 983 if (progress.isCanceled()) { | 977 if (progress.isCanceled()) { |
| 984 callback(null); | 978 callback(null); |
| 985 return; | 979 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 999 | 993 |
| 1000 /** | 994 /** |
| 1001 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedSt
yleResult | 995 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedSt
yleResult |
| 1002 */ | 996 */ |
| 1003 function matchedCallback(matchedStyleResult) | 997 function matchedCallback(matchedStyleResult) |
| 1004 { | 998 { |
| 1005 if (matchedStyleResult) | 999 if (matchedStyleResult) |
| 1006 targetResult.matchedCSSRules = matchedStyleResult.matchedCSS
Rules; | 1000 targetResult.matchedCSSRules = matchedStyleResult.matchedCSS
Rules; |
| 1007 } | 1001 } |
| 1008 | 1002 |
| 1003 /** |
| 1004 * @param {?WebInspector.CSSStyleDeclaration} computedStyle |
| 1005 */ |
| 1006 function computedCallback(computedStyle) |
| 1007 { |
| 1008 targetResult.computedStyle = computedStyle; |
| 1009 } |
| 1010 |
| 1009 if (!nodeIds || !nodeIds.length) | 1011 if (!nodeIds || !nodeIds.length) |
| 1010 doneCallback(); | 1012 doneCallback(); |
| 1011 | 1013 |
| 1014 var nodePromises = []; |
| 1012 for (var i = 0; nodeIds && i < nodeIds.length; ++i) { | 1015 for (var i = 0; nodeIds && i < nodeIds.length; ++i) { |
| 1013 cssModel.getMatchedStylesAsync(nodeIds[i], false, false, matched
Callback); | 1016 var stylePromises = [ |
| 1014 cssModel.getInlineStylesAsync(nodeIds[i], inlineCallback); | 1017 cssModel.matchedStylesPromise(nodeIds[i], false, false).then
(matchedCallback), |
| 1015 cssModel.getComputedStyleAsync(nodeIds[i], imageStylesReady.bind
(null, nodeIds[i], targetResult, i === nodeIds.length - 1)); | 1018 cssModel.inlineStylesPromise(nodeIds[i]).then(inlineCallback
), |
| 1019 cssModel.computedStylePromise(nodeIds[i]).then(computedCallb
ack) |
| 1020 ]; |
| 1021 var nodePromise = Promise.all(stylePromises).then(imageStylesRea
dy.bind(null, nodeIds[i], targetResult)); |
| 1022 nodePromises.push(nodePromise); |
| 1016 } | 1023 } |
| 1024 Promise.all(nodePromises) |
| 1025 .catchException(null) |
| 1026 .then(doneCallback); |
| 1017 } | 1027 } |
| 1018 | 1028 |
| 1019 function onDocumentAvailable(root) | 1029 function onDocumentAvailable(root) |
| 1020 { | 1030 { |
| 1021 if (progress.isCanceled()) { | 1031 if (progress.isCanceled()) { |
| 1022 callback(null); | 1032 callback(null); |
| 1023 return; | 1033 return; |
| 1024 } | 1034 } |
| 1025 domModel.querySelectorAll(root.id, "img[src]", getStyles); | 1035 domModel.querySelectorAll(root.id, "img[src]", getStyles); |
| 1026 } | 1036 } |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 result.violationCount = badUrls.length; | 1687 result.violationCount = badUrls.length; |
| 1678 }, | 1688 }, |
| 1679 | 1689 |
| 1680 _collectorCallback: function(matchingResourceData, request, cookie) | 1690 _collectorCallback: function(matchingResourceData, request, cookie) |
| 1681 { | 1691 { |
| 1682 matchingResourceData[request.url] = (matchingResourceData[request.url] |
| 0) + cookie.size(); | 1692 matchingResourceData[request.url] = (matchingResourceData[request.url] |
| 0) + cookie.size(); |
| 1683 }, | 1693 }, |
| 1684 | 1694 |
| 1685 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype | 1695 __proto__: WebInspector.AuditRules.CookieRuleBase.prototype |
| 1686 } | 1696 } |
| OLD | NEW |