summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/SelectionActionDelegateParent.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/actors/SelectionActionDelegateParent.sys.mjs')
-rw-r--r--mobile/android/actors/SelectionActionDelegateParent.sys.mjs72
1 files changed, 72 insertions, 0 deletions
diff --git a/mobile/android/actors/SelectionActionDelegateParent.sys.mjs b/mobile/android/actors/SelectionActionDelegateParent.sys.mjs
new file mode 100644
index 0000000000..3ef5830ce4
--- /dev/null
+++ b/mobile/android/actors/SelectionActionDelegateParent.sys.mjs
@@ -0,0 +1,72 @@
+/* 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 { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
+
+export class SelectionActionDelegateParent extends GeckoViewActorParent {
+ respondTo = null;
+ actionId = null;
+
+ get rootActor() {
+ return this.browsingContext.top.currentWindowGlobal.getActor(
+ "SelectionActionDelegate"
+ );
+ }
+
+ receiveMessage(aMessage) {
+ const { data, name } = aMessage;
+ switch (name) {
+ case "ShowSelectionAction": {
+ this.rootActor.showSelectionAction(this, data);
+ break;
+ }
+
+ case "HideSelectionAction": {
+ this.rootActor.hideSelectionAction(this, data.reason);
+ break;
+ }
+
+ default: {
+ super.receiveMessage(aMessage);
+ }
+ }
+ }
+
+ hideSelectionAction(aRespondTo, reason) {
+ // Mark previous actions as stale. Don't do this for "invisibleselection"
+ // or "scroll" because previous actions should still be valid even after
+ // these events occur.
+ if (reason !== "invisibleselection" && reason !== "scroll") {
+ this.actionId = null;
+ }
+
+ this.eventDispatcher?.sendRequest({
+ type: "GeckoView:HideSelectionAction",
+ reason,
+ });
+ }
+
+ showSelectionAction(aRespondTo, aData) {
+ this.actionId = Services.uuid.generateUUID().toString();
+ this.respondTo = aRespondTo;
+
+ this.eventDispatcher?.sendRequest({
+ type: "GeckoView:ShowSelectionAction",
+ actionId: this.actionId,
+ ...aData,
+ });
+ }
+
+ executeSelectionAction(aData) {
+ if (this.actionId === null || aData.actionId != this.actionId) {
+ warn`Stale response ${aData.id} ${aData.actionId}`;
+ return;
+ }
+ this.respondTo.sendAsyncMessage("ExecuteSelectionAction", aData);
+ }
+}
+
+const { debug, warn } = SelectionActionDelegateParent.initLogging(
+ "SelectionActionDelegate"
+);