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 (function() { | 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
9 | 9 |
10 native function GetChromeHidden(); | 10 chromeHidden.registerCustomHook('input.ime', function() { |
11 | |
12 GetChromeHidden().registerCustomHook('input.ime', function() { | |
13 chrome.input.ime.onKeyEvent.dispatch = function(engineID, keyData) { | 11 chrome.input.ime.onKeyEvent.dispatch = function(engineID, keyData) { |
14 var args = Array.prototype.slice.call(arguments); | 12 var args = Array.prototype.slice.call(arguments); |
15 if (this.validate_) { | 13 if (this.validate_) { |
16 var validationErrors = this.validate_(args); | 14 var validationErrors = this.validate_(args); |
17 if (validationErrors) { | 15 if (validationErrors) { |
18 chrome.input.ime.eventHandled(requestId, false); | 16 chrome.input.ime.eventHandled(requestId, false); |
19 return validationErrors; | 17 return validationErrors; |
20 } | 18 } |
21 } | 19 } |
22 if (this.listeners_.length > 1) { | 20 if (this.listeners_.length > 1) { |
23 console.error('Too many listeners for onKeyEvent: ' + e.stack); | 21 console.error('Too many listeners for onKeyEvent: ' + e.stack); |
24 chrome.input.ime.eventHandled(requestId, false); | 22 chrome.input.ime.eventHandled(requestId, false); |
25 return; | 23 return; |
26 } | 24 } |
27 for (var i = 0; i < this.listeners_.length; i++) { | 25 for (var i = 0; i < this.listeners_.length; i++) { |
28 try { | 26 try { |
29 var requestId = keyData.requestId; | 27 var requestId = keyData.requestId; |
30 var result = this.listeners_[i].apply(null, args); | 28 var result = this.listeners_[i].apply(null, args); |
31 chrome.input.ime.eventHandled(requestId, result); | 29 chrome.input.ime.eventHandled(requestId, result); |
32 } catch (e) { | 30 } catch (e) { |
33 console.error('Error in event handler for onKeyEvent: ' + e.stack); | 31 console.error('Error in event handler for onKeyEvent: ' + e.stack); |
34 chrome.input.ime.eventHandled(requestId, false); | 32 chrome.input.ime.eventHandled(requestId, false); |
35 } | 33 } |
36 } | 34 } |
37 }; | 35 }; |
38 }); | 36 }); |
39 | |
40 })(); | |
OLD | NEW |