OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 /** | 30 /** |
32 * @constructor | 31 * @unrestricted |
33 * @extends {WebInspector.PanelWithSidebar} | |
34 */ | 32 */ |
35 WebInspector.AuditsPanel = function() | 33 WebInspector.AuditsPanel = class extends WebInspector.PanelWithSidebar { |
36 { | 34 constructor() { |
37 WebInspector.PanelWithSidebar.call(this, "audits"); | 35 super('audits'); |
38 this.registerRequiredCSS("ui/panelEnablerView.css"); | 36 this.registerRequiredCSS('ui/panelEnablerView.css'); |
39 this.registerRequiredCSS("audits/auditsPanel.css"); | 37 this.registerRequiredCSS('audits/auditsPanel.css'); |
40 | 38 |
41 this._sidebarTree = new TreeOutlineInShadow(); | 39 this._sidebarTree = new TreeOutlineInShadow(); |
42 this._sidebarTree.registerRequiredCSS("audits/auditsSidebarTree.css"); | 40 this._sidebarTree.registerRequiredCSS('audits/auditsSidebarTree.css'); |
43 this.panelSidebarElement().appendChild(this._sidebarTree.element); | 41 this.panelSidebarElement().appendChild(this._sidebarTree.element); |
44 | 42 |
45 this._auditsItemTreeElement = new WebInspector.AuditsSidebarTreeElement(this
); | 43 this._auditsItemTreeElement = new WebInspector.AuditsSidebarTreeElement(this
); |
46 this._sidebarTree.appendChild(this._auditsItemTreeElement); | 44 this._sidebarTree.appendChild(this._auditsItemTreeElement); |
47 | 45 |
48 this._auditResultsTreeElement = new TreeElement(WebInspector.UIString("RESUL
TS"), true); | 46 this._auditResultsTreeElement = new TreeElement(WebInspector.UIString('RESUL
TS'), true); |
49 this._auditResultsTreeElement.selectable = false; | 47 this._auditResultsTreeElement.selectable = false; |
50 this._auditResultsTreeElement.listItemElement.classList.add("audits-sidebar-
results"); | 48 this._auditResultsTreeElement.listItemElement.classList.add('audits-sidebar-
results'); |
51 this._auditResultsTreeElement.expand(); | 49 this._auditResultsTreeElement.expand(); |
52 this._sidebarTree.appendChild(this._auditResultsTreeElement); | 50 this._sidebarTree.appendChild(this._auditResultsTreeElement); |
53 | 51 |
54 this._constructCategories(); | 52 this._constructCategories(); |
55 | 53 |
56 this._auditController = new WebInspector.AuditController(this); | 54 this._auditController = new WebInspector.AuditController(this); |
57 this._launcherView = new WebInspector.AuditLauncherView(this._auditControlle
r); | 55 this._launcherView = new WebInspector.AuditLauncherView(this._auditControlle
r); |
58 for (var id in this.categoriesById) | 56 for (var id in this.categoriesById) |
59 this._launcherView.addCategory(this.categoriesById[id]); | 57 this._launcherView.addCategory(this.categoriesById[id]); |
60 | 58 |
61 var extensionCategories = WebInspector.extensionServer.auditCategories(); | 59 var extensionCategories = WebInspector.extensionServer.auditCategories(); |
62 for (var i = 0; i < extensionCategories.length; ++i) { | 60 for (var i = 0; i < extensionCategories.length; ++i) { |
63 var category = extensionCategories[i]; | 61 var category = extensionCategories[i]; |
64 this.addCategory(new WebInspector.AuditExtensionCategory(category.extens
ionOrigin, category.id, category.displayName, category.ruleCount)); | 62 this.addCategory(new WebInspector.AuditExtensionCategory( |
65 } | 63 category.extensionOrigin, category.id, category.displayName, category.
ruleCount)); |
66 WebInspector.extensionServer.addEventListener(WebInspector.ExtensionServer.E
vents.AuditCategoryAdded, this._extensionAuditCategoryAdded, this); | 64 } |
67 }; | 65 WebInspector.extensionServer.addEventListener( |
68 | 66 WebInspector.ExtensionServer.Events.AuditCategoryAdded, this._extensionA
uditCategoryAdded, this); |
69 WebInspector.AuditsPanel.prototype = { | 67 } |
70 | 68 |
71 /** | 69 /** |
72 * @return {!Object.<string, !WebInspector.AuditCategory>} | 70 * @return {!WebInspector.AuditsPanel} |
73 */ | 71 */ |
74 get categoriesById() | 72 static instance() { |
75 { | 73 return /** @type {!WebInspector.AuditsPanel} */ (self.runtime.sharedInstance
(WebInspector.AuditsPanel)); |
76 return this._auditCategoriesById; | 74 } |
77 }, | 75 |
78 | 76 /** |
79 /** | 77 * @return {!Object.<string, !WebInspector.AuditCategory>} |
80 * @param {!WebInspector.AuditCategory} category | 78 */ |
81 */ | 79 get categoriesById() { |
82 addCategory: function(category) | 80 return this._auditCategoriesById; |
83 { | 81 } |
84 this.categoriesById[category.id] = category; | 82 |
85 this._launcherView.addCategory(category); | 83 /** |
86 }, | 84 * @param {!WebInspector.AuditCategory} category |
87 | 85 */ |
88 /** | 86 addCategory(category) { |
89 * @param {string} id | 87 this.categoriesById[category.id] = category; |
90 * @return {!WebInspector.AuditCategory} | 88 this._launcherView.addCategory(category); |
91 */ | 89 } |
92 getCategory: function(id) | 90 |
93 { | 91 /** |
94 return this.categoriesById[id]; | 92 * @param {string} id |
95 }, | 93 * @return {!WebInspector.AuditCategory} |
96 | 94 */ |
97 _constructCategories: function() | 95 getCategory(id) { |
98 { | 96 return this.categoriesById[id]; |
99 this._auditCategoriesById = {}; | 97 } |
100 for (var categoryCtorID in WebInspector.AuditCategories) { | 98 |
101 var auditCategory = new WebInspector.AuditCategories[categoryCtorID]
(); | 99 _constructCategories() { |
102 auditCategory._id = categoryCtorID; | 100 this._auditCategoriesById = {}; |
103 this.categoriesById[categoryCtorID] = auditCategory; | 101 for (var categoryCtorID in WebInspector.AuditCategories) { |
104 } | 102 var auditCategory = new WebInspector.AuditCategories[categoryCtorID](); |
105 }, | 103 auditCategory._id = categoryCtorID; |
106 | 104 this.categoriesById[categoryCtorID] = auditCategory; |
107 /** | 105 } |
108 * @param {string} mainResourceURL | 106 } |
109 * @param {!Array.<!WebInspector.AuditCategoryResult>} results | 107 |
110 */ | 108 /** |
111 auditFinishedCallback: function(mainResourceURL, results) | 109 * @param {string} mainResourceURL |
112 { | 110 * @param {!Array.<!WebInspector.AuditCategoryResult>} results |
113 var ordinal = 1; | 111 */ |
114 for (var child of this._auditResultsTreeElement.children()) { | 112 auditFinishedCallback(mainResourceURL, results) { |
115 if (child.mainResourceURL === mainResourceURL) | 113 var ordinal = 1; |
116 ordinal++; | 114 for (var child of this._auditResultsTreeElement.children()) { |
117 } | 115 if (child.mainResourceURL === mainResourceURL) |
118 | 116 ordinal++; |
119 var resultTreeElement = new WebInspector.AuditResultSidebarTreeElement(t
his, results, mainResourceURL, ordinal); | 117 } |
120 this._auditResultsTreeElement.appendChild(resultTreeElement); | 118 |
121 resultTreeElement.revealAndSelect(); | 119 var resultTreeElement = new WebInspector.AuditResultSidebarTreeElement(this,
results, mainResourceURL, ordinal); |
122 }, | 120 this._auditResultsTreeElement.appendChild(resultTreeElement); |
123 | 121 resultTreeElement.revealAndSelect(); |
124 /** | 122 } |
125 * @param {!Array.<!WebInspector.AuditCategoryResult>} categoryResults | 123 |
126 */ | 124 /** |
127 showResults: function(categoryResults) | 125 * @param {!Array.<!WebInspector.AuditCategoryResult>} categoryResults |
128 { | 126 */ |
129 if (!categoryResults._resultLocation) { | 127 showResults(categoryResults) { |
130 categoryResults.sort((a, b) => (a.title || "").localeCompare(b.title
|| "")); | 128 if (!categoryResults._resultLocation) { |
131 var resultView = WebInspector.viewManager.createStackLocation(); | 129 categoryResults.sort((a, b) => (a.title || '').localeCompare(b.title || ''
)); |
132 resultView.widget().element.classList.add("audit-result-view"); | 130 var resultView = WebInspector.viewManager.createStackLocation(); |
133 for (var i = 0; i < categoryResults.length; ++i) | 131 resultView.widget().element.classList.add('audit-result-view'); |
134 resultView.showView(new WebInspector.AuditCategoryResultPane(cat
egoryResults[i])); | 132 for (var i = 0; i < categoryResults.length; ++i) |
135 categoryResults._resultLocation = resultView; | 133 resultView.showView(new WebInspector.AuditCategoryResultPane(categoryRes
ults[i])); |
136 } | 134 categoryResults._resultLocation = resultView; |
137 this.visibleView = categoryResults._resultLocation.widget(); | 135 } |
138 }, | 136 this.visibleView = categoryResults._resultLocation.widget(); |
139 | 137 } |
140 showLauncherView: function() | 138 |
141 { | 139 showLauncherView() { |
142 this.visibleView = this._launcherView; | 140 this.visibleView = this._launcherView; |
143 }, | 141 } |
144 | 142 |
145 get visibleView() | 143 get visibleView() { |
146 { | 144 return this._visibleView; |
147 return this._visibleView; | 145 } |
148 }, | 146 |
149 | 147 set visibleView(x) { |
150 set visibleView(x) | 148 if (this._visibleView === x) |
151 { | 149 return; |
152 if (this._visibleView === x) | 150 |
153 return; | 151 if (this._visibleView) |
154 | 152 this._visibleView.detach(); |
155 if (this._visibleView) | 153 |
156 this._visibleView.detach(); | 154 this._visibleView = x; |
157 | 155 |
158 this._visibleView = x; | 156 if (x) |
159 | 157 this.splitWidget().setMainWidget(x); |
160 if (x) | 158 } |
161 this.splitWidget().setMainWidget(x); | 159 |
162 }, | 160 /** |
163 | 161 * @override |
164 wasShown: function() | 162 */ |
165 { | 163 wasShown() { |
166 WebInspector.Panel.prototype.wasShown.call(this); | 164 super.wasShown(); |
167 if (!this._visibleView) | 165 if (!this._visibleView) |
168 this._auditsItemTreeElement.select(); | 166 this._auditsItemTreeElement.select(); |
169 }, | 167 } |
170 | 168 |
171 /** | 169 /** |
172 * @override | 170 * @override |
173 */ | 171 */ |
174 focus: function() | 172 focus() { |
175 { | 173 this._sidebarTree.focus(); |
176 this._sidebarTree.focus(); | 174 } |
177 }, | 175 |
178 | 176 clearResults() { |
179 clearResults: function() | 177 this._auditsItemTreeElement.revealAndSelect(); |
180 { | 178 this._auditResultsTreeElement.removeChildren(); |
181 this._auditsItemTreeElement.revealAndSelect(); | 179 } |
182 this._auditResultsTreeElement.removeChildren(); | 180 |
183 }, | 181 /** |
184 | 182 * @param {!WebInspector.Event} event |
185 /** | 183 */ |
186 * @param {!WebInspector.Event} event | 184 _extensionAuditCategoryAdded(event) { |
187 */ | 185 var category = /** @type {!WebInspector.ExtensionAuditCategory} */ (event.da
ta); |
188 _extensionAuditCategoryAdded: function(event) | 186 this.addCategory(new WebInspector.AuditExtensionCategory( |
189 { | 187 category.extensionOrigin, category.id, category.displayName, category.ru
leCount)); |
190 var category = /** @type {!WebInspector.ExtensionAuditCategory} */ (even
t.data); | 188 } |
191 this.addCategory(new WebInspector.AuditExtensionCategory(category.extens
ionOrigin, category.id, category.displayName, category.ruleCount)); | 189 }; |
192 }, | 190 |
193 | 191 /** |
194 __proto__: WebInspector.PanelWithSidebar.prototype | |
195 }; | |
196 | |
197 /** | |
198 * @constructor | |
199 * @implements {WebInspector.AuditCategory} | 192 * @implements {WebInspector.AuditCategory} |
200 * @param {string} displayName | 193 * @unrestricted |
201 */ | 194 */ |
202 WebInspector.AuditCategoryImpl = function(displayName) | 195 WebInspector.AuditCategoryImpl = class { |
203 { | 196 /** |
| 197 * @param {string} displayName |
| 198 */ |
| 199 constructor(displayName) { |
204 this._displayName = displayName; | 200 this._displayName = displayName; |
205 this._rules = []; | 201 this._rules = []; |
206 }; | 202 } |
207 | 203 |
208 WebInspector.AuditCategoryImpl.prototype = { | 204 /** |
209 /** | 205 * @override |
210 * @override | 206 * @return {string} |
211 * @return {string} | 207 */ |
212 */ | 208 get id() { |
213 get id() | 209 // this._id value is injected at construction time. |
214 { | 210 return this._id; |
215 // this._id value is injected at construction time. | 211 } |
216 return this._id; | 212 |
217 }, | 213 /** |
218 | 214 * @override |
219 /** | 215 * @return {string} |
220 * @override | 216 */ |
221 * @return {string} | 217 get displayName() { |
222 */ | 218 return this._displayName; |
223 get displayName() | 219 } |
224 { | 220 |
225 return this._displayName; | 221 /** |
226 }, | 222 * @param {!WebInspector.AuditRule} rule |
227 | 223 * @param {!WebInspector.AuditRule.Severity} severity |
228 /** | 224 */ |
229 * @param {!WebInspector.AuditRule} rule | 225 addRule(rule, severity) { |
230 * @param {!WebInspector.AuditRule.Severity} severity | 226 rule.severity = severity; |
231 */ | 227 this._rules.push(rule); |
232 addRule: function(rule, severity) | 228 } |
233 { | 229 |
234 rule.severity = severity; | 230 /** |
235 this._rules.push(rule); | 231 * @override |
236 }, | 232 * @param {!WebInspector.Target} target |
237 | 233 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
238 /** | 234 * @param {function(!WebInspector.AuditRuleResult)} ruleResultCallback |
239 * @override | 235 * @param {!WebInspector.Progress} progress |
240 * @param {!WebInspector.Target} target | 236 */ |
241 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 237 run(target, requests, ruleResultCallback, progress) { |
242 * @param {function(!WebInspector.AuditRuleResult)} ruleResultCallback | 238 this._ensureInitialized(); |
243 * @param {!WebInspector.Progress} progress | 239 var remainingRulesCount = this._rules.length; |
244 */ | 240 progress.setTotalWork(remainingRulesCount); |
245 run: function(target, requests, ruleResultCallback, progress) | 241 function callbackWrapper(result) { |
246 { | 242 ruleResultCallback(result); |
247 this._ensureInitialized(); | 243 progress.worked(); |
248 var remainingRulesCount = this._rules.length; | 244 if (!--remainingRulesCount) |
249 progress.setTotalWork(remainingRulesCount); | 245 progress.done(); |
250 function callbackWrapper(result) | 246 } |
251 { | 247 for (var i = 0; i < this._rules.length; ++i) { |
252 ruleResultCallback(result); | 248 if (!progress.isCanceled()) |
253 progress.worked(); | 249 this._rules[i].run(target, requests, callbackWrapper, progress); |
254 if (!--remainingRulesCount) | 250 else |
255 progress.done(); | 251 callbackWrapper(null); |
256 } | 252 } |
257 for (var i = 0; i < this._rules.length; ++i) { | 253 } |
258 if (!progress.isCanceled()) | 254 |
259 this._rules[i].run(target, requests, callbackWrapper, progress); | 255 _ensureInitialized() { |
260 else | 256 if (!this._initialized) { |
261 callbackWrapper(null); | 257 if ('initialize' in this) |
262 } | 258 this.initialize(); |
263 }, | 259 this._initialized = true; |
264 | 260 } |
265 _ensureInitialized: function() | 261 } |
266 { | 262 }; |
267 if (!this._initialized) { | 263 |
268 if ("initialize" in this) | 264 /** |
269 this.initialize(); | 265 * @unrestricted |
270 this._initialized = true; | 266 */ |
271 } | 267 WebInspector.AuditRule = class { |
272 } | 268 /** |
273 }; | 269 * @param {string} id |
274 | 270 * @param {string} displayName |
275 /** | 271 */ |
276 * @constructor | 272 constructor(id, displayName) { |
277 * @param {string} id | |
278 * @param {string} displayName | |
279 */ | |
280 WebInspector.AuditRule = function(id, displayName) | |
281 { | |
282 this._id = id; | 273 this._id = id; |
283 this._displayName = displayName; | 274 this._displayName = displayName; |
| 275 } |
| 276 |
| 277 get id() { |
| 278 return this._id; |
| 279 } |
| 280 |
| 281 get displayName() { |
| 282 return this._displayName; |
| 283 } |
| 284 |
| 285 /** |
| 286 * @param {!WebInspector.AuditRule.Severity} severity |
| 287 */ |
| 288 set severity(severity) { |
| 289 this._severity = severity; |
| 290 } |
| 291 |
| 292 /** |
| 293 * @param {!WebInspector.Target} target |
| 294 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 295 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 296 * @param {!WebInspector.Progress} progress |
| 297 */ |
| 298 run(target, requests, callback, progress) { |
| 299 if (progress.isCanceled()) |
| 300 return; |
| 301 |
| 302 var result = new WebInspector.AuditRuleResult(this.displayName); |
| 303 result.severity = this._severity; |
| 304 this.doRun(target, requests, result, callback, progress); |
| 305 } |
| 306 |
| 307 /** |
| 308 * @param {!WebInspector.Target} target |
| 309 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 310 * @param {!WebInspector.AuditRuleResult} result |
| 311 * @param {function(?WebInspector.AuditRuleResult)} callback |
| 312 * @param {!WebInspector.Progress} progress |
| 313 */ |
| 314 doRun(target, requests, result, callback, progress) { |
| 315 throw new Error('doRun() not implemented'); |
| 316 } |
284 }; | 317 }; |
285 | 318 |
286 /** | 319 /** |
287 * @enum {string} | 320 * @enum {string} |
288 */ | 321 */ |
289 WebInspector.AuditRule.Severity = { | 322 WebInspector.AuditRule.Severity = { |
290 Info: "info", | 323 Info: 'info', |
291 Warning: "warning", | 324 Warning: 'warning', |
292 Severe: "severe" | 325 Severe: 'severe' |
293 }; | 326 }; |
294 | 327 |
295 WebInspector.AuditRule.SeverityOrder = { | 328 WebInspector.AuditRule.SeverityOrder = { |
296 "info": 3, | 329 'info': 3, |
297 "warning": 2, | 330 'warning': 2, |
298 "severe": 1 | 331 'severe': 1 |
299 }; | 332 }; |
300 | 333 |
301 WebInspector.AuditRule.prototype = { | 334 /** |
302 get id() | 335 * @unrestricted |
303 { | 336 */ |
304 return this._id; | 337 WebInspector.AuditCategoryResult = class { |
305 }, | 338 /** |
306 | 339 * @param {!WebInspector.AuditCategory} category |
307 get displayName() | 340 */ |
308 { | 341 constructor(category) { |
309 return this._displayName; | |
310 }, | |
311 | |
312 /** | |
313 * @param {!WebInspector.AuditRule.Severity} severity | |
314 */ | |
315 set severity(severity) | |
316 { | |
317 this._severity = severity; | |
318 }, | |
319 | |
320 /** | |
321 * @param {!WebInspector.Target} target | |
322 * @param {!Array.<!WebInspector.NetworkRequest>} requests | |
323 * @param {function(?WebInspector.AuditRuleResult)} callback | |
324 * @param {!WebInspector.Progress} progress | |
325 */ | |
326 run: function(target, requests, callback, progress) | |
327 { | |
328 if (progress.isCanceled()) | |
329 return; | |
330 | |
331 var result = new WebInspector.AuditRuleResult(this.displayName); | |
332 result.severity = this._severity; | |
333 this.doRun(target, requests, result, callback, progress); | |
334 }, | |
335 | |
336 /** | |
337 * @param {!WebInspector.Target} target | |
338 * @param {!Array.<!WebInspector.NetworkRequest>} requests | |
339 * @param {!WebInspector.AuditRuleResult} result | |
340 * @param {function(?WebInspector.AuditRuleResult)} callback | |
341 * @param {!WebInspector.Progress} progress | |
342 */ | |
343 doRun: function(target, requests, result, callback, progress) | |
344 { | |
345 throw new Error("doRun() not implemented"); | |
346 } | |
347 }; | |
348 | |
349 /** | |
350 * @constructor | |
351 * @param {!WebInspector.AuditCategory} category | |
352 */ | |
353 WebInspector.AuditCategoryResult = function(category) | |
354 { | |
355 this.title = category.displayName; | 342 this.title = category.displayName; |
356 this.ruleResults = []; | 343 this.ruleResults = []; |
357 }; | 344 } |
358 | 345 |
359 WebInspector.AuditCategoryResult.prototype = { | 346 /** |
360 /** | 347 * @param {!WebInspector.AuditRuleResult} ruleResult |
361 * @param {!WebInspector.AuditRuleResult} ruleResult | 348 */ |
362 */ | 349 addRuleResult(ruleResult) { |
363 addRuleResult: function(ruleResult) | 350 this.ruleResults.push(ruleResult); |
364 { | 351 } |
365 this.ruleResults.push(ruleResult); | 352 }; |
366 } | 353 |
367 }; | 354 /** |
368 | 355 * @unrestricted |
369 /** | 356 */ |
370 * @constructor | 357 WebInspector.AuditRuleResult = class { |
371 * @param {(string|boolean|number|!Object)} value | 358 /** |
372 * @param {boolean=} expanded | 359 * @param {(string|boolean|number|!Object)} value |
373 * @param {string=} className | 360 * @param {boolean=} expanded |
374 */ | 361 * @param {string=} className |
375 WebInspector.AuditRuleResult = function(value, expanded, className) | 362 */ |
376 { | 363 constructor(value, expanded, className) { |
377 this.value = value; | 364 this.value = value; |
378 this.className = className; | 365 this.className = className; |
379 this.expanded = expanded; | 366 this.expanded = expanded; |
380 this.violationCount = 0; | 367 this.violationCount = 0; |
381 this._formatters = { | 368 this._formatters = {r: WebInspector.AuditRuleResult.linkifyDisplayName}; |
382 r: WebInspector.AuditRuleResult.linkifyDisplayName | |
383 }; | |
384 var standardFormatters = Object.keys(String.standardFormatters); | 369 var standardFormatters = Object.keys(String.standardFormatters); |
385 for (var i = 0; i < standardFormatters.length; ++i) | 370 for (var i = 0; i < standardFormatters.length; ++i) |
386 this._formatters[standardFormatters[i]] = String.standardFormatters[stan
dardFormatters[i]]; | 371 this._formatters[standardFormatters[i]] = String.standardFormatters[standa
rdFormatters[i]]; |
387 }; | 372 } |
388 | 373 |
389 /** | 374 /** |
390 * @param {string} url | 375 * @param {string} url |
391 * @return {!Element} | 376 * @return {!Element} |
392 */ | 377 */ |
393 WebInspector.AuditRuleResult.linkifyDisplayName = function(url) | 378 static linkifyDisplayName(url) { |
394 { | |
395 return WebInspector.linkifyURLAsNode(url, WebInspector.displayNameForURL(url
)); | 379 return WebInspector.linkifyURLAsNode(url, WebInspector.displayNameForURL(url
)); |
396 }; | 380 } |
397 | 381 |
398 /** | 382 /** |
399 * @param {string} domain | 383 * @param {string} domain |
400 * @return {string} | 384 * @return {string} |
401 */ | 385 */ |
402 WebInspector.AuditRuleResult.resourceDomain = function(domain) | 386 static resourceDomain(domain) { |
403 { | 387 return domain || WebInspector.UIString('[empty domain]'); |
404 return domain || WebInspector.UIString("[empty domain]"); | 388 } |
405 }; | 389 |
406 | 390 /** |
407 WebInspector.AuditRuleResult.prototype = { | 391 * @param {(string|boolean|number|!Object)} value |
408 /** | 392 * @param {boolean=} expanded |
409 * @param {(string|boolean|number|!Object)} value | 393 * @param {string=} className |
410 * @param {boolean=} expanded | 394 * @return {!WebInspector.AuditRuleResult} |
411 * @param {string=} className | 395 */ |
412 * @return {!WebInspector.AuditRuleResult} | 396 addChild(value, expanded, className) { |
413 */ | 397 if (!this.children) |
414 addChild: function(value, expanded, className) | 398 this.children = []; |
415 { | 399 var entry = new WebInspector.AuditRuleResult(value, expanded, className); |
416 if (!this.children) | 400 this.children.push(entry); |
417 this.children = []; | 401 return entry; |
418 var entry = new WebInspector.AuditRuleResult(value, expanded, className)
; | 402 } |
419 this.children.push(entry); | 403 |
420 return entry; | 404 /** |
421 }, | 405 * @param {string} url |
422 | 406 */ |
423 /** | 407 addURL(url) { |
424 * @param {string} url | 408 this.addChild(WebInspector.AuditRuleResult.linkifyDisplayName(url)); |
425 */ | 409 } |
426 addURL: function(url) | 410 |
427 { | 411 /** |
428 this.addChild(WebInspector.AuditRuleResult.linkifyDisplayName(url)); | 412 * @param {!Array.<string>} urls |
429 }, | 413 */ |
430 | 414 addURLs(urls) { |
431 /** | 415 for (var i = 0; i < urls.length; ++i) |
432 * @param {!Array.<string>} urls | 416 this.addURL(urls[i]); |
433 */ | 417 } |
434 addURLs: function(urls) | 418 |
435 { | 419 /** |
436 for (var i = 0; i < urls.length; ++i) | 420 * @param {string} snippet |
437 this.addURL(urls[i]); | 421 */ |
438 }, | 422 addSnippet(snippet) { |
439 | 423 this.addChild(snippet, false, 'source-code'); |
440 /** | 424 } |
441 * @param {string} snippet | 425 |
442 */ | 426 /** |
443 addSnippet: function(snippet) | 427 * @param {string} format |
444 { | 428 * @param {...*} vararg |
445 this.addChild(snippet, false, "source-code"); | 429 * @return {!WebInspector.AuditRuleResult} |
446 }, | 430 */ |
447 | 431 addFormatted(format, vararg) { |
448 /** | 432 var substitutions = Array.prototype.slice.call(arguments, 1); |
449 * @param {string} format | 433 var fragment = createDocumentFragment(); |
450 * @param {...*} vararg | 434 |
451 * @return {!WebInspector.AuditRuleResult} | 435 function append(a, b) { |
452 */ | 436 if (!(b instanceof Node)) |
453 addFormatted: function(format, vararg) | 437 b = createTextNode(b); |
454 { | 438 a.appendChild(b); |
455 var substitutions = Array.prototype.slice.call(arguments, 1); | 439 return a; |
456 var fragment = createDocumentFragment(); | 440 } |
457 | 441 |
458 function append(a, b) | 442 var formattedResult = String.format(format, substitutions, this._formatters,
fragment, append).formattedResult; |
459 { | 443 if (formattedResult instanceof Node) |
460 if (!(b instanceof Node)) | 444 formattedResult.normalize(); |
461 b = createTextNode(b); | 445 return this.addChild(formattedResult); |
462 a.appendChild(b); | 446 } |
463 return a; | 447 }; |
464 } | 448 |
465 | 449 |
466 var formattedResult = String.format(format, substitutions, this._formatt
ers, fragment, append).formattedResult; | 450 /** |
467 if (formattedResult instanceof Node) | 451 * @unrestricted |
468 formattedResult.normalize(); | 452 */ |
469 return this.addChild(formattedResult); | 453 WebInspector.AuditsSidebarTreeElement = class extends TreeElement { |
470 } | 454 /** |
471 }; | 455 * @param {!WebInspector.AuditsPanel} panel |
472 | 456 */ |
473 /** | 457 constructor(panel) { |
474 * @constructor | 458 super(WebInspector.UIString('Audits'), false); |
475 * @extends {TreeElement} | |
476 * @param {!WebInspector.AuditsPanel} panel | |
477 */ | |
478 WebInspector.AuditsSidebarTreeElement = function(panel) | |
479 { | |
480 TreeElement.call(this, WebInspector.UIString("Audits"), false); | |
481 this.selectable = true; | 459 this.selectable = true; |
482 this._panel = panel; | 460 this._panel = panel; |
483 this.listItemElement.classList.add("audits-sidebar-header"); | 461 this.listItemElement.classList.add('audits-sidebar-header'); |
484 this.listItemElement.insertBefore(createElementWithClass("div", "icon"), thi
s.listItemElement.firstChild); | 462 this.listItemElement.insertBefore(createElementWithClass('div', 'icon'), thi
s.listItemElement.firstChild); |
485 }; | 463 } |
486 | 464 |
487 WebInspector.AuditsSidebarTreeElement.prototype = { | 465 /** |
488 /** | 466 * @override |
489 * @override | 467 * @return {boolean} |
490 * @return {boolean} | 468 */ |
491 */ | 469 onselect() { |
492 onselect: function() | 470 this._panel.showLauncherView(); |
493 { | 471 return true; |
494 this._panel.showLauncherView(); | 472 } |
495 return true; | 473 }; |
496 }, | 474 |
497 | 475 /** |
498 __proto__: TreeElement.prototype | 476 * @unrestricted |
499 }; | 477 */ |
500 | 478 WebInspector.AuditResultSidebarTreeElement = class extends TreeElement { |
501 /** | 479 /** |
502 * @constructor | 480 * @param {!WebInspector.AuditsPanel} panel |
503 * @extends {TreeElement} | 481 * @param {!Array.<!WebInspector.AuditCategoryResult>} results |
504 * @param {!WebInspector.AuditsPanel} panel | 482 * @param {string} mainResourceURL |
505 * @param {!Array.<!WebInspector.AuditCategoryResult>} results | 483 * @param {number} ordinal |
506 * @param {string} mainResourceURL | 484 */ |
507 * @param {number} ordinal | 485 constructor(panel, results, mainResourceURL, ordinal) { |
508 */ | 486 super(String.sprintf('%s (%d)', mainResourceURL, ordinal), false); |
509 WebInspector.AuditResultSidebarTreeElement = function(panel, results, mainResour
ceURL, ordinal) | |
510 { | |
511 TreeElement.call(this, String.sprintf("%s (%d)", mainResourceURL, ordinal),
false); | |
512 this.selectable = true; | 487 this.selectable = true; |
513 this._panel = panel; | 488 this._panel = panel; |
514 this.results = results; | 489 this.results = results; |
515 this.mainResourceURL = mainResourceURL; | 490 this.mainResourceURL = mainResourceURL; |
516 this.listItemElement.classList.add("audit-result-sidebar-tree-item"); | 491 this.listItemElement.classList.add('audit-result-sidebar-tree-item'); |
517 this.listItemElement.insertBefore(createElementWithClass("div", "icon"), thi
s.listItemElement.firstChild); | 492 this.listItemElement.insertBefore(createElementWithClass('div', 'icon'), thi
s.listItemElement.firstChild); |
518 }; | 493 } |
519 | 494 |
520 WebInspector.AuditResultSidebarTreeElement.prototype = { | 495 /** |
521 /** | 496 * @override |
522 * @override | 497 * @return {boolean} |
523 * @return {boolean} | 498 */ |
524 */ | 499 onselect() { |
525 onselect: function() | 500 this._panel.showResults(this.results); |
526 { | 501 return true; |
527 this._panel.showResults(this.results); | 502 } |
528 return true; | 503 }; |
529 }, | 504 |
530 | |
531 __proto__: TreeElement.prototype | |
532 }; | |
533 | |
534 /** | |
535 * @return {!WebInspector.AuditsPanel} | |
536 */ | |
537 WebInspector.AuditsPanel.instance = function() | |
538 { | |
539 return /** @type {!WebInspector.AuditsPanel} */ (self.runtime.sharedInstance
(WebInspector.AuditsPanel)); | |
540 }; | |
541 | 505 |
542 // Contributed audit rules should go into this namespace. | 506 // Contributed audit rules should go into this namespace. |
543 WebInspector.AuditRules = {}; | 507 WebInspector.AuditRules = {}; |
544 | 508 |
545 /** | 509 /** |
546 * Contributed audit categories should go into this namespace. | 510 * Contributed audit categories should go into this namespace. |
547 * @type {!Object.<string, function(new:WebInspector.AuditCategory)>} | 511 * @type {!Object.<string, function(new:WebInspector.AuditCategory)>} |
548 */ | 512 */ |
549 WebInspector.AuditCategories = {}; | 513 WebInspector.AuditCategories = {}; |
OLD | NEW |