Skip to content
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

Custom PermissionName definitions in other host environments #212

Closed
nayeemrmn opened this issue Jul 9, 2020 · 2 comments
Closed

Custom PermissionName definitions in other host environments #212

nayeemrmn opened this issue Jul 9, 2020 · 2 comments
Labels

Comments

@nayeemrmn
Copy link

nayeemrmn commented Jul 9, 2020

For an alternate host environment (seeking to be browser-compatible) which borrows the Permissions API, how would you advise extending the PermissionName enum with permissions specific to its domain?


In Deno, we borrow the Permissions API for powerful features not supported by browsers. We swap out the specified PermissionName definition for the following:

enum PermissionName {
  "run",
  "read",
  "write",
  "net",
  "env",
  "plugin",
  "hrtime",
};

The problem is the spec has it's own concretely defined enum. We've dodged that by defining ours in Deno.permissions instead of navigator.permissions, with the intention of reserving the latter for permissions that do exist in browser which we might also support isomorphically.

Since it's not ideal to have two separate permissions namespaces, we've been discussing just moving them all to navigator.permissions which would use a union of the w3c PermissionName and the one defined above.

My concerns are that:

  1. This violates the spec of navigator.permissions in the way it is currently written. Could it be changed to allow any DOMString as a permission name instead of an enum? Instead of throwing for unsupported permission names, could it return { state: "unknown" } or something? Ref Support for custom permission types #130, Maybe add navigator.permissions.supports()?  #136.
  2. There could be name conflicts in the future between the web's and Deno's permission names. We can address this by prefixing our permission names with "deno-*", I guess. Thoughts on that?

Given all of that, is it more advisable for us to commit to having a separate Deno.permissions namespace forever, or moving to navigator.permissions despite the incompatibilities with the current spec? (What's the status of the suggestions linked in concern 1?)

@marcoscaceres
Copy link
Member

Sorry for the delay...

I wonder if you could do:

enum DenoPermissionName {
  "run",
  "read",
  "write",
  "net",
  "env",
  "plugin",
  "hrtime",
};

enum PermissionName { 
"geolocation" 
 // ...etc...  
};

typedef (DenoPermissionName or PermissionName) ExtendedPermissionName; 

dictionary PermissionDescriptor {
  required ExtendedPermissionName name;
};

There could be name conflicts in the future between the web's and Deno's permission names. We can address this by prefixing our permission names with "deno-*", I guess. Thoughts on that?

That's also a lightweight and sensible solution, IMO.

Interested to hear where you ended up!

@marcoscaceres
Copy link
Member

Closing as it's a bit of out of scope, but happy to keep discussing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants