summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/GeckoViewClipboardPermissionChild.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /mobile/android/actors/GeckoViewClipboardPermissionChild.jsm
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/actors/GeckoViewClipboardPermissionChild.jsm')
-rw-r--r--mobile/android/actors/GeckoViewClipboardPermissionChild.jsm100
1 files changed, 100 insertions, 0 deletions
diff --git a/mobile/android/actors/GeckoViewClipboardPermissionChild.jsm b/mobile/android/actors/GeckoViewClipboardPermissionChild.jsm
new file mode 100644
index 0000000000..2a5ffd5eaa
--- /dev/null
+++ b/mobile/android/actors/GeckoViewClipboardPermissionChild.jsm
@@ -0,0 +1,100 @@
+/* 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/. */
+"use strict";
+
+const { GeckoViewActorChild } = ChromeUtils.importESModule(
+ "resource://gre/modules/GeckoViewActorChild.sys.mjs"
+);
+
+const EXPORTED_SYMBOLS = ["GeckoViewClipboardPermissionChild"];
+
+class GeckoViewClipboardPermissionChild extends GeckoViewActorChild {
+ constructor() {
+ super();
+ this._pendingPromise = null;
+ }
+
+ async promptPermissionForClipboardRead() {
+ const uri = this.contentWindow.location.href;
+
+ const { x, y } = await this.sendQuery(
+ "ClipboardReadTextPaste:GetLastPointerLocation"
+ );
+
+ const promise = this.eventDispatcher.sendRequestForResult({
+ type: "GeckoView:ClipboardPermissionRequest",
+ uri,
+ screenPoint: {
+ x,
+ y,
+ },
+ });
+
+ this._pendingPromise = promise;
+
+ try {
+ const allowOrDeny = await promise;
+ if (this._pendingPromise !== promise) {
+ // Current pending promise is newer. So it means that this promise
+ // is already resolved or rejected. Do nothing.
+ return;
+ }
+ this.contentWindow.navigator.clipboard.onUserReactedToPasteMenuPopup(
+ allowOrDeny
+ );
+ this._pendingPromise = null;
+ } catch (error) {
+ debug`Permission error: ${error}`;
+
+ if (this._pendingPromise !== promise) {
+ // Current pending promise is newer. So it means that this promise
+ // is already resolved or rejected. Do nothing.
+ return;
+ }
+
+ this.contentWindow.navigator.clipboard.onUserReactedToPasteMenuPopup(
+ false
+ );
+ this._pendingPromise = null;
+ }
+ }
+
+ handleEvent(aEvent) {
+ debug`handleEvent: ${aEvent.type}`;
+
+ switch (aEvent.type) {
+ case "MozClipboardReadPaste":
+ if (aEvent.isTrusted) {
+ this.promptPermissionForClipboardRead();
+ }
+ break;
+
+ // page hide or deactivate cancel clipboard permission.
+ case "pagehide":
+ // fallthrough for the next three events.
+ case "deactivate":
+ case "mousedown":
+ case "mozvisualscroll":
+ // Gecko desktop uses XUL popup to show clipboard permission prompt.
+ // So it will be closed automatically by scroll and other user
+ // activation. So GeckoView has to close permission prompt by some user
+ // activations, too.
+
+ this.eventDispatcher.sendRequest({
+ type: "GeckoView:DismissClipboardPermissionRequest",
+ });
+ if (this._pendingPromise) {
+ this.contentWindow.navigator.clipboard.onUserReactedToPasteMenuPopup(
+ false
+ );
+ this._pendingPromise = null;
+ }
+ break;
+ }
+ }
+}
+
+const { debug, warn } = GeckoViewClipboardPermissionChild.initLogging(
+ "GeckoViewClipboardPermissionChild"
+);