1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
6 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
10 // Ignore unused lazy property for PluginManager.
11 // eslint-disable-next-line mozilla/valid-lazy
12 ChromeUtils.defineESModuleGetters(lazy, {
13 AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs",
15 "resource://activity-stream/lib/ASRouterNewTabHook.sys.mjs",
16 ActorManagerParent: "resource://gre/modules/ActorManagerParent.sys.mjs",
17 AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
18 AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.sys.mjs",
19 AsyncShutdown: "resource://gre/modules/AsyncShutdown.sys.mjs",
20 Blocklist: "resource://gre/modules/Blocklist.sys.mjs",
21 BookmarkHTMLUtils: "resource://gre/modules/BookmarkHTMLUtils.sys.mjs",
22 BookmarkJSONUtils: "resource://gre/modules/BookmarkJSONUtils.sys.mjs",
23 BrowserSearchTelemetry: "resource:///modules/BrowserSearchTelemetry.sys.mjs",
24 BrowserUIUtils: "resource:///modules/BrowserUIUtils.sys.mjs",
25 BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.sys.mjs",
26 BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
27 BuiltInThemes: "resource:///modules/BuiltInThemes.sys.mjs",
28 ContextualIdentityService:
29 "resource://gre/modules/ContextualIdentityService.sys.mjs",
30 Corroborate: "resource://gre/modules/Corroborate.sys.mjs",
31 DAPTelemetrySender: "resource://gre/modules/DAPTelemetrySender.sys.mjs",
32 DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs",
33 Discovery: "resource:///modules/Discovery.sys.mjs",
34 DoHController: "resource:///modules/DoHController.sys.mjs",
35 DownloadsViewableInternally:
36 "resource:///modules/DownloadsViewableInternally.sys.mjs",
37 E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs",
38 ExtensionsUI: "resource:///modules/ExtensionsUI.sys.mjs",
39 FeatureGate: "resource://featuregates/FeatureGate.sys.mjs",
40 FxAccounts: "resource://gre/modules/FxAccounts.sys.mjs",
41 HomePage: "resource:///modules/HomePage.sys.mjs",
42 Integration: "resource://gre/modules/Integration.sys.mjs",
43 Interactions: "resource:///modules/Interactions.sys.mjs",
44 LoginBreaches: "resource:///modules/LoginBreaches.sys.mjs",
45 MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs",
46 NetUtil: "resource://gre/modules/NetUtil.sys.mjs",
47 NewTabUtils: "resource://gre/modules/NewTabUtils.sys.mjs",
48 NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
49 Normandy: "resource://normandy/Normandy.sys.mjs",
50 OsEnvironment: "resource://gre/modules/OsEnvironment.sys.mjs",
51 PageActions: "resource:///modules/PageActions.sys.mjs",
52 PageDataService: "resource:///modules/pagedata/PageDataService.sys.mjs",
53 PageThumbs: "resource://gre/modules/PageThumbs.sys.mjs",
54 PdfJs: "resource://pdf.js/PdfJs.sys.mjs",
55 PermissionUI: "resource:///modules/PermissionUI.sys.mjs",
56 PlacesBackups: "resource://gre/modules/PlacesBackups.sys.mjs",
57 PlacesDBUtils: "resource://gre/modules/PlacesDBUtils.sys.mjs",
58 PlacesUIUtils: "resource:///modules/PlacesUIUtils.sys.mjs",
59 PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs",
60 PluginManager: "resource:///actors/PluginParent.sys.mjs",
61 PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
62 ProcessHangMonitor: "resource:///modules/ProcessHangMonitor.sys.mjs",
64 "resource://gre/modules/netwerk-dns/PublicSuffixList.sys.mjs",
65 QuickSuggest: "resource:///modules/QuickSuggest.sys.mjs",
66 RFPHelper: "resource://gre/modules/RFPHelper.sys.mjs",
67 RemoteSecuritySettings:
68 "resource://gre/modules/psm/RemoteSecuritySettings.sys.mjs",
69 RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
70 ResetPBMPanel: "resource:///modules/ResetPBMPanel.sys.mjs",
71 SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
72 Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
73 SaveToPocket: "chrome://pocket/content/SaveToPocket.sys.mjs",
74 ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
75 SearchSERPDomainToCategoriesMap:
76 "resource:///modules/SearchSERPTelemetry.sys.mjs",
77 SearchSERPTelemetry: "resource:///modules/SearchSERPTelemetry.sys.mjs",
78 SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
79 SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
80 ShellService: "resource:///modules/ShellService.sys.mjs",
81 ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
82 ShoppingUtils: "resource:///modules/ShoppingUtils.sys.mjs",
83 SpecialMessageActions:
84 "resource://messaging-system/lib/SpecialMessageActions.sys.mjs",
85 TRRRacer: "resource:///modules/TRRPerformance.sys.mjs",
86 TabCrashHandler: "resource:///modules/ContentCrashHandlers.sys.mjs",
87 TabUnloader: "resource:///modules/TabUnloader.sys.mjs",
88 TelemetryUtils: "resource://gre/modules/TelemetryUtils.sys.mjs",
89 UIState: "resource://services-sync/UIState.sys.mjs",
90 UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
91 WebChannel: "resource://gre/modules/WebChannel.sys.mjs",
92 WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs",
93 WindowsRegistry: "resource://gre/modules/WindowsRegistry.sys.mjs",
94 WindowsGPOParser: "resource://gre/modules/policies/WindowsGPOParser.sys.mjs",
95 clearTimeout: "resource://gre/modules/Timer.sys.mjs",
96 setTimeout: "resource://gre/modules/Timer.sys.mjs",
99 XPCOMUtils.defineLazyModuleGetters(lazy, {
100 ASRouterDefaultConfig:
101 "resource://activity-stream/lib/ASRouterDefaultConfig.jsm",
102 ASRouter: "resource://activity-stream/lib/ASRouter.jsm",
103 OnboardingMessageProvider:
104 "resource://activity-stream/lib/OnboardingMessageProvider.jsm",
107 if (AppConstants.MOZ_UPDATER) {
108 ChromeUtils.defineESModuleGetters(lazy, {
109 UpdateListener: "resource://gre/modules/UpdateListener.sys.mjs",
112 if (AppConstants.MOZ_UPDATE_AGENT) {
113 ChromeUtils.defineESModuleGetters(lazy, {
114 BackgroundUpdate: "resource://gre/modules/BackgroundUpdate.sys.mjs",
118 // PluginManager is used in the listeners object below.
119 XPCOMUtils.defineLazyServiceGetters(lazy, {
120 BrowserHandler: ["@mozilla.org/browser/clh;1", "nsIBrowserHandler"],
121 PushService: ["@mozilla.org/push/Service;1", "nsIPushService"],
124 ChromeUtils.defineLazyGetter(
129 ["browser/accounts.ftl", "toolkit/branding/accounts.ftl"],
134 if (AppConstants.ENABLE_WEBDRIVER) {
135 XPCOMUtils.defineLazyServiceGetter(
138 "@mozilla.org/remote/marionette;1",
142 XPCOMUtils.defineLazyServiceGetter(
145 "@mozilla.org/remote/agent;1",
149 lazy.Marionette = { running: false };
150 lazy.RemoteAgent = { running: false };
153 const PREF_PDFJS_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
155 const PRIVATE_BROWSING_BINARY = "private_browsing.exe";
156 // Index of Private Browsing icon in private_browsing.exe
157 // Must line up with IDI_PBICON_PB_PB_EXE in nsNativeAppSupportWin.h.
158 const PRIVATE_BROWSING_EXE_ICON_INDEX = 1;
159 const PREF_PRIVATE_BROWSING_SHORTCUT_CREATED =
160 "browser.privacySegmentation.createdShortcut";
161 // Whether this launch was initiated by the OS. A launch-on-login will contain
162 // the "os-autostart" flag in the initial launch command line.
163 let gThisInstanceIsLaunchOnLogin = false;
164 // Whether this launch was initiated by a taskbar tab shortcut. A launch from
165 // a taskbar tab shortcut will contain the "taskbar-tab" flag.
166 let gThisInstanceIsTaskbarTab = false;
169 * Fission-compatible JSProcess implementations.
170 * Each actor options object takes the form of a ProcessActorOptions dictionary.
171 * Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
172 * available at https://firefox-source-docs.mozilla.org/dom/ipc/jsactors.html
174 let JSPROCESSACTORS = {
175 // Miscellaneous stuff that needs to be initialized per process.
178 esModuleURI: "resource:///actors/BrowserProcessChild.sys.mjs",
180 // WebRTC related notifications. They are here to avoid loading WebRTC
181 // components when not needed.
182 "getUserMedia:request",
183 "recording-device-stopped",
184 "PeerConnection:request",
185 "recording-device-events",
186 "recording-window-ended",
191 RefreshBlockerObserver: {
193 esModuleURI: "resource:///actors/RefreshBlockerChild.sys.mjs",
195 "webnavigation-create",
196 "chrome-webnavigation-create",
197 "webnavigation-destroy",
198 "chrome-webnavigation-destroy",
202 enablePreference: "accessibility.blockautorefresh",
203 onPreferenceChanged: (prefName, prevValue, isEnabled) => {
204 lazy.BrowserWindowTracker.orderedWindows.forEach(win => {
205 for (let browser of win.gBrowser.browsers) {
207 browser.sendMessageToActor(
221 * Fission-compatible JSWindowActor implementations.
222 * Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
223 * available at https://firefox-source-docs.mozilla.org/dom/ipc/jsactors.html
225 let JSWINDOWACTORS = {
228 esModuleURI: "resource:///actors/AboutLoginsParent.sys.mjs",
231 esModuleURI: "resource:///actors/AboutLoginsChild.sys.mjs",
233 AboutLoginsCopyLoginDetail: { wantUntrusted: true },
234 AboutLoginsCreateLogin: { wantUntrusted: true },
235 AboutLoginsDeleteLogin: { wantUntrusted: true },
236 AboutLoginsDismissBreachAlert: { wantUntrusted: true },
237 AboutLoginsImportFromBrowser: { wantUntrusted: true },
238 AboutLoginsImportFromFile: { wantUntrusted: true },
239 AboutLoginsImportReportInit: { wantUntrusted: true },
240 AboutLoginsImportReportReady: { wantUntrusted: true },
241 AboutLoginsInit: { wantUntrusted: true },
242 AboutLoginsGetHelp: { wantUntrusted: true },
243 AboutLoginsOpenPreferences: { wantUntrusted: true },
244 AboutLoginsOpenSite: { wantUntrusted: true },
245 AboutLoginsRecordTelemetryEvent: { wantUntrusted: true },
246 AboutLoginsRemoveAllLogins: { wantUntrusted: true },
247 AboutLoginsSortChanged: { wantUntrusted: true },
248 AboutLoginsSyncEnable: { wantUntrusted: true },
249 AboutLoginsSyncOptions: { wantUntrusted: true },
250 AboutLoginsUpdateLogin: { wantUntrusted: true },
251 AboutLoginsExportPasswords: { wantUntrusted: true },
254 matches: ["about:logins", "about:logins?*", "about:loginsimportreport"],
256 remoteTypes: ["privilegedabout"],
259 AboutMessagePreview: {
261 esModuleURI: "resource:///actors/AboutMessagePreviewParent.sys.mjs",
264 esModuleURI: "resource:///actors/AboutMessagePreviewChild.sys.mjs",
266 DOMDocElementInserted: { capture: true },
269 matches: ["about:messagepreview", "about:messagepreview?*"],
274 esModuleURI: "resource:///actors/AboutNewTabParent.sys.mjs",
277 esModuleURI: "resource:///actors/AboutNewTabChild.sys.mjs",
279 DOMDocElementInserted: {},
280 DOMContentLoaded: {},
281 load: { capture: true },
282 unload: { capture: true },
284 visibilitychange: {},
287 // The wildcard on about:newtab is for the # parameter
288 // that is used for the newtab devtools. The wildcard for about:home
289 // is similar, and also allows for falling back to loading the
290 // about:home document dynamically if an attempt is made to load
291 // about:home?jscache from the AboutHomeStartupCache as a top-level
293 matches: ["about:home*", "about:welcome", "about:newtab*"],
294 remoteTypes: ["privilegedabout"],
299 esModuleURI: "resource:///actors/AboutPocketParent.sys.mjs",
302 esModuleURI: "resource:///actors/AboutPocketChild.sys.mjs",
305 DOMDocElementInserted: { capture: true },
309 remoteTypes: ["privilegedabout"],
311 "about:pocket-saved*",
312 "about:pocket-signup*",
313 "about:pocket-home*",
314 "about:pocket-style-guide*",
318 AboutPrivateBrowsing: {
320 esModuleURI: "resource:///actors/AboutPrivateBrowsingParent.sys.mjs",
323 esModuleURI: "resource:///actors/AboutPrivateBrowsingChild.sys.mjs",
326 DOMDocElementInserted: { capture: true },
330 matches: ["about:privatebrowsing*"],
335 esModuleURI: "resource:///actors/AboutProtectionsParent.sys.mjs",
338 esModuleURI: "resource:///actors/AboutProtectionsChild.sys.mjs",
341 DOMDocElementInserted: { capture: true },
345 matches: ["about:protections", "about:protections?*"],
350 esModuleURI: "resource:///actors/AboutReaderParent.sys.mjs",
353 esModuleURI: "resource:///actors/AboutReaderChild.sys.mjs",
355 DOMContentLoaded: {},
356 pageshow: { mozSystemGroup: true },
357 // Don't try to create the actor if only the pagehide event fires.
358 // This can happen with the initial about:blank documents.
359 pagehide: { mozSystemGroup: true, createActor: false },
362 messageManagerGroups: ["browsers"],
367 esModuleURI: "resource:///actors/AboutTabCrashedParent.sys.mjs",
370 esModuleURI: "resource:///actors/AboutTabCrashedChild.sys.mjs",
372 DOMDocElementInserted: { capture: true },
376 matches: ["about:tabcrashed*"],
379 AboutWelcomeShopping: {
381 esModuleURI: "resource:///actors/AboutWelcomeParent.sys.mjs",
384 esModuleURI: "resource:///actors/AboutWelcomeChild.sys.mjs",
389 matches: ["about:shoppingsidebar"],
390 remoteTypes: ["privilegedabout"],
395 esModuleURI: "resource:///actors/AboutWelcomeParent.sys.mjs",
398 esModuleURI: "resource:///actors/AboutWelcomeChild.sys.mjs",
400 // This is added so the actor instantiates immediately and makes
401 // methods available to the page js on load.
402 DOMDocElementInserted: {},
405 matches: ["about:welcome"],
406 remoteTypes: ["privilegedabout"],
409 // Remove this preference check when we turn on separate about:welcome for all users.
410 enablePreference: "browser.aboutwelcome.enabled",
415 esModuleURI: "resource:///actors/BlockedSiteParent.sys.mjs",
418 esModuleURI: "resource:///actors/BlockedSiteChild.sys.mjs",
420 AboutBlockedLoaded: { wantUntrusted: true },
424 matches: ["about:blocked?*"],
430 esModuleURI: "resource:///actors/BrowserTabChild.sys.mjs",
433 messageManagerGroups: ["browsers"],
438 esModuleURI: "resource:///actors/ClickHandlerParent.sys.mjs",
441 esModuleURI: "resource:///actors/ClickHandlerChild.sys.mjs",
443 chromelinkclick: { capture: true, mozSystemGroup: true },
450 /* Note: this uses the same JSMs as ClickHandler, but because it
451 * relies on "normal" click events anywhere on the page (not just
452 * links) and is expensive, and only does something for the
453 * small group of people who have the feature enabled, it is its
454 * own actor which is only registered if the pref is enabled.
456 MiddleMousePasteHandler: {
458 esModuleURI: "resource:///actors/ClickHandlerParent.sys.mjs",
461 esModuleURI: "resource:///actors/ClickHandlerChild.sys.mjs",
463 auxclick: { capture: true, mozSystemGroup: true },
466 enablePreference: "middlemouse.contentLoadURL",
473 esModuleURI: "resource:///actors/ContentSearchParent.sys.mjs",
476 esModuleURI: "resource:///actors/ContentSearchChild.sys.mjs",
478 ContentSearchClient: { capture: true, wantUntrusted: true },
485 "about:privatebrowsing",
486 "about:test-about-content-search-ui",
488 remoteTypes: ["privilegedabout"],
493 esModuleURI: "resource:///actors/ContextMenuParent.sys.mjs",
497 esModuleURI: "resource:///actors/ContextMenuChild.sys.mjs",
499 contextmenu: { mozSystemGroup: true },
508 esModuleURI: "resource:///actors/DecoderDoctorParent.sys.mjs",
512 esModuleURI: "resource:///actors/DecoderDoctorChild.sys.mjs",
513 observers: ["decoder-doctor-notification"],
516 messageManagerGroups: ["browsers"],
522 esModuleURI: "resource:///actors/DOMFullscreenParent.sys.mjs",
526 esModuleURI: "resource:///actors/DOMFullscreenChild.sys.mjs",
528 "MozDOMFullscreen:Request": {},
529 "MozDOMFullscreen:Entered": {},
530 "MozDOMFullscreen:NewOrigin": {},
531 "MozDOMFullscreen:Exit": {},
532 "MozDOMFullscreen:Exited": {},
536 messageManagerGroups: ["browsers"],
542 esModuleURI: "resource:///actors/EncryptedMediaParent.sys.mjs",
546 esModuleURI: "resource:///actors/EncryptedMediaChild.sys.mjs",
547 observers: ["mediakeys-request"],
550 messageManagerGroups: ["browsers"],
556 esModuleURI: "resource:///actors/FormValidationParent.sys.mjs",
560 esModuleURI: "resource:///actors/FormValidationChild.sys.mjs",
563 // Listening to ‘pageshow’ event is only relevant if an invalid form
564 // popup was open, so don't create the actor when fired.
565 pageshow: { createActor: false },
574 esModuleURI: "resource:///actors/LightweightThemeChild.sys.mjs",
576 pageshow: { mozSystemGroup: true },
577 DOMContentLoaded: {},
587 "chrome://browser/content/syncedtabs/sidebar.xhtml",
588 "chrome://browser/content/places/historySidebar.xhtml",
589 "chrome://browser/content/places/bookmarksSidebar.xhtml",
596 esModuleURI: "resource:///actors/LinkHandlerParent.sys.mjs",
599 esModuleURI: "resource:///actors/LinkHandlerChild.sys.mjs",
601 DOMHeadElementParsed: {},
605 // The `pagehide` event is only used to clean up state which will not be
606 // present if the actor hasn't been created.
607 pagehide: { createActor: false },
611 messageManagerGroups: ["browsers"],
616 esModuleURI: "resource:///actors/PageInfoChild.sys.mjs",
624 esModuleURI: "resource:///actors/PageStyleParent.sys.mjs",
627 esModuleURI: "resource:///actors/PageStyleChild.sys.mjs",
629 pageshow: { createActor: false },
633 messageManagerGroups: ["browsers"],
639 esModuleURI: "resource://pdf.js/PdfjsParent.sys.mjs",
642 esModuleURI: "resource://pdf.js/PdfjsChild.sys.mjs",
647 // GMP crash reporting
650 esModuleURI: "resource:///actors/PluginParent.sys.mjs",
653 esModuleURI: "resource:///actors/PluginChild.sys.mjs",
655 PluginCrashed: { capture: true },
664 esModuleURI: "resource:///actors/PointerLockParent.sys.mjs",
667 esModuleURI: "resource:///actors/PointerLockChild.sys.mjs",
669 "MozDOMPointerLock:Entered": {},
670 "MozDOMPointerLock:Exited": {},
674 messageManagerGroups: ["browsers"],
680 esModuleURI: "resource:///actors/PromptParent.sys.mjs",
688 esModuleURI: "resource:///actors/RefreshBlockerParent.sys.mjs",
691 esModuleURI: "resource:///actors/RefreshBlockerChild.sys.mjs",
694 messageManagerGroups: ["browsers"],
695 enablePreference: "accessibility.blockautorefresh",
698 ScreenshotsComponent: {
700 esModuleURI: "resource:///modules/ScreenshotsUtils.sys.mjs",
703 esModuleURI: "resource:///actors/ScreenshotsComponentChild.sys.mjs",
705 "Screenshots:Close": { wantUntrusted: true },
706 "Screenshots:Copy": { wantUntrusted: true },
707 "Screenshots:Download": { wantUntrusted: true },
708 "Screenshots:HidePanel": { wantUntrusted: true },
709 "Screenshots:OverlaySelection": { wantUntrusted: true },
710 "Screenshots:RecordEvent": { wantUntrusted: true },
711 "Screenshots:ShowPanel": { wantUntrusted: true },
714 enablePreference: "screenshots.browser.component.enabled",
717 SearchSERPTelemetry: {
719 esModuleURI: "resource:///actors/SearchSERPTelemetryParent.sys.mjs",
722 esModuleURI: "resource:///actors/SearchSERPTelemetryChild.sys.mjs",
724 DOMContentLoaded: {},
725 pageshow: { mozSystemGroup: true },
726 // The 'pagehide' event is only used to clean up state, and should not
727 // force actor creation.
728 pagehide: { createActor: false },
729 load: { mozSystemGroup: true, capture: true },
732 matches: ["https://*/*"],
737 esModuleURI: "resource://normandy-content/ShieldFrameParent.sys.mjs",
740 esModuleURI: "resource://normandy-content/ShieldFrameChild.sys.mjs",
744 ShieldPageEvent: { wantUntrusted: true },
747 matches: ["about:studies*"],
752 esModuleURI: "resource:///actors/ShoppingSidebarParent.sys.mjs",
755 esModuleURI: "resource:///actors/ShoppingSidebarChild.sys.mjs",
757 ContentReady: { wantUntrusted: true },
758 PolledRequestMade: { wantUntrusted: true },
759 // This is added so the actor instantiates immediately and makes
760 // methods available to the page js on load.
761 DOMDocElementInserted: {},
762 ReportProductAvailable: { wantUntrusted: true },
763 AdClicked: { wantUntrusted: true },
764 AdImpression: { wantUntrusted: true },
767 matches: ["about:shoppingsidebar"],
768 remoteTypes: ["privilegedabout"],
773 esModuleURI: "resource:///actors/SpeechDispatcherParent.sys.mjs",
777 esModuleURI: "resource:///actors/SpeechDispatcherChild.sys.mjs",
778 observers: ["chrome-synth-voices-error"],
781 messageManagerGroups: ["browsers"],
787 esModuleURI: "resource:///actors/ASRouterParent.sys.mjs",
790 esModuleURI: "resource:///actors/ASRouterChild.sys.mjs",
792 // This is added so the actor instantiates immediately and makes
793 // methods available to the page js on load.
794 DOMDocElementInserted: {},
802 "about:privatebrowsing*",
804 remoteTypes: ["privilegedabout"],
807 SwitchDocumentDirection: {
809 esModuleURI: "resource:///actors/SwitchDocumentDirectionChild.sys.mjs",
817 esModuleURI: "resource:///modules/UITourParent.sys.mjs",
820 esModuleURI: "resource:///modules/UITourChild.sys.mjs",
822 mozUITour: { wantUntrusted: true },
826 messageManagerGroups: ["browsers"],
831 esModuleURI: "resource:///actors/WebRTCParent.sys.mjs",
834 esModuleURI: "resource:///actors/WebRTCChild.sys.mjs",
841 ChromeUtils.defineLazyGetter(
844 () => Cc["@mozilla.org/weave/service;1"].getService().wrappedJSObject
847 if (AppConstants.MOZ_CRASHREPORTER) {
848 ChromeUtils.defineESModuleGetters(lazy, {
849 UnsubmittedCrashHandler: "resource:///modules/ContentCrashHandlers.sys.mjs",
853 ChromeUtils.defineLazyGetter(lazy, "gBrandBundle", function () {
854 return Services.strings.createBundle(
855 "chrome://branding/locale/brand.properties"
859 ChromeUtils.defineLazyGetter(lazy, "gBrowserBundle", function () {
860 return Services.strings.createBundle(
861 "chrome://browser/locale/browser.properties"
865 ChromeUtils.defineLazyGetter(lazy, "log", () => {
866 let { ConsoleAPI } = ChromeUtils.importESModule(
867 "resource://gre/modules/Console.sys.mjs"
869 let consoleOptions = {
870 // tip: set maxLogLevel to "debug" and use lazy.log.debug() to create
871 // detailed messages during development. See LOG_LEVELS in Console.sys.mjs
873 maxLogLevel: "error",
874 maxLogLevelPref: "browser.policies.loglevel",
875 prefix: "BrowserGlue.sys.mjs",
877 return new ConsoleAPI(consoleOptions);
882 "gmp-plugin-crash": ["PluginManager"],
883 "plugin-crashed": ["PluginManager"],
886 observe(subject, topic, data) {
887 for (let module of this.observers[topic]) {
889 lazy[module].observe(subject, topic, data);
897 for (let observer of Object.keys(this.observers)) {
898 Services.obs.addObserver(this, observer);
902 if (AppConstants.MOZ_UPDATER) {
903 listeners.observers["update-downloading"] = ["UpdateListener"];
904 listeners.observers["update-staged"] = ["UpdateListener"];
905 listeners.observers["update-downloaded"] = ["UpdateListener"];
906 listeners.observers["update-available"] = ["UpdateListener"];
907 listeners.observers["update-error"] = ["UpdateListener"];
908 listeners.observers["update-swap"] = ["UpdateListener"];
911 // Seconds of idle before trying to create a bookmarks backup.
912 const BOOKMARKS_BACKUP_IDLE_TIME_SEC = 8 * 60;
913 // Minimum interval between backups. We try to not create more than one backup
915 const BOOKMARKS_BACKUP_MIN_INTERVAL_DAYS = 1;
916 // Seconds of idle time before the late idle tasks will be scheduled.
917 const LATE_TASKS_IDLE_TIME_SEC = 20;
918 // Time after we stop tracking startup crashes.
919 const STARTUP_CRASHES_END_DELAY_MS = 30 * 1000;
922 * OS X has the concept of zero-window sessions and therefore ignores the
923 * browser-lastwindow-close-* topics.
925 const OBSERVE_LASTWINDOW_CLOSE_TOPICS = AppConstants.platform != "macosx";
927 export let BrowserInitState = {};
928 BrowserInitState.startupIdleTaskPromise = new Promise(resolve => {
929 BrowserInitState._resolveStartupIdleTask = resolve;
932 export function BrowserGlue() {
933 XPCOMUtils.defineLazyServiceGetter(
936 "@mozilla.org/widget/useridleservice;1",
940 ChromeUtils.defineLazyGetter(this, "_distributionCustomizer", function () {
941 const { DistributionCustomizer } = ChromeUtils.importESModule(
942 "resource:///modules/distribution.sys.mjs"
944 return new DistributionCustomizer();
947 XPCOMUtils.defineLazyServiceGetter(
950 "@mozilla.org/alerts-service;1",
957 function WindowsRegPoliciesGetter(wrk, root, regLocation) {
958 wrk.open(root, regLocation, wrk.ACCESS_READ);
960 if (wrk.hasChild("Mozilla\\" + Services.appinfo.name)) {
961 policies = lazy.WindowsGPOParser.readPolicies(wrk, policies);
967 function isPrivateBrowsingAllowedInRegistry() {
968 // If there is an attempt to open Private Browsing before
969 // EnterprisePolicies are initialized the Windows registry
970 // can be checked to determine if it is enabled
971 if (Services.policies.status > Ci.nsIEnterprisePolicies.UNINITIALIZED) {
972 // Yield to policies engine if initialized
973 let privateAllowed = Services.policies.isAllowed("privatebrowsing");
975 `Yield to initialized policies engine: Private Browsing Allowed = ${privateAllowed}`
977 return privateAllowed;
979 if (AppConstants.platform !== "win") {
980 // Not using Windows so no registry, return true
982 "AppConstants.platform is not 'win': Private Browsing allowed"
986 // If all other checks fail only then do we check registry
987 let wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance(
990 let regLocation = "SOFTWARE\\Policies";
991 let userPolicies, machinePolicies;
992 // Only check HKEY_LOCAL_MACHINE if not in testing
993 if (!Cu.isInAutomation) {
994 machinePolicies = WindowsRegPoliciesGetter(
996 wrk.ROOT_KEY_LOCAL_MACHINE,
1000 // Check machine policies before checking user policies
1001 // HKEY_LOCAL_MACHINE supersedes HKEY_CURRENT_USER so only check
1002 // HKEY_CURRENT_USER if the registry key is not present in
1003 // HKEY_LOCAL_MACHINE at all
1004 if (machinePolicies && "DisablePrivateBrowsing" in machinePolicies) {
1006 `DisablePrivateBrowsing in HKEY_LOCAL_MACHINE is ${machinePolicies.DisablePrivateBrowsing}`
1008 return !(machinePolicies.DisablePrivateBrowsing === 1);
1010 userPolicies = WindowsRegPoliciesGetter(
1012 wrk.ROOT_KEY_CURRENT_USER,
1015 if (userPolicies && "DisablePrivateBrowsing" in userPolicies) {
1017 `DisablePrivateBrowsing in HKEY_CURRENT_USER is ${userPolicies.DisablePrivateBrowsing}`
1019 return !(userPolicies.DisablePrivateBrowsing === 1);
1021 // Private browsing allowed if no registry entry exists
1023 "No DisablePrivateBrowsing registry entry: Private Browsing allowed"
1028 BrowserGlue.prototype = {
1029 _saveSession: false,
1030 _migrationImportsDefaultBookmarks: false,
1031 _placesBrowserInitComplete: false,
1032 _isNewProfile: undefined,
1033 _defaultCookieBehaviorAtStartup: null,
1035 _setPrefToSaveSession: function BG__setPrefToSaveSession(aForce) {
1036 if (!this._saveSession && !aForce) {
1040 if (!lazy.PrivateBrowsingUtils.permanentPrivateBrowsing) {
1041 Services.prefs.setBoolPref(
1042 "browser.sessionstore.resume_session_once",
1047 // This method can be called via [NSApplication terminate:] on Mac, which
1048 // ends up causing prefs not to be flushed to disk, so we need to do that
1049 // explicitly here. See bug 497652.
1050 Services.prefs.savePrefFile(null);
1053 // nsIObserver implementation
1054 observe: async function BG_observe(subject, topic, data) {
1056 case "notifications-open-settings":
1057 this._openPreferences("privacy-permissions");
1059 case "final-ui-startup":
1060 this._beforeUIStartup();
1062 case "browser-delayed-startup-finished":
1063 this._onFirstWindowLoaded(subject);
1064 Services.obs.removeObserver(this, "browser-delayed-startup-finished");
1066 case "sessionstore-windows-restored":
1067 this._onWindowsRestored();
1069 case "browser:purge-session-history":
1070 // reset the console service's error buffer
1071 Services.console.logStringMessage(null); // clear the console (in case it's open)
1072 Services.console.reset();
1074 case "restart-in-safe-mode":
1075 this._onSafeModeRestart(subject);
1077 case "quit-application-requested":
1078 this._onQuitRequest(subject, data);
1080 case "quit-application-granted":
1081 this._onQuitApplicationGranted();
1083 case "browser-lastwindow-close-requested":
1084 if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
1085 // The application is not actually quitting, but the last full browser
1086 // window is about to be closed.
1087 this._onQuitRequest(subject, "lastwindow");
1090 case "browser-lastwindow-close-granted":
1091 if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
1092 this._setPrefToSaveSession();
1095 case "fxaccounts:onverified":
1096 this._onThisDeviceConnected();
1098 case "fxaccounts:device_connected":
1099 this._onDeviceConnected(data);
1101 case "fxaccounts:verify_login":
1102 this._onVerifyLoginNotification(JSON.parse(data));
1104 case "fxaccounts:device_disconnected":
1105 data = JSON.parse(data);
1106 if (data.isLocalDevice) {
1107 this._onDeviceDisconnected();
1110 case "fxaccounts:commands:open-uri":
1111 this._onDisplaySyncURIs(subject);
1113 case "session-save":
1114 this._setPrefToSaveSession(true);
1115 subject.QueryInterface(Ci.nsISupportsPRBool);
1116 subject.data = true;
1118 case "places-init-complete":
1119 Services.obs.removeObserver(this, "places-init-complete");
1120 if (!this._migrationImportsDefaultBookmarks) {
1121 this._initPlaces(false);
1125 this._backupBookmarks();
1127 case "distribution-customization-complete":
1128 Services.obs.removeObserver(
1130 "distribution-customization-complete"
1132 // Customization has finished, we don't need the customizer anymore.
1133 delete this._distributionCustomizer;
1135 case "browser-glue-test": // used by tests
1136 if (data == "force-ui-migration") {
1138 } else if (data == "force-distribution-customization") {
1139 this._distributionCustomizer.applyCustomizations();
1140 // To apply distribution bookmarks use "places-init-complete".
1141 } else if (data == "test-force-places-init") {
1142 this._placesInitialized = false;
1143 this._initPlaces(false);
1144 } else if (data == "mock-alerts-service") {
1145 Object.defineProperty(this, "AlertsService", {
1146 value: subject.wrappedJSObject,
1148 } else if (data == "places-browser-init-complete") {
1149 if (this._placesBrowserInitComplete) {
1150 Services.obs.notifyObservers(null, "places-browser-init-complete");
1152 } else if (data == "add-breaches-sync-handler") {
1153 this._addBreachesSyncHandler();
1156 case "initial-migration-will-import-default-bookmarks":
1157 this._migrationImportsDefaultBookmarks = true;
1159 case "initial-migration-did-import-default-bookmarks":
1160 this._initPlaces(true);
1162 case "handle-xul-text-link":
1163 let linkHandled = subject.QueryInterface(Ci.nsISupportsPRBool);
1164 if (!linkHandled.data) {
1165 let win = lazy.BrowserWindowTracker.getTopWindow();
1167 data = JSON.parse(data);
1168 let where = win.whereToOpenLink(data);
1169 // Preserve legacy behavior of non-modifier left-clicks
1170 // opening in a new selected tab.
1171 if (where == "current") {
1174 win.openTrustedLinkIn(data.href, where);
1175 linkHandled.data = true;
1179 case "profile-before-change":
1180 // Any component depending on Places should be finalized in
1181 // _onPlacesShutdown. Any component that doesn't need to act after
1182 // the UI has gone should be finalized in _onQuitApplicationGranted.
1185 case "keyword-search":
1186 // This notification is broadcast by the docshell when it "fixes up" a
1187 // URI that it's been asked to load into a keyword search.
1190 engine = Services.search.getEngineByName(
1191 subject.QueryInterface(Ci.nsISupportsString).data
1196 let win = lazy.BrowserWindowTracker.getTopWindow();
1197 lazy.BrowserSearchTelemetry.recordSearch(
1198 win.gBrowser.selectedBrowser,
1203 case "xpi-signature-changed":
1204 let disabledAddons = JSON.parse(data).disabled;
1205 let addons = await lazy.AddonManager.getAddonsByIDs(disabledAddons);
1206 if (addons.some(addon => addon)) {
1207 this._notifyUnsignedAddonsDisabled();
1210 case "sync-ui-state:update":
1211 this._updateFxaBadges(lazy.BrowserWindowTracker.getTopWindow());
1213 case "handlersvc-store-initialized":
1214 // Initialize PdfJs when running in-process and remote. This only
1215 // happens once since PdfJs registers global hooks. If the PdfJs
1216 // extension is installed the init method below will be overridden
1217 // leaving initialization to the extension.
1218 // parent only: configure default prefs, set up pref observers, register
1219 // pdf content handler, and initializes parent side message manager
1220 // shim for privileged api access.
1221 lazy.PdfJs.init(this._isNewProfile);
1223 // Allow certain viewable internally types to be opened from downloads.
1224 lazy.DownloadsViewableInternally.register();
1228 this._earlyBlankFirstPaint(subject);
1229 gThisInstanceIsTaskbarTab = subject.handleFlag("taskbar-tab", false);
1230 gThisInstanceIsLaunchOnLogin = subject.handleFlag(
1234 let launchOnLoginPref = "browser.startup.windowsLaunchOnLogin.enabled";
1235 let profileSvc = Cc[
1236 "@mozilla.org/toolkit/profile-service;1"
1237 ].getService(Ci.nsIToolkitProfileService);
1239 AppConstants.platform == "win" &&
1240 !profileSvc.startWithLastProfile
1242 // If we don't start with last profile, the user
1243 // likely sees the profile selector on launch.
1244 if (Services.prefs.getBoolPref(launchOnLoginPref)) {
1245 Services.telemetry.setEventRecordingEnabled(
1249 Services.telemetry.recordEvent(
1251 "last_profile_disable",
1255 Services.prefs.setBoolPref(launchOnLoginPref, false);
1256 // Only remove registry key, not shortcut here as we can assume
1257 // if a user manually created a shortcut they want this behavior.
1258 await lazy.WindowsLaunchOnLogin.removeLaunchOnLoginRegistryKey();
1264 // initialization (called on application startup)
1265 _init: function BG__init() {
1266 let os = Services.obs;
1268 "notifications-open-settings",
1270 "browser-delayed-startup-finished",
1271 "sessionstore-windows-restored",
1272 "browser:purge-session-history",
1273 "quit-application-requested",
1274 "quit-application-granted",
1275 "fxaccounts:onverified",
1276 "fxaccounts:device_connected",
1277 "fxaccounts:verify_login",
1278 "fxaccounts:device_disconnected",
1279 "fxaccounts:commands:open-uri",
1281 "places-init-complete",
1282 "distribution-customization-complete",
1283 "handle-xul-text-link",
1284 "profile-before-change",
1286 "restart-in-safe-mode",
1287 "xpi-signature-changed",
1288 "sync-ui-state:update",
1289 "handlersvc-store-initialized",
1290 ].forEach(topic => os.addObserver(this, topic, true));
1291 if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
1292 os.addObserver(this, "browser-lastwindow-close-requested", true);
1293 os.addObserver(this, "browser-lastwindow-close-granted", true);
1296 lazy.ActorManagerParent.addJSProcessActors(JSPROCESSACTORS);
1297 lazy.ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);
1299 this._firstWindowReady = new Promise(
1300 resolve => (this._firstWindowLoaded = resolve)
1304 // cleanup (called on application shutdown)
1305 _dispose: function BG__dispose() {
1306 // AboutHomeStartupCache might write to the cache during
1307 // quit-application-granted, so we defer uninitialization
1309 AboutHomeStartupCache.uninit();
1311 if (this._bookmarksBackupIdleTime) {
1312 this._userIdleService.removeIdleObserver(
1314 this._bookmarksBackupIdleTime
1316 this._bookmarksBackupIdleTime = null;
1318 if (this._lateTasksIdleObserver) {
1319 this._userIdleService.removeIdleObserver(
1320 this._lateTasksIdleObserver,
1321 LATE_TASKS_IDLE_TIME_SEC
1323 delete this._lateTasksIdleObserver;
1325 if (this._gmpInstallManager) {
1326 this._gmpInstallManager.uninit();
1327 delete this._gmpInstallManager;
1330 Services.prefs.removeObserver(
1331 "privacy.trackingprotection",
1332 this._matchCBCategory
1334 Services.prefs.removeObserver(
1335 "network.cookie.cookieBehavior",
1336 this._matchCBCategory
1338 Services.prefs.removeObserver(
1339 "network.cookie.cookieBehavior.pbmode",
1340 this._matchCBCategory
1342 Services.prefs.removeObserver(
1343 "network.http.referer.disallowCrossSiteRelaxingDefault",
1344 this._matchCBCategory
1346 Services.prefs.removeObserver(
1347 "network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation",
1348 this._matchCBCategory
1350 Services.prefs.removeObserver(
1351 "privacy.partition.network_state.ocsp_cache",
1352 this._matchCBCategory
1354 Services.prefs.removeObserver(
1355 "privacy.query_stripping.enabled",
1356 this._matchCBCategory
1358 Services.prefs.removeObserver(
1359 "privacy.query_stripping.enabled.pbmode",
1360 this._matchCBCategory
1362 Services.prefs.removeObserver(
1363 "privacy.fingerprintingProtection",
1364 this._matchCBCategory
1366 Services.prefs.removeObserver(
1367 "privacy.fingerprintingProtection.pbmode",
1368 this._matchCBCategory
1370 Services.prefs.removeObserver(
1371 ContentBlockingCategoriesPrefs.PREF_CB_CATEGORY,
1372 this._updateCBCategory
1374 Services.prefs.removeObserver(
1375 "privacy.trackingprotection",
1376 this._setPrefExpectations
1378 Services.prefs.removeObserver(
1379 "browser.contentblocking.features.strict",
1380 this._setPrefExpectationsAndUpdate
1384 // runs on startup, before the first command line handler is invoked
1385 // (i.e. before the first window is opened)
1386 _beforeUIStartup: function BG__beforeUIStartup() {
1387 lazy.SessionStartup.init();
1389 // check if we're in safe mode
1390 if (Services.appinfo.inSafeMode) {
1391 Services.ww.openWindow(
1393 "chrome://browser/content/safeMode.xhtml",
1395 "chrome,centerscreen,modal,resizable=no",
1400 // apply distribution customizations
1401 this._distributionCustomizer.applyCustomizations();
1403 // handle any UI migration
1406 if (!Services.prefs.prefHasUserValue(PREF_PDFJS_ISDEFAULT_CACHE_STATE)) {
1407 lazy.PdfJs.checkIsDefault(this._isNewProfile);
1412 lazy.SessionStore.init();
1414 lazy.BuiltInThemes.maybeInstallActiveBuiltInTheme();
1416 if (AppConstants.MOZ_NORMANDY) {
1417 lazy.Normandy.init();
1420 lazy.SaveToPocket.init();
1422 lazy.ResetPBMPanel.init();
1424 AboutHomeStartupCache.init();
1426 Services.obs.notifyObservers(null, "browser-ui-startup-complete");
1429 _checkForOldBuildUpdates() {
1430 // check for update if our build is old
1432 AppConstants.MOZ_UPDATER &&
1433 Services.prefs.getBoolPref("app.update.checkInstallTime")
1435 let buildID = Services.appinfo.appBuildID;
1436 let today = new Date().getTime();
1437 /* eslint-disable no-multi-spaces */
1438 let buildDate = new Date(
1439 buildID.slice(0, 4), // year
1440 buildID.slice(4, 6) - 1, // months are zero-based.
1441 buildID.slice(6, 8), // day
1442 buildID.slice(8, 10), // hour
1443 buildID.slice(10, 12), // min
1444 buildID.slice(12, 14)
1447 /* eslint-enable no-multi-spaces */
1449 const millisecondsIn24Hours = 86400000;
1451 Services.prefs.getIntPref("app.update.checkInstallTime.days") *
1452 millisecondsIn24Hours;
1454 if (buildDate + acceptableAge < today) {
1455 Cc["@mozilla.org/updates/update-service;1"]
1456 .getService(Ci.nsIApplicationUpdateService)
1457 .checkForBackgroundUpdates();
1462 async _onSafeModeRestart(window) {
1463 // prompt the user to confirm
1464 let productName = lazy.gBrandBundle.GetStringFromName("brandShortName");
1465 let strings = lazy.gBrowserBundle;
1466 let promptTitle = strings.formatStringFromName(
1467 "troubleshootModeRestartPromptTitle",
1470 let promptMessage = strings.GetStringFromName(
1471 "troubleshootModeRestartPromptMessage"
1473 let restartText = strings.GetStringFromName(
1474 "troubleshootModeRestartButton"
1477 Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_IS_STRING +
1478 Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL +
1479 Services.prompt.BUTTON_POS_0_DEFAULT;
1481 let rv = await Services.prompt.asyncConfirmEx(
1482 window.browsingContext,
1483 Ci.nsIPrompt.MODAL_TYPE_INTERNAL_WINDOW,
1493 if (rv.get("buttonNumClicked") != 0) {
1497 let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
1498 Ci.nsISupportsPRBool
1500 Services.obs.notifyObservers(
1502 "quit-application-requested",
1506 if (!cancelQuit.data) {
1507 Services.startup.restartInSafeMode(Ci.nsIAppStartup.eAttemptQuit);
1512 * Show a notification bar offering a reset.
1515 * String of either "unused" or "uninstall", specifying the reason
1516 * why a profile reset is offered.
1518 _resetProfileNotification(reason) {
1519 let win = lazy.BrowserWindowTracker.getTopWindow();
1524 const { ResetProfile } = ChromeUtils.importESModule(
1525 "resource://gre/modules/ResetProfile.sys.mjs"
1527 if (!ResetProfile.resetSupported()) {
1531 let productName = lazy.gBrandBundle.GetStringFromName("brandShortName");
1532 let resetBundle = Services.strings.createBundle(
1533 "chrome://global/locale/resetProfile.properties"
1537 if (reason == "unused") {
1538 message = resetBundle.formatStringFromName("resetUnusedProfile.message", [
1541 } else if (reason == "uninstall") {
1542 message = resetBundle.formatStringFromName("resetUninstalled.message", [
1547 `Unknown reason (${reason}) given to _resetProfileNotification.`
1552 label: resetBundle.formatStringFromName(
1553 "refreshProfile.resetButton.label",
1556 accessKey: resetBundle.GetStringFromName(
1557 "refreshProfile.resetButton.accesskey"
1560 ResetProfile.openConfirmationDialog(win);
1565 win.gNotificationBox.appendNotification(
1566 "reset-profile-notification",
1569 image: "chrome://global/skin/icons/question-64.png",
1570 priority: win.gNotificationBox.PRIORITY_INFO_LOW,
1576 _notifyUnsignedAddonsDisabled() {
1577 let win = lazy.BrowserWindowTracker.getTopWindow();
1582 let message = win.gNavigatorBundle.getString(
1583 "unsignedAddonsDisabled.message"
1587 label: win.gNavigatorBundle.getString(
1588 "unsignedAddonsDisabled.learnMore.label"
1590 accessKey: win.gNavigatorBundle.getString(
1591 "unsignedAddonsDisabled.learnMore.accesskey"
1594 win.BrowserOpenAddonsMgr("addons://list/extension?unsigned=true");
1599 win.gNotificationBox.appendNotification(
1600 "unsigned-addons-disabled",
1603 priority: win.gNotificationBox.PRIORITY_WARNING_MEDIUM,
1609 _earlyBlankFirstPaint(cmdLine) {
1610 let startTime = Cu.now();
1612 AppConstants.platform == "macosx" ||
1613 Services.startup.wasSilentlyStarted ||
1614 !Services.prefs.getBoolPref("browser.startup.blankWindow", false)
1619 // Until bug 1450626 and bug 1488384 are fixed, skip the blank window when
1620 // using a non-default theme.
1622 !Services.startup.showedPreXULSkeletonUI &&
1623 Services.prefs.getCharPref(
1624 "extensions.activeThemeID",
1625 "default-theme@mozilla.org"
1626 ) != "default-theme@mozilla.org"
1631 let store = Services.xulStore;
1632 let getValue = attr =>
1633 store.getValue(AppConstants.BROWSER_CHROME_URL, "main-window", attr);
1634 let width = getValue("width");
1635 let height = getValue("height");
1637 // The clean profile case isn't handled yet. Return early for now.
1638 if (!width || !height) {
1642 let browserWindowFeatures =
1643 "chrome,all,dialog=no,extrachrome,menubar,resizable,scrollbars,status," +
1644 "location,toolbar,personalbar";
1645 // This needs to be set when opening the window to ensure that the AppUserModelID
1646 // is set correctly on Windows. Without it, initial launches with `-private-window`
1647 // will show up under the regular Firefox taskbar icon first, and then switch
1648 // to the Private Browsing icon shortly thereafter.
1649 if (cmdLine.findFlag("private-window", false) != -1) {
1650 if (isPrivateBrowsingAllowedInRegistry()) {
1651 browserWindowFeatures += ",private";
1654 let win = Services.ww.openWindow(
1658 browserWindowFeatures,
1662 // Hide the titlebar if the actual browser window will draw in it.
1663 let hiddenTitlebar = Services.appinfo.drawInTitlebar;
1664 if (hiddenTitlebar) {
1665 win.windowUtils.setChromeMargin(0, 2, 2, 2);
1668 let docElt = win.document.documentElement;
1669 docElt.setAttribute("screenX", getValue("screenX"));
1670 docElt.setAttribute("screenY", getValue("screenY"));
1672 // The sizemode="maximized" attribute needs to be set before first paint.
1673 let sizemode = getValue("sizemode");
1674 if (sizemode == "maximized") {
1675 docElt.setAttribute("sizemode", sizemode);
1677 // Set the size to use when the user leaves the maximized mode.
1678 // The persisted size is the outer size, but the height/width
1679 // attributes set the inner size.
1680 let appWin = win.docShell.treeOwner
1681 .QueryInterface(Ci.nsIInterfaceRequestor)
1682 .getInterface(Ci.nsIAppWindow);
1683 height -= appWin.outerToInnerHeightDifferenceInCSSPixels;
1684 width -= appWin.outerToInnerWidthDifferenceInCSSPixels;
1685 docElt.setAttribute("height", height);
1686 docElt.setAttribute("width", width);
1688 // Setting the size of the window in the features string instead of here
1689 // causes the window to grow by the size of the titlebar.
1690 win.resizeTo(width, height);
1693 // Set this before showing the window so that graphics code can use it to
1694 // decide to skip some expensive code paths (eg. starting the GPU process).
1695 docElt.setAttribute("windowtype", "navigator:blank");
1697 // The window becomes visible after OnStopRequest, so make this happen now.
1700 ChromeUtils.addProfilerMarker("earlyBlankFirstPaint", startTime);
1701 win.openTime = Cu.now();
1703 let { TelemetryTimestamps } = ChromeUtils.importESModule(
1704 "resource://gre/modules/TelemetryTimestamps.sys.mjs"
1706 TelemetryTimestamps.add("blankWindowShown");
1709 _firstWindowTelemetry(aWindow) {
1710 let scaling = aWindow.devicePixelRatio * 100;
1712 Services.telemetry.getHistogramById("DISPLAY_SCALING").add(scaling);
1716 _collectStartupConditionsTelemetry() {
1717 let nowSeconds = Math.round(Date.now() / 1000);
1718 // Don't include cases where we don't have the pref. This rules out the first install
1719 // as well as the first run of a build since this was introduced. These could by some
1720 // definitions be referred to as "cold" startups, but probably not since we likely
1721 // just wrote many of the files we use to disk. This way we should approximate a lower
1722 // bound to the number of cold startups rather than an upper bound.
1723 let lastCheckSeconds = Services.prefs.getIntPref(
1724 "browser.startup.lastColdStartupCheck",
1727 Services.prefs.setIntPref(
1728 "browser.startup.lastColdStartupCheck",
1732 let secondsSinceLastOSRestart =
1733 Services.startup.secondsSinceLastOSRestart;
1735 nowSeconds - secondsSinceLastOSRestart > lastCheckSeconds;
1736 Services.telemetry.scalarSet("startup.is_cold", isColdStartup);
1737 Services.telemetry.scalarSet(
1738 "startup.seconds_since_last_os_restart",
1739 secondsSinceLastOSRestart
1746 // the first browser window has finished initializing
1747 _onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) {
1748 lazy.AboutNewTab.init();
1750 lazy.TabCrashHandler.init();
1752 lazy.ProcessHangMonitor.init();
1754 lazy.UrlbarPrefs.updateFirefoxSuggestScenario();
1756 // A channel for "remote troubleshooting" code...
1757 let channel = new lazy.WebChannel(
1758 "remote-troubleshooting",
1759 "remote-troubleshooting"
1761 channel.listen((id, data, target) => {
1762 if (data.command == "request") {
1763 let { Troubleshoot } = ChromeUtils.importESModule(
1764 "resource://gre/modules/Troubleshoot.sys.mjs"
1766 Troubleshoot.snapshot().then(snapshotData => {
1767 // for privacy we remove crash IDs and all preferences (but bug 1091944
1768 // exists to expose prefs once we are confident of privacy implications)
1769 delete snapshotData.crashes;
1770 delete snapshotData.modifiedPreferences;
1771 delete snapshotData.printingPreferences;
1772 channel.send(snapshotData, target);
1777 // Offer to reset a user's profile if it hasn't been used for 60 days.
1778 const OFFER_PROFILE_RESET_INTERVAL_MS = 60 * 24 * 60 * 60 * 1000;
1779 let lastUse = Services.appinfo.replacedLockTime;
1780 let disableResetPrompt = Services.prefs.getBoolPref(
1781 "browser.disableResetPrompt",
1786 !disableResetPrompt &&
1788 Date.now() - lastUse >= OFFER_PROFILE_RESET_INTERVAL_MS
1790 this._resetProfileNotification("unused");
1791 } else if (AppConstants.platform == "win" && !disableResetPrompt) {
1792 // Check if we were just re-installed and offer Firefox Reset
1795 updateChannel = ChromeUtils.importESModule(
1796 "resource://gre/modules/UpdateUtils.sys.mjs"
1797 ).UpdateUtils.UpdateChannel;
1799 if (updateChannel) {
1800 let uninstalledValue = lazy.WindowsRegistry.readRegKey(
1801 Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
1802 "Software\\Mozilla\\Firefox",
1803 `Uninstalled-${updateChannel}`
1805 let removalSuccessful = lazy.WindowsRegistry.removeRegKey(
1806 Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
1807 "Software\\Mozilla\\Firefox",
1808 `Uninstalled-${updateChannel}`
1810 if (removalSuccessful && uninstalledValue == "True") {
1811 this._resetProfileNotification("uninstall");
1816 this._checkForOldBuildUpdates();
1818 // Check if Sync is configured
1819 if (Services.prefs.prefHasUserValue("services.sync.username")) {
1820 lazy.WeaveService.init();
1823 lazy.PageThumbs.init();
1825 lazy.NewTabUtils.init();
1827 Services.telemetry.setEventRecordingEnabled(
1828 "security.ui.protections",
1832 Services.telemetry.setEventRecordingEnabled("security.doh.neterror", true);
1834 lazy.PageActions.init();
1836 lazy.DoHController.init();
1838 this._firstWindowTelemetry(aWindow);
1839 this._firstWindowLoaded();
1841 this._collectStartupConditionsTelemetry();
1843 // Set the default favicon size for UI views that use the page-icon protocol.
1844 lazy.PlacesUtils.favicons.setDefaultIconURIPreferredSize(
1845 16 * aWindow.devicePixelRatio
1848 this._setPrefExpectationsAndUpdate();
1849 this._matchCBCategory();
1851 // This observes the entire privacy.trackingprotection.* pref tree.
1852 Services.prefs.addObserver(
1853 "privacy.trackingprotection",
1854 this._matchCBCategory
1856 Services.prefs.addObserver(
1857 "network.cookie.cookieBehavior",
1858 this._matchCBCategory
1860 Services.prefs.addObserver(
1861 "network.cookie.cookieBehavior.pbmode",
1862 this._matchCBCategory
1864 Services.prefs.addObserver(
1865 "network.http.referer.disallowCrossSiteRelaxingDefault",
1866 this._matchCBCategory
1868 Services.prefs.addObserver(
1869 "network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation",
1870 this._matchCBCategory
1872 Services.prefs.addObserver(
1873 "privacy.partition.network_state.ocsp_cache",
1874 this._matchCBCategory
1876 Services.prefs.addObserver(
1877 "privacy.query_stripping.enabled",
1878 this._matchCBCategory
1880 Services.prefs.addObserver(
1881 "privacy.query_stripping.enabled.pbmode",
1882 this._matchCBCategory
1884 Services.prefs.addObserver(
1885 "privacy.fingerprintingProtection",
1886 this._matchCBCategory
1888 Services.prefs.addObserver(
1889 "privacy.fingerprintingProtection.pbmode",
1890 this._matchCBCategory
1892 Services.prefs.addObserver(
1893 ContentBlockingCategoriesPrefs.PREF_CB_CATEGORY,
1894 this._updateCBCategory
1896 Services.prefs.addObserver(
1897 "media.autoplay.default",
1898 this._updateAutoplayPref
1900 Services.prefs.addObserver(
1901 "privacy.trackingprotection",
1902 this._setPrefExpectations
1904 Services.prefs.addObserver(
1905 "browser.contentblocking.features.strict",
1906 this._setPrefExpectationsAndUpdate
1910 _updateAutoplayPref() {
1911 const blocked = Services.prefs.getIntPref("media.autoplay.default", 1);
1912 const telemetry = Services.telemetry.getHistogramById(
1913 "AUTOPLAY_DEFAULT_SETTING_CHANGE"
1915 const labels = { 0: "allow", 1: "blockAudible", 5: "blockAll" };
1916 if (blocked in labels) {
1917 telemetry.add(labels[blocked]);
1921 _setPrefExpectations() {
1922 ContentBlockingCategoriesPrefs.setPrefExpectations();
1925 _setPrefExpectationsAndUpdate() {
1926 ContentBlockingCategoriesPrefs.setPrefExpectations();
1927 ContentBlockingCategoriesPrefs.updateCBCategory();
1930 _matchCBCategory() {
1931 ContentBlockingCategoriesPrefs.matchCBCategory();
1934 _updateCBCategory() {
1935 ContentBlockingCategoriesPrefs.updateCBCategory();
1938 _recordContentBlockingTelemetry() {
1939 Services.telemetry.setEventRecordingEnabled(
1940 "security.ui.protectionspopup",
1941 Services.prefs.getBoolPref(
1942 "security.protectionspopup.recordEventTelemetry"
1945 Services.telemetry.setEventRecordingEnabled(
1946 "security.ui.app_menu",
1947 Services.prefs.getBoolPref("security.app_menu.recordEventTelemetry")
1950 let tpEnabled = Services.prefs.getBoolPref(
1951 "privacy.trackingprotection.enabled"
1954 .getHistogramById("TRACKING_PROTECTION_ENABLED")
1957 let tpPBDisabled = Services.prefs.getBoolPref(
1958 "privacy.trackingprotection.pbmode.enabled"
1961 .getHistogramById("TRACKING_PROTECTION_PBM_DISABLED")
1962 .add(!tpPBDisabled);
1964 let cookieBehavior = Services.prefs.getIntPref(
1965 "network.cookie.cookieBehavior"
1967 Services.telemetry.getHistogramById("COOKIE_BEHAVIOR").add(cookieBehavior);
1969 let fpEnabled = Services.prefs.getBoolPref(
1970 "privacy.trackingprotection.fingerprinting.enabled"
1972 let cmEnabled = Services.prefs.getBoolPref(
1973 "privacy.trackingprotection.cryptomining.enabled"
1977 Services.prefs.getStringPref("browser.contentblocking.category", null)
1989 // Any other value is unsupported.
1994 Services.telemetry.scalarSet(
1995 "contentblocking.fingerprinting_blocking_enabled",
1998 Services.telemetry.scalarSet(
1999 "contentblocking.cryptomining_blocking_enabled",
2002 Services.telemetry.scalarSet("contentblocking.category", categoryPref);
2005 _recordDataSanitizationPrefs() {
2006 Services.telemetry.scalarSet(
2007 "datasanitization.privacy_sanitize_sanitizeOnShutdown",
2008 Services.prefs.getBoolPref("privacy.sanitize.sanitizeOnShutdown")
2010 Services.telemetry.scalarSet(
2011 "datasanitization.privacy_clearOnShutdown_cookies",
2012 Services.prefs.getBoolPref("privacy.clearOnShutdown.cookies")
2014 Services.telemetry.scalarSet(
2015 "datasanitization.privacy_clearOnShutdown_history",
2016 Services.prefs.getBoolPref("privacy.clearOnShutdown.history")
2018 Services.telemetry.scalarSet(
2019 "datasanitization.privacy_clearOnShutdown_formdata",
2020 Services.prefs.getBoolPref("privacy.clearOnShutdown.formdata")
2022 Services.telemetry.scalarSet(
2023 "datasanitization.privacy_clearOnShutdown_downloads",
2024 Services.prefs.getBoolPref("privacy.clearOnShutdown.downloads")
2026 Services.telemetry.scalarSet(
2027 "datasanitization.privacy_clearOnShutdown_cache",
2028 Services.prefs.getBoolPref("privacy.clearOnShutdown.cache")
2030 Services.telemetry.scalarSet(
2031 "datasanitization.privacy_clearOnShutdown_sessions",
2032 Services.prefs.getBoolPref("privacy.clearOnShutdown.sessions")
2034 Services.telemetry.scalarSet(
2035 "datasanitization.privacy_clearOnShutdown_offlineApps",
2036 Services.prefs.getBoolPref("privacy.clearOnShutdown.offlineApps")
2038 Services.telemetry.scalarSet(
2039 "datasanitization.privacy_clearOnShutdown_siteSettings",
2040 Services.prefs.getBoolPref("privacy.clearOnShutdown.siteSettings")
2042 Services.telemetry.scalarSet(
2043 "datasanitization.privacy_clearOnShutdown_openWindows",
2044 Services.prefs.getBoolPref("privacy.clearOnShutdown.openWindows")
2048 for (let permission of Services.perms.all) {
2049 // We consider just permissions set for http, https and file URLs.
2051 permission.type == "cookie" &&
2052 permission.capability == Ci.nsICookiePermission.ACCESS_SESSION &&
2053 ["http", "https", "file"].some(scheme =>
2054 permission.principal.schemeIs(scheme)
2060 Services.telemetry.scalarSet(
2061 "datasanitization.session_permission_exceptions",
2067 * Application shutdown handler.
2069 _onQuitApplicationGranted() {
2071 // This pref must be set here because SessionStore will use its value
2072 // on quit-application.
2073 () => this._setPrefToSaveSession(),
2075 // Call trackStartupCrashEnd here in case the delayed call on startup hasn't
2076 // yet occurred (see trackStartupCrashEnd caller in browser.js).
2077 () => Services.startup.trackStartupCrashEnd(),
2080 if (this._bookmarksBackupIdleTime) {
2081 this._userIdleService.removeIdleObserver(
2083 this._bookmarksBackupIdleTime
2085 this._bookmarksBackupIdleTime = null;
2089 () => lazy.BrowserUsageTelemetry.uninit(),
2090 () => lazy.SearchSERPTelemetry.uninit(),
2091 () => lazy.Interactions.uninit(),
2092 () => lazy.PageDataService.uninit(),
2093 () => lazy.PageThumbs.uninit(),
2094 () => lazy.NewTabUtils.uninit(),
2095 () => lazy.Normandy.uninit(),
2096 () => lazy.RFPHelper.uninit(),
2097 () => lazy.ShoppingUtils.uninit(),
2098 () => lazy.ASRouterNewTabHook.destroy(),
2100 if (AppConstants.MOZ_UPDATER) {
2101 lazy.UpdateListener.reset();
2105 // bug 1839426 - The FOG service needs to be instantiated reliably so it
2106 // can perform at-shutdown tasks later in shutdown.
2111 for (let task of tasks) {
2115 console.error(`Error during quit-application-granted: ${ex}`);
2116 if (Cu.isInAutomation) {
2117 // This usually happens after the test harness is done collecting
2118 // test errors, thus we can't easily add a failure to it. The only
2119 // noticeable solution we have is crashing.
2120 Cc["@mozilla.org/xpcom/debug;1"]
2121 .getService(Ci.nsIDebug2)
2122 .abort(ex.filename, ex.lineNumber);
2128 // Set up a listener to enable/disable the screenshots extension
2129 // based on its preference.
2130 _monitorScreenshotsPref() {
2131 const SCREENSHOTS_PREF = "extensions.screenshots.disabled";
2132 const COMPONENT_PREF = "screenshots.browser.component.enabled";
2133 const ID = "screenshots@mozilla.org";
2134 const _checkScreenshotsPref = async () => {
2135 let addon = await lazy.AddonManager.getAddonByID(ID);
2139 let screenshotsDisabled = Services.prefs.getBoolPref(
2143 let componentEnabled = Services.prefs.getBoolPref(COMPONENT_PREF, false);
2144 if (screenshotsDisabled) {
2145 if (componentEnabled) {
2146 lazy.ScreenshotsUtils.uninitialize();
2148 await addon.disable({ allowSystemAddons: true });
2150 } else if (componentEnabled) {
2151 lazy.ScreenshotsUtils.initialize();
2152 await addon.disable({ allowSystemAddons: true });
2154 await addon.enable({ allowSystemAddons: true });
2155 lazy.ScreenshotsUtils.uninitialize();
2158 Services.prefs.addObserver(SCREENSHOTS_PREF, _checkScreenshotsPref);
2159 Services.prefs.addObserver(COMPONENT_PREF, _checkScreenshotsPref);
2160 _checkScreenshotsPref();
2163 _monitorWebcompatReporterPref() {
2164 const PREF = "extensions.webcompat-reporter.enabled";
2165 const ID = "webcompat-reporter@mozilla.org";
2166 Services.prefs.addObserver(PREF, async () => {
2167 let addon = await lazy.AddonManager.getAddonByID(ID);
2171 let enabled = Services.prefs.getBoolPref(PREF, false);
2172 if (enabled && !addon.isActive) {
2173 await addon.enable({ allowSystemAddons: true });
2174 } else if (!enabled && addon.isActive) {
2175 await addon.disable({ allowSystemAddons: true });
2180 async _setupSearchDetection() {
2181 // There is no pref for this add-on because it shouldn't be disabled.
2182 const ID = "addons-search-detection@mozilla.com";
2184 let addon = await lazy.AddonManager.getAddonByID(ID);
2186 // first time install of addon and install on firefox update
2188 (await lazy.AddonManager.maybeInstallBuiltinAddon(
2191 "resource://builtin-addons/search-detection/"
2194 if (!addon.isActive) {
2199 _monitorHTTPSOnlyPref() {
2200 const PREF_ENABLED = "dom.security.https_only_mode";
2201 const PREF_WAS_ENABLED = "dom.security.https_only_mode_ever_enabled";
2202 const _checkHTTPSOnlyPref = async () => {
2203 const enabled = Services.prefs.getBoolPref(PREF_ENABLED, false);
2204 const was_enabled = Services.prefs.getBoolPref(PREF_WAS_ENABLED, false);
2208 Services.prefs.setBoolPref(PREF_WAS_ENABLED, true);
2209 } else if (was_enabled) {
2212 Services.telemetry.scalarSet("security.https_only_mode_enabled", value);
2215 Services.prefs.addObserver(PREF_ENABLED, _checkHTTPSOnlyPref);
2216 _checkHTTPSOnlyPref();
2218 const PREF_PBM_WAS_ENABLED =
2219 "dom.security.https_only_mode_ever_enabled_pbm";
2220 const PREF_PBM_ENABLED = "dom.security.https_only_mode_pbm";
2222 const _checkHTTPSOnlyPBMPref = async () => {
2223 const enabledPBM = Services.prefs.getBoolPref(PREF_PBM_ENABLED, false);
2224 const was_enabledPBM = Services.prefs.getBoolPref(
2225 PREF_PBM_WAS_ENABLED,
2231 Services.prefs.setBoolPref(PREF_PBM_WAS_ENABLED, true);
2232 } else if (was_enabledPBM) {
2235 Services.telemetry.scalarSet(
2236 "security.https_only_mode_enabled_pbm",
2241 Services.prefs.addObserver(PREF_PBM_ENABLED, _checkHTTPSOnlyPBMPref);
2242 _checkHTTPSOnlyPBMPref();
2246 const PREF_ION_ID = "toolkit.telemetry.pioneerId";
2248 const _checkIonPref = async () => {
2249 for (let win of Services.wm.getEnumerator("navigator:browser")) {
2250 win.document.getElementById("ion-button").hidden =
2251 !Services.prefs.getStringPref(PREF_ION_ID, null);
2255 const windowListener = {
2256 onOpenWindow(xulWindow) {
2257 const win = xulWindow.docShell.domWindow;
2258 win.addEventListener("load", () => {
2259 const ionButton = win.document.getElementById("ion-button");
2261 ionButton.hidden = !Services.prefs.getStringPref(PREF_ION_ID, null);
2268 Services.prefs.addObserver(PREF_ION_ID, _checkIonPref);
2269 Services.wm.addListener(windowListener);
2273 _monitorIonStudies() {
2274 const STUDY_ADDON_COLLECTION_KEY = "pioneer-study-addons-v1";
2275 const PREF_ION_NEW_STUDIES_AVAILABLE =
2276 "toolkit.telemetry.pioneer-new-studies-available";
2278 const _badgeIcon = async () => {
2279 for (let win of Services.wm.getEnumerator("navigator:browser")) {
2281 .getElementById("ion-button")
2282 .querySelector(".toolbarbutton-badge")
2283 .classList.add("feature-callout");
2287 const windowListener = {
2288 onOpenWindow(xulWindow) {
2289 const win = xulWindow.docShell.domWindow;
2290 win.addEventListener("load", () => {
2291 const ionButton = win.document.getElementById("ion-button");
2293 const badge = ionButton.querySelector(".toolbarbutton-badge");
2295 Services.prefs.getBoolPref(PREF_ION_NEW_STUDIES_AVAILABLE, false)
2297 badge.classList.add("feature-callout");
2299 badge.classList.remove("feature-callout");
2307 // Update all open windows if the pref changes.
2308 Services.prefs.addObserver(PREF_ION_NEW_STUDIES_AVAILABLE, _badgeIcon);
2310 // Badge any currently-open windows.
2311 if (Services.prefs.getBoolPref(PREF_ION_NEW_STUDIES_AVAILABLE, false)) {
2315 lazy.RemoteSettings(STUDY_ADDON_COLLECTION_KEY).on("sync", async event => {
2316 Services.prefs.setBoolPref(PREF_ION_NEW_STUDIES_AVAILABLE, true);
2319 // When a new window opens, check if we need to badge the icon.
2320 Services.wm.addListener(windowListener);
2324 const FEATURE_PREF_ENABLED = "privacy.globalprivacycontrol.enabled";
2325 const FUNCTIONALITY_PREF_ENABLED =
2326 "privacy.globalprivacycontrol.functionality.enabled";
2327 const PREF_WAS_ENABLED = "privacy.globalprivacycontrol.was_ever_enabled";
2328 const _checkGPCPref = async () => {
2329 const feature_enabled = Services.prefs.getBoolPref(
2330 FEATURE_PREF_ENABLED,
2333 const functionality_enabled = Services.prefs.getBoolPref(
2334 FUNCTIONALITY_PREF_ENABLED,
2337 const was_enabled = Services.prefs.getBoolPref(PREF_WAS_ENABLED, false);
2339 if (feature_enabled && functionality_enabled) {
2341 Services.prefs.setBoolPref(PREF_WAS_ENABLED, true);
2342 } else if (was_enabled) {
2345 Services.telemetry.scalarSet(
2346 "security.global_privacy_control_enabled",
2351 Services.prefs.addObserver(FEATURE_PREF_ENABLED, _checkGPCPref);
2352 Services.prefs.addObserver(FUNCTIONALITY_PREF_ENABLED, _checkGPCPref);
2356 // All initial windows have opened.
2357 _onWindowsRestored: function BG__onWindowsRestored() {
2358 if (this._windowsWereRestored) {
2361 this._windowsWereRestored = true;
2363 lazy.BrowserUsageTelemetry.init();
2364 lazy.SearchSERPTelemetry.init();
2366 lazy.Interactions.init();
2367 lazy.PageDataService.init();
2368 lazy.ExtensionsUI.init();
2370 let signingRequired;
2371 if (AppConstants.MOZ_REQUIRE_SIGNING) {
2372 signingRequired = true;
2374 signingRequired = Services.prefs.getBoolPref(
2375 "xpinstall.signatures.required"
2379 if (signingRequired) {
2380 let disabledAddons = lazy.AddonManager.getStartupChanges(
2381 lazy.AddonManager.STARTUP_CHANGE_DISABLED
2383 lazy.AddonManager.getAddonsByIDs(disabledAddons).then(addons => {
2384 for (let addon of addons) {
2385 if (addon.signedState <= lazy.AddonManager.SIGNEDSTATE_MISSING) {
2386 this._notifyUnsignedAddonsDisabled();
2393 if (AppConstants.MOZ_CRASHREPORTER) {
2394 lazy.UnsubmittedCrashHandler.init();
2395 lazy.UnsubmittedCrashHandler.scheduleCheckForUnsubmittedCrashReports();
2396 lazy.FeatureGate.annotateCrashReporter();
2397 lazy.FeatureGate.observePrefChangesForCrashReportAnnotation();
2400 if (AppConstants.ASAN_REPORTER) {
2401 var { AsanReporter } = ChromeUtils.importESModule(
2402 "resource://gre/modules/AsanReporter.sys.mjs"
2404 AsanReporter.init();
2407 lazy.Sanitizer.onStartup();
2408 this._maybeShowRestoreSessionInfoBar();
2409 this._scheduleStartupIdleTasks();
2410 this._lateTasksIdleObserver = (idleService, topic, data) => {
2411 if (topic == "idle") {
2412 idleService.removeIdleObserver(
2413 this._lateTasksIdleObserver,
2414 LATE_TASKS_IDLE_TIME_SEC
2416 delete this._lateTasksIdleObserver;
2417 this._scheduleBestEffortUserIdleTasks();
2420 this._userIdleService.addIdleObserver(
2421 this._lateTasksIdleObserver,
2422 LATE_TASKS_IDLE_TIME_SEC
2425 this._monitorScreenshotsPref();
2426 this._monitorWebcompatReporterPref();
2427 this._monitorHTTPSOnlyPref();
2428 this._monitorIonPref();
2429 this._monitorIonStudies();
2430 this._setupSearchDetection();
2432 this._monitorGPCPref();
2434 // Loading the MigrationUtils module does the work of registering the
2435 // migration wizard JSWindowActor pair. In case nothing else has done
2436 // this yet, load the MigrationUtils so that the wizard is ready to be
2438 lazy.MigrationUtils;
2442 * Use this function as an entry point to schedule tasks that
2443 * need to run only once after startup, and can be scheduled
2444 * by using an idle callback.
2446 * The functions scheduled here will fire from idle callbacks
2447 * once every window has finished being restored by session
2448 * restore, and it's guaranteed that they will run before
2449 * the equivalent per-window idle tasks
2450 * (from _schedulePerWindowIdleTasks in browser.js).
2452 * If you have something that can wait even further than the
2453 * per-window initialization, and is okay with not being run in some
2454 * sessions, please schedule them using
2455 * _scheduleBestEffortUserIdleTasks.
2456 * Don't be fooled by thinking that the use of the timeout parameter
2457 * will delay your function: it will just ensure that it potentially
2458 * happens _earlier_ than expected (when the timeout limit has been reached),
2459 * but it will not make it happen later (and out of order) compared
2460 * to the other ones scheduled together.
2462 _scheduleStartupIdleTasks() {
2464 // It's important that SafeBrowsing is initialized reasonably
2465 // early, so we use a maximum timeout for it.
2467 name: "SafeBrowsing.init",
2469 lazy.SafeBrowsing.init();
2475 name: "ContextualIdentityService.load",
2477 await lazy.ContextualIdentityService.load();
2478 lazy.Discovery.update();
2483 name: "PlacesUIUtils.unblockToolbars",
2485 // We postponed loading bookmarks toolbar content until startup
2486 // has finished, so we can start loading it now:
2487 lazy.PlacesUIUtils.unblockToolbars();
2492 name: "PlacesDBUtils.telemetry",
2493 condition: lazy.TelemetryUtils.isTelemetryEnabled,
2495 lazy.PlacesDBUtils.telemetry().catch(console.error);
2499 // Begin listening for incoming push messages.
2501 name: "PushService.ensureReady",
2504 lazy.PushService.wrappedJSObject.ensureReady();
2506 // NS_ERROR_NOT_AVAILABLE will get thrown for the PushService
2507 // getter if the PushService is disabled.
2508 if (ex.result != Cr.NS_ERROR_NOT_AVAILABLE) {
2516 name: "BrowserGlue._recordContentBlockingTelemetry",
2518 this._recordContentBlockingTelemetry();
2523 name: "BrowserGlue._recordDataSanitizationPrefs",
2525 this._recordDataSanitizationPrefs();
2530 name: "enableCertErrorUITelemetry",
2532 let enableCertErrorUITelemetry = Services.prefs.getBoolPref(
2533 "security.certerrors.recordEventTelemetry",
2536 Services.telemetry.setEventRecordingEnabled(
2537 "security.ui.certerror",
2538 enableCertErrorUITelemetry
2543 // Load the Login Manager data from disk off the main thread, some time
2544 // after startup. If the data is required before this runs, for example
2545 // because a restored page contains a password field, it will be loaded on
2546 // the main thread, and this initialization request will be ignored.
2548 name: "Services.logins",
2559 // Add breach alerts pref observer reasonably early so the pref flip works
2561 name: "_addBreachAlertsPrefObserver",
2563 this._addBreachAlertsPrefObserver();
2567 // Report pinning status and the type of shortcut used to launch
2569 name: "pinningStatusTelemetry",
2570 condition: AppConstants.platform == "win",
2572 let shellService = Cc[
2573 "@mozilla.org/browser/shell-service;1"
2574 ].getService(Ci.nsIWindowsShellService);
2575 let winTaskbar = Cc["@mozilla.org/windows-taskbar;1"].getService(
2580 Services.telemetry.scalarSet(
2581 "os.environment.is_taskbar_pinned",
2582 await shellService.isCurrentAppPinnedToTaskbarAsync(
2583 winTaskbar.defaultGroupId
2586 Services.telemetry.scalarSet(
2587 "os.environment.is_taskbar_pinned_private",
2588 await shellService.isCurrentAppPinnedToTaskbarAsync(
2589 winTaskbar.defaultPrivateGroupId
2599 shortcut = Services.appinfo.processStartupShortcut;
2600 classification = shellService.classifyShortcut(shortcut);
2605 if (!classification) {
2606 if (gThisInstanceIsLaunchOnLogin) {
2607 classification = "Autostart";
2608 } else if (shortcut) {
2609 classification = "OtherShortcut";
2611 classification = "Other";
2614 // Because of how taskbar tabs work, it may be classifed as a taskbar
2615 // shortcut, in which case we want to overwrite it.
2616 if (gThisInstanceIsTaskbarTab) {
2617 classification = "TaskbarTab";
2619 Services.telemetry.scalarSet(
2620 "os.environment.launch_method",
2627 name: "dualBrowserProtocolHandler",
2629 AppConstants.platform == "win" &&
2630 !Services.prefs.getBoolPref(
2631 "browser.shell.customProtocolsRegistered"
2634 Services.prefs.setBoolPref(
2635 "browser.shell.customProtocolsRegistered",
2638 const FIREFOX_HANDLER_NAME = "firefox";
2639 const FIREFOX_PRIVATE_HANDLER_NAME = "firefox-private";
2640 const path = Services.dirsvc.get("XREExeF", Ci.nsIFile).path;
2641 let wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance(
2645 wrk.open(wrk.ROOT_KEY_CLASSES_ROOT, "", wrk.ACCESS_READ);
2646 let FxSet = wrk.hasChild(FIREFOX_HANDLER_NAME);
2647 let FxPrivateSet = wrk.hasChild(FIREFOX_PRIVATE_HANDLER_NAME);
2649 if (FxSet && FxPrivateSet) {
2653 wrk.ROOT_KEY_CURRENT_USER,
2654 "Software\\Classes",
2657 const maybeUpdateRegistry = (
2665 let FxKey = wrk.createChild(handler, wrk.ACCESS_ALL);
2667 // Write URL protocol key
2668 FxKey.writeStringValue("", protocolName);
2669 FxKey.writeStringValue("URL Protocol", "");
2671 // Write defaultIcon key
2673 FxKey.ROOT_KEY_CURRENT_USER,
2674 "Software\\Classes\\" + handler + "\\DefaultIcon",
2678 FxKey.ROOT_KEY_CURRENT_USER,
2679 "Software\\Classes\\" + handler + "\\DefaultIcon",
2682 FxKey.writeStringValue("", `\"${path}\",1`);
2684 // Write shell\\open\\command key
2686 FxKey.ROOT_KEY_CURRENT_USER,
2687 "Software\\Classes\\" + handler + "\\shell",
2691 FxKey.ROOT_KEY_CURRENT_USER,
2692 "Software\\Classes\\" + handler + "\\shell\\open",
2696 FxKey.ROOT_KEY_CURRENT_USER,
2697 "Software\\Classes\\" + handler + "\\shell\\open\\command",
2701 FxKey.ROOT_KEY_CURRENT_USER,
2702 "Software\\Classes\\" + handler + "\\shell\\open\\command",
2705 if (handler == FIREFOX_PRIVATE_HANDLER_NAME) {
2706 FxKey.writeStringValue(
2708 `\"${path}\" -osint -private-window \"%1\"`
2711 FxKey.writeStringValue("", `\"${path}\" -osint -url \"%1\"`);
2720 maybeUpdateRegistry(
2722 FIREFOX_HANDLER_NAME,
2723 "URL:Firefox Protocol"
2729 maybeUpdateRegistry(
2731 FIREFOX_PRIVATE_HANDLER_NAME,
2732 "URL:Firefox Private Browsing Protocol"
2746 // Ensure a Private Browsing Shortcut exists. This is needed in case
2747 // a user tries to use Windows functionality to pin our Private Browsing
2748 // mode icon to the Taskbar (eg: the "Pin to Taskbar" context menu item).
2749 // This is also created by the installer, but it's possible that a user
2750 // has removed it, or is running out of a zip build. The consequences of not
2751 // having a Shortcut for this are that regular Firefox will be pinned instead
2752 // of the Private Browsing version -- so it's quite important we do our best
2753 // to make sure one is available.
2754 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1762994 for additional
2757 name: "ensurePrivateBrowsingShortcutExists",
2759 AppConstants.platform == "win" &&
2760 // Pref'ed off until Private Browsing window separation is enabled by default
2761 // to avoid a situation where a user pins the Private Browsing shortcut to
2762 // the Taskbar, which will end up launching into a different Taskbar icon.
2763 lazy.NimbusFeatures.majorRelease2022.getVariable(
2764 "feltPrivacyWindowSeparation"
2766 // We don't want a shortcut if it's been disabled, eg: by enterprise policy.
2767 lazy.PrivateBrowsingUtils.enabled &&
2768 // Private Browsing shortcuts for packaged builds come with the package,
2769 // if they exist at all. We shouldn't try to create our own.
2770 !Services.sysinfo.getProperty("hasWinPackageId") &&
2771 // If we've ever done this successfully before, don't try again. The
2772 // user may have deleted the shortcut, and we don't want to force it
2774 !Services.prefs.getBoolPref(
2775 PREF_PRIVATE_BROWSING_SHORTCUT_CREATED,
2779 let shellService = Cc[
2780 "@mozilla.org/browser/shell-service;1"
2781 ].getService(Ci.nsIWindowsShellService);
2782 let winTaskbar = Cc["@mozilla.org/windows-taskbar;1"].getService(
2787 !(await shellService.hasMatchingShortcut(
2788 winTaskbar.defaultPrivateGroupId,
2792 let appdir = Services.dirsvc.get("GreD", Ci.nsIFile);
2793 let exe = appdir.clone();
2794 exe.append(PRIVATE_BROWSING_BINARY);
2795 let strings = new Localization(
2796 ["branding/brand.ftl", "browser/browser.ftl"],
2799 let [desc] = await strings.formatValues([
2800 "private-browsing-shortcut-text-2",
2802 await shellService.createShortcut(
2807 // The code we're calling indexes from 0 instead of 1
2808 PRIVATE_BROWSING_EXE_ICON_INDEX - 1,
2809 winTaskbar.defaultPrivateGroupId,
2815 // We always set this as long as no exception has been thrown. This
2816 // ensure that it is `true` both if we created one because it didn't
2817 // exist, or if it already existed (most likely because it was created
2818 // by the installer). This avoids the need to call `hasMatchingShortcut`
2819 // again, which necessarily does pointless I/O.
2820 Services.prefs.setBoolPref(
2821 PREF_PRIVATE_BROWSING_SHORTCUT_CREATED,
2827 // Report whether Firefox is the default handler for various files types,
2828 // in particular, ".pdf".
2830 name: "IsDefaultHandlerForPDF",
2831 condition: AppConstants.platform == "win",
2833 Services.telemetry.keyedScalarSet(
2834 "os.environment.is_default_handler",
2836 lazy.ShellService.isDefaultHandlerFor(".pdf")
2841 // Install built-in themes. We already installed the active built-in
2842 // theme, if any, before UI startup.
2844 name: "BuiltInThemes.ensureBuiltInThemes",
2846 await lazy.BuiltInThemes.ensureBuiltInThemes();
2851 name: "WinTaskbarJumpList.startup",
2852 condition: AppConstants.platform == "win",
2854 // For Windows 7, initialize the jump list module.
2855 const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
2857 WINTASKBAR_CONTRACTID in Cc &&
2858 Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available
2860 const { WinTaskbarJumpList } = ChromeUtils.importESModule(
2861 "resource:///modules/WindowsJumpLists.sys.mjs"
2863 WinTaskbarJumpList.startup();
2868 // Report macOS Dock status
2870 name: "MacDockSupport.isAppInDock",
2871 condition: AppConstants.platform == "macosx",
2874 Services.telemetry.scalarSet(
2875 "os.environment.is_kept_in_dock",
2876 Cc["@mozilla.org/widget/macdocksupport;1"].getService(
2877 Ci.nsIMacDockSupport
2887 name: "BrowserGlue._maybeShowDefaultBrowserPrompt",
2889 this._maybeShowDefaultBrowserPrompt();
2894 name: "ScreenshotsUtils.initialize",
2897 Services.prefs.getBoolPref("screenshots.browser.component.enabled")
2899 lazy.ScreenshotsUtils.initialize();
2905 name: "trackStartupCrashEndSetTimeout",
2907 lazy.setTimeout(function () {
2908 Services.tm.idleDispatchToMainThread(
2909 Services.startup.trackStartupCrashEnd
2911 }, STARTUP_CRASHES_END_DELAY_MS);
2916 name: "handlerService.asyncInit",
2918 let handlerService = Cc[
2919 "@mozilla.org/uriloader/handler-service;1"
2920 ].getService(Ci.nsIHandlerService);
2921 handlerService.asyncInit();
2926 name: "RFPHelper.init",
2928 lazy.RFPHelper.init();
2933 name: "Blocklist.loadBlocklistAsync",
2935 lazy.Blocklist.loadBlocklistAsync();
2940 name: "TabUnloader.init",
2942 lazy.TabUnloader.init();
2946 // Run TRR performance measurements for DoH.
2948 name: "doh-rollout.trrRacer.run",
2950 let enabledPref = "doh-rollout.trrRace.enabled";
2951 let completePref = "doh-rollout.trrRace.complete";
2953 if (Services.prefs.getBoolPref(enabledPref, false)) {
2954 if (!Services.prefs.getBoolPref(completePref, false)) {
2955 new lazy.TRRRacer().run(() => {
2956 Services.prefs.setBoolPref(completePref, true);
2960 Services.prefs.addObserver(enabledPref, function observer() {
2961 if (Services.prefs.getBoolPref(enabledPref, false)) {
2962 Services.prefs.removeObserver(enabledPref, observer);
2964 if (!Services.prefs.getBoolPref(completePref, false)) {
2965 new lazy.TRRRacer().run(() => {
2966 Services.prefs.setBoolPref(completePref, true);
2975 // FOG doesn't need to be initialized _too_ early because it has a
2978 name: "initializeFOG",
2980 Services.fog.initializeFOG();
2982 // Register Glean to listen for experiment updates releated to the
2983 // "gleanInternalSdk" feature defined in the t/c/nimbus/FeatureManifest.yaml
2984 // This feature is intended for internal Glean use only. For features wishing
2985 // to set a remote metric configuration, please use the "glean" feature for
2986 // the purpose of setting the data-control-plane features via Server Knobs.
2987 lazy.NimbusFeatures.gleanInternalSdk.onUpdate(() => {
2988 let cfg = lazy.NimbusFeatures.gleanInternalSdk.getVariable(
2989 "gleanMetricConfiguration"
2991 Services.fog.setMetricsFeatureConfig(JSON.stringify(cfg));
2994 // Register Glean to listen for experiment updates releated to the
2995 // "glean" feature defined in the t/c/nimbus/FeatureManifest.yaml
2996 lazy.NimbusFeatures.glean.onUpdate(() => {
2997 let cfg = lazy.NimbusFeatures.glean.getVariable(
2998 "gleanMetricConfiguration"
3000 Services.fog.setMetricsFeatureConfig(JSON.stringify(cfg));
3005 // Add the import button if this is the first startup.
3007 name: "PlacesUIUtils.ImportButton",
3009 // First check if we've already added the import button, in which
3010 // case we should check for events indicating we can remove it.
3012 Services.prefs.getBoolPref(
3013 "browser.bookmarks.addedImportButton",
3017 lazy.PlacesUIUtils.removeImportButtonWhenImportSucceeds();
3021 // Otherwise, check if this is a new profile where we need to add it.
3022 // `maybeAddImportButton` will call
3023 // `removeImportButtonWhenImportSucceeds`itself if/when it adds the
3024 // button. Doing things in this order avoids listening for removal
3027 this._isNewProfile &&
3028 // Not in automation: the button changes CUI state, breaking tests
3031 await lazy.PlacesUIUtils.maybeAddImportButton();
3037 name: "ASRouterNewTabHook.createInstance",
3039 lazy.ASRouterNewTabHook.createInstance(lazy.ASRouterDefaultConfig());
3044 name: "BackgroundUpdate",
3045 condition: AppConstants.MOZ_UPDATE_AGENT,
3047 // Never in automation! This is close to
3048 // `UpdateService.disabledForTesting`, but without creating the
3049 // service, which can perform a good deal of I/O in order to log its
3050 // state. Since this is in the startup path, we avoid all of that.
3051 let disabledForTesting =
3052 (Cu.isInAutomation ||
3053 lazy.Marionette.running ||
3054 lazy.RemoteAgent.running) &&
3055 Services.prefs.getBoolPref("app.update.disabledForTesting", false);
3056 if (!disabledForTesting) {
3058 await lazy.BackgroundUpdate.scheduleFirefoxMessagingSystemTargetingSnapshotting();
3061 "There was an error scheduling Firefox Messaging System targeting snapshotting: ",
3065 await lazy.BackgroundUpdate.maybeScheduleBackgroundUpdateTask();
3070 // Login detection service is used in fission to identify high value sites.
3072 name: "LoginDetection.init",
3074 let loginDetection = Cc[
3075 "@mozilla.org/login-detection-service;1"
3076 ].createInstance(Ci.nsILoginDetectionService);
3077 loginDetection.init();
3082 name: "BrowserGlue._collectTelemetryPiPEnabled",
3084 this._collectTelemetryPiPEnabled();
3087 // Schedule a sync (if enabled) after we've loaded
3089 name: "WeaveService",
3091 if (lazy.WeaveService.enabled) {
3092 await lazy.WeaveService.whenLoaded();
3093 lazy.WeaveService.Weave.Service.scheduler.autoConnect();
3099 name: "unblock-untrusted-modules-thread",
3100 condition: AppConstants.platform == "win",
3102 Services.obs.notifyObservers(
3104 "unblock-untrusted-modules-thread"
3110 name: "UpdateListener.maybeShowUnsupportedNotification",
3111 condition: AppConstants.MOZ_UPDATER,
3113 lazy.UpdateListener.maybeShowUnsupportedNotification();
3118 name: "QuickSuggest.init",
3120 lazy.QuickSuggest.init();
3125 name: "DAPTelemetrySender.startup",
3127 lazy.TelemetryUtils.isTelemetryEnabled &&
3128 lazy.NimbusFeatures.dapTelemetry.getVariable("enabled"),
3130 lazy.DAPTelemetrySender.startup();
3135 name: "ShoppingUtils.init",
3137 lazy.ShoppingUtils.init();
3142 // Starts the JSOracle process for ORB JavaScript validation, if it hasn't started already.
3143 name: "start-orb-javascript-oracle",
3145 ChromeUtils.ensureJSOracleStarted();
3150 name: "SearchSERPDomainToCategoriesMap.init",
3152 lazy.SearchSERPDomainToCategoriesMap.init().catch(console.error);
3157 name: "browser-startup-idle-tasks-finished",
3159 // Use idleDispatch a second time to run this after the per-window
3161 ChromeUtils.idleDispatch(() => {
3162 Services.obs.notifyObservers(
3164 "browser-startup-idle-tasks-finished"
3166 BrowserInitState._resolveStartupIdleTask();
3170 // Do NOT add anything after idle tasks finished.
3173 for (let task of idleTasks) {
3174 if ("condition" in task && !task.condition) {
3178 ChromeUtils.idleDispatch(
3180 if (!Services.startup.shuttingDown) {
3181 let startTime = Cu.now();
3187 ChromeUtils.addProfilerMarker(
3195 task.timeout ? { timeout: task.timeout } : undefined
3201 * Use this function as an entry point to schedule tasks that we hope
3202 * to run once per session, at any arbitrary point in time, and which we
3203 * are okay with sometimes not running at all.
3205 * This function will be called from an idle observer. Check the value of
3206 * LATE_TASKS_IDLE_TIME_SEC to see the current value for this idle
3209 * Note: this function may never be called if the user is never idle for the
3210 * requisite time (LATE_TASKS_IDLE_TIME_SEC). Be certain before adding
3211 * something here that it's okay that it never be run.
3213 _scheduleBestEffortUserIdleTasks() {
3215 function primaryPasswordTelemetry() {
3216 // Telemetry for primary-password - we do this after a delay as it
3217 // can cause IO if NSS/PSM has not already initialized.
3218 let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"].getService(
3221 let token = tokenDB.getInternalKeyToken();
3222 let mpEnabled = token.hasPassword;
3225 .getHistogramById("MASTER_PASSWORD_ENABLED")
3230 function GMPInstallManagerSimpleCheckAndInstall() {
3231 let { GMPInstallManager } = ChromeUtils.importESModule(
3232 "resource://gre/modules/GMPInstallManager.sys.mjs"
3234 this._gmpInstallManager = new GMPInstallManager();
3235 // We don't really care about the results, if someone is interested they
3236 // can check the log.
3237 this._gmpInstallManager.simpleCheckAndInstall().catch(() => {});
3240 function RemoteSettingsInit() {
3241 lazy.RemoteSettings.init();
3242 this._addBreachesSyncHandler();
3245 function PublicSuffixListInit() {
3246 lazy.PublicSuffixList.init();
3249 function RemoteSecuritySettingsInit() {
3250 lazy.RemoteSecuritySettings.init();
3253 function CorroborateInit() {
3254 if (Services.prefs.getBoolPref("corroborator.enabled", false)) {
3255 lazy.Corroborate.init().catch(console.error);
3259 function BrowserUsageTelemetryReportProfileCount() {
3260 lazy.BrowserUsageTelemetry.reportProfileCount();
3263 function reportAllowedAppSources() {
3264 lazy.OsEnvironment.reportAllowedAppSources();
3267 function searchBackgroundChecks() {
3268 Services.search.runBackgroundChecks();
3271 function reportInstallationTelemetry() {
3272 lazy.BrowserUsageTelemetry.reportInstallationTelemetry();
3275 RunOSKeyStoreSelfTest,
3278 for (let task of idleTasks) {
3279 ChromeUtils.idleDispatch(async () => {
3280 if (!Services.startup.shuttingDown) {
3281 let startTime = Cu.now();
3287 ChromeUtils.addProfilerMarker(
3288 "startupLateIdleTask",
3298 _addBreachesSyncHandler() {
3300 Services.prefs.getBoolPref(
3301 "signon.management.page.breach-alerts.enabled",
3306 .RemoteSettings(lazy.LoginBreaches.REMOTE_SETTINGS_COLLECTION)
3307 .on("sync", async event => {
3308 await lazy.LoginBreaches.update(event.data.current);
3313 _addBreachAlertsPrefObserver() {
3314 const BREACH_ALERTS_PREF = "signon.management.page.breach-alerts.enabled";
3315 const clearVulnerablePasswordsIfBreachAlertsDisabled = async function () {
3316 if (!Services.prefs.getBoolPref(BREACH_ALERTS_PREF)) {
3317 await lazy.LoginBreaches.clearAllPotentiallyVulnerablePasswords();
3320 clearVulnerablePasswordsIfBreachAlertsDisabled();
3321 Services.prefs.addObserver(
3323 clearVulnerablePasswordsIfBreachAlertsDisabled
3327 _quitSource: "unknown",
3328 _registerQuitSource(source) {
3329 this._quitSource = source;
3332 _onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {
3333 // If user has already dismissed quit request, then do nothing
3334 if (aCancelQuit instanceof Ci.nsISupportsPRBool && aCancelQuit.data) {
3338 // There are several cases where we won't show a dialog here:
3339 // 1. There is only 1 tab open in 1 window
3340 // 2. browser.warnOnQuit == false
3341 // 3. The browser is currently in Private Browsing mode
3342 // 4. The browser will be restarted.
3343 // 5. The user has automatic session restore enabled and
3344 // browser.sessionstore.warnOnQuit is not set to true.
3345 // 6. The user doesn't have automatic session restore enabled
3346 // and browser.tabs.warnOnClose is not set to true.
3348 // Otherwise, we will show the "closing multiple tabs" dialog.
3350 // aQuitType == "lastwindow" is overloaded. "lastwindow" is used to indicate
3351 // "the last window is closing but we're not quitting (a non-browser window is open)"
3352 // and also "we're quitting by closing the last window".
3354 if (aQuitType == "restart" || aQuitType == "os-restart") {
3358 // browser.warnOnQuit is a hidden global boolean to override all quit prompts.
3359 if (!Services.prefs.getBoolPref("browser.warnOnQuit")) {
3363 let windowcount = 0;
3365 let pinnedcount = 0;
3366 for (let win of lazy.BrowserWindowTracker.orderedWindows) {
3371 let tabbrowser = win.gBrowser;
3373 pinnedcount += tabbrowser._numPinnedTabs;
3374 pagecount += tabbrowser.visibleTabs.length - tabbrowser._numPinnedTabs;
3378 // No windows open so no need for a warning.
3383 // browser.warnOnQuitShortcut is checked when quitting using the shortcut key.
3384 // The warning will appear even when only one window/tab is open. For other
3385 // methods of quitting, the warning only appears when there is more than one
3386 // window or tab open.
3387 let shouldWarnForShortcut =
3388 this._quitSource == "shortcut" &&
3389 Services.prefs.getBoolPref("browser.warnOnQuitShortcut");
3390 let shouldWarnForTabs =
3391 pagecount >= 2 && Services.prefs.getBoolPref("browser.tabs.warnOnClose");
3392 if (!shouldWarnForTabs && !shouldWarnForShortcut) {
3400 let win = lazy.BrowserWindowTracker.getTopWindow();
3402 // Our prompt for quitting is most important, so replace others.
3403 win.gDialogBox.replaceDialogIfOpen();
3405 let titleId, buttonLabelId;
3406 if (windowcount > 1) {
3407 // More than 1 window. Compose our own message.
3409 id: "tabbrowser-confirm-close-windows-title",
3410 args: { windowCount: windowcount },
3412 buttonLabelId = "tabbrowser-confirm-close-windows-button";
3413 } else if (shouldWarnForShortcut) {
3414 titleId = "tabbrowser-confirm-close-tabs-with-key-title";
3415 buttonLabelId = "tabbrowser-confirm-close-tabs-with-key-button";
3418 id: "tabbrowser-confirm-close-tabs-title",
3419 args: { tabCount: pagecount },
3421 buttonLabelId = "tabbrowser-confirm-close-tabs-button";
3424 // The checkbox label is different depending on whether the shortcut
3425 // was used to quit or not.
3426 let checkboxLabelId;
3427 if (shouldWarnForShortcut) {
3428 const quitKeyElement = win.document.getElementById("key_quitApplication");
3429 const quitKey = lazy.ShortcutUtils.prettifyShortcut(quitKeyElement);
3431 id: "tabbrowser-confirm-close-tabs-with-key-checkbox",
3435 checkboxLabelId = "tabbrowser-confirm-close-tabs-checkbox";
3438 const [title, buttonLabel, checkboxLabel] =
3439 win.gBrowser.tabLocalization.formatMessagesSync([
3445 let warnOnClose = { value: true };
3447 Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
3448 Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1;
3449 // buttonPressed will be 0 for closing, 1 for cancel (don't close/quit)
3450 let buttonPressed = Services.prompt.confirmEx(
3458 checkboxLabel.value,
3461 Services.telemetry.setEventRecordingEnabled("close_tab_warning", true);
3462 let warnCheckbox = warnOnClose.value ? "checked" : "unchecked";
3464 let sessionWillBeRestored =
3465 Services.prefs.getIntPref("browser.startup.page") == 3 ||
3466 Services.prefs.getBoolPref("browser.sessionstore.resume_session_once");
3467 Services.telemetry.recordEvent(
3468 "close_tab_warning",
3473 source: this._quitSource,
3474 button: buttonPressed == 0 ? "close" : "cancel",
3475 warn_checkbox: warnCheckbox,
3476 closing_wins: "" + windowcount,
3477 closing_tabs: "" + (pagecount + pinnedcount),
3478 will_restore: sessionWillBeRestored ? "yes" : "no",
3482 // If the user has unticked the box, and has confirmed closing, stop showing
3484 if (buttonPressed == 0 && !warnOnClose.value) {
3485 if (shouldWarnForShortcut) {
3486 Services.prefs.setBoolPref("browser.warnOnQuitShortcut", false);
3488 Services.prefs.setBoolPref("browser.tabs.warnOnClose", false);
3492 this._quitSource = "unknown";
3494 aCancelQuit.data = buttonPressed != 0;
3499 * - imports the bookmarks html file if bookmarks database is empty, try to
3500 * restore bookmarks from a JSON backup if the backend indicates that the
3501 * database was corrupt.
3503 * These prefs can be set up by the frontend:
3505 * WARNING: setting these preferences to true will overwite existing bookmarks
3507 * - browser.places.importBookmarksHTML
3508 * Set to true will import the bookmarks.html file from the profile folder.
3509 * - browser.bookmarks.restore_default_bookmarks
3510 * Set to true by safe-mode dialog to indicate we must restore default
3513 _initPlaces: function BG__initPlaces(aInitialMigrationPerformed) {
3514 if (this._placesInitialized) {
3515 throw new Error("Cannot initialize Places more than once");
3517 this._placesInitialized = true;
3519 // We must instantiate the history service since it will tell us if we
3520 // need to import or restore bookmarks due to first-run, corruption or
3521 // forced migration (due to a major schema change).
3522 // If the database is corrupt or has been newly created we should
3523 // import bookmarks.
3524 let dbStatus = lazy.PlacesUtils.history.databaseStatus;
3526 // Show a notification with a "more info" link for a locked places.sqlite.
3527 if (dbStatus == lazy.PlacesUtils.history.DATABASE_STATUS_LOCKED) {
3528 // Note: initPlaces should always happen when the first window is ready,
3529 // in any case, better safe than sorry.
3530 this._firstWindowReady.then(() => {
3531 this._showPlacesLockedNotificationBox();
3532 this._placesBrowserInitComplete = true;
3533 Services.obs.notifyObservers(null, "places-browser-init-complete");
3538 let importBookmarks =
3539 !aInitialMigrationPerformed &&
3540 (dbStatus == lazy.PlacesUtils.history.DATABASE_STATUS_CREATE ||
3541 dbStatus == lazy.PlacesUtils.history.DATABASE_STATUS_CORRUPT);
3543 // Check if user or an extension has required to import bookmarks.html
3544 let importBookmarksHTML = false;
3546 importBookmarksHTML = Services.prefs.getBoolPref(
3547 "browser.places.importBookmarksHTML"
3549 if (importBookmarksHTML) {
3550 importBookmarks = true;
3554 // Support legacy bookmarks.html format for apps that depend on that format.
3555 let autoExportHTML = Services.prefs.getBoolPref(
3556 "browser.bookmarks.autoExportHTML",
3558 ); // Do not export.
3559 if (autoExportHTML) {
3560 // Sqlite.sys.mjs and Places shutdown happen at profile-before-change, thus,
3561 // to be on the safe side, this should run earlier.
3562 lazy.AsyncShutdown.profileChangeTeardown.addBlocker(
3563 "Places: export bookmarks.html",
3565 lazy.BookmarkHTMLUtils.exportToFile(
3566 lazy.BookmarkHTMLUtils.defaultPath
3572 // Check if Safe Mode or the user has required to restore bookmarks from
3573 // default profile's bookmarks.html
3574 let restoreDefaultBookmarks = false;
3576 restoreDefaultBookmarks = Services.prefs.getBoolPref(
3577 "browser.bookmarks.restore_default_bookmarks"
3579 if (restoreDefaultBookmarks) {
3580 // Ensure that we already have a bookmarks backup for today.
3581 await this._backupBookmarks();
3582 importBookmarks = true;
3586 // If the user did not require to restore default bookmarks, or import
3587 // from bookmarks.html, we will try to restore from JSON
3588 if (importBookmarks && !restoreDefaultBookmarks && !importBookmarksHTML) {
3589 // get latest JSON backup
3590 let lastBackupFile = await lazy.PlacesBackups.getMostRecentBackup();
3591 if (lastBackupFile) {
3592 // restore from JSON backup
3593 await lazy.BookmarkJSONUtils.importFromFile(lastBackupFile, {
3595 source: lazy.PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP,
3597 importBookmarks = false;
3599 // We have created a new database but we don't have any backup available
3600 importBookmarks = true;
3601 if (await IOUtils.exists(lazy.BookmarkHTMLUtils.defaultPath)) {
3602 // If bookmarks.html is available in current profile import it...
3603 importBookmarksHTML = true;
3605 // ...otherwise we will restore defaults
3606 restoreDefaultBookmarks = true;
3611 // Import default bookmarks when necessary.
3612 // Otherwise, if any kind of import runs, default bookmarks creation should be
3613 // delayed till the import operations has finished. Not doing so would
3614 // cause them to be overwritten by the newly imported bookmarks.
3615 if (!importBookmarks) {
3616 // Now apply distribution customized bookmarks.
3617 // This should always run after Places initialization.
3619 await this._distributionCustomizer.applyBookmarks();
3624 // An import operation is about to run.
3625 let bookmarksUrl = null;
3626 if (restoreDefaultBookmarks) {
3627 // User wants to restore the default set of bookmarks shipped with the
3628 // browser, those that new profiles start with.
3629 bookmarksUrl = "chrome://browser/content/default-bookmarks.html";
3630 } else if (await IOUtils.exists(lazy.BookmarkHTMLUtils.defaultPath)) {
3631 bookmarksUrl = PathUtils.toFileURI(
3632 lazy.BookmarkHTMLUtils.defaultPath
3637 // Import from bookmarks.html file.
3640 Services.policies.isAllowed("defaultBookmarks") &&
3641 // Default bookmarks are imported after startup, and they may
3642 // influence the outcome of tests, thus it's possible to use
3643 // this test-only pref to skip the import.
3645 Cu.isInAutomation &&
3646 Services.prefs.getBoolPref(
3647 "browser.bookmarks.testing.skipDefaultBookmarksImport",
3652 await lazy.BookmarkHTMLUtils.importFromURL(bookmarksUrl, {
3654 source: lazy.PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP,
3658 console.error("Bookmarks.html file could be corrupt. ", e);
3661 // Now apply distribution customized bookmarks.
3662 // This should always run after Places initialization.
3663 await this._distributionCustomizer.applyBookmarks();
3668 console.error(new Error("Unable to find bookmarks.html file."));
3671 // Reset preferences, so we won't try to import again at next run
3672 if (importBookmarksHTML) {
3673 Services.prefs.setBoolPref(
3674 "browser.places.importBookmarksHTML",
3678 if (restoreDefaultBookmarks) {
3679 Services.prefs.setBoolPref(
3680 "browser.bookmarks.restore_default_bookmarks",
3686 // Initialize bookmark archiving on idle.
3687 // If the last backup has been created before the last browser session,
3688 // and is days old, be more aggressive with the idle timer.
3689 let idleTime = BOOKMARKS_BACKUP_IDLE_TIME_SEC;
3690 if (!(await lazy.PlacesBackups.hasRecentBackup())) {
3693 this._userIdleService.addIdleObserver(this, idleTime);
3694 this._bookmarksBackupIdleTime = idleTime;
3696 if (this._isNewProfile) {
3697 // New profiles may have existing bookmarks (imported from another browser or
3698 // copied into the profile) and we want to show the bookmark toolbar for them
3700 await lazy.PlacesUIUtils.maybeToggleBookmarkToolbarVisibility();
3707 // NB: deliberately after the catch so that we always do this, even if
3708 // we threw halfway through initializing in the Task above.
3709 this._placesBrowserInitComplete = true;
3710 Services.obs.notifyObservers(null, "places-browser-init-complete");
3715 * If a backup for today doesn't exist, this creates one.
3717 _backupBookmarks: function BG__backupBookmarks() {
3718 return (async function () {
3719 let lastBackupFile = await lazy.PlacesBackups.getMostRecentBackup();
3720 // Should backup bookmarks if there are no backups or the maximum
3721 // interval between backups elapsed.
3724 new Date() - lazy.PlacesBackups.getDateForFile(lastBackupFile) >
3725 BOOKMARKS_BACKUP_MIN_INTERVAL_DAYS * 86400000
3727 let maxBackups = Services.prefs.getIntPref(
3728 "browser.bookmarks.max_backups"
3730 await lazy.PlacesBackups.create(maxBackups);
3736 * Show the notificationBox for a locked places database.
3738 _showPlacesLockedNotificationBox:
3739 function BG__showPlacesLockedNotificationBox() {
3740 var win = lazy.BrowserWindowTracker.getTopWindow();
3741 var buttons = [{ supportPage: "places-locked" }];
3743 var notifyBox = win.gBrowser.getNotificationBox();
3744 var notification = notifyBox.appendNotification(
3747 label: { "l10n-id": "places-locked-prompt" },
3748 priority: win.gNotificationBox.PRIORITY_CRITICAL_MEDIUM,
3752 notification.persistence = -1; // Until user closes it
3755 _onThisDeviceConnected() {
3756 const [title, body] = lazy.accountsL10n.formatValuesSync([
3757 "account-connection-title",
3758 "account-connection-connected",
3761 let clickCallback = (subject, topic, data) => {
3762 if (topic != "alertclickcallback") {
3765 this._openPreferences("sync");
3767 this.AlertsService.showAlertNotification(
3777 _migrateXULStoreForDocument(fromURL, toURL) {
3778 Array.from(Services.xulStore.getIDsEnumerator(fromURL)).forEach(id => {
3779 Array.from(Services.xulStore.getAttributeEnumerator(fromURL, id)).forEach(
3781 let value = Services.xulStore.getValue(fromURL, id, attr);
3782 Services.xulStore.setValue(toURL, id, attr, value);
3788 _migrateHashedKeysForXULStoreForDocument(docUrl) {
3789 Array.from(Services.xulStore.getIDsEnumerator(docUrl))
3790 .filter(id => id.startsWith("place:"))
3792 Services.xulStore.removeValue(docUrl, id, "open");
3793 let hashedId = lazy.PlacesUIUtils.obfuscateUrlForXulStore(id);
3794 Services.xulStore.setValue(docUrl, hashedId, "open", "true");
3798 // eslint-disable-next-line complexity
3800 // Use an increasing number to keep track of the current migration state.
3801 // Completely unrelated to the current Firefox release number.
3802 const UI_VERSION = 142;
3803 const BROWSER_DOCURL = AppConstants.BROWSER_CHROME_URL;
3805 if (!Services.prefs.prefHasUserValue("browser.migration.version")) {
3806 // This is a new profile, nothing to migrate.
3807 Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
3808 this._isNewProfile = true;
3812 this._isNewProfile = false;
3813 let currentUIVersion = Services.prefs.getIntPref(
3814 "browser.migration.version"
3816 if (currentUIVersion >= UI_VERSION) {
3820 let xulStore = Services.xulStore;
3822 if (currentUIVersion < 90) {
3823 this._migrateXULStoreForDocument(
3824 "chrome://browser/content/places/historySidebar.xul",
3825 "chrome://browser/content/places/historySidebar.xhtml"
3827 this._migrateXULStoreForDocument(
3828 "chrome://browser/content/places/places.xul",
3829 "chrome://browser/content/places/places.xhtml"
3831 this._migrateXULStoreForDocument(
3832 "chrome://browser/content/places/bookmarksSidebar.xul",
3833 "chrome://browser/content/places/bookmarksSidebar.xhtml"
3837 // Clear socks proxy values if they were shared from http, to prevent
3838 // websocket breakage after bug 1577862 (see bug 969282).
3840 currentUIVersion < 91 &&
3841 Services.prefs.getBoolPref("network.proxy.share_proxy_settings", false) &&
3842 Services.prefs.getIntPref("network.proxy.type", 0) == 1
3844 let httpProxy = Services.prefs.getCharPref("network.proxy.http", "");
3845 let httpPort = Services.prefs.getIntPref("network.proxy.http_port", 0);
3846 let socksProxy = Services.prefs.getCharPref("network.proxy.socks", "");
3847 let socksPort = Services.prefs.getIntPref("network.proxy.socks_port", 0);
3848 if (httpProxy && httpProxy == socksProxy && httpPort == socksPort) {
3849 Services.prefs.setCharPref(
3850 "network.proxy.socks",
3851 Services.prefs.getCharPref("network.proxy.backup.socks", "")
3853 Services.prefs.setIntPref(
3854 "network.proxy.socks_port",
3855 Services.prefs.getIntPref("network.proxy.backup.socks_port", 0)
3860 if (currentUIVersion < 92) {
3861 // privacy.userContext.longPressBehavior pref was renamed and changed to a boolean
3862 let longpress = Services.prefs.getIntPref(
3863 "privacy.userContext.longPressBehavior",
3866 if (longpress == 1) {
3867 Services.prefs.setBoolPref(
3868 "privacy.userContext.newTabContainerOnLeftClick.enabled",
3874 if (currentUIVersion < 93) {
3875 // The Gecko Profiler Addon is now an internal component. Remove the old
3876 // addon, and enable the new UI.
3878 function enableProfilerButton(wasAddonActive) {
3879 // Enable the feature pref. This will add it to the customization palette,
3880 // but not to the the navbar.
3881 Services.prefs.setBoolPref(
3882 "devtools.performance.popup.feature-flag",
3886 if (wasAddonActive) {
3887 const { ProfilerMenuButton } = ChromeUtils.import(
3888 "resource://devtools/client/performance-new/popup/menu-button.jsm.js"
3890 if (!ProfilerMenuButton.isInNavbar()) {
3891 // The profiler menu button is not enabled. Turn it on now.
3892 const win = lazy.BrowserWindowTracker.getTopWindow();
3893 if (win && win.document) {
3894 ProfilerMenuButton.addToNavbar(win.document);
3902 addonPromise = lazy.AddonManager.getAddonByID(
3903 "geckoprofiler@mozilla.com"
3907 "Could not access the AddonManager to upgrade the profile. This is most " +
3908 "likely because the upgrader is being run from an xpcshell test where " +
3909 "the AddonManager is not initialized."
3912 Promise.resolve(addonPromise).then(addon => {
3914 // Either the addon wasn't installed, or the call to getAddonByID failed.
3917 // Remove the old addon.
3918 const wasAddonActive = addon.isActive;
3921 .catch(console.error)
3922 .then(() => enableProfilerButton(wasAddonActive))
3923 .catch(console.error);
3927 // Clear unused socks proxy backup values - see bug 1625773.
3928 if (currentUIVersion < 94) {
3929 let backup = Services.prefs.getCharPref("network.proxy.backup.socks", "");
3930 let backupPort = Services.prefs.getIntPref(
3931 "network.proxy.backup.socks_port",
3934 let socksProxy = Services.prefs.getCharPref("network.proxy.socks", "");
3935 let socksPort = Services.prefs.getIntPref("network.proxy.socks_port", 0);
3936 if (backup == socksProxy) {
3937 Services.prefs.clearUserPref("network.proxy.backup.socks");
3939 if (backupPort == socksPort) {
3940 Services.prefs.clearUserPref("network.proxy.backup.socks_port");
3944 if (currentUIVersion < 95) {
3945 const oldPrefName = "media.autoplay.enabled.user-gestures-needed";
3946 const oldPrefValue = Services.prefs.getBoolPref(oldPrefName, true);
3947 const newPrefValue = oldPrefValue ? 0 : 1;
3948 Services.prefs.setIntPref("media.autoplay.blocking_policy", newPrefValue);
3949 Services.prefs.clearUserPref(oldPrefName);
3952 if (currentUIVersion < 96) {
3953 const oldPrefName = "browser.urlbar.openViewOnFocus";
3954 const oldPrefValue = Services.prefs.getBoolPref(oldPrefName, true);
3955 Services.prefs.setBoolPref(
3956 "browser.urlbar.suggest.topsites",
3959 Services.prefs.clearUserPref(oldPrefName);
3962 if (currentUIVersion < 97) {
3963 let userCustomizedWheelMax = Services.prefs.prefHasUserValue(
3964 "general.smoothScroll.mouseWheel.durationMaxMS"
3966 let userCustomizedWheelMin = Services.prefs.prefHasUserValue(
3967 "general.smoothScroll.mouseWheel.durationMinMS"
3970 if (!userCustomizedWheelMin && !userCustomizedWheelMax) {
3971 // If the user has an existing profile but hasn't customized the wheel
3972 // animation duration, they will now get the new default values. This
3973 // condition used to set a migrationPercent pref to 0, so that users
3974 // upgrading an older profile would gradually have their wheel animation
3975 // speed migrated to the new values. However, that "gradual migration"
3976 // was phased out by FF 86, so we don't need to set that pref anymore.
3977 } else if (userCustomizedWheelMin && !userCustomizedWheelMax) {
3978 // If they customized just one of the two, save the old value for the
3979 // other one as well, because the two values go hand-in-hand and we
3980 // don't want to move just one to a new value and leave the other one
3981 // at a customized value. In both of these cases, we leave the "migration
3982 // complete" percentage at 100, because they have customized this and
3983 // don't need any further migration.
3984 Services.prefs.setIntPref(
3985 "general.smoothScroll.mouseWheel.durationMaxMS",
3988 } else if (!userCustomizedWheelMin && userCustomizedWheelMax) {
3989 // Same as above case, but for the other pref.
3990 Services.prefs.setIntPref(
3991 "general.smoothScroll.mouseWheel.durationMinMS",
3995 // The last remaining case is if they customized both values, in which
3996 // case also don't need to do anything; the user's customized values
3997 // will be retained and respected.
4001 if (currentUIVersion < 98) {
4002 Services.prefs.clearUserPref("browser.search.cohort");
4005 if (currentUIVersion < 99) {
4006 Services.prefs.clearUserPref("security.tls.version.enable-deprecated");
4009 if (currentUIVersion < 102) {
4010 // In Firefox 83, we moved to a dynamic button, so it needs to be removed
4011 // from default placement. This is done early enough that it doesn't
4012 // impact adding new managed bookmarks.
4013 const { CustomizableUI } = ChromeUtils.importESModule(
4014 "resource:///modules/CustomizableUI.sys.mjs"
4016 CustomizableUI.removeWidgetFromArea("managed-bookmarks");
4019 // We have to rerun these because we had to use 102 on beta.
4020 // They were 101 and 102 before.
4021 if (currentUIVersion < 103) {
4022 // Set a pref if the bookmarks toolbar was already visible,
4023 // so we can keep it visible when navigating away from newtab
4024 let bookmarksToolbarWasVisible =
4025 Services.xulStore.getValue(
4030 if (bookmarksToolbarWasVisible) {
4031 // Migrate the user to the "always visible" value. See firefox.js for
4032 // the other possible states.
4033 Services.prefs.setCharPref(
4034 "browser.toolbars.bookmarks.visibility",
4038 Services.xulStore.removeValue(
4044 Services.prefs.clearUserPref(
4045 "browser.livebookmarks.migrationAttemptsLeft"
4049 // For existing profiles, continue putting bookmarks in the
4050 // "other bookmarks" folder.
4051 if (currentUIVersion < 104) {
4052 Services.prefs.setCharPref(
4053 "browser.bookmarks.defaultLocation",
4058 // Renamed and flipped the logic of a pref to make its purpose more clear.
4059 if (currentUIVersion < 105) {
4060 const oldPrefName = "browser.urlbar.imeCompositionClosesPanel";
4061 const oldPrefValue = Services.prefs.getBoolPref(oldPrefName, true);
4062 Services.prefs.setBoolPref(
4063 "browser.urlbar.keepPanelOpenDuringImeComposition",
4066 Services.prefs.clearUserPref(oldPrefName);
4069 // Initialize the new browser.urlbar.showSuggestionsBeforeGeneral pref.
4070 if (currentUIVersion < 106) {
4071 lazy.UrlbarPrefs.initializeShowSearchSuggestionsFirstPref();
4074 if (currentUIVersion < 107) {
4075 // Migrate old http URIs for mailto handlers to their https equivalents.
4076 // The handler service will do this. We need to wait with migrating
4077 // until the handler service has started up, so just set a pref here.
4078 const kPref = "browser.handlers.migrations";
4079 // We might have set up another migration further up. Create an array,
4080 // and drop empty strings resulting from the `split`:
4081 let migrations = Services.prefs
4082 .getCharPref(kPref, "")
4085 migrations.push("secure-mail");
4086 Services.prefs.setCharPref(kPref, migrations.join(","));
4089 if (currentUIVersion < 108) {
4090 // Migrate old ctrlTab pref to new ctrlTab pref
4091 let defaultValue = false;
4092 let oldPrefName = "browser.ctrlTab.recentlyUsedOrder";
4093 let oldPrefDefault = true;
4094 // Use old pref value if the user used Ctrl+Tab before, elsewise use new default value
4095 if (Services.prefs.getBoolPref("browser.engagement.ctrlTab.has-used")) {
4096 let newPrefValue = Services.prefs.getBoolPref(
4100 Services.prefs.setBoolPref(
4101 "browser.ctrlTab.sortByRecentlyUsed",
4105 Services.prefs.setBoolPref(
4106 "browser.ctrlTab.sortByRecentlyUsed",
4112 if (currentUIVersion < 109) {
4113 // Migrate old pref to new pref
4115 Services.prefs.prefHasUserValue("signon.recipes.remoteRecipesEnabled")
4117 // Fetch the previous value of signon.recipes.remoteRecipesEnabled and assign it to signon.recipes.remoteRecipes.enabled.
4118 Services.prefs.setBoolPref(
4119 "signon.recipes.remoteRecipes.enabled",
4120 Services.prefs.getBoolPref(
4121 "signon.recipes.remoteRecipesEnabled",
4125 //Then clear user pref
4126 Services.prefs.clearUserPref("signon.recipes.remoteRecipesEnabled");
4130 if (currentUIVersion < 120) {
4131 // Migrate old titlebar bool pref to new int-based one.
4132 const oldPref = "browser.tabs.drawInTitlebar";
4133 const newPref = "browser.tabs.inTitlebar";
4134 if (Services.prefs.prefHasUserValue(oldPref)) {
4135 // We may have int prefs for builds between bug 1736518 and bug 1739539.
4136 const oldPrefType = Services.prefs.getPrefType(oldPref);
4137 if (oldPrefType == Services.prefs.PREF_BOOL) {
4138 Services.prefs.setIntPref(
4140 Services.prefs.getBoolPref(oldPref) ? 1 : 0
4143 Services.prefs.setIntPref(
4145 Services.prefs.getIntPref(oldPref)
4148 Services.prefs.clearUserPref(oldPref);
4152 if (currentUIVersion < 121) {
4153 // Migrate stored uris and convert them to use hashed keys
4154 this._migrateHashedKeysForXULStoreForDocument(BROWSER_DOCURL);
4155 this._migrateHashedKeysForXULStoreForDocument(
4156 "chrome://browser/content/places/bookmarksSidebar.xhtml"
4158 this._migrateHashedKeysForXULStoreForDocument(
4159 "chrome://browser/content/places/historySidebar.xhtml"
4163 if (currentUIVersion < 122) {
4164 // Migrate xdg-desktop-portal pref from old to new prefs.
4166 const oldPref = "widget.use-xdg-desktop-portal";
4167 if (Services.prefs.getBoolPref(oldPref)) {
4168 Services.prefs.setIntPref(
4169 "widget.use-xdg-desktop-portal.file-picker",
4172 Services.prefs.setIntPref(
4173 "widget.use-xdg-desktop-portal.mime-handler",
4177 Services.prefs.clearUserPref(oldPref);
4181 // Bug 1745248: Due to multiple backouts, do not use UI Version 123
4182 // as this version is most likely set for the Nightly channel
4184 if (currentUIVersion < 124) {
4185 // Migrate "extensions.formautofill.available" and
4186 // "extensions.formautofill.creditCards.available" from old to new prefs
4187 const oldFormAutofillModule = "extensions.formautofill.available";
4188 const oldCreditCardsAvailable =
4189 "extensions.formautofill.creditCards.available";
4190 const newCreditCardsAvailable =
4191 "extensions.formautofill.creditCards.supported";
4192 const newAddressesAvailable =
4193 "extensions.formautofill.addresses.supported";
4194 if (Services.prefs.prefHasUserValue(oldFormAutofillModule)) {
4195 let moduleAvailability = Services.prefs.getCharPref(
4196 oldFormAutofillModule
4198 if (moduleAvailability == "on") {
4199 Services.prefs.setCharPref(newAddressesAvailable, moduleAvailability);
4200 Services.prefs.setCharPref(
4201 newCreditCardsAvailable,
4202 Services.prefs.getBoolPref(oldCreditCardsAvailable) ? "on" : "off"
4206 if (moduleAvailability == "off") {
4207 Services.prefs.setCharPref(
4208 newCreditCardsAvailable,
4211 Services.prefs.setCharPref(newAddressesAvailable, moduleAvailability);
4215 // after migrating, clear old prefs so we can remove them later.
4216 Services.prefs.clearUserPref(oldFormAutofillModule);
4217 Services.prefs.clearUserPref(oldCreditCardsAvailable);
4220 if (currentUIVersion < 125) {
4221 // Bug 1756243 - Clear PiP cached coordinates since we changed their
4222 // coordinate space.
4223 const PIP_PLAYER_URI =
4224 "chrome://global/content/pictureinpicture/player.xhtml";
4226 for (let value of ["left", "top", "width", "height"]) {
4227 Services.xulStore.removeValue(
4229 "picture-in-picture",
4234 console.error("Failed to clear XULStore PiP values: ", ex);
4238 function migrateXULAttributeToStyle(url, id, attr) {
4240 let value = Services.xulStore.getValue(url, id, attr);
4242 Services.xulStore.setValue(url, id, "style", `${attr}: ${value}px;`);
4245 console.error(`Error migrating ${id}'s ${attr} value: `, ex);
4249 // Bug 1792748 used version 129 with a buggy variant of the sidebar width
4250 // migration. This version is already in use in the nightly channel, so it
4251 // shouldn't be used.
4253 // Bug 1793366: migrate sidebar persisted attribute from width to style.
4254 if (currentUIVersion < 130) {
4255 migrateXULAttributeToStyle(BROWSER_DOCURL, "sidebar-box", "width");
4258 // Migration 131 was moved to 133 to allow for an uplift.
4260 if (currentUIVersion < 132) {
4261 // These attributes are no longer persisted, thus remove them from xulstore.
4263 "chrome://browser/content/places/bookmarkProperties.xhtml",
4264 "chrome://browser/content/places/bookmarkProperties2.xhtml",
4266 for (let attr of ["width", "screenX", "screenY"]) {
4267 xulStore.removeValue(url, "bookmarkproperties", attr);
4272 if (currentUIVersion < 133) {
4273 xulStore.removeValue(BROWSER_DOCURL, "urlbar-container", "width");
4276 // Migration 134 was removed because it was no longer necessary.
4278 if (currentUIVersion < 135 && AppConstants.platform == "linux") {
4279 // Avoid changing titlebar setting for users that used to had it off.
4281 if (!Services.prefs.prefHasUserValue("browser.tabs.inTitlebar")) {
4282 let de = Services.appinfo.desktopEnvironment;
4283 let oldDefault = de.includes("gnome") || de.includes("pantheon");
4285 Services.prefs.setIntPref("browser.tabs.inTitlebar", 0);
4289 console.error("Error migrating tabsInTitlebar setting", e);
4293 if (currentUIVersion < 136) {
4294 migrateXULAttributeToStyle(
4295 "chrome://browser/content/places/places.xhtml",
4301 if (currentUIVersion < 137) {
4302 // The default value for enabling smooth scrolls is now false if the
4303 // user prefers reduced motion. If the value was previously set, do
4304 // not reset it, but if it was not explicitly set preserve the old
4307 !Services.prefs.prefHasUserValue("general.smoothScroll") &&
4308 Services.appinfo.prefersReducedMotion
4310 Services.prefs.setBoolPref("general.smoothScroll", true);
4314 if (currentUIVersion < 138) {
4315 // Bug 1757297: Change scheme of all existing 'https-only-load-insecure'
4316 // permissions with https scheme to http scheme.
4319 .getAllByTypes(["https-only-load-insecure"])
4320 .filter(permission => permission.principal.schemeIs("https"))
4321 .forEach(permission => {
4322 const capability = permission.capability;
4323 const uri = permission.principal.URI.mutate()
4327 Services.scriptSecurityManager.createContentPrincipal(uri, {});
4328 Services.perms.removePermission(permission);
4329 Services.perms.addFromPrincipal(
4331 "https-only-load-insecure",
4336 console.error("Error migrating https-only-load-insecure permission", e);
4340 if (currentUIVersion < 139) {
4341 // Reset the default permissions to ALLOW_ACTION to rollback issues for
4342 // affected users, see Bug 1579517
4343 // originInfo in the format [origin, type]
4345 ["https://www.mozilla.org", "uitour"],
4346 ["https://support.mozilla.org", "uitour"],
4347 ["about:home", "uitour"],
4348 ["about:newtab", "uitour"],
4349 ["https://addons.mozilla.org", "install"],
4350 ["https://support.mozilla.org", "remote-troubleshooting"],
4351 ["about:welcome", "autoplay-media"],
4352 ].forEach(originInfo => {
4353 // Reset permission on the condition that it is set to
4354 // UNKNOWN_ACTION, we want to prevent resetting user
4355 // manipulated permissions
4357 Services.perms.UNKNOWN_ACTION ==
4358 Services.perms.testPermissionFromPrincipal(
4359 Services.scriptSecurityManager.createContentPrincipalFromOrigin(
4365 // Adding permissions which have default values does not create
4366 // new permissions, but rather remove the UNKNOWN_ACTION permission
4367 // overrides. User's not affected by Bug 1579517 will not be affected by this addition.
4368 Services.perms.addFromPrincipal(
4369 Services.scriptSecurityManager.createContentPrincipalFromOrigin(
4373 Services.perms.ALLOW_ACTION
4379 if (currentUIVersion < 140) {
4380 // Remove browser.fixup.alternate.enabled pref in Bug 1850902.
4381 Services.prefs.clearUserPref("browser.fixup.alternate.enabled");
4384 if (currentUIVersion < 141) {
4385 for (const filename of ["signons.sqlite", "signons.sqlite.corrupt"]) {
4386 const filePath = PathUtils.join(PathUtils.profileDir, filename);
4387 IOUtils.remove(filePath, { ignoreAbsent: true }).catch(console.error);
4391 if (currentUIVersion < 142) {
4392 // Bug 1860392 - Remove incorrectly persisted theming values from sidebar style.
4394 let value = xulStore.getValue(BROWSER_DOCURL, "sidebar-box", "style");
4396 // Remove custom properties.
4399 .filter(v => !v.trim().startsWith("--"))
4401 xulStore.setValue(BROWSER_DOCURL, "sidebar-box", "style", value);
4408 // Update the migration version.
4409 Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
4412 async _showUpgradeDialog() {
4413 const data = await lazy.OnboardingMessageProvider.getUpgradeMessage();
4414 const { gBrowser } = lazy.BrowserWindowTracker.getTopWindow();
4416 // We'll be adding a new tab open the tab-modal dialog in.
4419 const upgradeTabsProgressListener = {
4420 onLocationChange(aBrowser) {
4421 if (aBrowser === tab.linkedBrowser) {
4422 lazy.setTimeout(() => {
4423 // We're now far enough along in the load that we no longer have to
4424 // worry about a call to onLocationChange triggering SubDialog.abort,
4425 // so display the dialog
4427 type: "SHOW_SPOTLIGHT",
4430 lazy.SpecialMessageActions.handleAction(config, tab.linkedBrowser);
4432 gBrowser.removeTabsProgressListener(upgradeTabsProgressListener);
4438 // Make sure we're ready to show the dialog once onLocationChange gets
4440 gBrowser.addTabsProgressListener(upgradeTabsProgressListener);
4442 tab = gBrowser.addTrustedTab("about:home", {
4443 relatedToCurrent: true,
4446 gBrowser.selectedTab = tab;
4449 async _showAboutWelcomeModal() {
4450 const { gBrowser } = lazy.BrowserWindowTracker.getTopWindow();
4451 const data = await lazy.NimbusFeatures.aboutwelcome.getAllVariables();
4454 type: "SHOW_SPOTLIGHT",
4457 template: "multistage",
4458 id: data?.id || "ABOUT_WELCOME_MODAL",
4459 backdrop: data?.backdrop,
4460 screens: data?.screens,
4461 UTMTerm: data?.UTMTerm,
4466 lazy.SpecialMessageActions.handleAction(config, gBrowser);
4469 async _maybeShowDefaultBrowserPrompt() {
4470 // Highest priority is about:welcome window modal experiment
4471 // Second highest priority is the upgrade dialog, which can include a "primary
4472 // browser" request and is limited in various ways, e.g., major upgrades.
4474 lazy.BrowserHandler.firstRunProfile &&
4475 lazy.NimbusFeatures.aboutwelcome.getVariable("showModal")
4477 this._showAboutWelcomeModal();
4480 const dialogVersion = 106;
4481 const dialogVersionPref = "browser.startup.upgradeDialog.version";
4482 const dialogReason = await (async () => {
4483 if (!lazy.BrowserHandler.majorUpgrade) {
4486 const lastVersion = Services.prefs.getIntPref(dialogVersionPref, 0);
4487 if (lastVersion > dialogVersion) {
4488 return "newer-shown";
4490 if (lastVersion === dialogVersion) {
4491 return "already-shown";
4494 // Check the default branch as enterprise policies can set prefs there.
4495 const defaultPrefs = Services.prefs.getDefaultBranch("");
4497 !defaultPrefs.getBoolPref(
4498 "browser.messaging-system.whatsNewPanel.enabled",
4502 return "no-whatsNew";
4504 if (!defaultPrefs.getBoolPref("browser.aboutwelcome.enabled", true)) {
4505 return "no-welcome";
4507 if (!Services.policies.isAllowed("postUpdateCustomPage")) {
4508 return "disallow-postUpdate";
4511 const useMROnboarding =
4512 lazy.NimbusFeatures.majorRelease2022.getVariable("onboarding");
4513 const showUpgradeDialog =
4515 lazy.NimbusFeatures.upgradeDialog.getVariable("enabled");
4517 return showUpgradeDialog ? "" : "disabled";
4520 // Record why the dialog is showing or not.
4521 Services.telemetry.setEventRecordingEnabled("upgrade_dialog", true);
4522 Services.telemetry.recordEvent(
4526 dialogReason || "satisfied"
4529 // Show the upgrade dialog if allowed and remember the version.
4530 if (!dialogReason) {
4531 Services.prefs.setIntPref(dialogVersionPref, dialogVersion);
4532 this._showUpgradeDialog();
4536 const willPrompt = await DefaultBrowserCheck.willCheckDefaultBrowser(
4537 /* isStartupCheck */ true
4540 let win = lazy.BrowserWindowTracker.getTopWindow();
4541 DefaultBrowserCheck.prompt(win);
4542 } else if (await lazy.QuickSuggest.maybeShowOnboardingDialog()) {
4546 await lazy.ASRouter.waitForInitialized;
4547 lazy.ASRouter.sendTriggerMessage({
4549 lazy.BrowserWindowTracker.getTopWindow()?.gBrowser.selectedBrowser,
4550 // triggerId and triggerContext
4551 id: "defaultBrowserCheck",
4552 context: { willShowDefaultPrompt: willPrompt, source: "startup" },
4557 * Only show the infobar when canRestoreLastSession and the pref value == 1
4559 async _maybeShowRestoreSessionInfoBar() {
4560 let count = Services.prefs.getIntPref(
4561 "browser.startup.couldRestoreSession.count",
4564 if (count < 0 || count >= 2) {
4568 // We don't show the infobar right after the update which establishes this pref
4569 // Increment the counter so we can consider it next time
4570 Services.prefs.setIntPref(
4571 "browser.startup.couldRestoreSession.count",
4577 const win = lazy.BrowserWindowTracker.getTopWindow();
4578 // We've restarted at least once; we will show the notification if possible.
4579 // We can't do that if there's no session to restore, or this is a private window.
4581 !lazy.SessionStore.canRestoreLastSession ||
4582 lazy.PrivateBrowsingUtils.isWindowPrivate(win)
4587 Services.prefs.setIntPref(
4588 "browser.startup.couldRestoreSession.count",
4592 const messageFragment = win.document.createDocumentFragment();
4593 const message = win.document.createElement("span");
4594 const icon = win.document.createElement("img");
4595 icon.src = "chrome://browser/skin/menu.svg";
4596 icon.setAttribute("data-l10n-name", "icon");
4597 icon.className = "inline-icon";
4598 message.appendChild(icon);
4599 messageFragment.appendChild(message);
4600 win.document.l10n.setAttributes(
4602 "restore-session-startup-suggestion-message"
4607 "l10n-id": "restore-session-startup-suggestion-button",
4610 win.PanelUI.selectAndMarkItem([
4611 "appMenu-history-button",
4612 "appMenu-restoreSession",
4618 const notifyBox = win.gBrowser.getNotificationBox();
4619 const notification = notifyBox.appendNotification(
4620 "startup-restore-session-suggestion",
4622 label: messageFragment,
4623 priority: notifyBox.PRIORITY_INFO_MEDIUM,
4627 // Don't allow it to be immediately hidden:
4628 notification.timeout = Date.now() + 3000;
4632 * Open preferences even if there are no open windows.
4634 _openPreferences(...args) {
4635 let chromeWindow = lazy.BrowserWindowTracker.getTopWindow();
4637 chromeWindow.openPreferences(...args);
4641 if (Services.appShell.hiddenDOMWindow.openPreferences) {
4642 Services.appShell.hiddenDOMWindow.openPreferences(...args);
4646 _openURLInNewWindow(url) {
4647 let urlString = Cc["@mozilla.org/supports-string;1"].createInstance(
4648 Ci.nsISupportsString
4650 urlString.data = url;
4651 return new Promise(resolve => {
4652 let win = Services.ww.openWindow(
4654 AppConstants.BROWSER_CHROME_URL,
4656 "chrome,all,dialog=no",
4659 win.addEventListener(
4670 * Called as an observer when Sync's "display URIs" notification is fired.
4672 * We open the received URIs in background tabs.
4674 async _onDisplaySyncURIs(data) {
4676 // The payload is wrapped weirdly because of how Sync does notifications.
4677 const URIs = data.wrappedJSObject.object;
4679 // win can be null, but it's ok, we'll assign it later in openTab()
4680 let win = lazy.BrowserWindowTracker.getTopWindow({ private: false });
4682 const openTab = async URI => {
4685 win = await this._openURLInNewWindow(URI.uri);
4686 let tabs = win.gBrowser.tabs;
4687 tab = tabs[tabs.length - 1];
4689 tab = win.gBrowser.addWebTab(URI.uri);
4691 tab.attention = true;
4695 const firstTab = await openTab(URIs[0]);
4696 await Promise.all(URIs.slice(1).map(URI => openTab(URI)));
4698 const deviceName = URIs[0].sender && URIs[0].sender.name;
4699 let titleL10nId, body;
4700 if (URIs.length == 1) {
4701 // Due to bug 1305895, tabs from iOS may not have device information, so
4702 // we have separate strings to handle those cases. (See Also
4703 // unnamedTabsArrivingNotificationNoDevice.body below)
4704 titleL10nId = deviceName
4706 id: "account-single-tab-arriving-from-device-title",
4707 args: { deviceName },
4709 : { id: "account-single-tab-arriving-title" };
4710 // Use the page URL as the body. We strip the fragment and query (after
4711 // the `?` and `#` respectively) to reduce size, and also format it the
4712 // same way that the url bar would.
4713 let url = URIs[0].uri.replace(/([?#]).*$/, "$1");
4714 const wasTruncated = url.length < URIs[0].uri.length;
4715 url = lazy.BrowserUIUtils.trimURL(url);
4717 body = await lazy.accountsL10n.formatValue(
4718 "account-single-tab-arriving-truncated-url",
4725 titleL10nId = { id: "account-multiple-tabs-arriving-title" };
4726 const allKnownSender = URIs.every(URI => URI.sender != null);
4727 const allSameDevice =
4729 URIs.every(URI => URI.sender.id == URIs[0].sender.id);
4731 if (allSameDevice) {
4732 bodyL10nId = deviceName
4733 ? "account-multiple-tabs-arriving-from-single-device"
4734 : "account-multiple-tabs-arriving-from-unknown-device";
4736 bodyL10nId = "account-multiple-tabs-arriving-from-multiple-devices";
4739 body = await lazy.accountsL10n.formatValue(bodyL10nId, {
4741 tabCount: URIs.length,
4744 const title = await lazy.accountsL10n.formatValue(titleL10nId);
4746 const clickCallback = (obsSubject, obsTopic, obsData) => {
4747 if (obsTopic == "alertclickcallback") {
4748 win.gBrowser.selectedTab = firstTab;
4752 // Specify an icon because on Windows no icon is shown at the moment
4754 if (AppConstants.platform == "win") {
4755 imageURL = "chrome://branding/content/icon64.png";
4757 this.AlertsService.showAlertNotification(
4766 console.error("Error displaying tab(s) received by Sync: ", ex);
4770 async _onVerifyLoginNotification({ body, title, url }) {
4773 if (AppConstants.platform == "win") {
4774 imageURL = "chrome://branding/content/icon64.png";
4776 let win = lazy.BrowserWindowTracker.getTopWindow({ private: false });
4778 win = await this._openURLInNewWindow(url);
4779 let tabs = win.gBrowser.tabs;
4780 tab = tabs[tabs.length - 1];
4782 tab = win.gBrowser.addWebTab(url);
4784 tab.attention = true;
4785 let clickCallback = (subject, topic, data) => {
4786 if (topic != "alertclickcallback") {
4789 win.gBrowser.selectedTab = tab;
4793 this.AlertsService.showAlertNotification(
4802 console.error("Error notifying of a verify login event: ", ex);
4806 _onDeviceConnected(deviceName) {
4807 const [title, body] = lazy.accountsL10n.formatValuesSync([
4808 { id: "account-connection-title" },
4810 ? { id: "account-connection-connected-with", args: { deviceName } }
4811 : { id: "account-connection-connected-with-noname" },
4814 let clickCallback = async (subject, topic, data) => {
4815 if (topic != "alertclickcallback") {
4818 let url = await lazy.FxAccounts.config.promiseManageDevicesURI(
4819 "device-connected-notification"
4821 let win = lazy.BrowserWindowTracker.getTopWindow({ private: false });
4823 this._openURLInNewWindow(url);
4825 win.gBrowser.addWebTab(url);
4830 this.AlertsService.showAlertNotification(
4839 console.error("Error notifying of a new Sync device: ", ex);
4843 _onDeviceDisconnected() {
4844 const [title, body] = lazy.accountsL10n.formatValuesSync([
4845 "account-connection-title",
4846 "account-connection-disconnected",
4849 let clickCallback = (subject, topic, data) => {
4850 if (topic != "alertclickcallback") {
4853 this._openPreferences("sync");
4855 this.AlertsService.showAlertNotification(
4865 _updateFxaBadges(win) {
4866 let fxaButton = win.document.getElementById("fxa-toolbar-menu-button");
4867 let badge = fxaButton?.querySelector(".toolbarbutton-badge");
4869 let state = lazy.UIState.get();
4871 state.status == lazy.UIState.STATUS_LOGIN_FAILED ||
4872 state.status == lazy.UIState.STATUS_NOT_VERIFIED
4874 // If the fxa toolbar button is in the toolbox, we display the notification
4875 // on the fxa button instead of the app menu.
4876 let navToolbox = win.document.getElementById("navigator-toolbox");
4877 let isFxAButtonShown = navToolbox.contains(fxaButton);
4878 if (isFxAButtonShown) {
4879 state.status == lazy.UIState.STATUS_LOGIN_FAILED
4880 ? fxaButton?.setAttribute("badge-status", state.status)
4881 : badge?.classList.add("feature-callout");
4883 lazy.AppMenuNotifications.showBadgeOnlyNotification(
4884 "fxa-needs-authentication"
4888 fxaButton?.removeAttribute("badge-status");
4889 badge?.classList.remove("feature-callout");
4890 lazy.AppMenuNotifications.removeNotification("fxa-needs-authentication");
4894 _collectTelemetryPiPEnabled() {
4895 Services.telemetry.setEventRecordingEnabled(
4896 "pictureinpicture.settings",
4899 Services.telemetry.setEventRecordingEnabled("pictureinpicture", true);
4901 const TOGGLE_ENABLED_PREF =
4902 "media.videocontrols.picture-in-picture.video-toggle.enabled";
4904 const observe = (subject, topic, data) => {
4905 const enabled = Services.prefs.getBoolPref(TOGGLE_ENABLED_PREF, false);
4906 Services.telemetry.scalarSet("pictureinpicture.toggle_enabled", enabled);
4908 // Record events when preferences change
4909 if (topic === "nsPref:changed") {
4911 Services.telemetry.recordEvent(
4912 "pictureinpicture.settings",
4920 Services.prefs.addObserver(TOGGLE_ENABLED_PREF, observe);
4924 QueryInterface: ChromeUtils.generateQI([
4926 "nsISupportsWeakReference",
4930 var ContentBlockingCategoriesPrefs = {
4931 PREF_CB_CATEGORY: "browser.contentblocking.category",
4932 PREF_STRICT_DEF: "browser.contentblocking.features.strict",
4933 switchingCategory: false,
4935 setPrefExpectations() {
4936 // The prefs inside CATEGORY_PREFS are initial values.
4937 // If the pref remains null, then it will expect the default value.
4938 // The "standard" category is defined as expecting all 5 default values.
4939 this.CATEGORY_PREFS = {
4941 "network.cookie.cookieBehavior": null,
4942 "network.cookie.cookieBehavior.pbmode": null,
4943 "privacy.trackingprotection.pbmode.enabled": null,
4944 "privacy.trackingprotection.enabled": null,
4945 "privacy.trackingprotection.socialtracking.enabled": null,
4946 "privacy.trackingprotection.fingerprinting.enabled": null,
4947 "privacy.trackingprotection.cryptomining.enabled": null,
4948 "privacy.trackingprotection.emailtracking.enabled": null,
4949 "privacy.trackingprotection.emailtracking.pbmode.enabled": null,
4950 "privacy.annotate_channels.strict_list.enabled": null,
4951 "network.http.referer.disallowCrossSiteRelaxingDefault": null,
4952 "network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation":
4954 "privacy.partition.network_state.ocsp_cache": null,
4955 "privacy.query_stripping.enabled": null,
4956 "privacy.query_stripping.enabled.pbmode": null,
4957 "privacy.fingerprintingProtection": null,
4958 "privacy.fingerprintingProtection.pbmode": null,
4961 "network.cookie.cookieBehavior": null,
4962 "network.cookie.cookieBehavior.pbmode": null,
4963 "privacy.trackingprotection.pbmode.enabled": null,
4964 "privacy.trackingprotection.enabled": null,
4965 "privacy.trackingprotection.socialtracking.enabled": null,
4966 "privacy.trackingprotection.fingerprinting.enabled": null,
4967 "privacy.trackingprotection.cryptomining.enabled": null,
4968 "privacy.trackingprotection.emailtracking.enabled": null,
4969 "privacy.trackingprotection.emailtracking.pbmode.enabled": null,
4970 "privacy.annotate_channels.strict_list.enabled": null,
4971 "network.http.referer.disallowCrossSiteRelaxingDefault": null,
4972 "network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation":
4974 "privacy.partition.network_state.ocsp_cache": null,
4975 "privacy.query_stripping.enabled": null,
4976 "privacy.query_stripping.enabled.pbmode": null,
4977 "privacy.fingerprintingProtection": null,
4978 "privacy.fingerprintingProtection.pbmode": null,
4981 let type = "strict";
4982 let rulesArray = Services.prefs
4983 .getStringPref(this.PREF_STRICT_DEF)
4985 for (let item of rulesArray) {
4988 this.CATEGORY_PREFS[type][
4989 "privacy.trackingprotection.enabled"
4993 this.CATEGORY_PREFS[type][
4994 "privacy.trackingprotection.enabled"
4998 this.CATEGORY_PREFS[type][
4999 "privacy.trackingprotection.pbmode.enabled"
5003 this.CATEGORY_PREFS[type][
5004 "privacy.trackingprotection.pbmode.enabled"
5008 this.CATEGORY_PREFS[type][
5009 "privacy.trackingprotection.fingerprinting.enabled"
5013 this.CATEGORY_PREFS[type][
5014 "privacy.trackingprotection.fingerprinting.enabled"
5018 this.CATEGORY_PREFS[type][
5019 "privacy.trackingprotection.cryptomining.enabled"
5023 this.CATEGORY_PREFS[type][
5024 "privacy.trackingprotection.cryptomining.enabled"
5028 this.CATEGORY_PREFS[type][
5029 "privacy.trackingprotection.socialtracking.enabled"
5033 this.CATEGORY_PREFS[type][
5034 "privacy.trackingprotection.socialtracking.enabled"
5038 this.CATEGORY_PREFS[type][
5039 "privacy.trackingprotection.emailtracking.enabled"
5043 this.CATEGORY_PREFS[type][
5044 "privacy.trackingprotection.emailtracking.enabled"
5047 case "emailTPPrivate":
5048 this.CATEGORY_PREFS[type][
5049 "privacy.trackingprotection.emailtracking.pbmode.enabled"
5052 case "-emailTPPrivate":
5053 this.CATEGORY_PREFS[type][
5054 "privacy.trackingprotection.emailtracking.pbmode.enabled"
5058 this.CATEGORY_PREFS[type][
5059 "privacy.annotate_channels.strict_list.enabled"
5063 this.CATEGORY_PREFS[type][
5064 "privacy.annotate_channels.strict_list.enabled"
5068 this.CATEGORY_PREFS[type][
5069 "network.http.referer.disallowCrossSiteRelaxingDefault"
5073 this.CATEGORY_PREFS[type][
5074 "network.http.referer.disallowCrossSiteRelaxingDefault"
5078 this.CATEGORY_PREFS[type][
5079 "network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation"
5083 this.CATEGORY_PREFS[type][
5084 "network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation"
5088 this.CATEGORY_PREFS[type][
5089 "privacy.partition.network_state.ocsp_cache"
5093 this.CATEGORY_PREFS[type][
5094 "privacy.partition.network_state.ocsp_cache"
5098 this.CATEGORY_PREFS[type]["privacy.query_stripping.enabled"] = true;
5101 this.CATEGORY_PREFS[type]["privacy.query_stripping.enabled"] = false;
5104 this.CATEGORY_PREFS[type][
5105 "privacy.query_stripping.enabled.pbmode"
5109 this.CATEGORY_PREFS[type][
5110 "privacy.query_stripping.enabled.pbmode"
5114 this.CATEGORY_PREFS[type]["privacy.fingerprintingProtection"] = true;
5117 this.CATEGORY_PREFS[type]["privacy.fingerprintingProtection"] = false;
5120 this.CATEGORY_PREFS[type][
5121 "privacy.fingerprintingProtection.pbmode"
5125 this.CATEGORY_PREFS[type][
5126 "privacy.fingerprintingProtection.pbmode"
5129 case "cookieBehavior0":
5130 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior"] =
5131 Ci.nsICookieService.BEHAVIOR_ACCEPT;
5133 case "cookieBehavior1":
5134 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior"] =
5135 Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN;
5137 case "cookieBehavior2":
5138 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior"] =
5139 Ci.nsICookieService.BEHAVIOR_REJECT;
5141 case "cookieBehavior3":
5142 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior"] =
5143 Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN;
5145 case "cookieBehavior4":
5146 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior"] =
5147 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER;
5149 case "cookieBehavior5":
5150 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior"] =
5151 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
5153 case "cookieBehaviorPBM0":
5154 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior.pbmode"] =
5155 Ci.nsICookieService.BEHAVIOR_ACCEPT;
5157 case "cookieBehaviorPBM1":
5158 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior.pbmode"] =
5159 Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN;
5161 case "cookieBehaviorPBM2":
5162 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior.pbmode"] =
5163 Ci.nsICookieService.BEHAVIOR_REJECT;
5165 case "cookieBehaviorPBM3":
5166 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior.pbmode"] =
5167 Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN;
5169 case "cookieBehaviorPBM4":
5170 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior.pbmode"] =
5171 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER;
5173 case "cookieBehaviorPBM5":
5174 this.CATEGORY_PREFS[type]["network.cookie.cookieBehavior.pbmode"] =
5175 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
5178 console.error(`Error: Unknown rule observed ${item}`);
5184 * Checks if CB prefs match perfectly with one of our pre-defined categories.
5186 prefsMatch(category) {
5187 // The category pref must be either unset, or match.
5189 Services.prefs.prefHasUserValue(this.PREF_CB_CATEGORY) &&
5190 Services.prefs.getStringPref(this.PREF_CB_CATEGORY) != category
5194 for (let pref in this.CATEGORY_PREFS[category]) {
5195 let value = this.CATEGORY_PREFS[category][pref];
5196 if (value == null) {
5197 if (Services.prefs.prefHasUserValue(pref)) {
5201 let prefType = Services.prefs.getPrefType(pref);
5203 (prefType == Services.prefs.PREF_BOOL &&
5204 Services.prefs.getBoolPref(pref) != value) ||
5205 (prefType == Services.prefs.PREF_INT &&
5206 Services.prefs.getIntPref(pref) != value) ||
5207 (prefType == Services.prefs.PREF_STRING &&
5208 Services.prefs.getStringPref(pref) != value)
5218 if (this.switchingCategory) {
5221 // If PREF_CB_CATEGORY is not set match users to a Content Blocking category. Check if prefs fit
5222 // perfectly into strict or standard, otherwise match with custom. If PREF_CB_CATEGORY has previously been set,
5223 // a change of one of these prefs necessarily puts us in "custom".
5224 if (this.prefsMatch("standard")) {
5225 Services.prefs.setStringPref(this.PREF_CB_CATEGORY, "standard");
5226 } else if (this.prefsMatch("strict")) {
5227 Services.prefs.setStringPref(this.PREF_CB_CATEGORY, "strict");
5229 Services.prefs.setStringPref(this.PREF_CB_CATEGORY, "custom");
5232 // If there is a custom policy which changes a related pref, then put the user in custom so
5233 // they still have access to other content blocking prefs, and to keep our default definitions
5235 let policy = Services.policies.getActivePolicies();
5236 if (policy && (policy.EnableTrackingProtection || policy.Cookies)) {
5237 Services.prefs.setStringPref(this.PREF_CB_CATEGORY, "custom");
5241 updateCBCategory() {
5243 this.switchingCategory ||
5244 !Services.prefs.prefHasUserValue(this.PREF_CB_CATEGORY)
5248 // Turn on switchingCategory flag, to ensure that when the individual prefs that change as a result
5249 // of the category change do not trigger yet another category change.
5250 this.switchingCategory = true;
5251 let value = Services.prefs.getStringPref(this.PREF_CB_CATEGORY);
5252 this.setPrefsToCategory(value);
5253 this.switchingCategory = false;
5257 * Sets all user-exposed content blocking preferences to values that match the selected category.
5259 setPrefsToCategory(category) {
5260 // Leave prefs as they were if we are switching to "custom" category.
5261 if (category == "custom") {
5265 for (let pref in this.CATEGORY_PREFS[category]) {
5266 let value = this.CATEGORY_PREFS[category][pref];
5267 if (!Services.prefs.prefIsLocked(pref)) {
5268 if (value == null) {
5269 Services.prefs.clearUserPref(pref);
5271 switch (Services.prefs.getPrefType(pref)) {
5272 case Services.prefs.PREF_BOOL:
5273 Services.prefs.setBoolPref(pref, value);
5275 case Services.prefs.PREF_INT:
5276 Services.prefs.setIntPref(pref, value);
5278 case Services.prefs.PREF_STRING:
5279 Services.prefs.setStringPref(pref, value);
5289 * ContentPermissionIntegration is responsible for showing the user
5290 * simple permission prompts when content requests additional
5293 * While there are some built-in permission prompts, createPermissionPrompt
5294 * can also be overridden by system add-ons or tests to provide new ones.
5296 * This override ability is provided by Integration.sys.mjs. See
5297 * PermissionUI.sys.mjs for an example of how to provide a new prompt
5300 const ContentPermissionIntegration = {
5302 * Creates a PermissionPrompt for a given permission type and
5303 * nsIContentPermissionRequest.
5305 * @param {string} type
5306 * The type of the permission request from content. This normally
5307 * matches the "type" field of an nsIContentPermissionType, but it
5308 * can be something else if the permission does not use the
5309 * nsIContentPermissionRequest model. Note that this type might also
5310 * be different from the permission key used in the permissions
5312 * Example: "geolocation"
5313 * @param {nsIContentPermissionRequest} request
5314 * The request for a permission from content.
5315 * @return {PermissionPrompt} (see PermissionUI.sys.mjs),
5316 * or undefined if the type cannot be handled.
5318 createPermissionPrompt(type, request) {
5320 case "geolocation": {
5321 return new lazy.PermissionUI.GeolocationPermissionPrompt(request);
5324 return new lazy.PermissionUI.XRPermissionPrompt(request);
5326 case "desktop-notification": {
5327 return new lazy.PermissionUI.DesktopNotificationPermissionPrompt(
5331 case "persistent-storage": {
5332 return new lazy.PermissionUI.PersistentStoragePermissionPrompt(request);
5335 return new lazy.PermissionUI.MIDIPermissionPrompt(request);
5337 case "storage-access": {
5338 return new lazy.PermissionUI.StorageAccessPermissionPrompt(request);
5345 export function ContentPermissionPrompt() {}
5347 ContentPermissionPrompt.prototype = {
5348 classID: Components.ID("{d8903bf6-68d5-4e97-bcd1-e4d3012f721a}"),
5350 QueryInterface: ChromeUtils.generateQI(["nsIContentPermissionPrompt"]),
5353 * This implementation of nsIContentPermissionPrompt.prompt ensures
5354 * that there's only one nsIContentPermissionType in the request,
5355 * and that it's of type nsIContentPermissionType. Failing to
5356 * satisfy either of these conditions will result in this method
5357 * throwing NS_ERRORs. If the combined ContentPermissionIntegration
5358 * cannot construct a prompt for this particular request, an
5359 * NS_ERROR_FAILURE will be thrown.
5361 * Any time an error is thrown, the nsIContentPermissionRequest is
5362 * cancelled automatically.
5364 * @param {nsIContentPermissionRequest} request
5365 * The request that we're to show a prompt for.
5368 if (request.element && request.element.fxrPermissionPrompt) {
5369 // For Firefox Reality on Desktop, switch to a different mechanism to
5370 // prompt the user since fewer permissions are available and since many
5371 // UI dependencies are not availabe.
5372 request.element.fxrPermissionPrompt(request);
5378 // Only allow exactly one permission request here.
5379 let types = request.types.QueryInterface(Ci.nsIArray);
5380 if (types.length != 1) {
5381 throw Components.Exception(
5382 "Expected an nsIContentPermissionRequest with only 1 type.",
5383 Cr.NS_ERROR_UNEXPECTED
5387 type = types.queryElementAt(0, Ci.nsIContentPermissionType).type;
5388 let combinedIntegration = lazy.Integration.contentPermission.getCombined(
5389 ContentPermissionIntegration
5392 let permissionPrompt = combinedIntegration.createPermissionPrompt(
5396 if (!permissionPrompt) {
5397 throw Components.Exception(
5398 `Failed to handle permission of type ${type}`,
5403 permissionPrompt.prompt();
5410 let schemeHistogram = Services.telemetry.getKeyedHistogramById(
5411 "PERMISSION_REQUEST_ORIGIN_SCHEME"
5415 if (request.principal.schemeIs("http")) {
5417 } else if (request.principal.schemeIs("https")) {
5421 // If the request principal is not available at this point,
5422 // the request has likely been cancelled before being shown to the
5423 // user. We shouldn't record this request.
5424 if (ex.result != Cr.NS_ERROR_FAILURE) {
5429 schemeHistogram.add(type, scheme);
5431 let userInputHistogram = Services.telemetry.getKeyedHistogramById(
5432 "PERMISSION_REQUEST_HANDLING_USER_INPUT"
5434 userInputHistogram.add(
5436 request.hasValidTransientUserGestureActivation
5441 export var DefaultBrowserCheck = {
5443 const shellService = win.getShellService();
5444 const needPin = await shellService.doesAppNeedPin();
5446 win.MozXULElement.insertFTLIfNeeded("branding/brand.ftl");
5447 win.MozXULElement.insertFTLIfNeeded(
5448 "browser/defaultBrowserNotification.ftl"
5450 // Resolve the translations for the prompt elements and return only the
5453 AppConstants.platform == "macosx"
5454 ? "default-browser-prompt-message-pin-mac"
5455 : "default-browser-prompt-message-pin";
5456 let [promptTitle, promptMessage, askLabel, yesButton, notNowButton] = (
5457 await win.document.l10n.formatMessages([
5460 ? "default-browser-prompt-title-pin"
5461 : "default-browser-prompt-title-alt",
5464 id: needPin ? pinMessage : "default-browser-prompt-message-alt",
5466 { id: "default-browser-prompt-checkbox-not-again-label" },
5469 ? "default-browser-prompt-button-primary-pin"
5470 : "default-browser-prompt-button-primary-alt",
5472 { id: "default-browser-prompt-button-secondary" },
5474 ).map(({ value }) => value);
5476 let ps = Services.prompt;
5478 ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0 +
5479 ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_1 +
5480 ps.BUTTON_POS_0_DEFAULT;
5481 let rv = await ps.asyncConfirmEx(
5482 win.browsingContext,
5483 ps.MODAL_TYPE_INTERNAL_WINDOW,
5491 false, // checkbox state
5492 { headerIconURL: "chrome://branding/content/icon32.png" }
5494 let buttonNumClicked = rv.get("buttonNumClicked");
5495 let checkboxState = rv.get("checked");
5496 if (buttonNumClicked == 0) {
5498 await shellService.setAsDefault();
5500 this.log.error("Failed to set the default browser", e);
5503 shellService.pinToTaskbar();
5505 if (checkboxState) {
5506 shellService.shouldCheckDefaultBrowser = false;
5510 let resultEnum = buttonNumClicked * 2 + !checkboxState;
5512 .getHistogramById("BROWSER_SET_DEFAULT_RESULT")
5515 /* Don't break if Telemetry is acting up. */
5520 * Checks if the default browser check prompt will be shown.
5521 * @param {boolean} isStartupCheck
5522 * If true, prefs will be set and telemetry will be recorded.
5523 * @returns {boolean} True if the default browser check prompt will be shown.
5525 async willCheckDefaultBrowser(isStartupCheck) {
5526 let win = lazy.BrowserWindowTracker.getTopWindow();
5527 let shellService = win.getShellService();
5529 // Perform default browser checking.
5530 if (!shellService) {
5535 !AppConstants.DEBUG && shellService.shouldCheckDefaultBrowser;
5537 // Even if we shouldn't check the default browser, we still continue when
5538 // isStartupCheck = true to set prefs and telemetry.
5539 if (!shouldCheck && !isStartupCheck) {
5543 // Skip the "Set Default Browser" check during first-run or after the
5544 // browser has been run a few times.
5545 const skipDefaultBrowserCheck =
5546 Services.prefs.getBoolPref(
5547 "browser.shell.skipDefaultBrowserCheckOnFirstRun"
5549 !Services.prefs.getBoolPref(
5550 "browser.shell.didSkipDefaultBrowserCheckOnFirstRun"
5553 let promptCount = Services.prefs.getIntPref(
5554 "browser.shell.defaultBrowserCheckCount",
5558 // If SessionStartup's state is not initialized, checking sessionType will set
5559 // its internal state to "do not restore".
5560 await lazy.SessionStartup.onceInitialized;
5561 let willRecoverSession =
5562 lazy.SessionStartup.sessionType == lazy.SessionStartup.RECOVER_SESSION;
5564 // Don't show the prompt if we're already the default browser.
5565 let isDefault = false;
5566 let isDefaultError = false;
5568 isDefault = shellService.isDefaultBrowser(isStartupCheck, false);
5570 isDefaultError = true;
5573 if (isDefault && isStartupCheck) {
5574 let now = Math.floor(Date.now() / 1000).toString();
5575 Services.prefs.setCharPref(
5576 "browser.shell.mostRecentDateSetAsDefault",
5581 let willPrompt = shouldCheck && !isDefault && !willRecoverSession;
5584 if (skipDefaultBrowserCheck) {
5585 if (isStartupCheck) {
5586 Services.prefs.setBoolPref(
5587 "browser.shell.didSkipDefaultBrowserCheckOnFirstRun",
5594 if (isStartupCheck) {
5595 Services.prefs.setIntPref(
5596 "browser.shell.defaultBrowserCheckCount",
5600 if (!AppConstants.RELEASE_OR_BETA && promptCount > 3) {
5606 if (isStartupCheck) {
5608 // Report default browser status on startup to telemetry
5609 // so we can track whether we are the default.
5611 .getHistogramById("BROWSER_IS_USER_DEFAULT")
5614 .getHistogramById("BROWSER_IS_USER_DEFAULT_ERROR")
5615 .add(isDefaultError);
5617 .getHistogramById("BROWSER_SET_DEFAULT_ALWAYS_CHECK")
5620 .getHistogramById("BROWSER_SET_DEFAULT_DIALOG_PROMPT_RAWCOUNT")
5623 /* Don't break the default prompt if telemetry is broken. */
5632 * AboutHomeStartupCache is responsible for reading and writing the
5633 * initial about:home document from the HTTP cache as a startup
5634 * performance optimization. It only works when the "privileged about
5635 * content process" is enabled and when ENABLED_PREF is set to true.
5637 * See https://firefox-source-docs.mozilla.org/browser/components/newtab/docs/v2-system-addon/about_home_startup_cache.html
5638 * for further details.
5640 export var AboutHomeStartupCache = {
5641 ABOUT_HOME_URI_STRING: "about:home",
5642 SCRIPT_EXTENSION: "script",
5643 ENABLED_PREF: "browser.startup.homepage.abouthome_cache.enabled",
5644 PRELOADED_NEWTAB_PREF: "browser.newtab.preload",
5645 LOG_LEVEL_PREF: "browser.startup.homepage.abouthome_cache.loglevel",
5647 // It's possible that the layout of about:home will change such that
5648 // we want to invalidate any pre-existing caches. We do this by setting
5649 // this meta key in the nsICacheEntry for the page.
5651 // The version is currently set to the build ID, meaning that the cache
5652 // is invalidated after every upgrade (like the main startup cache).
5653 CACHE_VERSION_META_KEY: "version",
5655 LOG_NAME: "AboutHomeStartupCache",
5657 // These messages are used to request the "privileged about content process"
5658 // to create the cached document, and then to receive that document.
5659 CACHE_REQUEST_MESSAGE: "AboutHomeStartupCache:CacheRequest",
5660 CACHE_RESPONSE_MESSAGE: "AboutHomeStartupCache:CacheResponse",
5661 CACHE_USAGE_RESULT_MESSAGE: "AboutHomeStartupCache:UsageResult",
5663 // When a "privileged about content process" is launched, this message is
5664 // sent to give it some nsIInputStream's for the about:home document they
5666 SEND_STREAMS_MESSAGE: "AboutHomeStartupCache:InputStreams",
5668 // This time in ms is used to debounce messages that are broadcast to
5669 // all about:newtab's, or the preloaded about:newtab. We use those
5670 // messages as a signal that it's likely time to refresh the cache.
5671 CACHE_DEBOUNCE_RATE_MS: 5000,
5673 // This is how long we'll block the AsyncShutdown while waiting for
5674 // the cache to write. If we fail to write within that time, we will
5675 // allow the shutdown to proceed.
5676 SHUTDOWN_CACHE_WRITE_TIMEOUT_MS: 1000,
5678 // The following values are as possible values for the
5679 // browser.startup.abouthome_cache_result scalar. Keep these in sync with the
5680 // scalar definition in Scalars.yaml. See setDeferredResult for more
5682 CACHE_RESULT_SCALARS: {
5691 NOT_LOADING_ABOUTHOME: 8,
5692 PRELOADING_DISABLED: 9,
5695 // This will be set to one of the values of CACHE_RESULT_SCALARS
5696 // once it is determined which result best suits what occurred.
5697 _cacheDeferredResultScalar: -1,
5699 // A reference to the nsICacheEntry to read from and write to.
5702 // These nsIPipe's are sent down to the "privileged about content process"
5703 // immediately after the process launches. This allows us to race the loading
5704 // of the cache entry in the parent process with the load of the about:home
5705 // page in the content process, since we'll connect the InputStream's to
5706 // the pipes as soon as the nsICacheEntry is available.
5708 // The page pipe is for the HTML markup for the page.
5710 // The script pipe is for the JavaScript that the HTML markup loads
5711 // to set its internal state.
5713 _cacheDeferred: null,
5717 _hasWrittenThisSession: false,
5719 _firstPrivilegedProcessCreated: false,
5722 if (this._initted) {
5723 throw new Error("AboutHomeStartupCache already initted.");
5726 this.setDeferredResult(this.CACHE_RESULT_SCALARS.UNSET);
5728 this._enabled = !!lazy.NimbusFeatures.abouthomecache.getVariable("enabled");
5730 if (!this._enabled) {
5731 this.recordResult(this.CACHE_RESULT_SCALARS.DISABLED);
5735 this.log = console.createInstance({
5736 prefix: this.LOG_NAME,
5737 maxLogLevelPref: this.LOG_LEVEL_PREF,
5740 this.log.trace("Initting.");
5742 // If the user is not configured to load about:home at startup, then
5743 // let's not bother with the cache - loading it needlessly is more likely
5744 // to hinder what we're actually trying to load.
5745 let willLoadAboutHome =
5746 !lazy.HomePage.overridden &&
5747 Services.prefs.getIntPref("browser.startup.page") === 1;
5749 if (!willLoadAboutHome) {
5750 this.log.trace("Not configured to load about:home by default.");
5751 this.recordResult(this.CACHE_RESULT_SCALARS.NOT_LOADING_ABOUTHOME);
5755 if (!Services.prefs.getBoolPref(this.PRELOADED_NEWTAB_PREF, false)) {
5756 this.log.trace("Preloaded about:newtab disabled.");
5757 this.recordResult(this.CACHE_RESULT_SCALARS.PRELOADING_DISABLED);
5761 Services.obs.addObserver(this, "ipc:content-created");
5762 Services.obs.addObserver(this, "process-type-set");
5763 Services.obs.addObserver(this, "ipc:content-shutdown");
5764 Services.obs.addObserver(this, "intl:app-locales-changed");
5766 this.log.trace("Constructing pipes.");
5767 this._pagePipe = this.makePipe();
5768 this._scriptPipe = this.makePipe();
5770 this._cacheEntryPromise = new Promise(resolve => {
5771 this._cacheEntryResolver = resolve;
5774 let lci = Services.loadContextInfo.default;
5775 let storage = Services.cache2.diskCacheStorage(lci);
5777 storage.asyncOpenURI(
5780 Ci.nsICacheStorage.OPEN_PRIORITY,
5784 this.log.error("Failed to open about:home cache entry", e);
5787 this._cacheTask = new lazy.DeferredTask(async () => {
5788 await this.cacheNow();
5789 }, this.CACHE_DEBOUNCE_RATE_MS);
5791 lazy.AsyncShutdown.quitApplicationGranted.addBlocker(
5792 "AboutHomeStartupCache: Writing cache",
5794 await this.onShutdown();
5796 () => this._cacheProgress
5799 this._cacheDeferred = null;
5800 this._initted = true;
5801 this.log.trace("Initialized.");
5805 return this._initted;
5809 if (!this._enabled) {
5814 Services.obs.removeObserver(this, "ipc:content-created");
5815 Services.obs.removeObserver(this, "process-type-set");
5816 Services.obs.removeObserver(this, "ipc:content-shutdown");
5817 Services.obs.removeObserver(this, "intl:app-locales-changed");
5819 // If we failed to initialize and register for these observer
5820 // notifications, then attempting to remove them will throw.
5821 // It's fine to ignore that case on shutdown.
5824 if (this._cacheTask) {
5825 this._cacheTask.disarm();
5826 this._cacheTask = null;
5829 this._pagePipe = null;
5830 this._scriptPipe = null;
5831 this._initted = false;
5832 this._cacheEntry = null;
5833 this._hasWrittenThisSession = false;
5834 this._cacheEntryPromise = null;
5835 this._cacheEntryResolver = null;
5836 this._cacheDeferredResultScalar = -1;
5839 this.log.trace("Uninitialized.");
5843 this._procManager = null;
5844 this._procManagerID = null;
5845 this._appender = null;
5846 this._cacheDeferred = null;
5847 this._finalized = false;
5848 this._firstPrivilegedProcessCreated = false;
5851 _aboutHomeURI: null,
5853 get aboutHomeURI() {
5854 if (this._aboutHomeURI) {
5855 return this._aboutHomeURI;
5858 this._aboutHomeURI = Services.io.newURI(this.ABOUT_HOME_URI_STRING);
5859 return this._aboutHomeURI;
5862 // For the AsyncShutdown blocker, this is used to populate the progress
5864 _cacheProgress: "Not yet begun",
5867 * Called by the AsyncShutdown blocker on quit-application-granted
5868 * to potentially flush the most recent cache to disk. If one was
5869 * never written during the session, one is generated and written
5870 * before the async function resolves.
5872 * @param withTimeout (boolean)
5873 * Whether or not the timeout mechanism should be used. Defaults
5877 * If a cache has never been written, or a cache write is in
5878 * progress, resolves true when the cache has been written. Also
5879 * resolves to true if a cache didn't need to be written.
5881 * Resolves to false if a cache write unexpectedly timed out.
5883 async onShutdown(withTimeout = true) {
5884 // If we never wrote this session, arm the task so that the next
5885 // step can finalize.
5886 if (!this._hasWrittenThisSession) {
5887 this.log.trace("Never wrote a cache this session. Arming cache task.");
5888 this._cacheTask.arm();
5891 Services.telemetry.scalarSet(
5892 "browser.startup.abouthome_cache_shutdownwrite",
5893 this._cacheTask.isArmed
5896 if (this._cacheTask.isArmed) {
5897 this.log.trace("Finalizing cache task on shutdown");
5898 this._finalized = true;
5900 // To avoid hanging shutdowns, we'll ensure that we wait a maximum of
5901 // SHUTDOWN_CACHE_WRITE_TIMEOUT_MS millseconds before giving up.
5902 const TIMED_OUT = Symbol();
5905 let timeoutPromise = new Promise(resolve => {
5906 timeoutID = lazy.setTimeout(
5907 () => resolve(TIMED_OUT),
5908 this.SHUTDOWN_CACHE_WRITE_TIMEOUT_MS
5912 let promises = [this._cacheTask.finalize()];
5914 this.log.trace("Using timeout mechanism.");
5915 promises.push(timeoutPromise);
5917 this.log.trace("Skipping timeout mechanism.");
5920 let result = await Promise.race(promises);
5921 this.log.trace("Done blocking shutdown.");
5922 lazy.clearTimeout(timeoutID);
5923 if (result === TIMED_OUT) {
5924 this.log.error("Timed out getting cache streams. Skipping cache task.");
5928 this.log.trace("onShutdown is exiting");
5933 * Called by the _cacheTask DeferredTask to actually do the work of
5934 * caching the about:home document.
5937 * @resolves undefined
5938 * Resolves when a fresh version of the cache has been written.
5941 this.log.trace("Caching now.");
5942 this._cacheProgress = "Getting cache streams";
5944 let { pageInputStream, scriptInputStream } = await this.requestCache();
5946 if (!pageInputStream || !scriptInputStream) {
5947 this.log.trace("Failed to get cache streams.");
5948 this._cacheProgress = "Failed to get streams";
5952 this.log.trace("Got cache streams.");
5954 this._cacheProgress = "Writing to cache";
5957 this.log.trace("Populating cache.");
5958 await this.populateCache(pageInputStream, scriptInputStream);
5960 this._cacheProgress = "Failed to populate cache";
5961 this.log.error("Populating the cache failed: ", e);
5965 this._cacheProgress = "Done";
5966 this.log.trace("Done writing to cache.");
5967 this._hasWrittenThisSession = true;
5971 * Requests the cached document streams from the "privileged about content
5976 * Resolves with an Object with the following properties:
5978 * pageInputStream (nsIInputStream)
5979 * The page content to write to the cache, or null if request the streams
5982 * scriptInputStream (nsIInputStream)
5983 * The script content to write to the cache, or null if request the streams
5987 this.log.trace("Parent is requesting Activity Stream state object.");
5988 if (!this._procManager) {
5989 this.log.error("requestCache called with no _procManager!");
5990 return { pageInputStream: null, scriptInputStream: null };
5994 this._procManager.remoteType != lazy.E10SUtils.PRIVILEGEDABOUT_REMOTE_TYPE
5996 this.log.error("Somehow got the wrong process type.");
5997 return { pageInputStream: null, scriptInputStream: null };
6000 let state = lazy.AboutNewTab.activityStream.store.getState();
6001 return new Promise(resolve => {
6002 this._cacheDeferred = resolve;
6003 this.log.trace("Parent is requesting cache streams.");
6004 this._procManager.sendAsyncMessage(this.CACHE_REQUEST_MESSAGE, { state });
6009 * Helper function that returns a newly constructed nsIPipe instance.
6014 let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
6016 true /* non-blocking input */,
6017 true /* non-blocking output */,
6018 0 /* segment size */,
6019 0 /* max segments */
6025 return this._pagePipe;
6029 return this._scriptPipe;
6033 * Called when the nsICacheEntry has been accessed. If the nsICacheEntry
6034 * has content that we want to send down to the "privileged about content
6035 * process", then we connect that content to the nsIPipe's that may or
6036 * may not have already been sent down to the process.
6038 * In the event that the nsICacheEntry doesn't contain anything usable,
6039 * the nsInputStreams on the nsIPipe's are closed.
6042 this.log.trace(`Connecting nsICacheEntry to pipes.`);
6044 // If the cache doesn't yet exist, we'll know because the version metadata
6049 version = this._cacheEntry.getMetaDataElement(
6050 this.CACHE_VERSION_META_KEY
6053 if (e.result == Cr.NS_ERROR_NOT_AVAILABLE) {
6054 this.log.debug("Cache meta data does not exist. Closing streams.");
6055 this.pagePipe.outputStream.close();
6056 this.scriptPipe.outputStream.close();
6057 this.setDeferredResult(this.CACHE_RESULT_SCALARS.DOES_NOT_EXIST);
6064 this.log.info("Version retrieved is", version);
6066 if (version != Services.appinfo.appBuildID) {
6067 this.log.info("Version does not match! Dooming and closing streams.\n");
6068 // This cache is no good - doom it, and prepare for a new one.
6070 this.pagePipe.outputStream.close();
6071 this.scriptPipe.outputStream.close();
6072 this.setDeferredResult(this.CACHE_RESULT_SCALARS.INVALIDATED);
6076 let cachePageInputStream;
6079 cachePageInputStream = this._cacheEntry.openInputStream(0);
6081 this.log.error("Failed to open main input stream for cache entry", e);
6082 this.pagePipe.outputStream.close();
6083 this.scriptPipe.outputStream.close();
6084 this.setDeferredResult(this.CACHE_RESULT_SCALARS.CORRUPT_PAGE);
6088 this.log.trace("Connecting page stream to pipe.");
6089 lazy.NetUtil.asyncCopy(
6090 cachePageInputStream,
6091 this.pagePipe.outputStream,
6093 this.log.info("Page stream connected to pipe.");
6097 let cacheScriptInputStream;
6099 this.log.trace("Connecting script stream to pipe.");
6100 cacheScriptInputStream =
6101 this._cacheEntry.openAlternativeInputStream("script");
6102 lazy.NetUtil.asyncCopy(
6103 cacheScriptInputStream,
6104 this.scriptPipe.outputStream,
6106 this.log.info("Script stream connected to pipe.");
6110 if (e.result == Cr.NS_ERROR_NOT_AVAILABLE) {
6111 // For some reason, the script was not available. We'll close the pipe
6112 // without sending anything into it. The privileged about content process
6113 // will notice that there's nothing available in the pipe, and fall back
6114 // to dynamically generating the page.
6115 this.log.error("Script stream not available! Closing pipe.");
6116 this.scriptPipe.outputStream.close();
6117 this.setDeferredResult(this.CACHE_RESULT_SCALARS.CORRUPT_SCRIPT);
6123 this.setDeferredResult(this.CACHE_RESULT_SCALARS.VALID_AND_USED);
6124 this.log.trace("Streams connected to pipes.");
6128 * Called when we have received a the cache values from the "privileged
6129 * about content process". The page and script streams are written to
6130 * the nsICacheEntry.
6132 * This writing is asynchronous, and if a write happens to already be
6133 * underway when this function is called, that latter call will be
6136 * @param pageInputStream (nsIInputStream)
6137 * A stream containing the HTML markup to be saved to the cache.
6138 * @param scriptInputStream (nsIInputStream)
6139 * A stream containing the JS hydration script to be saved to the cache.
6141 * @resolves undefined
6142 * When the cache has been successfully written to.
6144 * Rejects with a JS Error if writing any part of the cache happens to
6147 async populateCache(pageInputStream, scriptInputStream) {
6148 await this.ensureCacheEntry();
6150 await new Promise((resolve, reject) => {
6151 // Doom the old cache entry, so we can start writing to a new one.
6152 this.log.trace("Populating the cache. Dooming old entry.");
6155 this.log.trace("Opening the page output stream.");
6156 let pageOutputStream;
6158 pageOutputStream = this._cacheEntry.openOutputStream(0, -1);
6164 this.log.info("Writing the page cache.");
6165 lazy.NetUtil.asyncCopy(pageInputStream, pageOutputStream, pageResult => {
6166 if (!Components.isSuccessCode(pageResult)) {
6167 this.log.error("Failed to write page. Result: " + pageResult);
6168 reject(new Error(pageResult));
6173 "Writing the page data is complete. Now opening the " +
6174 "script output stream."
6177 let scriptOutputStream;
6179 scriptOutputStream = this._cacheEntry.openAlternativeOutputStream(
6188 this.log.info("Writing the script cache.");
6189 lazy.NetUtil.asyncCopy(
6193 if (!Components.isSuccessCode(scriptResult)) {
6194 this.log.error("Failed to write script. Result: " + scriptResult);
6195 reject(new Error(scriptResult));
6200 "Writing the script cache is done. Setting version."
6203 this._cacheEntry.setMetaDataElement(
6205 Services.appinfo.appBuildID
6208 this.log.error("Failed to write version.");
6212 this.log.trace(`Version is set to ${Services.appinfo.appBuildID}.`);
6213 this.log.info("Caching of page and script is done.");
6220 this.log.trace("populateCache has finished.");
6224 * Returns a Promise that resolves once the nsICacheEntry for the cache
6225 * is available to write to and read from.
6228 * @resolves nsICacheEntry
6229 * Once the cache entry has become available.
6231 * Rejects with an error message if getting the cache entry is attempted
6232 * before the AboutHomeStartupCache component has been initialized.
6234 ensureCacheEntry() {
6235 if (!this._initted) {
6236 return Promise.reject(
6237 "Cannot ensureCacheEntry - AboutHomeStartupCache is not initted"
6241 return this._cacheEntryPromise;
6245 * Clears the contents of the cache.
6248 this.log.trace("Clearing the cache.");
6249 this._cacheEntry = this._cacheEntry.recreate();
6250 this._cacheEntryPromise = new Promise(resolve => {
6251 resolve(this._cacheEntry);
6253 this._hasWrittenThisSession = false;
6257 * Called when a content process is created. If this is the "privileged
6258 * about content process", then the cache streams will be sent to it.
6260 * @param childID (Number)
6261 * The unique ID for the content process that was created, as passed by
6262 * ipc:content-created.
6263 * @param procManager (ProcessMessageManager)
6264 * The ProcessMessageManager for the created content process.
6265 * @param processParent
6266 * The nsIDOMProcessParent for the tab.
6268 onContentProcessCreated(childID, procManager, processParent) {
6269 if (procManager.remoteType == lazy.E10SUtils.PRIVILEGEDABOUT_REMOTE_TYPE) {
6270 if (this._finalized) {
6272 "Ignoring privileged about content process launch after finalization."
6277 if (this._firstPrivilegedProcessCreated) {
6279 "Ignoring non-first privileged about content processes."
6285 `A privileged about content process is launching with ID ${childID}.`
6288 this.log.info("Sending input streams down to content process.");
6289 let actor = processParent.getActor("BrowserProcess");
6290 actor.sendAsyncMessage(this.SEND_STREAMS_MESSAGE, {
6291 pageInputStream: this.pagePipe.inputStream,
6292 scriptInputStream: this.scriptPipe.inputStream,
6295 procManager.addMessageListener(this.CACHE_RESPONSE_MESSAGE, this);
6296 procManager.addMessageListener(this.CACHE_USAGE_RESULT_MESSAGE, this);
6297 this._procManager = procManager;
6298 this._procManagerID = childID;
6299 this._firstPrivilegedProcessCreated = true;
6304 * Called when a content process is destroyed. Either it shut down normally,
6305 * or it crashed. If this is the "privileged about content process", then some
6306 * internal state is cleared.
6308 * @param childID (Number)
6309 * The unique ID for the content process that was created, as passed by
6310 * ipc:content-shutdown.
6312 onContentProcessShutdown(childID) {
6313 this.log.info(`Content process shutdown: ${childID}`);
6314 if (this._procManagerID == childID) {
6315 this.log.info("It was the current privileged about process.");
6316 if (this._cacheDeferred) {
6318 "A privileged about content process shut down while cache streams " +
6319 "were still en route."
6321 // The crash occurred while we were waiting on cache input streams to
6322 // be returned to us. Resolve with null streams instead.
6323 this._cacheDeferred({ pageInputStream: null, scriptInputStream: null });
6324 this._cacheDeferred = null;
6327 this._procManager.removeMessageListener(
6328 this.CACHE_RESPONSE_MESSAGE,
6331 this._procManager.removeMessageListener(
6332 this.CACHE_USAGE_RESULT_MESSAGE,
6335 this._procManager = null;
6336 this._procManagerID = null;
6341 * Called externally by ActivityStreamMessageChannel anytime
6342 * a message is broadcast to all about:newtabs, or sent to the
6343 * preloaded about:newtab. This is used to determine if we need
6344 * to refresh the cache.
6346 onPreloadedNewTabMessage() {
6347 if (!this._initted || !this._enabled) {
6351 if (this._finalized) {
6352 this.log.trace("Ignoring preloaded newtab update after finalization.");
6356 this.log.trace("Preloaded about:newtab was updated.");
6358 this._cacheTask.disarm();
6359 this._cacheTask.arm();
6363 * Stores the CACHE_RESULT_SCALARS value that most accurately represents
6364 * the current notion of how the cache has operated so far. It is stored
6365 * temporarily like this because we need to hear from the privileged
6366 * about content process to hear whether or not retrieving the cache
6367 * actually worked on that end. The success state reported back from
6368 * the privileged about content process will be compared against the
6369 * deferred result scalar to compute what will be recorded to
6372 * Note that this value will only be recorded if its value is GREATER
6373 * than the currently recorded value. This is because it's possible for
6374 * certain functions that record results to re-enter - but we want to record
6375 * the _first_ condition that caused the cache to not be read from.
6377 * @param result (Number)
6378 * One of the CACHE_RESULT_SCALARS values. If this value is less than
6379 * the currently recorded value, it is ignored.
6381 setDeferredResult(result) {
6382 if (this._cacheDeferredResultScalar < result) {
6383 this._cacheDeferredResultScalar = result;
6388 * Records the final result of how the cache operated for the user
6389 * during this session to Telemetry.
6391 recordResult(result) {
6392 // Note: this can be called very early on in the lifetime of
6393 // AboutHomeStartupCache, so things like this.log might not exist yet.
6394 Services.telemetry.scalarSet(
6395 "browser.startup.abouthome_cache_result",
6401 * Called when the parent process receives a message from the privileged
6402 * about content process saying whether or not reading from the cache
6405 * @param success (boolean)
6406 * True if reading from the cache succeeded.
6408 onUsageResult(success) {
6409 this.log.trace(`Received usage result. Success = ${success}`);
6412 this._cacheDeferredResultScalar !=
6413 this.CACHE_RESULT_SCALARS.VALID_AND_USED
6416 "Somehow got a success result despite having never " +
6417 "successfully sent down the cache streams"
6419 this.recordResult(this._cacheDeferredResultScalar);
6421 this.recordResult(this.CACHE_RESULT_SCALARS.VALID_AND_USED);
6428 this._cacheDeferredResultScalar ==
6429 this.CACHE_RESULT_SCALARS.VALID_AND_USED
6431 // We failed to read from the cache despite having successfully
6432 // sent it down to the content process. We presume then that the
6433 // streams just didn't provide any bytes in time.
6434 this.recordResult(this.CACHE_RESULT_SCALARS.LATE);
6436 // We failed to read the cache, but already knew why. We can
6437 // now record that value.
6438 this.recordResult(this._cacheDeferredResultScalar);
6442 QueryInterface: ChromeUtils.generateQI([
6443 "nsICacheEntryOpenallback",
6447 /** MessageListener **/
6449 receiveMessage(message) {
6450 // Only the privileged about content process can write to the cache.
6452 message.target.remoteType != lazy.E10SUtils.PRIVILEGEDABOUT_REMOTE_TYPE
6455 "Received a message from a non-privileged content process!"
6460 switch (message.name) {
6461 case this.CACHE_RESPONSE_MESSAGE: {
6462 this.log.trace("Parent received cache streams.");
6463 if (!this._cacheDeferred) {
6464 this.log.error("Parent doesn't have _cacheDeferred set up!");
6468 this._cacheDeferred(message.data);
6469 this._cacheDeferred = null;
6472 case this.CACHE_USAGE_RESULT_MESSAGE: {
6473 this.onUsageResult(message.data.success);
6481 observe(aSubject, aTopic, aData) {
6483 case "intl:app-locales-changed": {
6487 case "process-type-set":
6488 // Intentional fall-through
6489 case "ipc:content-created": {
6490 let childID = aData;
6491 let procManager = aSubject
6492 .QueryInterface(Ci.nsIInterfaceRequestor)
6493 .getInterface(Ci.nsIMessageSender);
6494 let pp = aSubject.QueryInterface(Ci.nsIDOMProcessParent);
6495 this.onContentProcessCreated(childID, procManager, pp);
6499 case "ipc:content-shutdown": {
6500 let childID = aData;
6501 this.onContentProcessShutdown(childID);
6507 /** nsICacheEntryOpenCallback **/
6509 onCacheEntryCheck(aEntry) {
6510 return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
6513 onCacheEntryAvailable(aEntry, aNew, aResult) {
6514 this.log.trace("Cache entry is available.");
6516 this._cacheEntry = aEntry;
6517 this.connectToPipes();
6518 this._cacheEntryResolver(this._cacheEntry);
6522 async function RunOSKeyStoreSelfTest() {
6523 // The linux implementation always causes an OS dialog, in contrast to
6524 // Windows and macOS (the latter of which causes an OS dialog to appear on
6525 // local developer builds), so only run on Windows and macOS and only if this
6526 // has been built and signed by Mozilla's infrastructure. Similarly, don't
6527 // run this code in automation.
6529 (AppConstants.platform != "win" && AppConstants.platform != "macosx") ||
6530 !AppConstants.MOZILLA_OFFICIAL ||
6531 Services.env.get("MOZ_AUTOMATION")
6535 let osKeyStore = Cc["@mozilla.org/security/oskeystore;1"].getService(
6538 let label = Services.prefs.getCharPref("security.oskeystore.test.label", "");
6540 label = Services.uuid.generateUUID().toString().slice(1, -1);
6541 Services.prefs.setCharPref("security.oskeystore.test.label", label);
6543 await osKeyStore.asyncGenerateSecret(label);
6544 Glean.oskeystore.selfTest.generate.set(true);
6546 Glean.oskeystore.selfTest.generate.set(false);
6550 let secretAvailable = await osKeyStore.asyncSecretAvailable(label);
6551 Glean.oskeystore.selfTest.available.set(secretAvailable);
6552 if (!secretAvailable) {
6555 let encrypted = Services.prefs.getCharPref(
6556 "security.oskeystore.test.encrypted",
6561 encrypted = await osKeyStore.asyncEncryptBytes(label, [1, 1, 3, 8]);
6562 Services.prefs.setCharPref(
6563 "security.oskeystore.test.encrypted",
6566 Glean.oskeystore.selfTest.encrypt.set(true);
6568 Glean.oskeystore.selfTest.encrypt.set(false);
6573 let decrypted = await osKeyStore.asyncDecryptBytes(label, encrypted);
6575 decrypted.length != 4 ||
6576 decrypted[0] != 1 ||
6577 decrypted[1] != 1 ||
6578 decrypted[2] != 3 ||
6581 throw new Error("decrypted value not as expected?");
6583 Glean.oskeystore.selfTest.decrypt.set(true);
6585 Glean.oskeystore.selfTest.decrypt.set(false);