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