| 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 bindings 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 chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 8 (function() { |
| 9 |
| 10 native function GetChromeHidden(); |
| 9 | 11 |
| 10 // Remove invalid characters from |text| so that it is suitable to use | 12 // Remove invalid characters from |text| so that it is suitable to use |
| 11 // for |AutocompleteMatch::contents|. | 13 // for |AutocompleteMatch::contents|. |
| 12 function sanitizeString(text, shouldTrim) { | 14 function sanitizeString(text, shouldTrim) { |
| 13 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. | 15 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. |
| 14 // 0x2028 = line separator; 0x2029 = paragraph separator. | 16 // 0x2028 = line separator; 0x2029 = paragraph separator. |
| 15 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; | 17 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; |
| 16 if (shouldTrim) | 18 if (shouldTrim) |
| 17 text = text.trimLeft(); | 19 text = text.trimLeft(); |
| 18 return text.replace(kRemoveChars, ''); | 20 return text.replace(kRemoveChars, ''); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 72 |
| 71 // Descend into all other nodes, even if they are unrecognized, for | 73 // Descend into all other nodes, even if they are unrecognized, for |
| 72 // forward compat. | 74 // forward compat. |
| 73 arguments.callee(child); | 75 arguments.callee(child); |
| 74 } | 76 } |
| 75 })(root); | 77 })(root); |
| 76 | 78 |
| 77 return result; | 79 return result; |
| 78 } | 80 } |
| 79 | 81 |
| 80 chromeHidden.registerCustomHook('omnibox', function(bindingsAPI) { | 82 GetChromeHidden().registerCustomHook('omnibox', function(bindingsAPI) { |
| 81 var apiFunctions = bindingsAPI.apiFunctions; | 83 var apiFunctions = bindingsAPI.apiFunctions; |
| 82 var sendRequest = bindingsAPI.sendRequest; | 84 var sendRequest = bindingsAPI.sendRequest; |
| 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 chrome.omnibox.onInputChanged.dispatch = | 103 chrome.omnibox.onInputChanged.dispatch = |
| 102 function(text, requestId) { | 104 function(text, requestId) { |
| 103 var suggestCallback = function(suggestions) { | 105 var suggestCallback = function(suggestions) { |
| 104 chrome.omnibox.sendSuggestions(requestId, suggestions); | 106 chrome.omnibox.sendSuggestions(requestId, suggestions); |
| 105 }; | 107 }; |
| 106 chrome.Event.prototype.dispatch.apply(this, [text, suggestCallback]); | 108 chrome.Event.prototype.dispatch.apply(this, [text, suggestCallback]); |
| 107 }; | 109 }; |
| 108 }); | 110 }); |
| 111 |
| 112 })(); |
| OLD | NEW |