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 --- browser/modules/BrowserUsageTelemetry.jsm | 1454 +++++++++++++++++++++++++++++ 1 file changed, 1454 insertions(+) create mode 100644 browser/modules/BrowserUsageTelemetry.jsm (limited to 'browser/modules/BrowserUsageTelemetry.jsm') diff --git a/browser/modules/BrowserUsageTelemetry.jsm b/browser/modules/BrowserUsageTelemetry.jsm new file mode 100644 index 0000000000..41525f06d0 --- /dev/null +++ b/browser/modules/BrowserUsageTelemetry.jsm @@ -0,0 +1,1454 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* 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/. */ + +"use strict"; + +var EXPORTED_SYMBOLS = [ + "BrowserUsageTelemetry", + "getUniqueDomainsVisitedInPast24Hours", + "URICountListener", + "MINIMUM_TAB_COUNT_INTERVAL_MS", +]; + +const { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); +const { AppConstants } = ChromeUtils.importESModule( + "resource://gre/modules/AppConstants.sys.mjs" +); + +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + ClientID: "resource://gre/modules/ClientID.sys.mjs", + CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs", + DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs", + PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", + ProvenanceData: "resource:///modules/ProvenanceData.sys.mjs", + SearchSERPTelemetry: "resource:///modules/SearchSERPTelemetry.sys.mjs", + SearchSERPTelemetryUtils: "resource:///modules/SearchSERPTelemetry.sys.mjs", + + WindowsInstallsInfo: + "resource://gre/modules/components-utils/WindowsInstallsInfo.sys.mjs", + + clearTimeout: "resource://gre/modules/Timer.sys.mjs", + setTimeout: "resource://gre/modules/Timer.sys.mjs", +}); + +XPCOMUtils.defineLazyModuleGetters(lazy, { + PageActions: "resource:///modules/PageActions.jsm", +}); + +// This pref is in seconds! +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "gRecentVisitedOriginsExpiry", + "browser.engagement.recent_visited_origins.expiry" +); + +// The upper bound for the count of the visited unique domain names. +const MAX_UNIQUE_VISITED_DOMAINS = 100; + +// Observed topic names. +const TAB_RESTORING_TOPIC = "SSTabRestoring"; +const TELEMETRY_SUBSESSIONSPLIT_TOPIC = + "internal-telemetry-after-subsession-split"; +const DOMWINDOW_OPENED_TOPIC = "domwindowopened"; + +// Probe names. +const MAX_TAB_COUNT_SCALAR_NAME = "browser.engagement.max_concurrent_tab_count"; +const MAX_WINDOW_COUNT_SCALAR_NAME = + "browser.engagement.max_concurrent_window_count"; +const TAB_OPEN_EVENT_COUNT_SCALAR_NAME = + "browser.engagement.tab_open_event_count"; +const MAX_TAB_PINNED_COUNT_SCALAR_NAME = + "browser.engagement.max_concurrent_tab_pinned_count"; +const TAB_PINNED_EVENT_COUNT_SCALAR_NAME = + "browser.engagement.tab_pinned_event_count"; +const WINDOW_OPEN_EVENT_COUNT_SCALAR_NAME = + "browser.engagement.window_open_event_count"; +const UNIQUE_DOMAINS_COUNT_SCALAR_NAME = + "browser.engagement.unique_domains_count"; +const TOTAL_URI_COUNT_SCALAR_NAME = "browser.engagement.total_uri_count"; +const UNFILTERED_URI_COUNT_SCALAR_NAME = + "browser.engagement.unfiltered_uri_count"; +const TOTAL_URI_COUNT_NORMAL_AND_PRIVATE_MODE_SCALAR_NAME = + "browser.engagement.total_uri_count_normal_and_private_mode"; + +const MINIMUM_TAB_COUNT_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes, in ms + +// The elements we consider to be interactive. +const UI_TARGET_ELEMENTS = [ + "menuitem", + "toolbarbutton", + "key", + "command", + "checkbox", + "input", + "button", + "image", + "radio", + "richlistitem", +]; + +// The containers of interactive elements that we care about and their pretty +// names. These should be listed in order of most-specific to least-specific, +// when iterating JavaScript will guarantee that ordering and so we will find +// the most specific area first. +const BROWSER_UI_CONTAINER_IDS = { + "toolbar-menubar": "menu-bar", + TabsToolbar: "tabs-bar", + PersonalToolbar: "bookmarks-bar", + "appMenu-popup": "app-menu", + tabContextMenu: "tabs-context", + contentAreaContextMenu: "content-context", + "widget-overflow-list": "overflow-menu", + "widget-overflow-fixed-list": "pinned-overflow-menu", + "page-action-buttons": "pageaction-urlbar", + pageActionPanel: "pageaction-panel", + "unified-extensions-area": "unified-extensions-area", + "allTabsMenu-allTabsView": "alltabs-menu", + + // This should appear last as some of the above are inside the nav bar. + "nav-bar": "nav-bar", +}; + +const ENTRYPOINT_TRACKED_CONTEXT_MENU_IDS = { + [BROWSER_UI_CONTAINER_IDS.tabContextMenu]: "tabs-context-entrypoint", +}; + +// A list of the expected panes in about:preferences +const PREFERENCES_PANES = [ + "paneHome", + "paneGeneral", + "panePrivacy", + "paneSearch", + "paneSearchResults", + "paneSync", + "paneContainers", + "paneExperimental", + "paneMoreFromMozilla", +]; + +const IGNORABLE_EVENTS = new WeakMap(); + +const KNOWN_ADDONS = []; + +// Buttons that, when clicked, set a preference to true. The convention +// is that the preference is named: +// +// browser.engagement.