/* 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 RPMSendQuery */ import { MozLitElement } from "chrome://global/content/lit-utils.mjs"; import { html } from "chrome://global/content/vendor/lit.all.mjs"; // eslint-disable-next-line import/no-unassigned-import import "chrome://global/content/elements/moz-card.mjs"; const CATEGORIES = [ { key: "trackers", prop: "trackers", icon: "chrome://browser/skin/canvas.svg", l10nId: "privacy-metrics-trackers", }, { key: "fingerprinters", prop: "fingerprinters", icon: "chrome://browser/skin/fingerprint.svg", l10nId: "privacy-metrics-fingerprinters", }, { key: "cookies", prop: "cookies", icon: "chrome://browser/skin/controlcenter/3rdpartycookies.svg", l10nId: "privacy-metrics-cookies", }, { key: "social", prop: "socialTrackers", icon: "chrome://browser/skin/thumb-down.svg", l10nId: "privacy-metrics-social", }, ]; export class PrivacyMetricsCard extends MozLitElement { static properties = { total: { type: Number, reflect: true }, trackers: { type: Number, reflect: true }, fingerprinters: { type: Number, reflect: true }, cookies: { type: Number, reflect: true }, socialTrackers: { type: Number, reflect: true }, _loading: { type: Boolean, state: true }, _error: { type: Boolean, state: true }, _isPrivate: { type: Boolean, state: true }, }; constructor() { super(); this.total = 0; this.trackers = 0; this.fingerprinters = 0; this.cookies = 0; this.socialTrackers = 0; this._loading = true; this._error = false; this._isPrivate = false; } async connectedCallback() { super.connectedCallback(); await this.#fetchStats(); } async #fetchStats() { this._loading = true; this._error = false; try { const stats = await RPMSendQuery("FetchPrivacyMetrics"); if (!this.isConnected) { return; } if (stats?.isPrivate) { this._isPrivate = true; return; } if (!stats) { this._error = true; return; } this.total = stats.total; this.trackers = stats.trackers; this.fingerprinters = stats.fingerprinters; this.cookies = stats.cookies; this.socialTrackers = stats.socialTrackers; } catch (e) { console.error("PrivacyMetricsCard: Failed to fetch stats", e); this._error = true; } finally { this._loading = false; } } #renderLoading() { return html`