From cd0b04c94c9d2dd922bcdd63b9325dfdacef3b85 Mon Sep 17 00:00:00 2001 From: "zork@chromium.org" Date: Thu, 8 Sep 2011 05:18:06 +0000 Subject: Make OnKeyEvent asynchronous to match the design. BUG=None TEST=None Review URL: http://codereview.chromium.org/7721006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100107 0039d316-1c4b-4281-b951-d872f2087c98 --- .../resources/extension_process_bindings.js | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'chrome/renderer') diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index c0c93ee..4dd5461 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -415,6 +415,35 @@ var chrome = chrome || {}; customBindings['ContentSetting'] = ContentSetting; } + function setupInputEvents() { + chrome.experimental.input.onKeyEvent.dispatch = + function(engineID, keyData) { + var args = Array.prototype.slice.call(arguments); + if (this.validate_) { + var validationErrors = this.validate_(args); + if (validationErrors) { + chrome.experimental.input.eventHandled(requestId, false); + return validationErrors; + } + } + if (this.listeners_.length > 1) { + console.error("Too many listeners for 'onKeyEvent': " + e.stack); + chrome.experimental.input.eventHandled(requestId, false); + return; + } + for (var i = 0; i < this.listeners_.length; i++) { + try { + var requestId = keyData.requestId; + var result = this.listeners_[i].apply(null, args); + chrome.experimental.input.eventHandled(requestId, result); + } catch (e) { + console.error("Error in event handler for 'onKeyEvent': " + e.stack); + chrome.experimental.input.eventHandled(requestId, false); + } + } + }; + } + // Page action events send (pageActionId, {tabId, tabUrl}). function setupPageActionEvents(extensionId) { var pageActions = GetCurrentPageActions(extensionId); @@ -1021,6 +1050,7 @@ var chrome = chrome || {}; setupPageActionEvents(extensionId); setupToolstripEvents(GetRenderViewId()); setupHiddenContextMenuEvent(extensionId); + setupInputEvents(); setupOmniboxEvents(); setupTtsEvents(); }); -- cgit v1.1