From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../GeckoViewClipboardPermissionChild.sys.mjs | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 mobile/android/actors/GeckoViewClipboardPermissionChild.sys.mjs (limited to 'mobile/android/actors/GeckoViewClipboardPermissionChild.sys.mjs') diff --git a/mobile/android/actors/GeckoViewClipboardPermissionChild.sys.mjs b/mobile/android/actors/GeckoViewClipboardPermissionChild.sys.mjs new file mode 100644 index 0000000000..56e7a39e7b --- /dev/null +++ b/mobile/android/actors/GeckoViewClipboardPermissionChild.sys.mjs @@ -0,0 +1,95 @@ +/* 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 { GeckoViewActorChild } from "resource://gre/modules/GeckoViewActorChild.sys.mjs"; + +export 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" +); -- cgit v1.2.3