| 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 bindings 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'); |
| 9 |
| 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 9 var sendRequest = require('sendRequest').sendRequest; | 11 var sendRequest = require('sendRequest').sendRequest; |
| 10 | 12 |
| 11 // 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 |
| 12 // for |AutocompleteMatch::contents|. | 14 // for |AutocompleteMatch::contents|. |
| 13 function sanitizeString(text, shouldTrim) { | 15 function sanitizeString(text, shouldTrim) { |
| 14 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. | 16 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. |
| 15 // 0x2028 = line separator; 0x2029 = paragraph separator. | 17 // 0x2028 = line separator; 0x2029 = paragraph separator. |
| 16 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; | 18 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; |
| 17 if (shouldTrim) | 19 if (shouldTrim) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 73 |
| 72 // Descend into all other nodes, even if they are unrecognized, for | 74 // Descend into all other nodes, even if they are unrecognized, for |
| 73 // forward compat. | 75 // forward compat. |
| 74 arguments.callee(child); | 76 arguments.callee(child); |
| 75 } | 77 } |
| 76 })(root); | 78 })(root); |
| 77 | 79 |
| 78 return result; | 80 return result; |
| 79 } | 81 } |
| 80 | 82 |
| 81 chromeHidden.registerCustomHook('omnibox', function(bindingsAPI) { | 83 binding.registerCustomHook(function(bindingsAPI) { |
| 82 var apiFunctions = bindingsAPI.apiFunctions; | 84 var apiFunctions = bindingsAPI.apiFunctions; |
| 83 | 85 |
| 84 apiFunctions.setHandleRequest('setDefaultSuggestion', function(details) { | 86 apiFunctions.setHandleRequest('setDefaultSuggestion', function(details) { |
| 85 var parseResult = parseOmniboxDescription(details.description); | 87 var parseResult = parseOmniboxDescription(details.description); |
| 86 sendRequest(this.name, [parseResult], this.definition.parameters); | 88 sendRequest(this.name, [parseResult], this.definition.parameters); |
| 87 }); | 89 }); |
| 88 | 90 |
| 89 apiFunctions.setUpdateArgumentsPostValidate( | 91 apiFunctions.setUpdateArgumentsPostValidate( |
| 90 'sendSuggestions', function(requestId, userSuggestions) { | 92 'sendSuggestions', function(requestId, userSuggestions) { |
| 91 var suggestions = []; | 93 var suggestions = []; |
| 92 for (var i = 0; i < userSuggestions.length; i++) { | 94 for (var i = 0; i < userSuggestions.length; i++) { |
| 93 var parseResult = parseOmniboxDescription( | 95 var parseResult = parseOmniboxDescription( |
| 94 userSuggestions[i].description); | 96 userSuggestions[i].description); |
| 95 parseResult.content = userSuggestions[i].content; | 97 parseResult.content = userSuggestions[i].content; |
| 96 suggestions.push(parseResult); | 98 suggestions.push(parseResult); |
| 97 } | 99 } |
| 98 return [requestId, suggestions]; | 100 return [requestId, suggestions]; |
| 99 }); | 101 }); |
| 100 }); | 102 }); |
| 101 | 103 |
| 102 chromeHidden.Event.registerArgumentMassager('omnibox.onInputChanged', | 104 chromeHidden.Event.registerArgumentMassager('omnibox.onInputChanged', |
| 103 function(args, dispatch) { | 105 function(args, dispatch) { |
| 104 var text = args[0]; | 106 var text = args[0]; |
| 105 var requestId = args[1]; | 107 var requestId = args[1]; |
| 106 var suggestCallback = function(suggestions) { | 108 var suggestCallback = function(suggestions) { |
| 107 chrome.omnibox.sendSuggestions(requestId, suggestions); | 109 chrome.omnibox.sendSuggestions(requestId, suggestions); |
| 108 }; | 110 }; |
| 109 dispatch([text, suggestCallback]); | 111 dispatch([text, suggestCallback]); |
| 110 }); | 112 }); |
| 113 |
| 114 exports.binding = binding.generate(); |
| OLD | NEW |