| 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. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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('show-details').addEventListener( |
| 29 'change', refresh); | 29 'change', refresh); |
| 30 document.getElementById('show-incomplete-results').addEventListener( | 30 document.getElementById('show-incomplete-results').addEventListener( |
| 31 'change', refresh); | 31 'change', refresh); |
| 32 document.getElementById('show-all-providers').addEventListener( |
| 33 'change', refresh); |
| 32 } | 34 } |
| 33 | 35 |
| 34 /** | 36 /** |
| 35 * @type {Array.<Object>} an array of all autocomplete results we've seen | 37 * @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 | 38 * for this query. We append to this list once for every call to |
| 37 * handleNewAutocompleteResult. For details on the structure of | 39 * handleNewAutocompleteResult. For details on the structure of |
| 38 * the object inside, see the comments by addResultToOutput. | 40 * the object inside, see the comments by addResultToOutput. |
| 39 */ | 41 */ |
| 40 var progressiveAutocompleteResults = []; | 42 var progressiveAutocompleteResults = []; |
| 41 | 43 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 * @type {Array.<Object>} | 84 * @type {Array.<Object>} |
| 83 * @const | 85 * @const |
| 84 */ | 86 */ |
| 85 var PROPERTY_OUTPUT_ORDER = [ | 87 var PROPERTY_OUTPUT_ORDER = [ |
| 86 new PresentationInfoRecord('URL', '', 'destination_url', true), | 88 new PresentationInfoRecord('URL', '', 'destination_url', true), |
| 87 new PresentationInfoRecord('Provider Name', '', 'provider_name', true), | 89 new PresentationInfoRecord('Provider Name', '', 'provider_name', true), |
| 88 new PresentationInfoRecord('Type', '', 'type', true), | 90 new PresentationInfoRecord('Type', '', 'type', true), |
| 89 new PresentationInfoRecord('Relevance', '', 'relevance', true), | 91 new PresentationInfoRecord('Relevance', '', 'relevance', true), |
| 90 new PresentationInfoRecord('Starred', '', 'starred', false), | 92 new PresentationInfoRecord('Starred', '', 'starred', false), |
| 91 new PresentationInfoRecord( | 93 new PresentationInfoRecord( |
| 92 '== default_match iterator', '', 'is_default_match', false), | |
| 93 new PresentationInfoRecord( | |
| 94 'Is History What You Typed Match', '', | 94 'Is History What You Typed Match', '', |
| 95 'is_history_what_you_typed_match', false), | 95 'is_history_what_you_typed_match', false), |
| 96 new PresentationInfoRecord('Description', '', 'description', false), | 96 new PresentationInfoRecord('Description', '', 'description', false), |
| 97 new PresentationInfoRecord('Contents', '', 'contents', false), | 97 new PresentationInfoRecord('Contents', '', 'contents', false), |
| 98 new PresentationInfoRecord('Fill Into Edit', '', 'fill_into_edit', false), | 98 new PresentationInfoRecord('Fill Into Edit', '', 'fill_into_edit', false), |
| 99 new PresentationInfoRecord( | 99 new PresentationInfoRecord( |
| 100 'Inline Autocomplete Offset', '', 'inline_autocomplete_offset', false), | 100 'Inline Autocomplete Offset', '', 'inline_autocomplete_offset', false), |
| 101 new PresentationInfoRecord('Deletable', '', 'deletable', false), | 101 new PresentationInfoRecord('Deletable', '', 'deletable', false), |
| 102 new PresentationInfoRecord('From Previous', '', 'from_previous', false), | 102 new PresentationInfoRecord('From Previous', '', 'from_previous', false), |
| 103 new PresentationInfoRecord( | 103 new PresentationInfoRecord( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 /** | 181 /** |
| 182 * Appends some human-readable information about the provided | 182 * Appends some human-readable information about the provided |
| 183 * autocomplete result to the HTML node with id omnibox-debug-text. | 183 * autocomplete result to the HTML node with id omnibox-debug-text. |
| 184 * The current human-readable form is a few lines about general | 184 * The current human-readable form is a few lines about general |
| 185 * autocomplete result statistics followed by a table with one line | 185 * autocomplete result statistics followed by a table with one line |
| 186 * for each autocomplete match. The input parameter result is a | 186 * for each autocomplete match. The input parameter result is a |
| 187 * complex Object with lots of information about various | 187 * complex Object with lots of information about various |
| 188 * autocomplete matches. Here's an example of what it looks like: | 188 * autocomplete matches. Here's an example of what it looks like: |
| 189 * <pre> | 189 * <pre> |
| 190 * {@code | 190 * {@code |
| 191 * { 'done': false, | 191 * { |
| 192 * 'done': false, |
| 192 * 'time_since_omnibox_started_ms': 15, | 193 * 'time_since_omnibox_started_ms': 15, |
| 193 * 'num_items': 4, | 194 * 'combined_results' : { |
| 194 * 'item_0': { | 195 * 'num_items': 4, |
| 195 * 'destination_url': 'http://mail.google.com', | 196 * 'item_0': { |
| 196 * 'provider_name': 'HistoryURL', | 197 * 'destination_url': 'http://mail.google.com', |
| 197 * 'relevance': 1410, | 198 * 'provider_name': 'HistoryURL', |
| 198 * 'is_default_match': true, | 199 * 'relevance': 1410, |
| 200 * ... |
| 201 * } |
| 202 * 'item_1: { |
| 203 * ... |
| 204 * } |
| 199 * ... | 205 * ... |
| 200 * } | 206 * } |
| 201 * 'item_1: { | 207 * 'results_by_provider': { |
| 208 * 'HistoryURL' : { |
| 209 * 'num_items': 3, |
| 210 * ... |
| 211 * } |
| 212 * 'Search' : { |
| 213 * 'num_items': 1, |
| 214 * ... |
| 215 * } |
| 202 * ... | 216 * ... |
| 203 * } | 217 * } |
| 204 * ... | |
| 205 * } | 218 * } |
| 206 * } | 219 * } |
| 207 * </pre> | 220 * </pre> |
| 208 * For information on how the result is packed, see the | 221 * For more information on how the result is packed, see the |
| 209 * corresponding code in chrome/browser/ui/webui/omnibox_ui.cc | 222 * corresponding code in chrome/browser/ui/webui/omnibox_ui.cc |
| 210 */ | 223 */ |
| 211 function addResultToOutput(result) { | 224 function addResultToOutput(result) { |
| 212 var output = document.getElementById('omnibox-debug-text'); | 225 var output = document.getElementById('omnibox-debug-text'); |
| 213 var inDetailedMode = document.getElementById('show-details').checked; | 226 var inDetailedMode = document.getElementById('show-details').checked; |
| 214 var showIncompleteResults = | 227 var showIncompleteResults = |
| 215 document.getElementById('show-incomplete-results').checked; | 228 document.getElementById('show-incomplete-results').checked; |
| 229 var showPerProviderResults = |
| 230 document.getElementById('show-all-providers').checked; |
| 216 | 231 |
| 217 // Output the result-level features in detailed mode and in | 232 // Output the result-level features in detailed mode and in |
| 218 // show incomplete results mode. We do the latter because without | 233 // show incomplete results mode. We do the latter because without |
| 219 // these result-level features, one can't make sense of each | 234 // these result-level features, one can't make sense of each |
| 220 // batch of results. | 235 // batch of results. |
| 221 if (inDetailedMode || showIncompleteResults) { | 236 if (inDetailedMode || showIncompleteResults) { |
| 222 var p1 = document.createElement('p'); | 237 var p1 = document.createElement('p'); |
| 223 p1.textContent = 'elapsed time = ' + | 238 p1.textContent = 'elapsed time = ' + |
| 224 result.time_since_omnibox_started_ms + 'ms'; | 239 result.time_since_omnibox_started_ms + 'ms'; |
| 225 output.appendChild(p1); | 240 output.appendChild(p1); |
| 226 var p2 = document.createElement('p'); | 241 var p2 = document.createElement('p'); |
| 227 p2.textContent = 'all providers done = ' + result.done; | 242 p2.textContent = 'all providers done = ' + result.done; |
| 228 output.appendChild(p2); | 243 output.appendChild(p2); |
| 229 } | 244 } |
| 230 | 245 |
| 246 if (!showPerProviderResults) { |
| 247 // Add combined/merged result table (without label). |
| 248 output.appendChild(addResultTableToOutput(result.combined_results)); |
| 249 } else { |
| 250 // Add combined/merged result table with label. |
| 251 var p = document.createElement('p'); |
| 252 p.textContent = 'combined results:'; |
| 253 p.appendChild(addResultTableToOutput(result.combined_results)); |
| 254 output.appendChild(p); |
| 255 // Add the pre-provider result tables with labels. |
| 256 for (var provider in result.results_by_provider) { |
| 257 p = document.createElement('p'); |
| 258 p.appendChild(document.createTextNode(provider + ' provider results:')); |
| 259 p.appendChild(addResultTableToOutput( |
| 260 result.results_by_provider[provider])); |
| 261 output.appendChild(p); |
| 262 } |
| 263 } |
| 264 } |
| 265 |
| 266 /** |
| 267 * @param {Object} result either the combined_results component of |
| 268 * the structure described in the comment by addResultToOutput() |
| 269 * above or one of the per-provider results in the structure. |
| 270 * (Both have the same format.) |
| 271 * @return {HTMLTableCellElement} that is a user-readable HTML |
| 272 * representation of this object. |
| 273 */ |
| 274 function addResultTableToOutput(result) { |
| 275 var inDetailedMode = document.getElementById('show-details').checked; |
| 231 // Create a table to hold all the autocomplete items. | 276 // Create a table to hold all the autocomplete items. |
| 232 var table = document.createElement('table'); | 277 var table = document.createElement('table'); |
| 233 table.className = 'autocomplete-results-table'; | 278 table.className = 'autocomplete-results-table'; |
| 234 table.appendChild(createAutocompleteResultTableHeader()); | 279 table.appendChild(createAutocompleteResultTableHeader()); |
| 235 // Loop over every autocomplete item and add it as a row in the table. | 280 // Loop over every autocomplete item and add it as a row in the table. |
| 236 for (var i = 0; i < result.num_items; i++) { | 281 for (var i = 0; i < result.num_items; i++) { |
| 237 var autocompleteSuggestion = result['item_' + i]; | 282 var autocompleteSuggestion = result['item_' + i]; |
| 238 var row = document.createElement('tr'); | 283 var row = document.createElement('tr'); |
| 239 // Loop over all the columns/properties and output either them | 284 // Loop over all the columns/properties and output either them |
| 240 // all (if we're in detailed mode) or only the ones marked displayAlways. | 285 // all (if we're in detailed mode) or only the ones marked displayAlways. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 261 if (!displayedProperties[key]) { | 306 if (!displayedProperties[key]) { |
| 262 var cell = document.createElement('td'); | 307 var cell = document.createElement('td'); |
| 263 cell.textContent = key + '=' + autocompleteSuggestion[key]; | 308 cell.textContent = key + '=' + autocompleteSuggestion[key]; |
| 264 row.appendChild(cell); | 309 row.appendChild(cell); |
| 265 } | 310 } |
| 266 } | 311 } |
| 267 } | 312 } |
| 268 | 313 |
| 269 table.appendChild(row); | 314 table.appendChild(row); |
| 270 } | 315 } |
| 271 output.appendChild(table); | 316 return table; |
| 272 } | 317 } |
| 273 | 318 |
| 274 /* Repaints the page based on the contents of the array | 319 /* Repaints the page based on the contents of the array |
| 275 * progressiveAutocompleteResults, which represents consecutive | 320 * progressiveAutocompleteResults, which represents consecutive |
| 276 * autocomplete results. We only display the last (most recent) | 321 * autocomplete results. We only display the last (most recent) |
| 277 * entry unless we're asked to display incomplete results. For an | 322 * entry unless we're asked to display incomplete results. For an |
| 278 * example of the output, play with chrome://omnibox/ | 323 * example of the output, play with chrome://omnibox/ |
| 279 */ | 324 */ |
| 280 function refresh() { | 325 function refresh() { |
| 281 // Erase whatever is currently being displayed. | 326 // Erase whatever is currently being displayed. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 293 } | 338 } |
| 294 | 339 |
| 295 return { | 340 return { |
| 296 initialize: initialize, | 341 initialize: initialize, |
| 297 startOmniboxQuery: startOmniboxQuery, | 342 startOmniboxQuery: startOmniboxQuery, |
| 298 handleNewAutocompleteResult: handleNewAutocompleteResult | 343 handleNewAutocompleteResult: handleNewAutocompleteResult |
| 299 }; | 344 }; |
| 300 }); | 345 }); |
| 301 | 346 |
| 302 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); | 347 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); |
| OLD | NEW |