summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs')
-rw-r--r--mobile/android/actors/GeckoViewPermissionProcessParent.sys.mjs56
1 files changed, 56 insertions, 0 deletions
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"
+);