From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001
From: Daniel Baumann <daniel.baumann@progress-linux.org>
Date: Sun, 7 Apr 2024 11:22:09 +0200
Subject: Adding upstream version 110.0.1.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
---
 .../components/protections/content/vpn-card.mjs    | 102 +++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 browser/components/protections/content/vpn-card.mjs

(limited to 'browser/components/protections/content/vpn-card.mjs')

diff --git a/browser/components/protections/content/vpn-card.mjs b/browser/components/protections/content/vpn-card.mjs
new file mode 100644
index 0000000000..9b7602f75c
--- /dev/null
+++ b/browser/components/protections/content/vpn-card.mjs
@@ -0,0 +1,102 @@
+/* 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/. */
+
+/* eslint-env mozilla/remote-page */
+
+export default class VPNCard {
+  constructor(document) {
+    this.doc = document;
+  }
+
+  init() {
+    const vpnLink = this.doc.getElementById("get-vpn-link");
+    const vpnBannerLink = this.doc.getElementById("vpn-banner-link");
+    vpnLink.href = RPMGetStringPref(
+      "browser.contentblocking.report.vpn.url",
+      ""
+    );
+    vpnBannerLink.href = RPMGetStringPref(
+      "browser.contentblocking.report.vpn-promo.url",
+      ""
+    );
+
+    vpnLink.addEventListener("click", () => {
+      this.doc.sendTelemetryEvent("click", "vpn_card_link");
+    });
+    let androidVPNAppLink = document.getElementById(
+      "vpn-google-playstore-link"
+    );
+    androidVPNAppLink.href = RPMGetStringPref(
+      "browser.contentblocking.report.vpn-android.url"
+    );
+    androidVPNAppLink.addEventListener("click", () => {
+      document.sendTelemetryEvent("click", "vpn_app_link_android");
+    });
+    let iosVPNAppLink = document.getElementById("vpn-app-store-link");
+    iosVPNAppLink.href = RPMGetStringPref(
+      "browser.contentblocking.report.vpn-ios.url"
+    );
+    iosVPNAppLink.addEventListener("click", () => {
+      document.sendTelemetryEvent("click", "vpn_app_link_ios");
+    });
+
+    const vpnBanner = this.doc.querySelector(".vpn-banner");
+    const exitIcon = vpnBanner.querySelector(".exit-icon");
+    vpnBannerLink.addEventListener("click", () => {
+      this.doc.sendTelemetryEvent("click", "vpn_banner_link");
+    });
+    // User has closed the vpn banner, hide it.
+    exitIcon.addEventListener("click", () => {
+      vpnBanner.classList.add("hidden");
+      this.doc.sendTelemetryEvent("click", "vpn_banner_close");
+    });
+
+    this.showVPNCard();
+  }
+
+  // Show the VPN card if user is located in areas, and on platforms, it serves
+  async showVPNCard() {
+    const showVPNBanner = this.showVPNBanner.bind(this);
+    RPMSendQuery("FetchShowVPNCard", {}).then(shouldShow => {
+      if (!shouldShow) {
+        return;
+      }
+      const vpnCard = this.doc.querySelector(".vpn-card");
+
+      // add 'subscribed' class if user is subscribed to vpn
+      RPMSendQuery("FetchVPNSubStatus", {}).then(async hasVPN => {
+        if (hasVPN) {
+          vpnCard.classList.add("subscribed");
+          vpnCard
+            .querySelector(".card-title")
+            .setAttribute("data-l10n-id", "vpn-title-subscribed");
+
+          // hide the promo banner if the user is already subscribed to vpn
+          await RPMSetBoolPref(
+            "browser.contentblocking.report.hide_vpn_banner",
+            true
+          );
+        }
+
+        vpnCard.classList.remove("hidden");
+        showVPNBanner();
+      });
+    });
+  }
+
+  showVPNBanner() {
+    if (
+      RPMGetBoolPref("browser.contentblocking.report.hide_vpn_banner", false) ||
+      !RPMGetBoolPref("browser.vpn_promo.enabled", false)
+    ) {
+      return;
+    }
+
+    const vpnBanner = this.doc.querySelector(".vpn-banner");
+    vpnBanner.classList.remove("hidden");
+    this.doc.sendTelemetryEvent("show", "vpn_banner");
+    // VPN banner only shows on the first visit, flip a pref so it does not show again.
+    RPMSetBoolPref("browser.contentblocking.report.hide_vpn_banner", true);
+  }
+}
-- 
cgit v1.2.3