| 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 input ime API. Only injected into the | 5 // Custom binding 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 binding = require('binding').Binding.create('input.ime'); | 8 var binding = require('binding').Binding.create('input.ime'); |
| 9 | 9 |
| 10 var Event = require('event_bindings').Event; |
| 11 |
| 10 binding.registerCustomHook(function(api) { | 12 binding.registerCustomHook(function(api) { |
| 11 var input_ime = api.compiledApi; | 13 var input_ime = api.compiledApi; |
| 12 | 14 |
| 13 input_ime.onKeyEvent.dispatchToListener = function(callback, args) { | 15 input_ime.onKeyEvent.dispatchToListener = function(callback, args) { |
| 14 var engineID = args[0]; | 16 var engineID = args[0]; |
| 15 var keyData = args[1]; | 17 var keyData = args[1]; |
| 16 | 18 |
| 17 var result = false; | 19 var result = false; |
| 18 try { | 20 try { |
| 19 result = chrome.Event.prototype.dispatchToListener(callback, args); | 21 result = Event.prototype.dispatchToListener(callback, args); |
| 20 } catch (e) { | 22 } catch (e) { |
| 21 console.error('Error in event handler for onKeyEvent: ' + e.stack); | 23 console.error('Error in event handler for onKeyEvent: ' + e.stack); |
| 22 } | 24 } |
| 23 if (!input_ime.onKeyEvent.async) | 25 if (!input_ime.onKeyEvent.async) |
| 24 input_ime.keyEventHandled(keyData.requestId, result); | 26 input_ime.keyEventHandled(keyData.requestId, result); |
| 25 }; | 27 }; |
| 26 | 28 |
| 27 input_ime.onKeyEvent.addListener = function(cb, opt_extraInfo) { | 29 input_ime.onKeyEvent.addListener = function(cb, opt_extraInfo) { |
| 28 input_ime.onKeyEvent.async = false; | 30 input_ime.onKeyEvent.async = false; |
| 29 if (opt_extraInfo instanceof Array) { | 31 if (opt_extraInfo instanceof Array) { |
| 30 for (var i = 0; i < opt_extraInfo.length; ++i) { | 32 for (var i = 0; i < opt_extraInfo.length; ++i) { |
| 31 if (opt_extraInfo[i] == "async") { | 33 if (opt_extraInfo[i] == "async") { |
| 32 input_ime.onKeyEvent.async = true; | 34 input_ime.onKeyEvent.async = true; |
| 33 } | 35 } |
| 34 } | 36 } |
| 35 } | 37 } |
| 36 chrome.Event.prototype.addListener.call(this, cb, null); | 38 Event.prototype.addListener.call(this, cb, null); |
| 37 }; | 39 }; |
| 38 }); | 40 }); |
| 39 | 41 |
| 40 exports.binding = binding.generate(); | 42 exports.binding = binding.generate(); |
| OLD | NEW |