| 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 // Custom binding for the omnibox API. Only injected into the v8 contexts | 5 // Custom binding for the omnibox API. Only injected into the v8 contexts |
| 6 // for extensions which have permission for the omnibox API. | 6 // for extensions which have permission for the omnibox API. |
| 7 | 7 |
| 8 var binding = require('binding').Binding.create('omnibox'); | 8 var binding = require('binding').Binding.create('omnibox'); |
| 9 | 9 |
| 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 10 var eventBindings = require('event_bindings'); |
| 11 var sendRequest = require('sendRequest').sendRequest; | 11 var sendRequest = require('sendRequest').sendRequest; |
| 12 | 12 |
| 13 // Remove invalid characters from |text| so that it is suitable to use | 13 // Remove invalid characters from |text| so that it is suitable to use |
| 14 // for |AutocompleteMatch::contents|. | 14 // for |AutocompleteMatch::contents|. |
| 15 function sanitizeString(text, shouldTrim) { | 15 function sanitizeString(text, shouldTrim) { |
| 16 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. | 16 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. |
| 17 // 0x2028 = line separator; 0x2029 = paragraph separator. | 17 // 0x2028 = line separator; 0x2029 = paragraph separator. |
| 18 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; | 18 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; |
| 19 if (shouldTrim) | 19 if (shouldTrim) |
| 20 text = text.trimLeft(); | 20 text = text.trimLeft(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 for (var i = 0; i < userSuggestions.length; i++) { | 104 for (var i = 0; i < userSuggestions.length; i++) { |
| 105 var parseResult = parseOmniboxDescription( | 105 var parseResult = parseOmniboxDescription( |
| 106 userSuggestions[i].description); | 106 userSuggestions[i].description); |
| 107 parseResult.content = userSuggestions[i].content; | 107 parseResult.content = userSuggestions[i].content; |
| 108 suggestions.push(parseResult); | 108 suggestions.push(parseResult); |
| 109 } | 109 } |
| 110 return [requestId, suggestions]; | 110 return [requestId, suggestions]; |
| 111 }); | 111 }); |
| 112 }); | 112 }); |
| 113 | 113 |
| 114 chromeHidden.Event.registerArgumentMassager('omnibox.onInputChanged', | 114 eventBindings.registerArgumentMassager('omnibox.onInputChanged', |
| 115 function(args, dispatch) { | 115 function(args, dispatch) { |
| 116 var text = args[0]; | 116 var text = args[0]; |
| 117 var requestId = args[1]; | 117 var requestId = args[1]; |
| 118 var suggestCallback = function(suggestions) { | 118 var suggestCallback = function(suggestions) { |
| 119 chrome.omnibox.sendSuggestions(requestId, suggestions); | 119 chrome.omnibox.sendSuggestions(requestId, suggestions); |
| 120 }; | 120 }; |
| 121 dispatch([text, suggestCallback]); | 121 dispatch([text, suggestCallback]); |
| 122 }); | 122 }); |
| 123 | 123 |
| 124 exports.binding = binding.generate(); | 124 exports.binding = binding.generate(); |
| OLD | NEW |