Skip to content

Commit

Permalink
Bug 1580567 - Implement XR device access permission UI r=fluent-revie…
Browse files Browse the repository at this point in the history
…wers,bzbarsky,pbz,daoshengmu,imanol

Added @rbarker as a reviewer to check if this will work well within GeckoView for FxR / Android.
Added @bzbarsky for test_interfaces.html.  -- I'd like to re-land the secure origin requirement for WebVR as part of this patch, as it doesn't help to have UI that can't guarantee the identity of the origin.  (This was backed out due to test failures originally, and since been fixed)

Differential Revision: https://phabricator.services.mozilla.com/D45951
  • Loading branch information
Kearwood Kip Gilbert committed Dec 4, 2019
1 parent 13b9941 commit a7d1770
Show file tree
Hide file tree
Showing 42 changed files with 603 additions and 81 deletions.
2 changes: 2 additions & 0 deletions browser/app/profile/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ pref("permissions.manager.defaultsUrl", "resource://app/defaults/permissions");
pref("permissions.default.camera", 0);
pref("permissions.default.microphone", 0);
pref("permissions.default.geo", 0);
pref("permissions.default.xr", 0);
pref("permissions.default.desktop-notification", 0);
pref("permissions.default.shortcuts", 0);

Expand Down Expand Up @@ -837,6 +838,7 @@ pref("gecko.handlerService.schemes.ircs.3.name", "chrome://browser-region/locale
pref("gecko.handlerService.schemes.ircs.3.uriTemplate", "chrome://browser-region/locale/region.properties");

pref("browser.geolocation.warning.infoURL", "https://www.mozilla.org/%LOCALE%/firefox/geolocation/");
pref("browser.xr.warning.infoURL", "https://www.mozilla.org/%LOCALE%/firefox/xr/");

pref("browser.sessionstore.resume_from_crash", true);
pref("browser.sessionstore.resume_session_once", false);
Expand Down
36 changes: 32 additions & 4 deletions browser/base/content/browser-siteIdentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ var gIdentityHandler = {
return (this._geoSharingIcon = document.getElementById("geo-sharing-icon"));
},

get _xrSharingIcon() {
delete this._xrSharingIcon;
return (this._xrSharingIcon = document.getElementById("xr-sharing-icon"));
},

get _webRTCSharingIcon() {
delete this._webRTCSharingIcon;
return (this._webRTCSharingIcon = document.getElementById(
Expand Down Expand Up @@ -572,6 +577,7 @@ var gIdentityHandler = {
this._webRTCSharingIcon.removeAttribute("paused");
this._webRTCSharingIcon.removeAttribute("sharing");
this._geoSharingIcon.removeAttribute("sharing");
this._xrSharingIcon.removeAttribute("sharing");

if (this._sharingState) {
if (
Expand All @@ -591,6 +597,9 @@ var gIdentityHandler = {
if (this._sharingState.geo) {
this._geoSharingIcon.setAttribute("sharing", this._sharingState.geo);
}
if (this._sharingState.xr) {
this._xrSharingIcon.setAttribute("sharing", this._sharingState.xr);
}
}

if (this._identityPopup.state == "open") {
Expand Down Expand Up @@ -1345,6 +1354,20 @@ var gIdentityHandler = {
}
}

if (this._sharingState && this._sharingState.xr) {
let xrPermission = permissions.find(perm => perm.id === "xr");
if (xrPermission) {
xrPermission.sharingState = true;
} else {
permissions.push({
id: "xr",
state: SitePermissions.ALLOW,
scope: SitePermissions.SCOPE_REQUEST,
sharingState: true,
});
}
}

if (this._sharingState && this._sharingState.webRTC) {
let webrtcState = this._sharingState.webRTC;
// If WebRTC device or screen permissions are in use, we need to find
Expand Down Expand Up @@ -1572,9 +1595,12 @@ var gIdentityHandler = {
return container;
}

if (aPermission.id == "geo") {
if (aPermission.id == "geo" || aPermission.id == "xr") {
let block = document.createXULElement("vbox");
block.setAttribute("id", "identity-popup-geo-container");
block.setAttribute(
"id",
"identity-popup-" + aPermission.id + "-container"
);

let button = this._createPermissionClearButton(aPermission, block);
container.appendChild(button);
Expand Down Expand Up @@ -1608,8 +1634,8 @@ var gIdentityHandler = {
let browser = gBrowser.selectedBrowser;
this._permissionList.removeChild(container);
if (aPermission.sharingState) {
if (aPermission.id === "geo") {
let origins = browser.getDevicePermissionOrigins("geo");
if (aPermission.id === "geo" || aPermission.id === "xr") {
let origins = browser.getDevicePermissionOrigins(aPermission.id);
for (let origin of origins) {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
origin
Expand Down Expand Up @@ -1664,6 +1690,8 @@ var gIdentityHandler = {

if (aPermission.id === "geo") {
gBrowser.updateBrowserSharing(browser, { geo: false });
} else if (aPermission.id === "xr") {
gBrowser.updateBrowserSharing(browser, { xr: false });
}
});

Expand Down
5 changes: 5 additions & 0 deletions browser/base/content/browser.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,13 @@
<box style="pointer-events: none;">
<image class="sharing-icon" id="webrtc-sharing-icon"/>
<image class="sharing-icon geo-icon" id="geo-sharing-icon"/>
<image class="sharing-icon xr-icon" id="xr-sharing-icon"/>
</box>
<box id="blocked-permissions-container" align="center">
<image data-permission-id="geo" class="blocked-permission-icon geo-icon" role="button"
data-l10n-id="urlbar-geolocation-blocked"/>
<image data-permission-id="xr" class="blocked-permission-icon xr-icon" role="button"
data-l10n-id="urlbar-xr-blocked"/>
<image data-permission-id="desktop-notification" class="blocked-permission-icon desktop-notification-icon" role="button"
data-l10n-id="urlbar-web-notifications-blocked"/>
<image data-permission-id="camera" class="blocked-permission-icon camera-icon" role="button"
Expand Down Expand Up @@ -924,6 +927,8 @@
data-l10n-id="urlbar-default-notification-anchor"/>
<image id="geo-notification-icon" class="notification-anchor-icon geo-icon" role="button"
data-l10n-id="urlbar-geolocation-notification-anchor"/>
<image id="xr-notification-icon" class="notification-anchor-icon xr-icon" role="button"
data-l10n-id="urlbar-xr-notification-anchor"/>
<image id="autoplay-media-notification-icon" class="notification-anchor-icon autoplay-media-icon" role="button"
data-l10n-id="urlbar-autoplay-notification-anchor"/>
<image id="addons-notification-icon" class="notification-anchor-icon install-icon" role="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ add_task(async function testTempPermissionRequestAfterExpiry() {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
ORIGIN
);
let ids = ["geo", "camera"];
let ids = ["geo", "camera", "xr"];

for (let id of ids) {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function(
Expand Down
1 change: 1 addition & 0 deletions browser/base/content/test/permissions/permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<!-- This page could eventually request permissions from content
and make sure that chrome responds appropriately -->
<button id="geo" onclick="requestGeo()">Geolocation</button>
<button id="xr" onclick="navigator.getVRDisplays()">XR</button>
<button id="desktop-notification" onclick="Notification.requestPermission()">Notifications</button>
<button id="push" onclick="requestPush()">Push Notifications</button>
<button id="camera" onclick="navigator.mediaDevices.getUserMedia({video: true, fake: true})">Camera</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ async function check(contentTask, options = {}) {
let panel = await popupShownPromise;
let notification = panel.children[0];
let body = notification.querySelector(".popup-notification-body");
if (notification.id == "geolocation-notification") {
if (
notification.id == "geolocation-notification" ||
notification.id == "xr-notification"
) {
ok(
body.innerHTML.includes("local file"),
`file:// URIs should be displayed as local file.`
Expand Down Expand Up @@ -96,6 +99,12 @@ add_task(async function test_displayURI_geo() {
});
});

add_task(async function test_displayURI_xr() {
await check(async function() {
content.navigator.getVRDisplays();
});
});

add_task(async function test_displayURI_camera() {
await check(async function() {
content.navigator.mediaDevices.getUserMedia({ video: true, fake: true });
Expand All @@ -115,6 +124,18 @@ add_task(async function test_displayURI_geo_blob() {
);
});

add_task(async function test_displayURI_xr_blob() {
await check(
async function() {
let text = "<script>navigator.getVRDisplays()</script>";
let blob = new Blob([text], { type: "text/html" });
let url = content.URL.createObjectURL(blob);
content.location.href = url;
},
{ skipOnExtension: true }
);
});

add_task(async function test_displayURI_camera_blob() {
await check(
async function() {
Expand Down
3 changes: 3 additions & 0 deletions browser/components/BrowserGlue.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -4031,6 +4031,9 @@ const ContentPermissionIntegration = {
case "geolocation": {
return new PermissionUI.GeolocationPermissionPrompt(request);
}
case "xr": {
return new PermissionUI.XRPermissionPrompt(request);
}
case "desktop-notification": {
return new PermissionUI.DesktopNotificationPermissionPrompt(request);
}
Expand Down
24 changes: 24 additions & 0 deletions browser/components/preferences/in-content/privacy.inc.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,30 @@
" />
</hbox>
</hbox>

<hbox id="xrSettingsRow" align="center" role="group" aria-labelledby="xrPermissionsLabel">
<description flex="1">
<image class="xr-icon permission-icon" />
<separator orient="vertical" class="thin"/>
<label id="xrPermissionsLabel" data-l10n-id="permissions-xr"/>
</description>
<hbox pack="end">
<button id="xrSettingsButton"
is="highlightable-button"
class="accessory-button"
data-l10n-id="permissions-xr-settings"
search-l10n-ids="
permissions-remove.label,
permissions-remove-all.label,
permissions-button-cancel.label,
permissions-button-ok.label,
permissions-site-xr-window.title,
permissions-site-xr-desc,
permissions-site-xr-disable-label,
permissions-site-xr-disable-desc,
" />
</hbox>
</hbox>
</vbox>

<separator flex="1"/>
Expand Down
21 changes: 21 additions & 0 deletions browser/components/preferences/in-content/privacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ var gPrivacyPane = {
"command",
gPrivacyPane.showLocationExceptions
);
setEventListener(
"xrSettingsButton",
"command",
gPrivacyPane.showXRExceptions
);
setEventListener(
"cameraSettingsButton",
"command",
Expand Down Expand Up @@ -1679,6 +1684,22 @@ var gPrivacyPane = {
);
},

// XR

/**
* Displays the XR exceptions dialog where specific site XR
* preferences can be set.
*/
showXRExceptions() {
let params = { permissionType: "xr" };

gSubDialog.open(
"chrome://browser/content/preferences/sitePermissions.xul",
"resizable=yes",
params
);
},

// CAMERA

/**
Expand Down
6 changes: 6 additions & 0 deletions browser/components/preferences/sitePermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const sitePermissionsL10n = {
disableLabel: "permissions-site-location-disable-label",
disableDescription: "permissions-site-location-disable-desc",
},
xr: {
window: "permissions-site-xr-window",
description: "permissions-site-xr-desc",
disableLabel: "permissions-site-xr-disable-label",
disableDescription: "permissions-site-xr-disable-desc",
},
camera: {
window: "permissions-site-camera-window",
description: "permissions-site-camera-desc",
Expand Down
5 changes: 3 additions & 2 deletions browser/components/privatebrowsing/test/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ tags = openwindow
support-files =
browser_privatebrowsing_concurrent_page.html
browser_privatebrowsing_geoprompt_page.html
browser_privatebrowsing_xrprompt_page.html
browser_privatebrowsing_localStorage_before_after_page.html
browser_privatebrowsing_localStorage_before_after_page2.html
browser_privatebrowsing_localStorage_page1.html
Expand Down Expand Up @@ -35,8 +36,6 @@ skip-if = verify
[browser_privatebrowsing_downloadLastDir_c.js]
[browser_privatebrowsing_downloadLastDir_toggle.js]
[browser_privatebrowsing_favicon.js]
[browser_privatebrowsing_geoprompt.js]
tags = geolocation
[browser_privatebrowsing_lastpbcontextexited.js]
[browser_privatebrowsing_localStorage.js]
[browser_privatebrowsing_localStorage_before_after.js]
Expand All @@ -47,6 +46,8 @@ tags = geolocation
[browser_privatebrowsing_placestitle.js]
[browser_privatebrowsing_popupblocker.js]
[browser_privatebrowsing_protocolhandler.js]
[browser_privatebrowsing_rememberprompt.js]
tags = geolocation xr
[browser_privatebrowsing_sidebar.js]
[browser_privatebrowsing_theming.js]
[browser_privatebrowsing_ui.js]
Expand Down
Loading

0 comments on commit a7d1770

Please sign in to comment.