diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /browser/base/content/newInstallPage.js | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/newInstallPage.js')
-rw-r--r-- | browser/base/content/newInstallPage.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/browser/base/content/newInstallPage.js b/browser/base/content/newInstallPage.js new file mode 100644 index 0000000000..2b378a30d4 --- /dev/null +++ b/browser/base/content/newInstallPage.js @@ -0,0 +1,74 @@ +/* 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/. */ + +/* global RPMGetUpdateChannel, RPMGetFxAccountsEndpoint */ + +const PARAMS = new URL(location).searchParams; +const ENTRYPOINT = "new-install-page"; +const SOURCE = `new-install-page-${RPMGetUpdateChannel()}`; +const CAMPAIGN = "dedicated-profiles"; +const ENDPOINT = PARAMS.get("endpoint"); + +function appendAccountsParams(url) { + url.searchParams.set("entrypoint", ENTRYPOINT); + url.searchParams.set("utm_source", SOURCE); + url.searchParams.set("utm_campaign", CAMPAIGN); +} + +function appendParams(url, params) { + appendAccountsParams(url); + + for (let [key, value] of Object.entries(params)) { + url.searchParams.set(key, value); + } +} + +async function requestFlowMetrics() { + let requestURL = new URL(await endpoint); + requestURL.pathname = "metrics-flow"; + appendParams(requestURL, { + form_type: "email", + }); + + let response = await fetch(requestURL, { credentials: "omit" }); + if (response.status === 200) { + return response.json(); + } + + throw new Error(`Failed to retrieve metrics: ${response.status}`); +} + +async function submitForm(event) { + // We never want to submit the form. + event.preventDefault(); + + let input = document.getElementById("sync-input"); + + let { flowId, flowBeginTime } = await metrics; + + let requestURL = new URL(await endpoint); + appendParams(requestURL, { + action: "email", + utm_campaign: CAMPAIGN, + email: input.value, + flow_id: flowId, + flow_begin_time: flowBeginTime, + }); + + window.open(requestURL, "_blank", "noopener"); + document.getElementById("sync").hidden = true; +} + +const endpoint = RPMGetFxAccountsEndpoint(ENTRYPOINT); + +// This must come before the CSP is set or it will be blocked. +const metrics = requestFlowMetrics(); + +document.addEventListener( + "DOMContentLoaded", + () => { + document.getElementById("sync").addEventListener("submit", submitForm); + }, + { once: true } +); |