From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../GeckoViewPermissionProcessParent.sys.mjs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs (limited to 'mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs') diff --git a/mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs b/mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs new file mode 100644 index 0000000000..47b98602a5 --- /dev/null +++ b/mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs @@ -0,0 +1,56 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs"; + +// See: http://developer.android.com/reference/android/Manifest.permission.html +const PERM_CAMERA = "android.permission.CAMERA"; +const PERM_RECORD_AUDIO = "android.permission.RECORD_AUDIO"; + +export class GeckoViewPermissionProcessParent extends JSProcessActorParent { + async askDevicePermission(aType) { + const perms = []; + if (aType === "video" || aType === "all") { + perms.push(PERM_CAMERA); + } + if (aType === "audio" || aType === "all") { + perms.push(PERM_RECORD_AUDIO); + } + + try { + // This looks sketchy but it's fine: Android needs the audio/video + // permission to enumerate devices, which Gecko wants to do even before + // we expose the list to web pages. + // So really it doesn't matter what the request source is, because we + // will, separately, issue a windowId-specific request to let the webpage + // actually have access to the list of devices. So even if the source of + // *this* request is incorrect, no actual harm will be done, as the user + // will always receive the request with the right origin after this. + const window = Services.wm.getMostRecentWindow("navigator:geckoview"); + const windowActor = window.browsingContext.currentWindowGlobal.getActor( + "GeckoViewPermission" + ); + await windowActor.getAppPermissions(perms); + } catch (error) { + // We can't really do anything here so we pretend we got the permission. + warn`Error getting app permission: ${error}`; + } + } + + receiveMessage(aMessage) { + debug`receiveMessage ${aMessage.name}`; + + switch (aMessage.name) { + case "AskDevicePermission": { + return this.askDevicePermission(aMessage.data); + } + } + + return super.receiveMessage(aMessage); + } +} + +const { debug, warn } = GeckoViewUtils.initLogging( + "GeckoViewPermissionProcess" +); -- cgit v1.2.3