forked from mirrors/gecko-dev
This patch adds the ability to run SingletonEventManager handlers in different modes: sync, async, raw (no exception handling, arg cloning, or asynchrony), or asyncWithoutClone. When you call the handler, you're required to specify which variant you want. Existing uses of SingletonEventManager are all converted to async calls. Note that some of them were previously synchronous, but it didn't appear to be necessary. Also added a callOnClose for SingletonEventManager when the last listener is removed. MozReview-Commit-ID: ATHO97dWf3X --HG-- extra : rebase_source : bf02d79e3fbab84892be8a7e52ea7a1caf2e003d
31 lines
1 KiB
JavaScript
31 lines
1 KiB
JavaScript
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* vim: set sts=2 sw=2 et tw=80: */
|
|
"use strict";
|
|
|
|
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
|
|
|
|
var {
|
|
SingletonEventManager,
|
|
} = ExtensionUtils;
|
|
|
|
extensions.registerSchemaAPI("omnibox", "addon_child", context => {
|
|
return {
|
|
omnibox: {
|
|
onInputChanged: new SingletonEventManager(context, "omnibox.onInputChanged", fire => {
|
|
let listener = (text, id) => {
|
|
fire.asyncWithoutClone(text, suggestions => {
|
|
// TODO: Switch to using callParentFunctionNoReturn once bug 1314903 is fixed.
|
|
context.childManager.callParentAsyncFunction("omnibox_internal.addSuggestions", [
|
|
id,
|
|
suggestions,
|
|
]);
|
|
});
|
|
};
|
|
context.childManager.getParentEvent("omnibox_internal.onInputChanged").addListener(listener);
|
|
return () => {
|
|
context.childManager.getParentEvent("omnibox_internal.onInputChanged").removeListener(listener);
|
|
};
|
|
}).api(),
|
|
},
|
|
};
|
|
});
|