Bug 1869043 add a main thread record of track audio outputs r=padenot
[gecko.git] / mobile / android / actors / SelectionActionDelegateParent.sys.mjs
blob3ef5830ce4bd4ea2a893e17211790137d5635543
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 { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
7 export class SelectionActionDelegateParent extends GeckoViewActorParent {
8   respondTo = null;
9   actionId = null;
11   get rootActor() {
12     return this.browsingContext.top.currentWindowGlobal.getActor(
13       "SelectionActionDelegate"
14     );
15   }
17   receiveMessage(aMessage) {
18     const { data, name } = aMessage;
19     switch (name) {
20       case "ShowSelectionAction": {
21         this.rootActor.showSelectionAction(this, data);
22         break;
23       }
25       case "HideSelectionAction": {
26         this.rootActor.hideSelectionAction(this, data.reason);
27         break;
28       }
30       default: {
31         super.receiveMessage(aMessage);
32       }
33     }
34   }
36   hideSelectionAction(aRespondTo, reason) {
37     // Mark previous actions as stale. Don't do this for "invisibleselection"
38     // or "scroll" because previous actions should still be valid even after
39     // these events occur.
40     if (reason !== "invisibleselection" && reason !== "scroll") {
41       this.actionId = null;
42     }
44     this.eventDispatcher?.sendRequest({
45       type: "GeckoView:HideSelectionAction",
46       reason,
47     });
48   }
50   showSelectionAction(aRespondTo, aData) {
51     this.actionId = Services.uuid.generateUUID().toString();
52     this.respondTo = aRespondTo;
54     this.eventDispatcher?.sendRequest({
55       type: "GeckoView:ShowSelectionAction",
56       actionId: this.actionId,
57       ...aData,
58     });
59   }
61   executeSelectionAction(aData) {
62     if (this.actionId === null || aData.actionId != this.actionId) {
63       warn`Stale response ${aData.id} ${aData.actionId}`;
64       return;
65     }
66     this.respondTo.sendAsyncMessage("ExecuteSelectionAction", aData);
67   }
70 const { debug, warn } = SelectionActionDelegateParent.initLogging(
71   "SelectionActionDelegate"