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

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

Issue 2945493002: [Extensions Bindings] Update IME custom bindings (Closed)
Patch Set: s/Dispatch/dispatch() Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 binding for the input ime API. Only injected into the 5 // Custom binding 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 binding = require('binding').Binding.create('input.ime'); 8 var binding = apiBridge || require('binding').Binding.create('input.ime');
9 var appWindowNatives = requireNative('app_window_natives');
10 var registerArgumentMassager = bindingUtil ?
11 $Function.bind(bindingUtil.registerEventArgumentMassager, bindingUtil) :
12 require('event_bindings').registerArgumentMassager;
9 13
10 var Event = require('event_bindings').Event; 14 // TODO(crbug.com/733825): These bindings have some issues.
11 15
12 var appWindowNatives = requireNative('app_window_natives'); 16 var inputIme;
17 registerArgumentMassager('input.ime.onKeyEvent',
18 function(args, dispatch) {
19 var keyData = args[1];
20 var result = false;
21 try {
22 // dispatch() is weird - it returns an object {results: array<results>} iff
23 // there is at least one result value that !== undefined. Since onKeyEvent
24 // has a maximum of one listener, we know that any result we find is the one
25 // we're interested in.
26 var dispatchResult = dispatch(args);
27 if (dispatchResult && dispatchResult.results)
28 result = dispatchResult.results[0];
29 } catch (e) {
30 console.error('Error in event handler for onKeyEvent: ' + e.stack);
31 }
32 if (!inputIme.onKeyEvent.async)
33 inputIme.keyEventHandled(keyData.requestId, result);
34 });
13 35
14 binding.registerCustomHook(function(api) { 36 binding.registerCustomHook(function(api) {
15 var input_ime = api.compiledApi; 37 inputIme = api.compiledApi;
16 38
17 input_ime.onKeyEvent.dispatchToListener = function(callback, args) { 39 var originalAddListener = inputIme.onKeyEvent.addListener;
18 var engineID = args[0]; 40 inputIme.onKeyEvent.addListener = function(cb, opt_extraInfo) {
19 var keyData = args[1]; 41 inputIme.onKeyEvent.async = false;
20
21 var result = false;
22 try {
23 result = $Function.call(Event.prototype.dispatchToListener,
24 this, callback, args);
25 } catch (e) {
26 console.error('Error in event handler for onKeyEvent: ' + e.stack);
27 }
28 if (!input_ime.onKeyEvent.async) {
29 input_ime.keyEventHandled(keyData.requestId, result);
30 }
31 };
32
33 input_ime.onKeyEvent.addListener = function(cb, opt_extraInfo) {
34 input_ime.onKeyEvent.async = false;
35 if (opt_extraInfo instanceof Array) { 42 if (opt_extraInfo instanceof Array) {
36 for (var i = 0; i < opt_extraInfo.length; ++i) { 43 for (var i = 0; i < opt_extraInfo.length; ++i) {
37 if (opt_extraInfo[i] == "async") { 44 if (opt_extraInfo[i] == 'async') {
38 input_ime.onKeyEvent.async = true; 45 inputIme.onKeyEvent.async = true;
39 } 46 }
40 } 47 }
41 } 48 }
42 $Function.call(Event.prototype.addListener, this, cb); 49 $Function.call(originalAddListener, this, cb);
43 }; 50 };
44 51
45 api.apiFunctions.setCustomCallback('createWindow', 52 api.apiFunctions.setCustomCallback('createWindow',
46 function(name, request, callback, windowParams) { 53 function(name, request, callback, windowParams) {
47 if (!callback) { 54 if (!callback) {
48 return; 55 return;
49 } 56 }
50 var view; 57 var view;
51 if (windowParams && windowParams.frameId) { 58 if (windowParams && windowParams.frameId) {
52 view = appWindowNatives.GetFrame( 59 view = appWindowNatives.GetFrame(
53 windowParams.frameId, false /* notifyBrowser */); 60 windowParams.frameId, false /* notifyBrowser */);
54 view.id = windowParams.frameId; 61 view.id = windowParams.frameId;
55 } 62 }
56 callback(view); 63 callback(view);
57 }); 64 });
58 }); 65 });
59 66
60 exports.$set('binding', binding.generate()); 67 if (!apiBridge)
68 exports.$set('binding', binding.generate());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698