1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
6 import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
8 export class GeckoViewPermissionParent extends GeckoViewActorParent {
11 async getAppPermissions(aPermissions) {
12 const perms = aPermissions.filter(perm => !this._appPermissions[perm]);
14 return Promise.resolve(/* granted */ true);
17 const granted = await this.eventDispatcher.sendRequestForResult({
18 type: "GeckoView:AndroidPermission",
23 for (const perm of perms) {
24 this._appPermissions[perm] = true;
31 addCameraPermission() {
33 Services.scriptSecurityManager.createContentPrincipalFromOrigin(
34 this.browsingContext.top.currentWindowGlobal.documentPrincipal.origin
37 // Although the lifetime is "session" it will be removed upon
38 // use so it's more of a one-shot.
39 Services.perms.addFromPrincipal(
42 Services.perms.ALLOW_ACTION,
43 Services.perms.EXPIRE_SESSION
49 receiveMessage(aMessage) {
50 debug`receiveMessage ${aMessage.name}`;
52 switch (aMessage.name) {
53 case "GetAppPermissions": {
54 return this.getAppPermissions(aMessage.data);
56 case "AddCameraPermission": {
57 return this.addCameraPermission();
61 return super.receiveMessage(aMessage);
65 const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewPermissionParent");