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