Skip to content

Add Permissions types #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ interface DeviceOrientationEventInit extends EventInit {
gamma?: number | null;
}

interface DevicePermissionDescriptor extends PermissionDescriptor {
deviceId?: string;
name: "camera" | "microphone" | "speaker";
}

interface DeviceRotationRateDict {
alpha?: number | null;
beta?: number | null;
Expand Down Expand Up @@ -738,6 +743,11 @@ interface MessageEventInit extends EventInit {
source?: MessageEventSource | null;
}

interface MidiPermissionDescriptor extends PermissionDescriptor {
name: "midi";
sysex?: boolean;
}

interface MouseEventInit extends EventModifierInit {
button?: number;
buttons?: number;
Expand Down Expand Up @@ -911,6 +921,10 @@ interface PeriodicWaveOptions extends PeriodicWaveConstraints {
real?: number[] | Float32Array;
}

interface PermissionDescriptor {
name: PermissionName;
}

interface PipeOptions {
preventAbort?: boolean;
preventCancel?: boolean;
Expand Down Expand Up @@ -958,6 +972,11 @@ interface PropertyIndexedKeyframes {
[property: string]: string | string[] | number | null | (number | null)[] | undefined;
}

interface PushPermissionDescriptor extends PermissionDescriptor {
name: "push";
userVisibleOnly?: boolean;
}

interface PushSubscriptionJSON {
endpoint?: string;
expirationTime?: number | null;
Expand Down Expand Up @@ -10504,6 +10523,7 @@ interface Navigator extends NavigatorID, NavigatorOnLine, NavigatorContentUtils,
readonly msManipulationViewsEnabled: boolean;
readonly msMaxTouchPoints: number;
readonly msPointerEnabled: boolean;
readonly permissions: Permissions;
readonly plugins: PluginArray;
readonly pointerEnabled: boolean;
readonly serviceWorker: ServiceWorkerContainer;
Expand Down Expand Up @@ -11368,6 +11388,33 @@ declare var PermissionRequestedEvent: {
new(): PermissionRequestedEvent;
};

interface PermissionStatusEventMap {
"change": Event;
}

interface PermissionStatus extends EventTarget {
onchange: ((this: PermissionStatus, ev: Event) => any) | null;
readonly state: PermissionState;
addEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

declare var PermissionStatus: {
prototype: PermissionStatus;
new(): PermissionStatus;
};

interface Permissions {
query(permissionDesc: PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor): Promise<PermissionStatus>;
}

declare var Permissions: {
prototype: Permissions;
new(): Permissions;
};

/** Provides information about a browser plugin. */
interface Plugin {
readonly description: string;
Expand Down Expand Up @@ -18486,6 +18533,8 @@ type OverSampleType = "none" | "2x" | "4x";
type PanningModelType = "equalpower" | "HRTF";
type PaymentComplete = "success" | "fail" | "unknown";
type PaymentShippingType = "shipping" | "delivery" | "pickup";
type PermissionName = "geolocation" | "notifications" | "push" | "midi" | "camera" | "microphone" | "speaker" | "device-info" | "background-sync" | "bluetooth" | "persistent-storage" | "ambient-light-sensor" | "accelerometer" | "gyroscope" | "magnetometer" | "clipboard";
type PermissionState = "granted" | "denied" | "prompt";
type PlaybackDirection = "normal" | "reverse" | "alternate" | "alternate-reverse";
type PositionAlignSetting = "line-left" | "center" | "line-right" | "auto";
type PushEncryptionKeyName = "p256dh" | "auth";
Expand Down
49 changes: 49 additions & 0 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ interface DOMRectInit {
y?: number;
}

interface DevicePermissionDescriptor extends PermissionDescriptor {
deviceId?: string;
name: "camera" | "microphone" | "speaker";
}

interface EcKeyGenParams extends Algorithm {
namedCurve: NamedCurve;
}
Expand Down Expand Up @@ -243,6 +248,11 @@ interface MessageEventInit extends EventInit {
source?: MessageEventSource | null;
}

interface MidiPermissionDescriptor extends PermissionDescriptor {
name: "midi";
sysex?: boolean;
}

interface NavigationPreloadState {
enabled?: boolean;
headerValue?: string;
Expand Down Expand Up @@ -287,6 +297,10 @@ interface PerformanceObserverInit {
entryTypes: string[];
}

interface PermissionDescriptor {
name: PermissionName;
}

interface PipeOptions {
preventAbort?: boolean;
preventCancel?: boolean;
Expand All @@ -308,6 +322,11 @@ interface PushEventInit extends ExtendableEventInit {
data?: PushMessageDataInit;
}

interface PushPermissionDescriptor extends PermissionDescriptor {
name: "push";
userVisibleOnly?: boolean;
}

interface PushSubscriptionChangeInit extends ExtendableEventInit {
newSubscription?: PushSubscription;
oldSubscription?: PushSubscription;
Expand Down Expand Up @@ -2332,6 +2351,33 @@ declare var PerformanceResourceTiming: {
new(): PerformanceResourceTiming;
};

interface PermissionStatusEventMap {
"change": Event;
}

interface PermissionStatus extends EventTarget {
onchange: ((this: PermissionStatus, ev: Event) => any) | null;
readonly state: PermissionState;
addEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof PermissionStatusEventMap>(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

declare var PermissionStatus: {
prototype: PermissionStatus;
new(): PermissionStatus;
};

interface Permissions {
query(permissionDesc: PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor): Promise<PermissionStatus>;
}

declare var Permissions: {
prototype: Permissions;
new(): Permissions;
};

/** 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>). */
interface ProgressEvent extends Event {
readonly lengthComputable: boolean;
Expand Down Expand Up @@ -4078,6 +4124,7 @@ declare var WorkerLocation: {

/** 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. */
interface WorkerNavigator extends NavigatorID, NavigatorOnLine, NavigatorBeacon, NavigatorConcurrentHardware, NavigatorStorage {
readonly permissions: Permissions;
readonly serviceWorker: ServiceWorkerContainer;
}

Expand Down Expand Up @@ -4509,6 +4556,8 @@ type KeyType = "public" | "private" | "secret";
type KeyUsage = "encrypt" | "decrypt" | "sign" | "verify" | "deriveKey" | "deriveBits" | "wrapKey" | "unwrapKey";
type NotificationDirection = "auto" | "ltr" | "rtl";
type NotificationPermission = "default" | "denied" | "granted";
type PermissionName = "geolocation" | "notifications" | "push" | "midi" | "camera" | "microphone" | "speaker" | "device-info" | "background-sync" | "bluetooth" | "persistent-storage" | "ambient-light-sensor" | "accelerometer" | "gyroscope" | "magnetometer" | "clipboard";
type PermissionState = "granted" | "denied" | "prompt";
type PushEncryptionKeyName = "p256dh" | "auth";
type PushPermissionState = "denied" | "granted" | "prompt";
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
Expand Down
61 changes: 61 additions & 0 deletions inputfiles/idl/Permissions.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
dictionary PermissionDescriptor {
required PermissionName name;
};

enum PermissionState {
"granted",
"denied",
"prompt",
};

[Exposed=(Window,Worker)]
interface PermissionStatus : EventTarget {
readonly attribute PermissionState state;
attribute EventHandler onchange;
};

[Exposed=(Window)]
partial interface Navigator {
readonly attribute Permissions permissions;
};

[Exposed=(Worker)]
partial interface WorkerNavigator {
readonly attribute Permissions permissions;
};

[Exposed=(Window,Worker)]
interface Permissions {
Promise<PermissionStatus> query(object permissionDesc);
};

enum PermissionName {
"geolocation",
"notifications",
"push",
"midi",
"camera",
"microphone",
"speaker",
"device-info",
"background-sync",
"bluetooth",
"persistent-storage",
"ambient-light-sensor",
"accelerometer",
"gyroscope",
"magnetometer",
"clipboard",
};

dictionary PushPermissionDescriptor : PermissionDescriptor {
boolean userVisibleOnly = false;
};

dictionary MidiPermissionDescriptor : PermissionDescriptor {
boolean sysex = false;
};

dictionary DevicePermissionDescriptor : PermissionDescriptor {
DOMString deviceId;
};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@
"url": "https://w3c.github.io/performance-timeline/",
"title": "Performance Timeline"
},
{
"url": "https://www.w3.org/TR/permissions/",
"title": "Permissions"
},
{
"url": "https://www.w3.org/TR/pointerevents2/",
"title": "Pointer Events"
Expand Down
10 changes: 10 additions & 0 deletions inputfiles/knownTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ConstrainDouble",
"ConstrainLong",
"ConstrainVideoFacingModeParameters",
"DevicePermissionDescriptor",
"DisplayCaptureSurfaceType",
"EcKeyAlgorithm",
"EcKeyGenParams",
Expand All @@ -41,10 +42,14 @@
"KeyType",
"KeyUsage",
"Keyframe",
"MidiPermissionDescriptor",
"MutationRecordType",
"NamedCurve",
"Pbkdf2Params",
"PermissionDescriptor",
"PermissionName",
"PropertyIndexedKeyframes",
"PushPermissionDescriptor",
"RTCAnswerOptions",
"RTCCertificateExpiration",
"RTCDtlsParameters",
Expand Down Expand Up @@ -94,6 +99,7 @@
"BigInteger",
"ClientTypes",
"CryptoKeyPair",
"DevicePermissionDescriptor",
"EcdhKeyDeriveParams",
"EcdsaParams",
"EcKeyGenParams",
Expand All @@ -103,8 +109,12 @@
"HmacKeyGenParams",
"IDBArrayKey",
"IDBValidKey",
"MidiPermissionDescriptor",
"NamedCurve",
"Pbkdf2Params",
"PermissionDescriptor",
"PermissionName",
"PushPermissionDescriptor",
"RsaHashedImportParams",
"RsaHashedKeyGenParams",
"RsaKeyGenParams",
Expand Down
44 changes: 44 additions & 0 deletions inputfiles/overridingTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -2749,6 +2749,17 @@
}
}
}
},
"Permissions": {
"methods": {
"method": {
"query": {
"override-signatures": [
"query(permissionDesc: PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor): Promise<PermissionStatus>"
]
}
}
}
}
}
},
Expand Down Expand Up @@ -3093,6 +3104,39 @@
}
}
},
"DevicePermissionDescriptor": {
"members": {
"member": {
"name": {
"name": "name",
"required": 1,
"override-type": "\"camera\" | \"microphone\" | \"speaker\""
}
}
}
},
"MidiPermissionDescriptor": {
"members": {
"member": {
"name": {
"name": "name",
"required": 1,
"override-type": "\"midi\""
}
}
}
},
"PushPermissionDescriptor": {
"members": {
"member": {
"name": {
"name": "name",
"required": 1,
"override-type": "\"push\""
}
}
}
},
"ModuleExportDescriptor": {
"legacy-namespace": "WebAssembly"
},
Expand Down
3 changes: 2 additions & 1 deletion src/idlfetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ interface IDLSource {
const idlSelector = [
"pre.idl:not(.extract):not(.example)", // bikeshed and ReSpec
"pre.code code.idl-code", // Web Cryptography
"pre:not(.extract) code.idl" // HTML
"pre:not(.extract) code.idl", // HTML
"#permission-registry + pre.highlight" // Permissions
].join(",");

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