| 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 input ime API. Only injected into the | 5 // Custom bindings for the input ime API. Only injected into the |
| 6 // v8 contexts for extensions which have permission for the API. | 6 // v8 contexts for extensions which have permission for the API. |
| 7 | 7 |
| 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 8 (function() { |
| 9 | 9 |
| 10 chromeHidden.registerCustomHook('input.ime', function() { | 10 native function GetChromeHidden(); |
| 11 |
| 12 GetChromeHidden().registerCustomHook('input.ime', function() { |
| 11 chrome.input.ime.onKeyEvent.dispatch = function(engineID, keyData) { | 13 chrome.input.ime.onKeyEvent.dispatch = function(engineID, keyData) { |
| 12 var args = Array.prototype.slice.call(arguments); | 14 var args = Array.prototype.slice.call(arguments); |
| 13 if (this.validate_) { | 15 if (this.validate_) { |
| 14 var validationErrors = this.validate_(args); | 16 var validationErrors = this.validate_(args); |
| 15 if (validationErrors) { | 17 if (validationErrors) { |
| 16 chrome.input.ime.eventHandled(requestId, false); | 18 chrome.input.ime.eventHandled(requestId, false); |
| 17 return validationErrors; | 19 return validationErrors; |
| 18 } | 20 } |
| 19 } | 21 } |
| 20 if (this.listeners_.length > 1) { | 22 if (this.listeners_.length > 1) { |
| 21 console.error('Too many listeners for onKeyEvent: ' + e.stack); | 23 console.error('Too many listeners for onKeyEvent: ' + e.stack); |
| 22 chrome.input.ime.eventHandled(requestId, false); | 24 chrome.input.ime.eventHandled(requestId, false); |
| 23 return; | 25 return; |
| 24 } | 26 } |
| 25 for (var i = 0; i < this.listeners_.length; i++) { | 27 for (var i = 0; i < this.listeners_.length; i++) { |
| 26 try { | 28 try { |
| 27 var requestId = keyData.requestId; | 29 var requestId = keyData.requestId; |
| 28 var result = this.listeners_[i].apply(null, args); | 30 var result = this.listeners_[i].apply(null, args); |
| 29 chrome.input.ime.eventHandled(requestId, result); | 31 chrome.input.ime.eventHandled(requestId, result); |
| 30 } catch (e) { | 32 } catch (e) { |
| 31 console.error('Error in event handler for onKeyEvent: ' + e.stack); | 33 console.error('Error in event handler for onKeyEvent: ' + e.stack); |
| 32 chrome.input.ime.eventHandled(requestId, false); | 34 chrome.input.ime.eventHandled(requestId, false); |
| 33 } | 35 } |
| 34 } | 36 } |
| 35 }; | 37 }; |
| 36 }); | 38 }); |
| 39 |
| 40 })(); |
| OLD | NEW |