diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts index 24a2142b4d..748e1db4a0 100644 --- a/types/chrome-apps/index.d.ts +++ b/types/chrome-apps/index.d.ts @@ -2935,7 +2935,7 @@ declare namespace chrome { ports?: Array; } /** An object which allows the addition and removal of listeners for a Chrome event. */ - interface Event { + interface Event { /** * Registers an event listener callback to an event. * @param callback Called when an event occurs. The parameters of this function depend on the type of event. @@ -2997,6 +2997,25 @@ declare namespace chrome { hasListeners(): boolean; } + interface EventFilter { + [key: string]: string; + } + + /** + * An object which allows the addition and removal of listeners for a Chrome event. + * Also provides the possibility to provide a filter + * @template T Callback function. + * @template F Filter interface, leave this for default + */ + interface FilteredEvent extends Event { + /** + * Registers an event listener callback to an event. + * @param callback Called when an event occurs. The parameters of this function depend on the type of event. + * @param [filter] Optional key/value dictionary you can provide to filter the events + */ + addListener(callback: T, filter?: F): void; + } + /** * Description of a declarative rule for handling events. * @template T Type for conditions array, default: any. @@ -5203,6 +5222,21 @@ declare namespace chrome { /** Metadata for an mDNS advertised service. */ serviceData: string[]; } + + /** + * Locked to this because it's the only one that can be used. + * + * const char kEventFilterServiceTypeKey[] = "serviceType"; + * @see[Source: event_matcher.cc, line 19]{@link https://github.com/chromium/chromium/tree/master/extensions/common/event_matcher.cc} + */ + type ValidServiceTypes = 'serviceType'; + + /** + * Dictionary + * [key in ValidServiceTypes]: string + */ + type ServiceTypes = Record; + /** * The maximum number of service instances that will be * included in onServiceList events. If more instances @@ -5229,8 +5263,12 @@ declare namespace chrome { * discovering should be specified as the event filter * with the 'serviceType' key. Not specifying an event * filter will not start any discovery listeners. + * @example + * Filter example: + * chrome.mdns.onServiceList.addListener(() => { }, + * { 'serviceType': 'definitelyTyped._tcp.local' }); */ - const onServiceList: chrome.events.Event<(services: Service[]) => void>; + const onServiceList: chrome.events.FilteredEvent<(services: Service[]) => void, ServiceTypes>; } // #endregion @@ -10698,6 +10736,14 @@ declare namespace chrome { // #endregion // #region chrome.webViewRequest + ///////////////////// + // WebView Request // + ///////////////////// + /** + * @requires Permissions: 'webview' + * @description + * Use the *chrome.webViewRequest* API to intercept, block, or modify requests in-flight. + */ namespace webViewRequest { type Stage = 'onBeforeRequest' | 'onBeforeSendHeaders' | 'onHeadersReceived' | 'onAuthRequired'; type DeclarativeWebRequestEventList = @@ -11295,7 +11341,7 @@ declare namespace chrome { * @constructor */ const Event: { - new (): chrome.events.Event; + new (): chrome.events.Event; } // #endregion diff --git a/types/chrome-apps/test/index.ts b/types/chrome-apps/test/index.ts index b2dbc60f0b..dfae00f342 100644 --- a/types/chrome-apps/test/index.ts +++ b/types/chrome-apps/test/index.ts @@ -828,7 +828,14 @@ chrome.instanceID; // @todo TODO Tests chrome.management; // @todo TODO Tests -chrome.mdns; // @todo TODO Tests +// #region chrome.mdns +chrome.mdns.onServiceList.addListener( + () => { }, + { 'serviceType': 'definitelyTyped._tcp.local' }); +chrome.mdns.onServiceList.addListener(function (services) { + chrome.mdns.forceDiscovery(() => { return true; }); +}, { 'serviceType': '_googlecast._tcp.local' }); +// #endregion // #region chrome.mediaGalleries @@ -1299,7 +1306,23 @@ chrome.usb.getUserSelectedDevices({ // #endregion -chrome.virtualKeyboard; // @todo TODO Tests +// #region chrome.virtualKeyboard +chrome.virtualKeyboard.restrictFeatures( + { + autoCompleteEnabled: false, + autoCorrectEnabled: false, + spellCheckEnabled: false, + voiceInputEnabled: false, + handwritingEnabled: false + }, + (update) => { + if (update.autoCompleteEnabled = false) { + return true; + } + } +); +// #endregion + chrome.vpnProvider; // @todo TODO Tests chrome.wallpaper; // @todo TODO Tests chrome.webViewRequest; // @todo TODO Tests @@ -1383,7 +1406,7 @@ wve.request.onRequest.addRules([rule]); // #endregion -//#region Embedding & AppView +// #region Embedding & AppView chrome.app.runtime.onEmbedRequested.addListener((request) => { request.allow('foobar.html'); });