contextlets icon indicating copy to clipboard operation
contextlets copied to clipboard

Move most of the required permissions to optional permissions

Open davidmhammond opened this issue 6 years ago • 0 comments

Currently, Contextlets has a relatively large number of required permissions, so that contextlet scripts can use those APIs. We ought to move most of these permissions (and perhaps a number of additional permissions) to "optional_permissions" that individual contextlets can request as needed.

Firefox only allows scripts to request permissions from within the lifecycle of a direct user action. This includes context item clicks, but it probably doesn't include receivers of cross-extension messages that happen to have been invoked by a context item click. In other words, a contextlet script that is assigned to an "extra" contextlet extension probably won't be able to request permissions directly.

So, we may need the permission request to occur in some user action within the configuration UI. Here's my thinking: The contextlet would define which permissions it needs (similarly to how it defines the contexts in which the item appears). If any of the required permissions are not currently met, there should be some indicator and a button to request those permissions.

A few additional notes:

  • The extra contextlet can't do the permission request itself, because the contextlet script that needs those permissions is executed within the main Contextlets extension. It's the main extension that needs those permissions.
  • We want the UI to stay relatively lean, so we don't want to just list all the possible permissions like we're currently listing the possible contexts. We'll need some UI that tucks these permissions out of view until you want to see them. For example, we could have two tabs: Contexts and Permissions, with scrollable bodies. Or maybe collapsable sections. However we do it, it should always be obvious when the permissions aren't met, and the request should take just one click.
  • It would be nice if we could automatically request permissions as soon as a contextlet is imported, but that probably isn't possible: by the time the file reader callbacks are invoked, it probably no longer counts as a user action handler.

davidmhammond avatar Jan 17 '19 00:01 davidmhammond