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 |
(...skipping 12 matching lines...) Expand all Loading... |
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 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @implements {WebInspector.AuditCategory} | |
34 * @param {!WebInspector.ExtensionServer} server | |
35 * @param {string} extensionOrigin | 33 * @param {string} extensionOrigin |
36 * @param {string} id | 34 * @param {string} id |
37 * @param {string} displayName | 35 * @param {string} displayName |
38 * @param {number=} ruleCount | 36 * @param {number=} ruleCount |
39 */ | 37 */ |
40 WebInspector.ExtensionAuditCategory = function(server, extensionOrigin, id, disp
layName, ruleCount) | 38 WebInspector.ExtensionAuditCategory = function(extensionOrigin, id, displayName,
ruleCount) |
41 { | 39 { |
42 this._server = server; | 40 this.extensionOrigin = extensionOrigin; |
43 this._extensionOrigin = extensionOrigin; | 41 this.id = id; |
44 this._id = id; | 42 this.displayName = displayName; |
45 this._displayName = displayName; | 43 this.ruleCount = ruleCount; |
46 this._ruleCount = ruleCount; | |
47 } | |
48 | |
49 WebInspector.ExtensionAuditCategory.prototype = { | |
50 /** | |
51 * @override | |
52 */ | |
53 get id() | |
54 { | |
55 return this._id; | |
56 }, | |
57 | |
58 /** | |
59 * @override | |
60 */ | |
61 get displayName() | |
62 { | |
63 return this._displayName; | |
64 }, | |
65 | |
66 /** | |
67 * @override | |
68 * @param {!WebInspector.Target} target | |
69 * @param {!Array.<!WebInspector.NetworkRequest>} requests | |
70 * @param {function(!WebInspector.AuditRuleResult)} ruleResultCallbac
k | |
71 * @param {function()} categoryDoneCallback | |
72 * @param {!WebInspector.Progress} progress | |
73 */ | |
74 run: function(target, requests, ruleResultCallback, categoryDoneCallback, pr
ogress) | |
75 { | |
76 var results = new WebInspector.ExtensionAuditCategoryResults(this, targe
t, ruleResultCallback, categoryDoneCallback, progress); | |
77 this._server.startAuditRun(this, results); | |
78 } | |
79 } | 44 } |
80 | 45 |
81 /** | 46 /** |
82 * @constructor | 47 * @interface |
83 * @param {!WebInspector.ExtensionAuditCategory} category | |
84 * @param {!WebInspector.Target} target | |
85 * @param {function(!WebInspector.AuditRuleResult)} ruleResultCallback | |
86 * @param {function()} categoryDoneCallback | |
87 * @param {!WebInspector.Progress} progress | |
88 */ | 48 */ |
89 WebInspector.ExtensionAuditCategoryResults = function(category, target, ruleResu
ltCallback, categoryDoneCallback, progress) | 49 WebInspector.ExtensionAuditCategoryResults = function() |
90 { | 50 { |
91 this._target = target; | |
92 this._category = category; | |
93 this._ruleResultCallback = ruleResultCallback; | |
94 this._categoryDoneCallback = categoryDoneCallback; | |
95 this._progress = progress; | |
96 this._progress.setTotalWork(1); | |
97 this._expectedResults = category._ruleCount; | |
98 this._actualResults = 0; | |
99 | |
100 this.id = category.id + "-" + ++WebInspector.ExtensionAuditCategoryResults._
lastId; | |
101 } | 51 } |
102 | 52 |
103 WebInspector.ExtensionAuditCategoryResults.prototype = { | 53 WebInspector.ExtensionAuditCategoryResults.prototype = { |
104 done: function() | 54 /** |
105 { | 55 * @return {string} |
106 this._category._server.stopAuditRun(this); | 56 */ |
107 this._progress.done(); | 57 id: function() { }, |
108 this._categoryDoneCallback(); | |
109 }, | |
110 | 58 |
111 addResult: function(displayName, description, severity, details) | 59 /** |
112 { | 60 * @param {string} displayName |
113 var result = new WebInspector.AuditRuleResult(displayName); | 61 * @param {string} description |
114 result.addChild(description); | 62 * @param {string} severity |
115 result.severity = severity; | 63 * @param {!Object} details |
116 if (details) | 64 */ |
117 this._addNode(result, details); | 65 addResult: function(displayName, description, severity, details) { }, |
118 this._addResult(result); | |
119 }, | |
120 | |
121 _addNode: function(parent, node) | |
122 { | |
123 var contents = WebInspector.auditFormatters.partiallyApply(WebInspector.
ExtensionAuditFormatters, this, node.contents); | |
124 var addedNode = parent.addChild(contents, node.expanded); | |
125 if (node.children) { | |
126 for (var i = 0; i < node.children.length; ++i) | |
127 this._addNode(addedNode, node.children[i]); | |
128 } | |
129 }, | |
130 | |
131 _addResult: function(result) | |
132 { | |
133 this._ruleResultCallback(result); | |
134 ++this._actualResults; | |
135 if (typeof this._expectedResults === "number") { | |
136 this._progress.setWorked(this._actualResults / this._expectedResults
); | |
137 if (this._actualResults === this._expectedResults) | |
138 this.done(); | |
139 } | |
140 }, | |
141 | 66 |
142 /** | 67 /** |
143 * @param {number} progress | 68 * @param {number} progress |
144 */ | 69 */ |
145 updateProgress: function(progress) | 70 updateProgress: function(progress) { }, |
146 { | |
147 this._progress.setWorked(progress); | |
148 }, | |
149 | 71 |
150 /** | 72 done: function() { } |
151 * @param {string} expression | |
152 * @param {?Object} evaluateOptions | |
153 * @param {function(!WebInspector.RemoteObject)} callback | |
154 */ | |
155 evaluate: function(expression, evaluateOptions, callback) | |
156 { | |
157 /** | |
158 * @param {?string} error | |
159 * @param {!RuntimeAgent.RemoteObject} result | |
160 * @param {boolean=} wasThrown | |
161 * @this {WebInspector.ExtensionAuditCategoryResults} | |
162 */ | |
163 function onEvaluate(error, result, wasThrown) | |
164 { | |
165 if (wasThrown) | |
166 return; | |
167 var object = this._target.runtimeModel.createRemoteObject(result); | |
168 callback(object); | |
169 } | |
170 this._category._server.evaluate(expression, false, false, evaluateOption
s, this._category._extensionOrigin, onEvaluate.bind(this)); | |
171 } | |
172 } | 73 } |
173 | |
174 WebInspector.ExtensionAuditFormatters = { | |
175 /** | |
176 * @this {WebInspector.ExtensionAuditCategoryResults} | |
177 * @param {string} expression | |
178 * @param {string} title | |
179 * @param {?Object} evaluateOptions | |
180 * @return {!Element} | |
181 */ | |
182 object: function(expression, title, evaluateOptions) | |
183 { | |
184 var parentElement = createElement("div"); | |
185 function onEvaluate(remoteObject) | |
186 { | |
187 var section = new WebInspector.ObjectPropertiesSection(remoteObject,
title); | |
188 section.expanded = true; | |
189 section.editable = false; | |
190 parentElement.appendChild(section.element); | |
191 } | |
192 this.evaluate(expression, evaluateOptions, onEvaluate); | |
193 return parentElement; | |
194 }, | |
195 | |
196 /** | |
197 * @this {WebInspector.ExtensionAuditCategoryResults} | |
198 * @param {string} expression | |
199 * @param {?Object} evaluateOptions | |
200 * @return {!Element} | |
201 */ | |
202 node: function(expression, evaluateOptions) | |
203 { | |
204 var parentElement = createElement("div"); | |
205 this.evaluate(expression, evaluateOptions, onEvaluate); | |
206 | |
207 /** | |
208 * @param {!WebInspector.RemoteObject} remoteObject | |
209 */ | |
210 function onEvaluate(remoteObject) | |
211 { | |
212 WebInspector.Renderer.renderPromise(remoteObject).then(appendRendere
r).thenOrCatch(remoteObject.release.bind(remoteObject)).done(); | |
213 | |
214 /** | |
215 * @param {!Element} element | |
216 */ | |
217 function appendRenderer(element) | |
218 { | |
219 parentElement.appendChild(element); | |
220 } | |
221 } | |
222 return parentElement; | |
223 } | |
224 } | |
225 | |
226 WebInspector.ExtensionAuditCategoryResults._lastId = 0; | |
OLD | NEW |