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