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 define('main', [ | 19 define('main', [ |
| 20 'mojo/public/js/bindings', |
| 21 'mojo/public/js/core', |
20 'mojo/public/js/connection', | 22 'mojo/public/js/connection', |
21 'chrome/browser/ui/webui/omnibox/omnibox.mojom', | 23 'chrome/browser/ui/webui/omnibox/omnibox.mojom', |
22 'content/public/renderer/service_provider', | 24 'content/public/renderer/service_provider', |
23 ], function(connector, browser, serviceProvider) { | 25 ], function(bindings, core, connection, browser, serviceProvider) { |
24 'use strict'; | 26 'use strict'; |
25 | 27 |
26 var connection; | |
27 var page; | 28 var page; |
28 | 29 |
29 /** | 30 /** |
30 * Register our event handlers. | 31 * Register our event handlers. |
31 */ | 32 */ |
32 function initialize() { | 33 function initialize() { |
33 $('omnibox-input-form').addEventListener( | 34 $('omnibox-input-form').addEventListener( |
34 'submit', startOmniboxQuery, false); | 35 'submit', startOmniboxQuery, false); |
35 $('prevent-inline-autocomplete').addEventListener( | 36 $('prevent-inline-autocomplete').addEventListener( |
36 'change', startOmniboxQuery); | 37 'change', startOmniboxQuery); |
(...skipping 27 matching lines...) Expand all Loading... |
64 function startOmniboxQuery(event) { | 65 function startOmniboxQuery(event) { |
65 // First, clear the results of past calls (if any). | 66 // First, clear the results of past calls (if any). |
66 progressiveAutocompleteResults = []; | 67 progressiveAutocompleteResults = []; |
67 // Then, call chrome with a five-element list: | 68 // Then, call chrome with a five-element list: |
68 // - first element: the value in the text box | 69 // - first element: the value in the text box |
69 // - second element: the location of the cursor in the text box | 70 // - second element: the location of the cursor in the text box |
70 // - third element: the value of prevent-inline-autocomplete | 71 // - third element: the value of prevent-inline-autocomplete |
71 // - forth element: the value of prefer-keyword | 72 // - forth element: the value of prefer-keyword |
72 // - fifth element: the value of page-classification | 73 // - fifth element: the value of page-classification |
73 cursorPositionUsed = $('input-text').selectionEnd; | 74 cursorPositionUsed = $('input-text').selectionEnd; |
| 75 var pipe = core.createMessagePipe(); |
| 76 var stub = connection.bindHandleToStub(pipe.handle0, browser.OmniboxPage); |
| 77 bindings.StubBindings(stub).delegate = page; |
| 78 page.stub_ = stub; |
74 page.browser_.startOmniboxQuery( | 79 page.browser_.startOmniboxQuery( |
75 $('input-text').value, | 80 $('input-text').value, |
76 cursorPositionUsed, | 81 cursorPositionUsed, |
77 $('prevent-inline-autocomplete').checked, | 82 $('prevent-inline-autocomplete').checked, |
78 $('prefer-keyword').checked, | 83 $('prefer-keyword').checked, |
79 parseInt($('page-classification').value)); | 84 parseInt($('page-classification').value), |
| 85 pipe.handle1); |
80 // Cancel the submit action. i.e., don't submit the form. (We handle | 86 // Cancel the submit action. i.e., don't submit the form. (We handle |
81 // display the results solely with Javascript.) | 87 // display the results solely with Javascript.) |
82 event.preventDefault(); | 88 event.preventDefault(); |
83 } | 89 } |
84 | 90 |
85 /** | 91 /** |
86 * Returns a simple object with information about how to display an | 92 * Returns a simple object with information about how to display an |
87 * autocomplete result data field. | 93 * autocomplete result data field. |
88 * @param {string} header the label for the top of the column/table. | 94 * @param {string} header the label for the top of the column/table. |
89 * @param {string} urlLabelForHeader the URL that the header should point | 95 * @param {string} urlLabelForHeader the URL that the header should point |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 var startIndex = showIncompleteResults ? 0 : | 420 var startIndex = showIncompleteResults ? 0 : |
415 progressiveAutocompleteResults.length - 1; | 421 progressiveAutocompleteResults.length - 1; |
416 for (var i = startIndex; i < progressiveAutocompleteResults.length; i++) { | 422 for (var i = startIndex; i < progressiveAutocompleteResults.length; i++) { |
417 addResultToOutput(progressiveAutocompleteResults[i]); | 423 addResultToOutput(progressiveAutocompleteResults[i]); |
418 } | 424 } |
419 } | 425 } |
420 } | 426 } |
421 | 427 |
422 function OmniboxPageImpl(browser) { | 428 function OmniboxPageImpl(browser) { |
423 this.browser_ = browser; | 429 this.browser_ = browser; |
424 page = this; | |
425 initialize(); | 430 initialize(); |
426 } | 431 } |
427 | 432 |
428 OmniboxPageImpl.prototype = | 433 OmniboxPageImpl.prototype = |
429 Object.create(browser.OmniboxPage.stubClass.prototype); | 434 Object.create(browser.OmniboxPage.stubClass.prototype); |
430 | 435 |
431 OmniboxPageImpl.prototype.handleNewAutocompleteResult = function(result) { | 436 OmniboxPageImpl.prototype.handleNewAutocompleteResult = function(result) { |
432 progressiveAutocompleteResults.push(result); | 437 progressiveAutocompleteResults.push(result); |
433 refresh(); | 438 refresh(); |
434 }; | 439 }; |
435 | 440 |
436 return function() { | 441 return function() { |
437 connection = new connector.Connection( | 442 var browserProxy = connection.bindHandleToProxy( |
438 serviceProvider.connectToService( | 443 serviceProvider.connectToService( |
439 browser.OmniboxUIHandlerMojo.name), | 444 browser.OmniboxUIHandlerMojo.name), |
440 OmniboxPageImpl, | 445 browser.OmniboxUIHandlerMojo); |
441 browser.OmniboxUIHandlerMojo.proxyClass); | 446 page = new OmniboxPageImpl(browserProxy); |
442 }; | 447 }; |
443 }); | 448 }); |
OLD | NEW |