fune/browser/components/extensions/child/ext-omnibox.js
Andrew Swan e71d1d5a82 Bug 1450388 Part 1 Refactor EventManager r=kmag
As we add more behaviors to EventManager, the signature of the constructor
is going to get really clumsy.  Head that off by converting it to take a
general parameters object.

This introduces a compatibility problem for existing webextension experiments,
put in a backward-compatibility shim for now.

MozReview-Commit-ID: 72QDfiwRm5j

--HG--
extra : rebase_source : 31c3fd561f373a5d75c4336de830aa5a2abfe797
2018-03-14 14:52:44 -07:00

30 lines
937 B
JavaScript

/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
this.omnibox = class extends ExtensionAPI {
getAPI(context) {
return {
omnibox: {
onInputChanged: new EventManager({
context,
name: "omnibox.onInputChanged",
register: fire => {
let listener = (text, id) => {
fire.asyncWithoutClone(text, suggestions => {
context.childManager.callParentFunctionNoReturn("omnibox.addSuggestions", [
id,
suggestions,
]);
});
};
context.childManager.getParentEvent("omnibox.onInputChanged").addListener(listener);
return () => {
context.childManager.getParentEvent("omnibox.onInputChanged").removeListener(listener);
};
},
}).api(),
},
};
}
};