Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/resources/omnibox/omnibox.js

Issue 9289028: Make chrome://omnibox/ be able to report per-provider matches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove friend. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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('show-details').addEventListener(
arv (Not doing code reviews) 2012/01/31 18:55:36 How about listing to an ancestor? $('omnibox-inpu
Mark P 2012/01/31 20:10:40 Sure. Done. See corresponding HTML changes (if y
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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 * { 'done': false,
192 * 'time_since_omnibox_started_ms': 15, 192 * 'time_since_omnibox_started_ms': 15,
193 * 'num_items': 4, 193 * 'combined_results' :
194 * 'item_0': { 194 * { 'num_items': 4,
195 * 'destination_url': 'http://mail.google.com', 195 * 'item_0':
196 * 'provider_name': 'HistoryURL', 196 * { 'destination_url': 'http://mail.google.com',
arv (Not doing code reviews) 2012/01/31 18:55:36 { 'key': value ... }
Mark P 2012/01/31 20:10:40 I was wondering if someone who call me on the inco
197 * 'relevance': 1410, 197 * 'provider_name': 'HistoryURL',
198 * 'is_default_match': true, 198 * 'relevance': 1410,
199 * ... 199 * ...
200 * } 200 * }
201 * 'item_1: { 201 * 'item_1: {
202 * ... 202 * ...
203 * } 203 * }
204 * ... 204 * ...
205 * }
206 * 'results_by_provider':
207 * { 'HistoryURL' :
208 * { 'num_items': 3,
209 * ...
210 * }
211 * 'Search' :
212 * { 'num_items': 1,
213 * ...
214 * }
215 * ...
216 * }
205 * } 217 * }
206 * } 218 * }
207 * </pre> 219 * </pre>
208 * For information on how the result is packed, see the 220 * For more information on how the result is packed, see the
209 * corresponding code in chrome/browser/ui/webui/omnibox_ui.cc 221 * corresponding code in chrome/browser/ui/webui/omnibox_ui.cc
210 */ 222 */
211 function addResultToOutput(result) { 223 function addResultToOutput(result) {
212 var output = document.getElementById('omnibox-debug-text'); 224 var output = document.getElementById('omnibox-debug-text');
213 var inDetailedMode = document.getElementById('show-details').checked; 225 var inDetailedMode = document.getElementById('show-details').checked;
214 var showIncompleteResults = 226 var showIncompleteResults =
215 document.getElementById('show-incomplete-results').checked; 227 document.getElementById('show-incomplete-results').checked;
228 var showPerProviderResults =
229 document.getElementById('show-all-providers').checked;
216 230
217 // Output the result-level features in detailed mode and in 231 // Output the result-level features in detailed mode and in
218 // show incomplete results mode. We do the latter because without 232 // show incomplete results mode. We do the latter because without
219 // these result-level features, one can't make sense of each 233 // these result-level features, one can't make sense of each
220 // batch of results. 234 // batch of results.
221 if (inDetailedMode || showIncompleteResults) { 235 if (inDetailedMode || showIncompleteResults) {
222 var p1 = document.createElement('p'); 236 var p1 = document.createElement('p');
223 p1.textContent = 'elapsed time = ' + 237 p1.textContent = 'elapsed time = ' +
224 result.time_since_omnibox_started_ms + 'ms'; 238 result.time_since_omnibox_started_ms + 'ms';
225 output.appendChild(p1); 239 output.appendChild(p1);
226 var p2 = document.createElement('p'); 240 var p2 = document.createElement('p');
227 p2.textContent = 'all providers done = ' + result.done; 241 p2.textContent = 'all providers done = ' + result.done;
228 output.appendChild(p2); 242 output.appendChild(p2);
229 } 243 }
230 244
245 if (!showPerProviderResults) {
246 // Add combined/merged result table (without label).
247 output.appendChild(addResultTableToOutput(result.combined_results));
248 } else {
249 // Add combined/merged result table with label.
250 var p = document.createElement('p');
251 p.appendChild(document.createTextNode('combined results:'));
arv (Not doing code reviews) 2012/01/31 18:55:36 textContent
Mark P 2012/01/31 20:10:40 Done.
252 p.appendChild(addResultTableToOutput(result.combined_results));
253 output.appendChild(p);
254 // Add the pre-provider result tables with labels.
255 for (var provider in result.results_by_provider) {
256 p = document.createElement('p');
257 p.appendChild(document.createTextNode(provider + ' provider results:'));
258 p.appendChild(addResultTableToOutput(
259 result.results_by_provider[provider]));
260 output.appendChild(p);
261 }
262 }
263 }
264
265 /**
266 * @param {Object} |result| is either the combined_results component
arv (Not doing code reviews) 2012/01/31 18:55:36 @param {Type} paramName Description.
Mark P 2012/01/31 20:10:40 Fixed.
267 * of the structure described in the comment by addResultToOutput()
268 * above or is one of the per-provider results in the structure.
269 * (Both have the same format.)
270 * @return {HTMLTableCellElement} that is a user-readable HTML
271 * representation of this object.
272 */
273 function addResultTableToOutput(result) {
274 var inDetailedMode = document.getElementById('show-details').checked;
231 // Create a table to hold all the autocomplete items. 275 // Create a table to hold all the autocomplete items.
232 var table = document.createElement('table'); 276 var table = document.createElement('table');
233 table.className = 'autocomplete-results-table'; 277 table.className = 'autocomplete-results-table';
234 table.appendChild(createAutocompleteResultTableHeader()); 278 table.appendChild(createAutocompleteResultTableHeader());
235 // Loop over every autocomplete item and add it as a row in the table. 279 // Loop over every autocomplete item and add it as a row in the table.
236 for (var i = 0; i < result.num_items; i++) { 280 for (var i = 0; i < result.num_items; i++) {
237 var autocompleteSuggestion = result['item_' + i]; 281 var autocompleteSuggestion = result['item_' + i];
238 var row = document.createElement('tr'); 282 var row = document.createElement('tr');
239 // Loop over all the columns/properties and output either them 283 // Loop over all the columns/properties and output either them
240 // all (if we're in detailed mode) or only the ones marked displayAlways. 284 // all (if we're in detailed mode) or only the ones marked displayAlways.
(...skipping 20 matching lines...) Expand all
261 if (!displayedProperties[key]) { 305 if (!displayedProperties[key]) {
262 var cell = document.createElement('td'); 306 var cell = document.createElement('td');
263 cell.textContent = key + '=' + autocompleteSuggestion[key]; 307 cell.textContent = key + '=' + autocompleteSuggestion[key];
264 row.appendChild(cell); 308 row.appendChild(cell);
265 } 309 }
266 } 310 }
267 } 311 }
268 312
269 table.appendChild(row); 313 table.appendChild(row);
270 } 314 }
271 output.appendChild(table); 315 return table;
272 } 316 }
273 317
274 /* Repaints the page based on the contents of the array 318 /* Repaints the page based on the contents of the array
275 * progressiveAutocompleteResults, which represents consecutive 319 * progressiveAutocompleteResults, which represents consecutive
276 * autocomplete results. We only display the last (most recent) 320 * autocomplete results. We only display the last (most recent)
277 * entry unless we're asked to display incomplete results. For an 321 * entry unless we're asked to display incomplete results. For an
278 * example of the output, play with chrome://omnibox/ 322 * example of the output, play with chrome://omnibox/
279 */ 323 */
280 function refresh() { 324 function refresh() {
281 // Erase whatever is currently being displayed. 325 // Erase whatever is currently being displayed.
(...skipping 11 matching lines...) Expand all
293 } 337 }
294 338
295 return { 339 return {
296 initialize: initialize, 340 initialize: initialize,
297 startOmniboxQuery: startOmniboxQuery, 341 startOmniboxQuery: startOmniboxQuery,
298 handleNewAutocompleteResult: handleNewAutocompleteResult 342 handleNewAutocompleteResult: handleNewAutocompleteResult
299 }; 343 };
300 }); 344 });
301 345
302 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); 346 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/omnibox/omnibox.html ('k') | chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698