chrome.mdns fixes - added extra filter parameter + tests

This commit is contained in:
Nikolai Ommundsen 2018-08-23 11:26:00 +02:00
parent 7ace836a16
commit cc4c27210b
2 changed files with 75 additions and 6 deletions

View File

@ -2935,7 +2935,7 @@ declare namespace chrome {
ports?: Array<integer | integer[]>;
}
/** An object which allows the addition and removal of listeners for a Chrome event. */
interface Event<T> {
interface Event<T extends Function> {
/**
* 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<T extends Function, F = EventFilter> extends Event<T> {
/**
* 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<ValidServiceTypes, string>;
/**
* 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 <T = any>(): chrome.events.Event<T>;
new <T extends Function>(): chrome.events.Event<T>;
}
// #endregion

View File

@ -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');
});