Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: chrome/renderer/resources/extensions/input.ime_custom_bindings.js

Issue 10704073: Plumb listenerIDs correctly for events that clobber chrome.Event.prototype.dispatch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.dispatch = function(engineID, keyData) { 11 chrome.input.ime.onKeyEvent.dispatchToListener = function(callback, args) {
12 var args = Array.prototype.slice.call(arguments); 12 var engineID = args[0];
13 if (this.validate_) { 13 var keyData = args[1];
14 var validationErrors = this.validate_(args); 14
15 if (validationErrors) { 15 var result = false;
16 chrome.input.ime.eventHandled(requestId, false); 16 try {
17 return validationErrors; 17 result = chrome.Event.prototype.dispatchToListener(callback, args);
18 } 18 } catch (e) {
19 console.error('Error in event handler for onKeyEvent: ' + e.stack);
19 } 20 }
20 if (this.listeners_.length > 1) { 21 chrome.input.ime.eventHandled(keyData.requestId, result);
21 console.error('Too many listeners for onKeyEvent: ' + e.stack);
22 chrome.input.ime.eventHandled(requestId, false);
23 return;
24 }
25 for (var i = 0; i < this.listeners_.length; i++) {
26 try {
27 var requestId = keyData.requestId;
28 var result = this.listeners_[i].callback.apply(null, args);
29 chrome.input.ime.eventHandled(requestId, result);
30 } catch (e) {
31 console.error('Error in event handler for onKeyEvent: ' + e.stack);
32 chrome.input.ime.eventHandled(requestId, false);
33 }
34 }
35 }; 22 };
36 }); 23 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698