summaryrefslogtreecommitdiffstats
path: root/toolkit/components/satchel/FormHandlerChild.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /toolkit/components/satchel/FormHandlerChild.sys.mjs
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/satchel/FormHandlerChild.sys.mjs')
-rw-r--r--toolkit/components/satchel/FormHandlerChild.sys.mjs72
1 files changed, 72 insertions, 0 deletions
diff --git a/toolkit/components/satchel/FormHandlerChild.sys.mjs b/toolkit/components/satchel/FormHandlerChild.sys.mjs
new file mode 100644
index 0000000000..6b1af3dbc3
--- /dev/null
+++ b/toolkit/components/satchel/FormHandlerChild.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/. */
+
+/**
+ * The FormHandlerChild is the place to implement logic that is shared
+ * by child actors like FormAutofillChild, LoginManagerChild and FormHistoryChild
+ * or in general components that deal with form data.
+ */
+
+export const FORM_SUBMISSION_REASON = {
+ FORM_SUBMIT_EVENT: "form-submit-event",
+ FORM_REMOVAL_AFTER_FETCH: "form-removal-after-fetch",
+ IFRAME_PAGEHIDE: "iframe-pagehide",
+ PAGE_NAVIGATION: "page-navigation",
+};
+
+export class FormHandlerChild extends JSWindowActorChild {
+ handleEvent(event) {
+ if (!event.isTrusted) {
+ return;
+ }
+ switch (event.type) {
+ case "DOMFormBeforeSubmit":
+ this.processDOMFormBeforeSubmitEvent(event);
+ break;
+ default:
+ throw new Error("Unexpected event type");
+ }
+ }
+
+ /**
+ * Process the DOMFormBeforeSubmitEvent that is dispatched
+ * after a form submit event. Extract event data
+ * that is relevant to the form submission listeners
+ *
+ * @param {Event} event DOMFormBeforeSubmit
+ */
+ processDOMFormBeforeSubmitEvent(event) {
+ const form = event.target;
+ const formSubmissionReason = FORM_SUBMISSION_REASON.FORM_SUBMIT_EVENT;
+
+ this.#dispatchFormSubmissionEvent(form, formSubmissionReason);
+ }
+
+ // handle form-removal-after-fetch
+ processFormRemovalAfterFetch(params) {}
+
+ // handle iframe-pagehide
+ processIframePagehide(params) {}
+
+ // handle page-navigation
+ processPageNavigation(params) {}
+
+ /**
+ * Dispatch the CustomEvent form-submission-detected also transfer
+ * the information:
+ * detail.form - the form that is being submitted
+ * detail.reason - the heuristic that detected the form submission
+ * (see FORM_SUBMISSION_REASON)
+ *
+ * @param {HTMLFormElement} form
+ * @param {string} reason
+ */
+ #dispatchFormSubmissionEvent(form, reason) {
+ const formSubmissionEvent = new CustomEvent("form-submission-detected", {
+ detail: { form, reason },
+ bubbles: true,
+ });
+ this.document.dispatchEvent(formSubmissionEvent);
+ }
+}