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