Bug 1599927 - Support WebXR device access permission in GeckoSession. r=imanol,rbarker,geckoview-reviewers,snorp

Differential Revision: https://phabricator.services.mozilla.com/D55043

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daosheng Mu 2019-12-11 03:35:58 +00:00
parent 19ba3b0322
commit f81abc3e13
6 changed files with 28 additions and 8 deletions

View File

@ -113,9 +113,9 @@ public class GeckoViewActivity extends AppCompatActivity {
### Content Permissions
Content permissions are requested whenever a site wants access to content that is stored on the device. The content permissions that can be requested through GeckoView are; [`Geolocation`][10], [`Site Notifications`][11] and [`Persistent Storage`][12] access.
Content permissions are requested whenever a site wants access to content that is stored on the device. The content permissions that can be requested through GeckoView are; [`Geolocation`][10], [`Site Notifications`][11] [`Persistent Storage`][12] and [`XR`][13] access.
When you receive an [`onContentPermissionRequest`][13] call, you will also receive the `GeckoSession` the request was sent from, the URI of the site that requested the permission, as a String, the type of the content permission requested (geolocation, site notification or persistent storage), and a [`Callback`][4] to respond to the request. It is then up to the app to present UI to the user asking for the permissions, and to notify GeckoView of the response via the `Callback`.
When you receive an [`onContentPermissionRequest`][14] call, you will also receive the `GeckoSession` the request was sent from, the URI of the site that requested the permission, as a String, the type of the content permission requested (geolocation, site notification or persistent storage), and a [`Callback`][4] to respond to the request. It is then up to the app to present UI to the user asking for the permissions, and to notify GeckoView of the response via the `Callback`.
*Please note, in the case of `PERMISSION_DESKTOP_NOTIFICATION` and `PERMISSION_PERSISTENT_STORAGE`, GeckoView does not track accepted permissions and prevent further requests being sent for a particular site. It is therefore up to the calling app to do this if that is the desired behaviour. The code below demonstrates how to track storage permissions by site and track notification permission rejection for the whole app*
@ -145,6 +145,8 @@ private class ExamplePermissionDelegate implements GeckoSession.PermissionDelega
return;
}
resId = R.string.request_storage;
} else if (PERMISSION_XR == type) {
resId = R.string.request_xr;
} else { // unknown permission type
callback.reject();
return;
@ -183,7 +185,7 @@ private class ExamplePermissionDelegate implements GeckoSession.PermissionDelega
### Media Permissions
Media permissions are requested whenever a site wants access to play or record media from the device's camera and microphone.
When you receive an [`onMediaPermissionRequest`][14] call, you will also receive the `GeckoSession` the request was sent from, the URI of the site that requested the permission, as a String, the list of video devices available, if requesting video, the list of audio devices available, if requesting audio, and a [`MediaCallback`][15] to respond to the request.
When you receive an [`onMediaPermissionRequest`][15] call, you will also receive the `GeckoSession` the request was sent from, the URI of the site that requested the permission, as a String, the list of video devices available, if requesting video, the list of audio devices available, if requesting audio, and a [`MediaCallback`][17] to respond to the request.
It is up to the app to present UI to the user asking for the permissions, and to notify GeckoView of the response via the `MediaCallback`.
@ -280,7 +282,8 @@ To see the `PermissionsDelegate` in action, you can find the full example implem
[10]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#PERMISSION_GEOLOCATION
[11]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#PERMISSION_DESKTOP_NOTIFICATION
[12]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#PERMISSION_PERSISTENT_STORAGE
[13]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#onContentPermissionRequest-org.mozilla.geckoview.GeckoSession-java.lang.String-int-org.mozilla.geckoview.GeckoSession.PermissionDelegate.Callback-
[14]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#onMediaPermissionRequest-org.mozilla.geckoview.GeckoSession-java.lang.String-org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaSource:A-org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaSource:A-org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaCallback-
[15]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.MediaCallback.html
[16]: https://searchfox.org/mozilla-central/source/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java#686
[13]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#PERMISSION_XR
[14]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#onContentPermissionRequest-org.mozilla.geckoview.GeckoSession-java.lang.String-int-org.mozilla.geckoview.GeckoSession.PermissionDelegate.Callback-
[15]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.html#onMediaPermissionRequest-org.mozilla.geckoview.GeckoSession-java.lang.String-org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaSource:A-org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaSource:A-org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaCallback-
[16]: {{ site.url }}{{ site.baseurl }}/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSession.PermissionDelegate.MediaCallback.html
[17]: https://searchfox.org/mozilla-central/source/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java#686

View File

@ -777,6 +777,7 @@ package org.mozilla.geckoview {
field public static final int PERMISSION_DESKTOP_NOTIFICATION = 1;
field public static final int PERMISSION_GEOLOCATION = 0;
field public static final int PERMISSION_PERSISTENT_STORAGE = 2;
field public static final int PERMISSION_XR = 3;
}
public static interface GeckoSession.PermissionDelegate.Callback {

View File

@ -792,6 +792,8 @@ public class GeckoSession implements Parcelable {
type = PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION;
} else if ("persistent-storage".equals(typeString)) {
type = PermissionDelegate.PERMISSION_PERSISTENT_STORAGE;
} else if ("xr".equals(typeString)) {
type = PermissionDelegate.PERMISSION_XR;
} else if ("midi".equals(typeString)) {
// We can get this from WPT and presumably other content, but Gecko
// doesn't support Web MIDI.
@ -4959,6 +4961,12 @@ public class GeckoSession implements Parcelable {
*/
int PERMISSION_PERSISTENT_STORAGE = 2;
/**
* Permission for using the WebXR API.
* See: https://www.w3.org/TR/webxr
*/
int PERMISSION_XR = 3;
/**
* Callback interface for notifying the result of a permission request.
*/
@ -5010,6 +5018,7 @@ public class GeckoSession implements Parcelable {
* PERMISSION_GEOLOCATION
* PERMISSION_DESKTOP_NOTIFICATION
* PERMISSION_PERSISTENT_STORAGE
* PERMISSION_XR
* @param callback Callback interface.
*/
@UiThread
@ -5207,7 +5216,8 @@ public class GeckoSession implements Parcelable {
@Retention(RetentionPolicy.SOURCE)
@IntDef({PermissionDelegate.PERMISSION_GEOLOCATION,
PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION})
PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION,
PermissionDelegate.PERMISSION_XR})
/* package */ @interface Permission {}
/**

View File

@ -62,6 +62,8 @@ exclude: true
accept a JSON object instead of a Map. Said object also includes the
application name that was previously passed as the fourth argument to the
method, which was thus removed.
- Added WebXR device access permission support, [`PERMISSION_PERSISTENT_XR`][72.24].
([bug 1599927]({{bugzilla}}1599927))
[72.1]: {{javadoc_uri}}/GeckoSession.NavigationDelegate.LoadRequest#hasUserGesture-
[72.2]: {{javadoc_uri}}/Autofill.html
@ -86,6 +88,7 @@ exclude: true
[72.21]: {{javadoc_uri}}/WebExtension.Icon.html
[72.22]: {{javadoc_uri}}/GeckoWebExecutor.html#FETCH_FLAGS_STREAM_FAILURE_TEST
[72.23]: {{javadoc_uri}}/CrashReporter#sendCrashReport-android.content.Context-java.io.File-org.json.JSONObject-
[72.24]: {{javadoc_uri}}/GeckoSession.PermissionDelegate.html#PERMISSION_PERSISTENT_XR
## v71
- Added a content blocking flag for blocked social cookies to [`ContentBlocking`][70.17].

View File

@ -1186,6 +1186,8 @@ public class GeckoViewActivity
}
resId = R.string.request_storage;
contentPermissionCallback = new ExamplePersistentStorageCallback(callback, uri);
} else if (PERMISSION_XR == type) {
resId = R.string.request_xr;
} else {
Log.w(LOGTAG, "Unknown permission: " + type);
callback.reject();

View File

@ -11,6 +11,7 @@
<string name="request_video">Share video with "%1$s"</string>
<string name="request_audio">Share audio with "%1$s"</string>
<string name="request_media">Share video and audio with "%1$s"</string>
<string name="request_xr">Share WebXR displays with "%1$s"?</string>
<string name="media_back_camera">Back camera</string>
<string name="media_front_camera">Front camera</string>
<string name="media_microphone">Microphone</string>