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

Add permission request API #68

Merged
merged 1 commit into from
Mar 19, 2019
Merged

Conversation

cdumez
Copy link
Contributor

@cdumez cdumez commented Mar 13, 2019

Add requestPermission() static operation to both DeviceOrientationEvent and DeviceMotionEvent
so that JavaScript can request permission to use the API so that user agents may ask the user
before sharing the device orientation & motion with the page.

Fixes: #57


Preview | Diff

@cdumez
Copy link
Contributor Author

cdumez commented Mar 13, 2019

This is based on the Notification API's requestPermission().

@cdumez
Copy link
Contributor Author

cdumez commented Mar 13, 2019

I landed initial support in WebKit via https://bugs.webkit.org/show_bug.cgi?id=195329 although it is still disabled by default given there was no spec PR yet.

@wseltzer
Copy link
Member

W3C has recorded a license commitment for this contribution, so I'm clearing the IPR check.

@wseltzer
Copy link
Member

wseltzer commented Mar 13, 2019

Marked as non substantive for IPR from ash-nazg. [Meant to reflect commitment-received, but tooling doesn't yet show that option.]

index.bs Outdated Show resolved Hide resolved
@cdumez cdumez force-pushed the requestPermission_api branch 3 times, most recently from 7326206 to e8765ac Compare March 13, 2019 22:22
@cdumez
Copy link
Contributor Author

cdumez commented Mar 13, 2019

I moved the user gesture check a bit later to allow websites to detect if they already have permission without a user gesture, as proposed in #57 (comment).

index.bs Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
Add requestPermission() static operation to both DeviceOrientationEvent and DeviceMotionEvent
so that JavaScript can request permission to use the API so that user agents may ask the user
before sharing the device orientation & motion with the page.

Fixes: w3c#57
@cdumez cdumez force-pushed the requestPermission_api branch from e8765ac to deeac36 Compare March 15, 2019 23:18
@anssiko
Copy link
Member

anssiko commented Mar 16, 2019

All - please submit your remaining review comments by EOB next Monday 18 March.

@anssiko
Copy link
Member

anssiko commented Mar 19, 2019

Hearing no further concerns I will merge this PR now.

Thank you @cdumez for the PR and reviewers for your insightful comments.

@anssiko anssiko merged commit 59a9299 into w3c:gh-pages Mar 19, 2019
@anssiko
Copy link
Member

anssiko commented Mar 19, 2019

(For completeness, submitted a separate PR #69 for a typo fix.)

@annevk
Copy link
Member

annevk commented Mar 19, 2019

Thanks for your work on this @cdumez. I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1536382 to track this for Firefox.

@rakuco
Copy link
Member

rakuco commented Apr 9, 2019

For future reference, we're tracking this in https://bugs.chromium.org/p/chromium/issues/detail?id=947112 for Chromium.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 18, 2019
…ion}Event

STILL WIP, BLOCKED ON https://crbug.com/952824

Implement w3c/deviceorientation#68, which has added
a static requestPermission() method to both DeviceOrientationEvent as well
as DeviceMotionEvent. Scripts wishing to listen to these events (as well as
deviceorientationabsolute) must first request permission from users by
calling those methods; until then, any event listeners are registered but
never triggered.

Permission granted via requestPermission() is checked for after other
existing checks (if the requires feature policy checks fail, for example, we
still do not register the event handler at all).

Implementing this requires changing how sensors permissions work in the
browser: so far, users could choose between always allowing and always
blocking sensor access. It is now possible to choose "Ask" as an option, in
which case a modal prompt asks the user for access (dismissing the prompt or
choosing "Block" both mean "Block" to the new web API). In any case, we keep
"Allow" as the default option for backwards compatibility. Specifically:
* In the desktop UI, it is possible to choose between "Allow", "Ask" and
  "Block" for sensors in chrome://settings/content/siteDetails and between
  "Allow" and "Ask" in chrome://settings/content/sensors.
* On Android, it is currrently not possible to have per-site sensor
  settings; on the global site settings, we now have a tri-state choice
  between "Allow", "Ask" and "Block".

Bug: 947112
Change-Id: I0e34b48fd21d56d6ac35ad55f69f992065a4bc62
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 19, 2019
…ion}Event

Implement w3c/deviceorientation#68, which has added
a static requestPermission() method to both DeviceOrientationEvent as well
as DeviceMotionEvent.

Permission granted via requestPermission() is checked for after other
existing checks (if the requires feature policy checks fail, for example, we
still do not register the event handler at all).

The spec is somewhat vague in how permission handling should be implemented.
For Chromium, we have settled on the following behavior:
* If sensor access is set to "Allow", event listeners can be registered at
  any time, and calling requestPermission() returns a promise that resolves
  to "granted".
* If sensor access is set to "Block", event listeners will only receive a
  single null event, and calling requestPermission() returns a promise that
  resolves to "blocked".
* If sensor access is set to "Ask", event listeners will only receive a
  single null event until requestPermission() is called and access is
  granted (i.e. the user explicitly clicked "Allow" in the permission
  bubble, any other behavior including dismissing the bubble results in
  denial). If requestPermission() is NOT called through a user gesture, it
  will return a promise that rejecs with a NotAllowedError DOMException. If
  access is granted, requestPermission() returns a promise that resolves to
  "granted"; if access is denied, requestPermission() returns a promise that
  resolves to "blocked".

Bug: 947112
Change-Id: Ibb6ad43b78ca54189cf8f7ef802a4f812c5030df
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 20, 2019
…ion}Event

Implement w3c/deviceorientation#68, which has added
a static requestPermission() method to both DeviceOrientationEvent as well
as DeviceMotionEvent.

Permission granted via requestPermission() is checked for after other
existing checks (if the requires feature policy checks fail, for example, we
still do not register the event handler at all).

The spec is somewhat vague in how permission handling should be implemented.
For Chromium, we have settled on the following behavior:
* If sensor access is set to "Allow", event listeners can be registered at
  any time, and calling requestPermission() returns a promise that resolves
  to "granted".
* If sensor access is set to "Block", event listeners will only receive a
  single null event, and calling requestPermission() returns a promise that
  resolves to "blocked".
* If sensor access is set to "Ask", event listeners will only receive a
  single null event until requestPermission() is called and access is
  granted (i.e. the user explicitly clicked "Allow" in the permission
  bubble, any other behavior including dismissing the bubble results in
  denial). If requestPermission() is NOT called through a user gesture, it
  will return a promise that rejecs with a NotAllowedError DOMException. If
  access is granted, requestPermission() returns a promise that resolves to
  "granted"; if access is denied, requestPermission() returns a promise that
  resolves to "blocked".

Bug: 947112
Change-Id: Ibb6ad43b78ca54189cf8f7ef802a4f812c5030df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants