Bug 1891710: part 2) Enable <Element-outerHTML.html> WPT for Trusted Types. r=smaug
[gecko.git] / mobile / android / actors / GeckoViewPermissionParent.sys.mjs
blobc4a5cf56cf0b27d0a8d67feaba3489c27ca92ffc
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 {
9   _appPermissions = {};
11   async getAppPermissions(aPermissions) {
12     const perms = aPermissions.filter(perm => !this._appPermissions[perm]);
13     if (!perms.length) {
14       return Promise.resolve(/* granted */ true);
15     }
17     const granted = await this.eventDispatcher.sendRequestForResult({
18       type: "GeckoView:AndroidPermission",
19       perms,
20     });
22     if (granted) {
23       for (const perm of perms) {
24         this._appPermissions[perm] = true;
25       }
26     }
28     return granted;
29   }
31   addCameraPermission() {
32     const principal =
33       Services.scriptSecurityManager.createContentPrincipalFromOrigin(
34         this.browsingContext.top.currentWindowGlobal.documentPrincipal.origin
35       );
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(
40       principal,
41       "MediaManagerVideo",
42       Services.perms.ALLOW_ACTION,
43       Services.perms.EXPIRE_SESSION
44     );
46     return null;
47   }
49   receiveMessage(aMessage) {
50     debug`receiveMessage ${aMessage.name}`;
52     switch (aMessage.name) {
53       case "GetAppPermissions": {
54         return this.getAppPermissions(aMessage.data);
55       }
56       case "AddCameraPermission": {
57         return this.addCameraPermission();
58       }
59     }
61     return super.receiveMessage(aMessage);
62   }
65 const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewPermissionParent");