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