OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Javascript for omnibox.html, served from chrome://omnibox/ | 6 * Javascript for omnibox.html, served from chrome://omnibox/ |
7 * This is used to debug omnibox ranking. The user enters some text | 7 * This is used to debug omnibox ranking. The user enters some text |
8 * into a box, submits it, and then sees lots of debug information | 8 * into a box, submits it, and then sees lots of debug information |
9 * from the autocompleter that shows what omnibox would do with that | 9 * from the autocompleter that shows what omnibox would do with that |
10 * input. | 10 * input. |
11 * | 11 * |
12 * The simple object defined in this javascript file listens for | 12 * The simple object defined in this javascript file listens for |
13 * certain events on omnibox.html, sends (when appropriate) the | 13 * certain events on omnibox.html, sends (when appropriate) the |
14 * input text to C++ code to start the omnibox autcomplete controller | 14 * input text to C++ code to start the omnibox autcomplete controller |
15 * working, and listens from callbacks from the C++ code saying that | 15 * working, and listens from callbacks from the C++ code saying that |
16 * results are available. When results (possibly intermediate ones) | 16 * results are available. When results (possibly intermediate ones) |
17 * are available, the Javascript formats them and displays them. | 17 * are available, the Javascript formats them and displays them. |
18 */ | 18 */ |
19 cr.define('omniboxDebug', function() { | 19 cr.define('omniboxDebug', function() { |
20 'use strict'; | 20 'use strict'; |
21 | 21 |
22 /** | 22 /** |
23 * Register our event handlers. | 23 * Register our event handlers. |
24 */ | 24 */ |
25 function initialize() { | 25 function initialize() { |
26 document.getElementById('omnibox-input-form').addEventListener( | 26 document.getElementById('omnibox-input-form').addEventListener( |
27 'submit', startOmniboxQuery, false); | 27 'submit', startOmniboxQuery, false); |
28 document.getElementById('show-details').addEventListener( | 28 document.getElementById('omnibox-input-form-options').addEventListener( |
29 'change', refresh); | |
30 document.getElementById('show-incomplete-results').addEventListener( | |
31 'change', refresh); | 29 'change', refresh); |
arv (Not doing code reviews)
2012/01/31 20:29:05
you need to pass a third argument here
Mark P
2012/01/31 20:55:34
false?
You do realize that in an earlier code rev
| |
32 } | 30 } |
33 | 31 |
34 /** | 32 /** |
35 * @type {Array.<Object>} an array of all autocomplete results we've seen | 33 * @type {Array.<Object>} an array of all autocomplete results we've seen |
36 * for this query. We append to this list once for every call to | 34 * for this query. We append to this list once for every call to |
37 * handleNewAutocompleteResult. For details on the structure of | 35 * handleNewAutocompleteResult. For details on the structure of |
38 * the object inside, see the comments by addResultToOutput. | 36 * the object inside, see the comments by addResultToOutput. |
39 */ | 37 */ |
40 var progressiveAutocompleteResults = []; | 38 var progressiveAutocompleteResults = []; |
41 | 39 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 * @type {Array.<Object>} | 80 * @type {Array.<Object>} |
83 * @const | 81 * @const |
84 */ | 82 */ |
85 var PROPERTY_OUTPUT_ORDER = [ | 83 var PROPERTY_OUTPUT_ORDER = [ |
86 new PresentationInfoRecord('URL', '', 'destination_url', true), | 84 new PresentationInfoRecord('URL', '', 'destination_url', true), |
87 new PresentationInfoRecord('Provider Name', '', 'provider_name', true), | 85 new PresentationInfoRecord('Provider Name', '', 'provider_name', true), |
88 new PresentationInfoRecord('Type', '', 'type', true), | 86 new PresentationInfoRecord('Type', '', 'type', true), |
89 new PresentationInfoRecord('Relevance', '', 'relevance', true), | 87 new PresentationInfoRecord('Relevance', '', 'relevance', true), |
90 new PresentationInfoRecord('Starred', '', 'starred', false), | 88 new PresentationInfoRecord('Starred', '', 'starred', false), |
91 new PresentationInfoRecord( | 89 new PresentationInfoRecord( |
92 '== default_match iterator', '', 'is_default_match', false), | |
93 new PresentationInfoRecord( | |
94 'Is History What You Typed Match', '', | 90 'Is History What You Typed Match', '', |
95 'is_history_what_you_typed_match', false), | 91 'is_history_what_you_typed_match', false), |
96 new PresentationInfoRecord('Description', '', 'description', false), | 92 new PresentationInfoRecord('Description', '', 'description', false), |
97 new PresentationInfoRecord('Contents', '', 'contents', false), | 93 new PresentationInfoRecord('Contents', '', 'contents', false), |
98 new PresentationInfoRecord('Fill Into Edit', '', 'fill_into_edit', false), | 94 new PresentationInfoRecord('Fill Into Edit', '', 'fill_into_edit', false), |
99 new PresentationInfoRecord( | 95 new PresentationInfoRecord( |
100 'Inline Autocomplete Offset', '', 'inline_autocomplete_offset', false), | 96 'Inline Autocomplete Offset', '', 'inline_autocomplete_offset', false), |
101 new PresentationInfoRecord('Deletable', '', 'deletable', false), | 97 new PresentationInfoRecord('Deletable', '', 'deletable', false), |
102 new PresentationInfoRecord('From Previous', '', 'from_previous', false), | 98 new PresentationInfoRecord('From Previous', '', 'from_previous', false), |
103 new PresentationInfoRecord( | 99 new PresentationInfoRecord( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 /** | 177 /** |
182 * Appends some human-readable information about the provided | 178 * Appends some human-readable information about the provided |
183 * autocomplete result to the HTML node with id omnibox-debug-text. | 179 * autocomplete result to the HTML node with id omnibox-debug-text. |
184 * The current human-readable form is a few lines about general | 180 * The current human-readable form is a few lines about general |
185 * autocomplete result statistics followed by a table with one line | 181 * autocomplete result statistics followed by a table with one line |
186 * for each autocomplete match. The input parameter result is a | 182 * for each autocomplete match. The input parameter result is a |
187 * complex Object with lots of information about various | 183 * complex Object with lots of information about various |
188 * autocomplete matches. Here's an example of what it looks like: | 184 * autocomplete matches. Here's an example of what it looks like: |
189 * <pre> | 185 * <pre> |
190 * {@code | 186 * {@code |
191 * { 'done': false, | 187 * { |
188 * 'done': false, | |
192 * 'time_since_omnibox_started_ms': 15, | 189 * 'time_since_omnibox_started_ms': 15, |
193 * 'num_items': 4, | 190 * 'combined_results' : { |
194 * 'item_0': { | 191 * 'num_items': 4, |
195 * 'destination_url': 'http://mail.google.com', | 192 * 'item_0': { |
196 * 'provider_name': 'HistoryURL', | 193 * 'destination_url': 'http://mail.google.com', |
197 * 'relevance': 1410, | 194 * 'provider_name': 'HistoryURL', |
198 * 'is_default_match': true, | 195 * 'relevance': 1410, |
196 * ... | |
197 * } | |
198 * 'item_1: { | |
199 * ... | |
200 * } | |
199 * ... | 201 * ... |
200 * } | 202 * } |
201 * 'item_1: { | 203 * 'results_by_provider': { |
204 * 'HistoryURL' : { | |
205 * 'num_items': 3, | |
206 * ... | |
207 * } | |
208 * 'Search' : { | |
209 * 'num_items': 1, | |
210 * ... | |
211 * } | |
202 * ... | 212 * ... |
203 * } | 213 * } |
204 * ... | |
205 * } | 214 * } |
206 * } | 215 * } |
207 * </pre> | 216 * </pre> |
208 * For information on how the result is packed, see the | 217 * For more information on how the result is packed, see the |
209 * corresponding code in chrome/browser/ui/webui/omnibox_ui.cc | 218 * corresponding code in chrome/browser/ui/webui/omnibox_ui.cc |
210 */ | 219 */ |
211 function addResultToOutput(result) { | 220 function addResultToOutput(result) { |
212 var output = document.getElementById('omnibox-debug-text'); | 221 var output = document.getElementById('omnibox-debug-text'); |
213 var inDetailedMode = document.getElementById('show-details').checked; | 222 var inDetailedMode = document.getElementById('show-details').checked; |
214 var showIncompleteResults = | 223 var showIncompleteResults = |
215 document.getElementById('show-incomplete-results').checked; | 224 document.getElementById('show-incomplete-results').checked; |
225 var showPerProviderResults = | |
226 document.getElementById('show-all-providers').checked; | |
216 | 227 |
217 // Output the result-level features in detailed mode and in | 228 // Output the result-level features in detailed mode and in |
218 // show incomplete results mode. We do the latter because without | 229 // show incomplete results mode. We do the latter because without |
219 // these result-level features, one can't make sense of each | 230 // these result-level features, one can't make sense of each |
220 // batch of results. | 231 // batch of results. |
221 if (inDetailedMode || showIncompleteResults) { | 232 if (inDetailedMode || showIncompleteResults) { |
222 var p1 = document.createElement('p'); | 233 var p1 = document.createElement('p'); |
223 p1.textContent = 'elapsed time = ' + | 234 p1.textContent = 'elapsed time = ' + |
224 result.time_since_omnibox_started_ms + 'ms'; | 235 result.time_since_omnibox_started_ms + 'ms'; |
225 output.appendChild(p1); | 236 output.appendChild(p1); |
226 var p2 = document.createElement('p'); | 237 var p2 = document.createElement('p'); |
227 p2.textContent = 'all providers done = ' + result.done; | 238 p2.textContent = 'all providers done = ' + result.done; |
228 output.appendChild(p2); | 239 output.appendChild(p2); |
229 } | 240 } |
230 | 241 |
242 if (!showPerProviderResults) { | |
243 // Add combined/merged result table (without label). | |
244 output.appendChild(addResultTableToOutput(result.combined_results)); | |
245 } else { | |
246 // Add combined/merged result table with label. | |
247 var p = document.createElement('p'); | |
248 p.textContent = 'combined results:'; | |
249 p.appendChild(addResultTableToOutput(result.combined_results)); | |
250 output.appendChild(p); | |
251 // Add the pre-provider result tables with labels. | |
252 for (var provider in result.results_by_provider) { | |
253 p = document.createElement('p'); | |
254 p.appendChild(document.createTextNode(provider + ' provider results:')); | |
255 p.appendChild(addResultTableToOutput( | |
256 result.results_by_provider[provider])); | |
257 output.appendChild(p); | |
258 } | |
259 } | |
260 } | |
261 | |
262 /** | |
263 * @param {Object} result either the combined_results component of | |
264 * the structure described in the comment by addResultToOutput() | |
265 * above or one of the per-provider results in the structure. | |
266 * (Both have the same format.) | |
267 * @return {HTMLTableCellElement} that is a user-readable HTML | |
268 * representation of this object. | |
269 */ | |
270 function addResultTableToOutput(result) { | |
271 var inDetailedMode = document.getElementById('show-details').checked; | |
231 // Create a table to hold all the autocomplete items. | 272 // Create a table to hold all the autocomplete items. |
232 var table = document.createElement('table'); | 273 var table = document.createElement('table'); |
233 table.className = 'autocomplete-results-table'; | 274 table.className = 'autocomplete-results-table'; |
234 table.appendChild(createAutocompleteResultTableHeader()); | 275 table.appendChild(createAutocompleteResultTableHeader()); |
235 // Loop over every autocomplete item and add it as a row in the table. | 276 // Loop over every autocomplete item and add it as a row in the table. |
236 for (var i = 0; i < result.num_items; i++) { | 277 for (var i = 0; i < result.num_items; i++) { |
237 var autocompleteSuggestion = result['item_' + i]; | 278 var autocompleteSuggestion = result['item_' + i]; |
238 var row = document.createElement('tr'); | 279 var row = document.createElement('tr'); |
239 // Loop over all the columns/properties and output either them | 280 // Loop over all the columns/properties and output either them |
240 // all (if we're in detailed mode) or only the ones marked displayAlways. | 281 // all (if we're in detailed mode) or only the ones marked displayAlways. |
(...skipping 20 matching lines...) Expand all Loading... | |
261 if (!displayedProperties[key]) { | 302 if (!displayedProperties[key]) { |
262 var cell = document.createElement('td'); | 303 var cell = document.createElement('td'); |
263 cell.textContent = key + '=' + autocompleteSuggestion[key]; | 304 cell.textContent = key + '=' + autocompleteSuggestion[key]; |
264 row.appendChild(cell); | 305 row.appendChild(cell); |
265 } | 306 } |
266 } | 307 } |
267 } | 308 } |
268 | 309 |
269 table.appendChild(row); | 310 table.appendChild(row); |
270 } | 311 } |
271 output.appendChild(table); | 312 return table; |
272 } | 313 } |
273 | 314 |
274 /* Repaints the page based on the contents of the array | 315 /* Repaints the page based on the contents of the array |
275 * progressiveAutocompleteResults, which represents consecutive | 316 * progressiveAutocompleteResults, which represents consecutive |
276 * autocomplete results. We only display the last (most recent) | 317 * autocomplete results. We only display the last (most recent) |
277 * entry unless we're asked to display incomplete results. For an | 318 * entry unless we're asked to display incomplete results. For an |
278 * example of the output, play with chrome://omnibox/ | 319 * example of the output, play with chrome://omnibox/ |
279 */ | 320 */ |
280 function refresh() { | 321 function refresh() { |
281 // Erase whatever is currently being displayed. | 322 // Erase whatever is currently being displayed. |
(...skipping 11 matching lines...) Expand all Loading... | |
293 } | 334 } |
294 | 335 |
295 return { | 336 return { |
296 initialize: initialize, | 337 initialize: initialize, |
297 startOmniboxQuery: startOmniboxQuery, | 338 startOmniboxQuery: startOmniboxQuery, |
298 handleNewAutocompleteResult: handleNewAutocompleteResult | 339 handleNewAutocompleteResult: handleNewAutocompleteResult |
299 }; | 340 }; |
300 }); | 341 }); |
301 | 342 |
302 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); | 343 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); |
OLD | NEW |