Skip to content

Commit 9ee7163

Browse files
saschanazsandersn
authored andcommitted
add Permissions types (#665)
1 parent 7af05a3 commit 9ee7163

File tree

7 files changed

+219
-1
lines changed

7 files changed

+219
-1
lines changed

baselines/dom.generated.d.ts

+49
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ interface DeviceOrientationEventInit extends EventInit {
334334
gamma?: number | null;
335335
}
336336

337+
interface DevicePermissionDescriptor extends PermissionDescriptor {
338+
deviceId?: string;
339+
name: "camera" | "microphone" | "speaker";
340+
}
341+
337342
interface DeviceRotationRateDict {
338343
alpha?: number | null;
339344
beta?: number | null;
@@ -738,6 +743,11 @@ interface MessageEventInit extends EventInit {
738743
source?: MessageEventSource | null;
739744
}
740745

746+
interface MidiPermissionDescriptor extends PermissionDescriptor {
747+
name: "midi";
748+
sysex?: boolean;
749+
}
750+
741751
interface MouseEventInit extends EventModifierInit {
742752
button?: number;
743753
buttons?: number;
@@ -911,6 +921,10 @@ interface PeriodicWaveOptions extends PeriodicWaveConstraints {
911921
real?: number[] | Float32Array;
912922
}
913923

924+
interface PermissionDescriptor {
925+
name: PermissionName;
926+
}
927+
914928
interface PipeOptions {
915929
preventAbort?: boolean;
916930
preventCancel?: boolean;
@@ -958,6 +972,11 @@ interface PropertyIndexedKeyframes {
958972
[property: string]: string | string[] | number | null | (number | null)[] | undefined;
959973
}
960974

975+
interface PushPermissionDescriptor extends PermissionDescriptor {
976+
name: "push";
977+
userVisibleOnly?: boolean;
978+
}
979+
961980
interface PushSubscriptionJSON {
962981
endpoint?: string;
963982
expirationTime?: number | null;
@@ -10504,6 +10523,7 @@ interface Navigator extends NavigatorID, NavigatorOnLine, NavigatorContentUtils,
1050410523
readonly msManipulationViewsEnabled: boolean;
1050510524
readonly msMaxTouchPoints: number;
1050610525
readonly msPointerEnabled: boolean;
10526+
readonly permissions: Permissions;
1050710527
readonly plugins: PluginArray;
1050810528
readonly pointerEnabled: boolean;
1050910529
readonly serviceWorker: ServiceWorkerContainer;
@@ -11368,6 +11388,33 @@ declare var PermissionRequestedEvent: {
1136811388
new(): PermissionRequestedEvent;
1136911389
};
1137011390

11391+
interface PermissionStatusEventMap {
11392+
"change": Event;
11393+
}
11394+
11395+
interface PermissionStatus extends EventTarget {
11396+
onchange: ((this: PermissionStatus, ev: Event) => any) | null;
11397+
readonly state: PermissionState;
11398+
addEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
11399+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
11400+
removeEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
11401+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
11402+
}
11403+
11404+
declare var PermissionStatus: {
11405+
prototype: PermissionStatus;
11406+
new(): PermissionStatus;
11407+
};
11408+
11409+
interface Permissions {
11410+
query(permissionDesc: PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor): Promise<PermissionStatus>;
11411+
}
11412+
11413+
declare var Permissions: {
11414+
prototype: Permissions;
11415+
new(): Permissions;
11416+
};
11417+
1137111418
/** Provides information about a browser plugin. */
1137211419
interface Plugin {
1137311420
readonly description: string;
@@ -18486,6 +18533,8 @@ type OverSampleType = "none" | "2x" | "4x";
1848618533
type PanningModelType = "equalpower" | "HRTF";
1848718534
type PaymentComplete = "success" | "fail" | "unknown";
1848818535
type PaymentShippingType = "shipping" | "delivery" | "pickup";
18536+
type PermissionName = "geolocation" | "notifications" | "push" | "midi" | "camera" | "microphone" | "speaker" | "device-info" | "background-sync" | "bluetooth" | "persistent-storage" | "ambient-light-sensor" | "accelerometer" | "gyroscope" | "magnetometer" | "clipboard";
18537+
type PermissionState = "granted" | "denied" | "prompt";
1848918538
type PlaybackDirection = "normal" | "reverse" | "alternate" | "alternate-reverse";
1849018539
type PositionAlignSetting = "line-left" | "center" | "line-right" | "auto";
1849118540
type PushEncryptionKeyName = "p256dh" | "auth";

baselines/webworker.generated.d.ts

+49
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ interface DOMRectInit {
120120
y?: number;
121121
}
122122

123+
interface DevicePermissionDescriptor extends PermissionDescriptor {
124+
deviceId?: string;
125+
name: "camera" | "microphone" | "speaker";
126+
}
127+
123128
interface EcKeyGenParams extends Algorithm {
124129
namedCurve: NamedCurve;
125130
}
@@ -243,6 +248,11 @@ interface MessageEventInit extends EventInit {
243248
source?: MessageEventSource | null;
244249
}
245250

251+
interface MidiPermissionDescriptor extends PermissionDescriptor {
252+
name: "midi";
253+
sysex?: boolean;
254+
}
255+
246256
interface NavigationPreloadState {
247257
enabled?: boolean;
248258
headerValue?: string;
@@ -287,6 +297,10 @@ interface PerformanceObserverInit {
287297
entryTypes: string[];
288298
}
289299

300+
interface PermissionDescriptor {
301+
name: PermissionName;
302+
}
303+
290304
interface PipeOptions {
291305
preventAbort?: boolean;
292306
preventCancel?: boolean;
@@ -308,6 +322,11 @@ interface PushEventInit extends ExtendableEventInit {
308322
data?: PushMessageDataInit;
309323
}
310324

325+
interface PushPermissionDescriptor extends PermissionDescriptor {
326+
name: "push";
327+
userVisibleOnly?: boolean;
328+
}
329+
311330
interface PushSubscriptionChangeInit extends ExtendableEventInit {
312331
newSubscription?: PushSubscription;
313332
oldSubscription?: PushSubscription;
@@ -2332,6 +2351,33 @@ declare var PerformanceResourceTiming: {
23322351
new(): PerformanceResourceTiming;
23332352
};
23342353

2354+
interface PermissionStatusEventMap {
2355+
"change": Event;
2356+
}
2357+
2358+
interface PermissionStatus extends EventTarget {
2359+
onchange: ((this: PermissionStatus, ev: Event) => any) | null;
2360+
readonly state: PermissionState;
2361+
addEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
2362+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
2363+
removeEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
2364+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
2365+
}
2366+
2367+
declare var PermissionStatus: {
2368+
prototype: PermissionStatus;
2369+
new(): PermissionStatus;
2370+
};
2371+
2372+
interface Permissions {
2373+
query(permissionDesc: PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor): Promise<PermissionStatus>;
2374+
}
2375+
2376+
declare var Permissions: {
2377+
prototype: Permissions;
2378+
new(): Permissions;
2379+
};
2380+
23352381
/** Events measuring progress of an underlying process, like an HTTP request (for an XMLHttpRequest, or the loading of the underlying resource of an <img>, <audio>, <video>, <style> or <link>). */
23362382
interface ProgressEvent extends Event {
23372383
readonly lengthComputable: boolean;
@@ -4078,6 +4124,7 @@ declare var WorkerLocation: {
40784124

40794125
/** A subset of the Navigator interface allowed to be accessed from a Worker. Such an object is initialized for each worker and is available via the WorkerGlobalScope.navigator property obtained by calling window.self.navigator. */
40804126
interface WorkerNavigator extends NavigatorID, NavigatorOnLine, NavigatorBeacon, NavigatorConcurrentHardware, NavigatorStorage {
4127+
readonly permissions: Permissions;
40814128
readonly serviceWorker: ServiceWorkerContainer;
40824129
}
40834130

@@ -4509,6 +4556,8 @@ type KeyType = "public" | "private" | "secret";
45094556
type KeyUsage = "encrypt" | "decrypt" | "sign" | "verify" | "deriveKey" | "deriveBits" | "wrapKey" | "unwrapKey";
45104557
type NotificationDirection = "auto" | "ltr" | "rtl";
45114558
type NotificationPermission = "default" | "denied" | "granted";
4559+
type PermissionName = "geolocation" | "notifications" | "push" | "midi" | "camera" | "microphone" | "speaker" | "device-info" | "background-sync" | "bluetooth" | "persistent-storage" | "ambient-light-sensor" | "accelerometer" | "gyroscope" | "magnetometer" | "clipboard";
4560+
type PermissionState = "granted" | "denied" | "prompt";
45124561
type PushEncryptionKeyName = "p256dh" | "auth";
45134562
type PushPermissionState = "denied" | "granted" | "prompt";
45144563
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";

inputfiles/idl/Permissions.widl

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
dictionary PermissionDescriptor {
2+
required PermissionName name;
3+
};
4+
5+
enum PermissionState {
6+
"granted",
7+
"denied",
8+
"prompt",
9+
};
10+
11+
[Exposed=(Window,Worker)]
12+
interface PermissionStatus : EventTarget {
13+
readonly attribute PermissionState state;
14+
attribute EventHandler onchange;
15+
};
16+
17+
[Exposed=(Window)]
18+
partial interface Navigator {
19+
readonly attribute Permissions permissions;
20+
};
21+
22+
[Exposed=(Worker)]
23+
partial interface WorkerNavigator {
24+
readonly attribute Permissions permissions;
25+
};
26+
27+
[Exposed=(Window,Worker)]
28+
interface Permissions {
29+
Promise<PermissionStatus> query(object permissionDesc);
30+
};
31+
32+
enum PermissionName {
33+
"geolocation",
34+
"notifications",
35+
"push",
36+
"midi",
37+
"camera",
38+
"microphone",
39+
"speaker",
40+
"device-info",
41+
"background-sync",
42+
"bluetooth",
43+
"persistent-storage",
44+
"ambient-light-sensor",
45+
"accelerometer",
46+
"gyroscope",
47+
"magnetometer",
48+
"clipboard",
49+
};
50+
51+
dictionary PushPermissionDescriptor : PermissionDescriptor {
52+
boolean userVisibleOnly = false;
53+
};
54+
55+
dictionary MidiPermissionDescriptor : PermissionDescriptor {
56+
boolean sysex = false;
57+
};
58+
59+
dictionary DevicePermissionDescriptor : PermissionDescriptor {
60+
DOMString deviceId;
61+
};

inputfiles/idlSources.json

+4
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@
234234
"url": "https://w3c.github.io/performance-timeline/",
235235
"title": "Performance Timeline"
236236
},
237+
{
238+
"url": "https://www.w3.org/TR/permissions/",
239+
"title": "Permissions"
240+
},
237241
{
238242
"url": "https://www.w3.org/TR/pointerevents2/",
239243
"title": "Pointer Events"

inputfiles/knownTypes.json

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"ConstrainDouble",
2222
"ConstrainLong",
2323
"ConstrainVideoFacingModeParameters",
24+
"DevicePermissionDescriptor",
2425
"DisplayCaptureSurfaceType",
2526
"EcKeyAlgorithm",
2627
"EcKeyGenParams",
@@ -41,10 +42,14 @@
4142
"KeyType",
4243
"KeyUsage",
4344
"Keyframe",
45+
"MidiPermissionDescriptor",
4446
"MutationRecordType",
4547
"NamedCurve",
4648
"Pbkdf2Params",
49+
"PermissionDescriptor",
50+
"PermissionName",
4751
"PropertyIndexedKeyframes",
52+
"PushPermissionDescriptor",
4853
"RTCAnswerOptions",
4954
"RTCCertificateExpiration",
5055
"RTCDtlsParameters",
@@ -94,6 +99,7 @@
9499
"BigInteger",
95100
"ClientTypes",
96101
"CryptoKeyPair",
102+
"DevicePermissionDescriptor",
97103
"EcdhKeyDeriveParams",
98104
"EcdsaParams",
99105
"EcKeyGenParams",
@@ -103,8 +109,12 @@
103109
"HmacKeyGenParams",
104110
"IDBArrayKey",
105111
"IDBValidKey",
112+
"MidiPermissionDescriptor",
106113
"NamedCurve",
107114
"Pbkdf2Params",
115+
"PermissionDescriptor",
116+
"PermissionName",
117+
"PushPermissionDescriptor",
108118
"RsaHashedImportParams",
109119
"RsaHashedKeyGenParams",
110120
"RsaKeyGenParams",

inputfiles/overridingTypes.json

+44
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,17 @@
27492749
}
27502750
}
27512751
}
2752+
},
2753+
"Permissions": {
2754+
"methods": {
2755+
"method": {
2756+
"query": {
2757+
"override-signatures": [
2758+
"query(permissionDesc: PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor): Promise<PermissionStatus>"
2759+
]
2760+
}
2761+
}
2762+
}
27522763
}
27532764
}
27542765
},
@@ -3093,6 +3104,39 @@
30933104
}
30943105
}
30953106
},
3107+
"DevicePermissionDescriptor": {
3108+
"members": {
3109+
"member": {
3110+
"name": {
3111+
"name": "name",
3112+
"required": 1,
3113+
"override-type": "\"camera\" | \"microphone\" | \"speaker\""
3114+
}
3115+
}
3116+
}
3117+
},
3118+
"MidiPermissionDescriptor": {
3119+
"members": {
3120+
"member": {
3121+
"name": {
3122+
"name": "name",
3123+
"required": 1,
3124+
"override-type": "\"midi\""
3125+
}
3126+
}
3127+
}
3128+
},
3129+
"PushPermissionDescriptor": {
3130+
"members": {
3131+
"member": {
3132+
"name": {
3133+
"name": "name",
3134+
"required": 1,
3135+
"override-type": "\"push\""
3136+
}
3137+
}
3138+
}
3139+
},
30963140
"ModuleExportDescriptor": {
30973141
"legacy-namespace": "WebAssembly"
30983142
},

src/idlfetcher.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ interface IDLSource {
1515
const idlSelector = [
1616
"pre.idl:not(.extract):not(.example)", // bikeshed and ReSpec
1717
"pre.code code.idl-code", // Web Cryptography
18-
"pre:not(.extract) code.idl" // HTML
18+
"pre:not(.extract) code.idl", // HTML
19+
"#permission-registry + pre.highlight" // Permissions
1920
].join(",");
2021

2122
const cssPropSelector = "dfn.css[data-dfn-type=property]";

0 commit comments

Comments
 (0)