SSL BrowserGlue.sys.mjs
Sprache: unbekannt
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs",
AccountsGlue: "resource:///modules/AccountsGlue.sys.mjs",
AWToolbarButton: "resource:///modules/aboutwelcome/AWToolbarUtils.sys.mjs",
ASRouter: "resource:///modules/asrouter/ASRouter.sys.mjs",
ASRouterDefaultConfig:
"resource:///modules/asrouter/ASRouterDefaultConfig.sys.mjs",
ASRouterNewTabHook: "resource:///modules/asrouter/ASRouterNewTabHook.sys.mjs",
ActorManagerParent: "resource://gre/modules/ActorManagerParent.sys.mjs",
AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
AsyncShutdown: "resource://gre/modules/AsyncShutdown.sys.mjs",
BackupService: "resource:///modules/backup/BackupService.sys.mjs",
Blocklist: "resource://gre/modules/Blocklist.sys.mjs",
BookmarkHTMLUtils: "resource://gre/modules/BookmarkHTMLUtils.sys.mjs",
BookmarkJSONUtils: "resource://gre/modules/BookmarkJSONUtils.sys.mjs",
BrowserSearchTelemetry: "resource:///modules/BrowserSearchTelemetry.sys.mjs",
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.sys.mjs",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
BuiltInThemes: "resource:///modules/BuiltInThemes.sys.mjs",
CaptchaDetectionPingUtils:
"resource://gre/modules/CaptchaDetectionPingUtils.sys.mjs",
CommonDialog: "resource://gre/modules/CommonDialog.sys.mjs",
ContentRelevancyManager:
"resource://gre/modules/ContentRelevancyManager.sys.mjs",
ContextualIdentityService:
"resource://gre/modules/ContextualIdentityService.sys.mjs",
DAPTelemetrySender: "resource://gre/modules/DAPTelemetrySender.sys.mjs",
DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs",
Discovery: "resource:///modules/Discovery.sys.mjs",
DoHController: "resource:///modules/DoHController.sys.mjs",
DownloadsViewableInternally:
"resource:///modules/DownloadsViewableInternally.sys.mjs",
E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs",
ExtensionsUI: "resource:///modules/ExtensionsUI.sys.mjs",
FeatureGate: "resource://featuregates/FeatureGate.sys.mjs",
FirefoxBridgeExtensionUtils:
"resource:///modules/FirefoxBridgeExtensionUtils.sys.mjs",
// FilePickerCrashed is used by the `listeners` object below.
// eslint-disable-next-line mozilla/valid-lazy
FilePickerCrashed: "resource:///modules/FilePickerCrashed.sys.mjs",
FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs",
GenAI: "resource:///modules/GenAI.sys.mjs",
HomePage: "resource:///modules/HomePage.sys.mjs",
Integration: "resource://gre/modules/Integration.sys.mjs",
Interactions: "resource:///modules/Interactions.sys.mjs",
LoginBreaches: "resource:///modules/LoginBreaches.sys.mjs",
LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs",
MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs",
NetUtil: "resource://gre/modules/NetUtil.sys.mjs",
NewTabUtils: "resource://gre/modules/NewTabUtils.sys.mjs",
NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
Normandy: "resource://normandy/Normandy.sys.mjs",
OnboardingMessageProvider:
"resource:///modules/asrouter/OnboardingMessageProvider.sys.mjs",
OsEnvironment: "resource://gre/modules/OsEnvironment.sys.mjs",
PageActions: "resource:///modules/PageActions.sys.mjs",
PageDataService: "resource:///modules/pagedata/PageDataService.sys.mjs",
PageThumbs: "resource://gre/modules/PageThumbs.sys.mjs",
PdfJs: "resource://pdf.js/PdfJs.sys.mjs",
PermissionUI: "resource:///modules/PermissionUI.sys.mjs",
PlacesBackups: "resource://gre/modules/PlacesBackups.sys.mjs",
PlacesDBUtils: "resource://gre/modules/PlacesDBUtils.sys.mjs",
PlacesUIUtils: "resource:///modules/PlacesUIUtils.sys.mjs",
PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs",
// PluginManager is used by the `listeners` object below.
// eslint-disable-next-line mozilla/valid-lazy
PluginManager: "resource:///actors/PluginParent.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
ProcessHangMonitor: "resource:///modules/ProcessHangMonitor.sys.mjs",
QuickSuggest: "resource:///modules/QuickSuggest.sys.mjs",
RFPHelper: "resource://gre/modules/RFPHelper.sys.mjs",
RemoteSecuritySettings:
"resource://gre/modules/psm/RemoteSecuritySettings.sys.mjs",
RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
ResetPBMPanel: "resource:///modules/ResetPBMPanel.sys.mjs",
SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
SandboxUtils: "resource://gre/modules/SandboxUtils.sys.mjs",
SaveToPocket: "chrome://pocket/content/SaveToPocket.sys.mjs",
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
SearchSERPCategorization: "resource:///modules/SearchSERPTelemetry.sys.mjs",
SearchSERPTelemetry: "resource:///modules/SearchSERPTelemetry.sys.mjs",
SelectableProfileService:
"resource:///modules/profiles/SelectableProfileService.sys.mjs",
SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
ShellService: "resource:///modules/ShellService.sys.mjs",
ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
ShoppingUtils: "resource:///modules/ShoppingUtils.sys.mjs",
SpecialMessageActions:
"resource://messaging-system/lib/SpecialMessageActions.sys.mjs",
TelemetryReportingPolicy:
"resource://gre/modules/TelemetryReportingPolicy.sys.mjs",
TRRRacer: "resource:///modules/TRRPerformance.sys.mjs",
TabCrashHandler: "resource:///modules/ContentCrashHandlers.sys.mjs",
TabUnloader: "resource:///modules/TabUnloader.sys.mjs",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
UrlbarSearchTermsPersistence:
"resource:///modules/UrlbarSearchTermsPersistence.sys.mjs",
UsageReporting: "resource://gre/modules/UsageReporting.sys.mjs",
WebChannel: "resource://gre/modules/WebChannel.sys.mjs",
WebProtocolHandlerRegistrar:
"resource:///modules/WebProtocolHandlerRegistrar.sys.mjs",
WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs",
WindowsRegistry: "resource://gre/modules/WindowsRegistry.sys.mjs",
WindowsGPOParser: "resource://gre/modules/policies/WindowsGPOParser.sys.mjs",
clearTimeout: "resource://gre/modules/Timer.sys.mjs",
setTimeout: "resource://gre/modules/Timer.sys.mjs",
});
if (AppConstants.MOZ_UPDATER) {
ChromeUtils.defineESModuleGetters(lazy, {
UpdateListener: "resource://gre/modules/UpdateListener.sys.mjs",
});
XPCOMUtils.defineLazyServiceGetters(lazy, {
UpdateServiceStub: [
"@mozilla.org/updates/update-service-stub;1",
"nsIApplicationUpdateServiceStub",
],
});
}
if (AppConstants.MOZ_UPDATE_AGENT) {
ChromeUtils.defineESModuleGetters(lazy, {
BackgroundUpdate: "resource://gre/modules/BackgroundUpdate.sys.mjs",
});
}
// PluginManager is used in the listeners object below.
XPCOMUtils.defineLazyServiceGetters(lazy, {
BrowserHandler: ["@mozilla.org/browser/clh;1", "nsIBrowserHandler"],
PushService: ["@mozilla.org/push/Service;1", "nsIPushService"],
});
if (AppConstants.ENABLE_WEBDRIVER) {
XPCOMUtils.defineLazyServiceGetter(
lazy,
"Marionette",
"@mozilla.org/remote/marionette;1",
"nsIMarionette"
);
XPCOMUtils.defineLazyServiceGetter(
lazy,
"RemoteAgent",
"@mozilla.org/remote/agent;1",
"nsIRemoteAgent"
);
} else {
lazy.Marionette = { running: false };
lazy.RemoteAgent = { running: false };
}
const PREF_PDFJS_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
const PRIVATE_BROWSING_BINARY = "private_browsing.exe";
// Index of Private Browsing icon in private_browsing.exe
// Must line up with IDI_PBICON_PB_PB_EXE in nsNativeAppSupportWin.h.
const PRIVATE_BROWSING_EXE_ICON_INDEX = 1;
const PREF_PRIVATE_BROWSING_SHORTCUT_CREATED =
"browser.privacySegmentation.createdShortcut";
// Whether this launch was initiated by the OS. A launch-on-login will contain
// the "os-autostart" flag in the initial launch command line.
let gThisInstanceIsLaunchOnLogin = false;
// Whether this launch was initiated by a taskbar tab shortcut. A launch from
// a taskbar tab shortcut will contain the "taskbar-tab" flag.
let gThisInstanceIsTaskbarTab = false;
/**
* Fission-compatible JSProcess implementations.
* Each actor options object takes the form of a ProcessActorOptions dictionary.
* Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
* available at https://firefox-source-docs.mozilla.org/dom/ipc/jsactors.html
*/
let JSPROCESSACTORS = {
// Miscellaneous stuff that needs to be initialized per process.
BrowserProcess: {
child: {
esModuleURI: "resource:///actors/BrowserProcessChild.sys.mjs",
observers: [
// WebRTC related notifications. They are here to avoid loading WebRTC
// components when not needed.
"getUserMedia:request",
"recording-device-stopped",
"PeerConnection:request",
"recording-device-events",
"recording-window-ended",
],
},
},
RefreshBlockerObserver: {
child: {
esModuleURI: "resource:///actors/RefreshBlockerChild.sys.mjs",
observers: [
"webnavigation-create",
"chrome-webnavigation-create",
"webnavigation-destroy",
"chrome-webnavigation-destroy",
],
},
enablePreference: "accessibility.blockautorefresh",
onPreferenceChanged: (prefName, prevValue, isEnabled) => {
lazy.BrowserWindowTracker.orderedWindows.forEach(win => {
for (let browser of win.gBrowser.browsers) {
try {
browser.sendMessageToActor(
"PreferenceChanged",
{ isEnabled },
"RefreshBlocker",
"all"
);
} catch (ex) {}
}
});
},
},
};
/**
* Fission-compatible JSWindowActor implementations.
* Detailed documentation of these options is in dom/docs/ipc/jsactors.rst,
* available at https://firefox-source-docs.mozilla.org/dom/ipc/jsactors.html
*/
let JSWINDOWACTORS = {
Megalist: {
parent: {
esModuleURI: "resource://gre/actors/MegalistParent.sys.mjs",
},
child: {
esModuleURI: "resource://gre/actors/MegalistChild.sys.mjs",
events: {
DOMContentLoaded: {},
},
},
includeChrome: true,
matches: ["chrome://global/content/megalist/megalist.html"],
allFrames: true,
enablePreference: "browser.contextual-password-manager.enabled",
},
AboutLogins: {
parent: {
esModuleURI: "resource:///actors/AboutLoginsParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutLoginsChild.sys.mjs",
events: {
AboutLoginsCopyLoginDetail: { wantUntrusted: true },
AboutLoginsCreateLogin: { wantUntrusted: true },
AboutLoginsDeleteLogin: { wantUntrusted: true },
AboutLoginsDismissBreachAlert: { wantUntrusted: true },
AboutLoginsImportFromBrowser: { wantUntrusted: true },
AboutLoginsImportFromFile: { wantUntrusted: true },
AboutLoginsImportReportInit: { wantUntrusted: true },
AboutLoginsImportReportReady: { wantUntrusted: true },
AboutLoginsInit: { wantUntrusted: true },
AboutLoginsGetHelp: { wantUntrusted: true },
AboutLoginsOpenPreferences: { wantUntrusted: true },
AboutLoginsOpenSite: { wantUntrusted: true },
AboutLoginsRecordTelemetryEvent: { wantUntrusted: true },
AboutLoginsRemoveAllLogins: { wantUntrusted: true },
AboutLoginsSortChanged: { wantUntrusted: true },
AboutLoginsSyncEnable: { wantUntrusted: true },
AboutLoginsUpdateLogin: { wantUntrusted: true },
AboutLoginsExportPasswords: { wantUntrusted: true },
},
},
matches: ["about:logins", "about:logins?*", "about:loginsimportreport"],
allFrames: true,
remoteTypes: ["privilegedabout"],
},
AboutMessagePreview: {
parent: {
esModuleURI: "resource:///actors/AboutMessagePreviewParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutMessagePreviewChild.sys.mjs",
events: {
DOMDocElementInserted: { capture: true },
},
},
matches: ["about:messagepreview", "about:messagepreview?*"],
},
AboutPocket: {
parent: {
esModuleURI: "resource:///actors/AboutPocketParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutPocketChild.sys.mjs",
events: {
DOMDocElementInserted: { capture: true },
},
},
remoteTypes: ["privilegedabout"],
matches: [
"about:pocket-saved*",
"about:pocket-signup*",
"about:pocket-home*",
"about:pocket-style-guide*",
],
},
AboutPrivateBrowsing: {
parent: {
esModuleURI: "resource:///actors/AboutPrivateBrowsingParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutPrivateBrowsingChild.sys.mjs",
events: {
DOMDocElementInserted: { capture: true },
},
},
matches: ["about:privatebrowsing*"],
},
AboutProtections: {
parent: {
esModuleURI: "resource:///actors/AboutProtectionsParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutProtectionsChild.sys.mjs",
events: {
DOMDocElementInserted: { capture: true },
},
},
matches: ["about:protections", "about:protections?*"],
},
AboutReader: {
parent: {
esModuleURI: "resource:///actors/AboutReaderParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutReaderChild.sys.mjs",
events: {
DOMContentLoaded: {},
pageshow: { mozSystemGroup: true },
// Don't try to create the actor if only the pagehide event fires.
// This can happen with the initial about:blank documents.
pagehide: { mozSystemGroup: true, createActor: false },
},
},
messageManagerGroups: ["browsers"],
},
AboutTabCrashed: {
parent: {
esModuleURI: "resource:///actors/AboutTabCrashedParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutTabCrashedChild.sys.mjs",
events: {
DOMDocElementInserted: { capture: true },
},
},
matches: ["about:tabcrashed*"],
},
AboutWelcomeShopping: {
parent: {
esModuleURI: "resource:///actors/AboutWelcomeParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutWelcomeChild.sys.mjs",
events: {
Update: {},
},
},
matches: ["about:shoppingsidebar"],
remoteTypes: ["privilegedabout"],
messageManagerGroups: ["shopping-sidebar", "browsers", "review-checker"],
},
AboutWelcome: {
parent: {
esModuleURI: "resource:///actors/AboutWelcomeParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/AboutWelcomeChild.sys.mjs",
events: {
// This is added so the actor instantiates immediately and makes
// methods available to the page js on load.
DOMDocElementInserted: {},
},
},
matches: ["about:welcome"],
remoteTypes: ["privilegedabout"],
// See Bug 1618306
// Remove this preference check when we turn on separate about:welcome for all users.
enablePreference: "browser.aboutwelcome.enabled",
},
BackupUI: {
parent: {
esModuleURI: "resource:///actors/BackupUIParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/BackupUIChild.sys.mjs",
events: {
"BackupUI:InitWidget": { wantUntrusted: true },
"BackupUI:EnableScheduledBackups": { wantUntrusted: true },
"BackupUI:DisableScheduledBackups": { wantUntrusted: true },
"BackupUI:ShowFilepicker": { wantUntrusted: true },
"BackupUI:GetBackupFileInfo": { wantUntrusted: true },
"BackupUI:RestoreFromBackupFile": { wantUntrusted: true },
"BackupUI:RestoreFromBackupChooseFile": { wantUntrusted: true },
"BackupUI:EnableEncryption": { wantUntrusted: true },
"BackupUI:DisableEncryption": { wantUntrusted: true },
"BackupUI:RerunEncryption": { wantUntrusted: true },
"BackupUI:ShowBackupLocation": { wantUntrusted: true },
"BackupUI:EditBackupLocation": { wantUntrusted: true },
},
},
matches: ["about:preferences*", "about:settings*"],
enablePreference: "browser.backup.preferences.ui.enabled",
},
BlockedSite: {
parent: {
esModuleURI: "resource:///actors/BlockedSiteParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/BlockedSiteChild.sys.mjs",
events: {
AboutBlockedLoaded: { wantUntrusted: true },
click: {},
},
},
matches: ["about:blocked?*"],
allFrames: true,
},
BrowserTab: {
child: {
esModuleURI: "resource:///actors/BrowserTabChild.sys.mjs",
},
messageManagerGroups: ["browsers"],
},
ClickHandler: {
parent: {
esModuleURI: "resource:///actors/ClickHandlerParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ClickHandlerChild.sys.mjs",
events: {
chromelinkclick: { capture: true, mozSystemGroup: true },
},
},
allFrames: true,
},
/* Note: this uses the same JSMs as ClickHandler, but because it
* relies on "normal" click events anywhere on the page (not just
* links) and is expensive, and only does something for the
* small group of people who have the feature enabled, it is its
* own actor which is only registered if the pref is enabled.
*/
MiddleMousePasteHandler: {
parent: {
esModuleURI: "resource:///actors/ClickHandlerParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ClickHandlerChild.sys.mjs",
events: {
auxclick: { capture: true, mozSystemGroup: true },
},
},
enablePreference: "middlemouse.contentLoadURL",
allFrames: true,
},
ContentSearch: {
parent: {
esModuleURI: "resource:///actors/ContentSearchParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ContentSearchChild.sys.mjs",
events: {
ContentSearchClient: { capture: true, wantUntrusted: true },
},
},
matches: [
"about:home",
"about:welcome",
"about:newtab",
"about:privatebrowsing",
"about:test-about-content-search-ui",
],
remoteTypes: ["privilegedabout"],
},
ContextMenu: {
parent: {
esModuleURI: "resource:///actors/ContextMenuParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ContextMenuChild.sys.mjs",
events: {
contextmenu: { mozSystemGroup: true },
},
},
allFrames: true,
},
DecoderDoctor: {
parent: {
esModuleURI: "resource:///actors/DecoderDoctorParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/DecoderDoctorChild.sys.mjs",
observers: ["decoder-doctor-notification"],
},
messageManagerGroups: ["browsers"],
allFrames: true,
},
DOMFullscreen: {
parent: {
esModuleURI: "resource:///actors/DOMFullscreenParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/DOMFullscreenChild.sys.mjs",
events: {
"MozDOMFullscreen:Request": {},
"MozDOMFullscreen:Entered": {},
"MozDOMFullscreen:NewOrigin": {},
"MozDOMFullscreen:Exit": {},
"MozDOMFullscreen:Exited": {},
},
},
messageManagerGroups: ["browsers"],
allFrames: true,
},
EncryptedMedia: {
parent: {
esModuleURI: "resource:///actors/EncryptedMediaParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/EncryptedMediaChild.sys.mjs",
observers: ["mediakeys-request"],
},
messageManagerGroups: ["browsers"],
allFrames: true,
},
FormValidation: {
parent: {
esModuleURI: "resource:///actors/FormValidationParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/FormValidationChild.sys.mjs",
events: {
MozInvalidForm: {},
// Listening to ‘pageshow’ event is only relevant if an invalid form
// popup was open, so don't create the actor when fired.
pageshow: { createActor: false },
},
},
allFrames: true,
},
GenAI: {
parent: {
esModuleURI: "resource:///actors/GenAIParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/GenAIChild.sys.mjs",
events: {
DOMContentLoaded: {},
mousemove: {},
resize: {},
scroll: {},
},
},
allFrames: true,
onAddActor(register, unregister) {
// Register the actor if we have a provider set and not yet registered
const maybeRegister = (val, prev) => {
if (val) {
if (!prev) {
register();
}
} else {
unregister();
}
};
// Detect pref changes and handle initial value
XPCOMUtils.defineLazyPreferenceGetter(
this,
"_pref",
"browser.ml.chat.provider",
"",
(_pref, prev, val) => maybeRegister(val, prev)
);
maybeRegister(this._pref);
},
},
LightweightTheme: {
child: {
esModuleURI: "resource:///actors/LightweightThemeChild.sys.mjs",
events: {
pageshow: { mozSystemGroup: true },
DOMContentLoaded: {},
},
},
includeChrome: true,
allFrames: true,
matches: [
"about:asrouter",
"about:home",
"about:newtab",
"about:welcome",
"chrome://browser/content/syncedtabs/sidebar.xhtml",
"chrome://browser/content/places/historySidebar.xhtml",
"chrome://browser/content/places/bookmarksSidebar.xhtml",
"about:firefoxview",
"about:editprofile",
"about:deleteprofile",
"about:newprofile",
],
},
LinkHandler: {
parent: {
esModuleURI: "resource:///actors/LinkHandlerParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/LinkHandlerChild.sys.mjs",
events: {
DOMHeadElementParsed: {},
DOMLinkAdded: {},
DOMLinkChanged: {},
pageshow: {},
// The `pagehide` event is only used to clean up state which will not be
// present if the actor hasn't been created.
pagehide: { createActor: false },
},
},
messageManagerGroups: ["browsers"],
},
PageInfo: {
child: {
esModuleURI: "resource:///actors/PageInfoChild.sys.mjs",
},
allFrames: true,
},
PageStyle: {
parent: {
esModuleURI: "resource:///actors/PageStyleParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/PageStyleChild.sys.mjs",
events: {
pageshow: { createActor: false },
},
},
messageManagerGroups: ["browsers"],
allFrames: true,
},
Pdfjs: {
parent: {
esModuleURI: "resource://pdf.js/PdfjsParent.sys.mjs",
},
child: {
esModuleURI: "resource://pdf.js/PdfjsChild.sys.mjs",
},
allFrames: true,
},
// GMP crash reporting
Plugin: {
parent: {
esModuleURI: "resource:///actors/PluginParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/PluginChild.sys.mjs",
events: {
PluginCrashed: { capture: true },
},
},
allFrames: true,
},
PointerLock: {
parent: {
esModuleURI: "resource:///actors/PointerLockParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/PointerLockChild.sys.mjs",
events: {
"MozDOMPointerLock:Entered": {},
"MozDOMPointerLock:Exited": {},
},
},
messageManagerGroups: ["browsers"],
allFrames: true,
},
Profiles: {
parent: {
esModuleURI: "resource:///actors/ProfilesParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ProfilesChild.sys.mjs",
events: {
DOMDocElementInserted: { wantUntrusted: true },
},
},
matches: ["about:editprofile", "about:deleteprofile", "about:newprofile"],
remoteTypes: ["privilegedabout"],
enablePreference: "browser.profiles.enabled",
},
Prompt: {
parent: {
esModuleURI: "resource:///actors/PromptParent.sys.mjs",
},
includeChrome: true,
allFrames: true,
},
RefreshBlocker: {
parent: {
esModuleURI: "resource:///actors/RefreshBlockerParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/RefreshBlockerChild.sys.mjs",
},
messageManagerGroups: ["browsers"],
enablePreference: "accessibility.blockautorefresh",
},
ReviewChecker: {
parent: {
esModuleURI: "resource:///actors/ReviewCheckerParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ReviewCheckerChild.sys.mjs",
events: {
ContentReady: { wantUntrusted: true },
PolledRequestMade: { wantUntrusted: true },
// This is added so the actor instantiates immediately and makes
// methods available to the page js on load.
DOMDocElementInserted: {},
ReportProductAvailable: { wantUntrusted: true },
AdClicked: { wantUntrusted: true },
AdImpression: { wantUntrusted: true },
DisableShopping: { wantUntrusted: true },
CloseShoppingSidebar: { wantUntrusted: true },
},
},
matches: ["about:shoppingsidebar"],
remoteTypes: ["privilegedabout"],
messageManagerGroups: ["review-checker", "browsers"],
enablePreference: "browser.shopping.experience2023.integratedSidebar",
},
ScreenshotsComponent: {
parent: {
esModuleURI: "resource:///modules/ScreenshotsUtils.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ScreenshotsComponentChild.sys.mjs",
events: {
"Screenshots:Close": {},
"Screenshots:Copy": {},
"Screenshots:Download": {},
"Screenshots:HidePanel": {},
"Screenshots:OverlaySelection": {},
"Screenshots:RecordEvent": {},
"Screenshots:ShowPanel": {},
"Screenshots:FocusPanel": {},
},
},
enablePreference: "screenshots.browser.component.enabled",
},
ScreenshotsHelper: {
parent: {
esModuleURI: "resource:///modules/ScreenshotsUtils.sys.mjs",
},
child: {
esModuleURI: "resource:///modules/ScreenshotsHelperChild.sys.mjs",
},
allFrames: true,
enablePreference: "screenshots.browser.component.enabled",
},
SearchSERPTelemetry: {
parent: {
esModuleURI: "resource:///actors/SearchSERPTelemetryParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/SearchSERPTelemetryChild.sys.mjs",
events: {
DOMContentLoaded: {},
pageshow: { mozSystemGroup: true },
// The 'pagehide' event is only used to clean up state, and should not
// force actor creation.
pagehide: { createActor: false },
load: { mozSystemGroup: true, capture: true },
},
},
matches: ["https://*/*"],
},
ShieldFrame: {
parent: {
esModuleURI: "resource://normandy-content/ShieldFrameParent.sys.mjs",
},
child: {
esModuleURI: "resource://normandy-content/ShieldFrameChild.sys.mjs",
events: {
pageshow: {},
pagehide: {},
ShieldPageEvent: { wantUntrusted: true },
},
},
matches: ["about:studies*"],
},
ShoppingSidebar: {
parent: {
esModuleURI: "resource:///actors/ShoppingSidebarParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ShoppingSidebarChild.sys.mjs",
events: {
ContentReady: { wantUntrusted: true },
PolledRequestMade: { wantUntrusted: true },
// This is added so the actor instantiates immediately and makes
// methods available to the page js on load.
DOMDocElementInserted: {},
ReportProductAvailable: { wantUntrusted: true },
AdClicked: { wantUntrusted: true },
AdImpression: { wantUntrusted: true },
DisableShopping: { wantUntrusted: true },
},
},
matches: ["about:shoppingsidebar"],
remoteTypes: ["privilegedabout"],
messageManagerGroups: ["shopping-sidebar", "browsers"],
enablePreference: "browser.shopping.experience2023.shoppingSidebar",
},
SpeechDispatcher: {
parent: {
esModuleURI: "resource:///actors/SpeechDispatcherParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/SpeechDispatcherChild.sys.mjs",
observers: ["chrome-synth-voices-error"],
},
messageManagerGroups: ["browsers"],
allFrames: true,
},
ASRouter: {
parent: {
esModuleURI: "resource:///actors/ASRouterParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/ASRouterChild.sys.mjs",
events: {
// This is added so the actor instantiates immediately and makes
// methods available to the page js on load.
DOMDocElementInserted: {},
},
},
matches: ["about:asrouter*", "about:welcome*", "about:privatebrowsing*"],
remoteTypes: ["privilegedabout"],
},
SwitchDocumentDirection: {
child: {
esModuleURI: "resource:///actors/SwitchDocumentDirectionChild.sys.mjs",
},
allFrames: true,
},
UITour: {
parent: {
esModuleURI: "resource:///modules/UITourParent.sys.mjs",
},
child: {
esModuleURI: "resource:///modules/UITourChild.sys.mjs",
events: {
mozUITour: { wantUntrusted: true },
},
},
messageManagerGroups: ["browsers"],
},
WebRTC: {
parent: {
esModuleURI: "resource:///actors/WebRTCParent.sys.mjs",
},
child: {
esModuleURI: "resource:///actors/WebRTCChild.sys.mjs",
},
allFrames: true,
},
};
ChromeUtils.defineLazyGetter(
lazy,
"WeaveService",
() => Cc["@mozilla.org/weave/service;1"].getService().wrappedJSObject
);
if (AppConstants.MOZ_CRASHREPORTER) {
ChromeUtils.defineESModuleGetters(lazy, {
UnsubmittedCrashHandler: "resource:///modules/ContentCrashHandlers.sys.mjs",
});
}
ChromeUtils.defineLazyGetter(lazy, "gBrandBundle", function () {
return Services.strings.createBundle(
"chrome://branding/locale/brand.properties"
);
});
ChromeUtils.defineLazyGetter(lazy, "gBrowserBundle", function () {
return Services.strings.createBundle(
"chrome://browser/locale/browser.properties"
);
});
ChromeUtils.defineLazyGetter(lazy, "log", () => {
let { ConsoleAPI } = ChromeUtils.importESModule(
"resource://gre/modules/Console.sys.mjs"
);
let consoleOptions = {
// tip: set maxLogLevel to "debug" and use lazy.log.debug() to create
// detailed messages during development. See LOG_LEVELS in Console.sys.mjs
// for details.
maxLogLevel: "error",
maxLogLevelPref: "browser.policies.loglevel",
prefix: "BrowserGlue.sys.mjs",
};
return new ConsoleAPI(consoleOptions);
});
const listeners = {
observers: {
"file-picker-crashed": ["FilePickerCrashed"],
"gmp-plugin-crash": ["PluginManager"],
"plugin-crashed": ["PluginManager"],
},
observe(subject, topic, data) {
for (let module of this.observers[topic]) {
try {
lazy[module].observe(subject, topic, data);
} catch (e) {
console.error(e);
}
}
},
init() {
for (let observer of Object.keys(this.observers)) {
Services.obs.addObserver(this, observer);
}
},
};
if (AppConstants.MOZ_UPDATER) {
listeners.observers["update-downloading"] = ["UpdateListener"];
listeners.observers["update-staged"] = ["UpdateListener"];
listeners.observers["update-downloaded"] = ["UpdateListener"];
listeners.observers["update-available"] = ["UpdateListener"];
listeners.observers["update-error"] = ["UpdateListener"];
listeners.observers["update-swap"] = ["UpdateListener"];
}
// Seconds of idle before trying to create a bookmarks backup.
const BOOKMARKS_BACKUP_IDLE_TIME_SEC = 8 * 60;
// Minimum interval between backups. We try to not create more than one backup
// per interval.
const BOOKMARKS_BACKUP_MIN_INTERVAL_DAYS = 1;
// Seconds of idle time before the late idle tasks will be scheduled.
const LATE_TASKS_IDLE_TIME_SEC = 20;
// Time after we stop tracking startup crashes.
const STARTUP_CRASHES_END_DELAY_MS = 30 * 1000;
/*
* OS X has the concept of zero-window sessions and therefore ignores the
* browser-lastwindow-close-* topics.
*/
const OBSERVE_LASTWINDOW_CLOSE_TOPICS = AppConstants.platform != "macosx";
export let BrowserInitState = {};
BrowserInitState.startupIdleTaskPromise = new Promise(resolve => {
BrowserInitState._resolveStartupIdleTask = resolve;
});
export function BrowserGlue() {
XPCOMUtils.defineLazyServiceGetter(
this,
"_userIdleService",
"@mozilla.org/widget/useridleservice;1",
"nsIUserIdleService"
);
ChromeUtils.defineLazyGetter(this, "_distributionCustomizer", function () {
const { DistributionCustomizer } = ChromeUtils.importESModule(
"resource:///modules/distribution.sys.mjs"
);
return new DistributionCustomizer();
});
this._init();
}
function WindowsRegPoliciesGetter(wrk, root, regLocation) {
wrk.open(root, regLocation, wrk.ACCESS_READ);
let policies;
if (wrk.hasChild("Mozilla\\" + Services.appinfo.name)) {
policies = lazy.WindowsGPOParser.readPolicies(wrk, policies);
}
wrk.close();
return policies;
}
function isPrivateBrowsingAllowedInRegistry() {
// If there is an attempt to open Private Browsing before
// EnterprisePolicies are initialized the Windows registry
// can be checked to determine if it is enabled
if (Services.policies.status > Ci.nsIEnterprisePolicies.UNINITIALIZED) {
// Yield to policies engine if initialized
let privateAllowed = Services.policies.isAllowed("privatebrowsing");
lazy.log.debug(
`Yield to initialized policies engine: Private Browsing Allowed = ${privateAllowed}`
);
return privateAllowed;
}
if (AppConstants.platform !== "win") {
// Not using Windows so no registry, return true
lazy.log.debug(
"AppConstants.platform is not 'win': Private Browsing allowed"
);
return true;
}
// If all other checks fail only then do we check registry
let wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance(
Ci.nsIWindowsRegKey
);
let regLocation = "SOFTWARE\\Policies";
let userPolicies, machinePolicies;
// Only check HKEY_LOCAL_MACHINE if not in testing
if (!Cu.isInAutomation) {
machinePolicies = WindowsRegPoliciesGetter(
wrk,
wrk.ROOT_KEY_LOCAL_MACHINE,
regLocation
);
}
// Check machine policies before checking user policies
// HKEY_LOCAL_MACHINE supersedes HKEY_CURRENT_USER so only check
// HKEY_CURRENT_USER if the registry key is not present in
// HKEY_LOCAL_MACHINE at all
if (machinePolicies && "DisablePrivateBrowsing" in machinePolicies) {
lazy.log.debug(
`DisablePrivateBrowsing in HKEY_LOCAL_MACHINE is ${machinePolicies.DisablePrivateBrowsing}`
);
return !(machinePolicies.DisablePrivateBrowsing === 1);
}
userPolicies = WindowsRegPoliciesGetter(
wrk,
wrk.ROOT_KEY_CURRENT_USER,
regLocation
);
if (userPolicies && "DisablePrivateBrowsing" in userPolicies) {
lazy.log.debug(
`DisablePrivateBrowsing in HKEY_CURRENT_USER is ${userPolicies.DisablePrivateBrowsing}`
);
return !(userPolicies.DisablePrivateBrowsing === 1);
}
// Private browsing allowed if no registry entry exists
lazy.log.debug(
"No DisablePrivateBrowsing registry entry: Private Browsing allowed"
);
return true;
}
BrowserGlue.prototype = {
_saveSession: false,
_migrationImportsDefaultBookmarks: false,
_placesBrowserInitComplete: false,
_isNewProfile: undefined,
_defaultCookieBehaviorAtStartup: null,
_setPrefToSaveSession: function BG__setPrefToSaveSession(aForce) {
if (!this._saveSession && !aForce) {
return;
}
if (!lazy.PrivateBrowsingUtils.permanentPrivateBrowsing) {
Services.prefs.setBoolPref(
"browser.sessionstore.resume_session_once",
true
);
}
// This method can be called via [NSApplication terminate:] on Mac, which
// ends up causing prefs not to be flushed to disk, so we need to do that
// explicitly here. See bug 497652.
Services.prefs.savePrefFile(null);
},
// nsIObserver implementation
observe: async function BG_observe(subject, topic, data) {
switch (topic) {
case "notifications-open-settings":
this._openPreferences("privacy-permissions");
break;
case "final-ui-startup":
this._beforeUIStartup();
break;
case "browser-delayed-startup-finished":
this._onFirstWindowLoaded(subject);
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
break;
case "sessionstore-windows-restored":
this._onWindowsRestored();
break;
case "browser:purge-session-history":
// reset the console service's error buffer
Services.console.logStringMessage(null); // clear the console (in case it's open)
Services.console.reset();
break;
case "restart-in-safe-mode":
this._onSafeModeRestart(subject);
break;
case "quit-application-requested":
this._onQuitRequest(subject, data);
break;
case "quit-application-granted":
this._onQuitApplicationGranted();
break;
case "browser-lastwindow-close-requested":
if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
// The application is not actually quitting, but the last full browser
// window is about to be closed.
this._onQuitRequest(subject, "lastwindow");
}
break;
case "browser-lastwindow-close-granted":
if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
this._setPrefToSaveSession();
}
break;
case "session-save":
this._setPrefToSaveSession(true);
subject.QueryInterface(Ci.nsISupportsPRBool);
subject.data = true;
break;
case "places-init-complete":
Services.obs.removeObserver(this, "places-init-complete");
if (!this._migrationImportsDefaultBookmarks) {
this._initPlaces(false);
}
break;
case "idle":
this._backupBookmarks();
break;
case "distribution-customization-complete":
Services.obs.removeObserver(
this,
"distribution-customization-complete"
);
// Customization has finished, we don't need the customizer anymore.
delete this._distributionCustomizer;
break;
case "browser-glue-test": // used by tests
if (data == "force-ui-migration") {
this._migrateUI();
} else if (data == "force-distribution-customization") {
this._distributionCustomizer.applyCustomizations();
// To apply distribution bookmarks use "places-init-complete".
} else if (data == "test-force-places-init") {
this._placesInitialized = false;
this._initPlaces(false);
} else if (data == "places-browser-init-complete") {
if (this._placesBrowserInitComplete) {
Services.obs.notifyObservers(null, "places-browser-init-complete");
}
} else if (data == "add-breaches-sync-handler") {
this._addBreachesSyncHandler();
}
break;
case "initial-migration-will-import-default-bookmarks":
this._migrationImportsDefaultBookmarks = true;
break;
case "initial-migration-did-import-default-bookmarks":
this._initPlaces(true);
break;
case "handle-xul-text-link": {
let linkHandled = subject.QueryInterface(Ci.nsISupportsPRBool);
if (!linkHandled.data) {
let win = lazy.BrowserWindowTracker.getTopWindow();
if (win) {
data = JSON.parse(data);
let where = lazy.BrowserUtils.whereToOpenLink(data);
// Preserve legacy behavior of non-modifier left-clicks
// opening in a new selected tab.
if (where == "current") {
where = "tab";
}
win.openTrustedLinkIn(data.href, where);
linkHandled.data = true;
}
}
break;
}
case "profile-before-change":
// Any component depending on Places should be finalized in
// _onPlacesShutdown. Any component that doesn't need to act after
// the UI has gone should be finalized in _onQuitApplicationGranted.
this._dispose();
break;
case "keyword-search": {
// This notification is broadcast by the docshell when it "fixes up" a
// URI that it's been asked to load into a keyword search.
let engine = null;
try {
engine = Services.search.getEngineByName(
subject.QueryInterface(Ci.nsISupportsString).data
);
} catch (ex) {
console.error(ex);
}
let win = lazy.BrowserWindowTracker.getTopWindow();
lazy.BrowserSearchTelemetry.recordSearch(
win.gBrowser.selectedBrowser,
engine,
"urlbar"
);
break;
}
case "xpi-signature-changed": {
let disabledAddons = JSON.parse(data).disabled;
let addons = await lazy.AddonManager.getAddonsByIDs(disabledAddons);
if (addons.some(addon => addon)) {
this._notifyUnsignedAddonsDisabled();
}
break;
}
case "handlersvc-store-initialized":
// Initialize PdfJs when running in-process and remote. This only
// happens once since PdfJs registers global hooks. If the PdfJs
// extension is installed the init method below will be overridden
// leaving initialization to the extension.
// parent only: configure default prefs, set up pref observers, register
// pdf content handler, and initializes parent side message manager
// shim for privileged api access.
lazy.PdfJs.init(this._isNewProfile);
// Allow certain viewable internally types to be opened from downloads.
lazy.DownloadsViewableInternally.register();
break;
case "app-startup": {
this._earlyBlankFirstPaint(subject);
gThisInstanceIsTaskbarTab = subject.handleFlag("taskbar-tab", false);
gThisInstanceIsLaunchOnLogin = subject.handleFlag(
"os-autostart",
false
);
let launchOnLoginPref = "browser.startup.windowsLaunchOnLogin.enabled";
let profileSvc = Cc[
"@mozilla.org/toolkit/profile-service;1"
].getService(Ci.nsIToolkitProfileService);
if (
AppConstants.platform == "win" &&
!profileSvc.startWithLastProfile
) {
// If we don't start with last profile, the user
// likely sees the profile selector on launch.
if (Services.prefs.getBoolPref(launchOnLoginPref)) {
Glean.launchOnLogin.lastProfileDisableStartup.record();
// Disable launch on login messaging if we are disabling the
// feature.
Services.prefs.setBoolPref(
"browser.startup.windowsLaunchOnLogin.disableLaunchOnLoginPrompt",
true
);
}
// To reduce confusion when running multiple Gecko profiles,
// delete launch on login shortcuts and registry keys so that
// users are not presented with the outdated profile selector
// dialog.
lazy.WindowsLaunchOnLogin.removeLaunchOnLogin();
}
break;
}
}
},
// initialization (called on application startup)
_init: function BG__init() {
let os = Services.obs;
[
"notifications-open-settings",
"final-ui-startup",
"browser-delayed-startup-finished",
"sessionstore-windows-restored",
"browser:purge-session-history",
"quit-application-requested",
"quit-application-granted",
"session-save",
"places-init-complete",
"distribution-customization-complete",
"handle-xul-text-link",
"profile-before-change",
"keyword-search",
"restart-in-safe-mode",
"xpi-signature-changed",
"handlersvc-store-initialized",
].forEach(topic => os.addObserver(this, topic, true));
if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
os.addObserver(this, "browser-lastwindow-close-requested", true);
os.addObserver(this, "browser-lastwindow-close-granted", true);
}
lazy.ActorManagerParent.addJSProcessActors(JSPROCESSACTORS);
lazy.ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);
this._firstWindowReady = new Promise(
resolve => (this._firstWindowLoaded = resolve)
);
},
// cleanup (called on application shutdown)
_dispose: function BG__dispose() {
// AboutHomeStartupCache might write to the cache during
// quit-application-granted, so we defer uninitialization
// until here.
AboutHomeStartupCache.uninit();
if (this._bookmarksBackupIdleTime) {
this._userIdleService.removeIdleObserver(
this,
this._bookmarksBackupIdleTime
);
this._bookmarksBackupIdleTime = null;
}
if (this._lateTasksIdleObserver) {
this._userIdleService.removeIdleObserver(
this._lateTasksIdleObserver,
LATE_TASKS_IDLE_TIME_SEC
);
delete this._lateTasksIdleObserver;
}
if (this._gmpInstallManager) {
this._gmpInstallManager.uninit();
delete this._gmpInstallManager;
}
Services.prefs.removeObserver(
"privacy.trackingprotection",
this._matchCBCategory
);
Services.prefs.removeObserver(
"network.cookie.cookieBehavior",
this._matchCBCategory
);
Services.prefs.removeObserver(
"network.cookie.cookieBehavior.pbmode",
this._matchCBCategory
);
Services.prefs.removeObserver(
"network.http.referer.disallowCrossSiteRelaxingDefault",
this._matchCBCategory
);
Services.prefs.removeObserver(
"network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation",
this._matchCBCategory
);
Services.prefs.removeObserver(
"privacy.partition.network_state.ocsp_cache",
this._matchCBCategory
);
Services.prefs.removeObserver(
"privacy.query_stripping.enabled",
this._matchCBCategory
);
Services.prefs.removeObserver(
"privacy.query_stripping.enabled.pbmode",
this._matchCBCategory
);
Services.prefs.removeObserver(
"privacy.fingerprintingProtection",
this._matchCBCategory
);
Services.prefs.removeObserver(
"privacy.fingerprintingProtection.pbmode",
this._matchCBCategory
);
Services.prefs.removeObserver(
ContentBlockingCategoriesPrefs.PREF_CB_CATEGORY,
this._updateCBCategory
);
Services.prefs.removeObserver(
"privacy.trackingprotection",
this._setPrefExpectations
);
Services.prefs.removeObserver(
"browser.contentblocking.features.strict",
this._setPrefExpectationsAndUpdate
);
},
// runs on startup, before the first command line handler is invoked
// (i.e. before the first window is opened)
_beforeUIStartup: function BG__beforeUIStartup() {
lazy.SessionStartup.init();
// check if we're in safe mode
if (Services.appinfo.inSafeMode) {
Services.ww.openWindow(
null,
"chrome://browser/content/safeMode.xhtml",
"_blank",
"chrome,centerscreen,modal,resizable=no",
null
);
}
// apply distribution customizations
this._distributionCustomizer.applyCustomizations();
// handle any UI migration
this._migrateUI();
if (!Services.prefs.prefHasUserValue(PREF_PDFJS_ISDEFAULT_CACHE_STATE)) {
lazy.PdfJs.checkIsDefault(this._isNewProfile);
}
if (!AppConstants.NIGHTLY_BUILD && this._isNewProfile) {
lazy.FormAutofillUtils.setOSAuthEnabled(
lazy.FormAutofillUtils.AUTOFILL_CREDITCARDS_REAUTH_PREF,
false
);
lazy.LoginHelper.setOSAuthEnabled(
lazy.LoginHelper.OS_AUTH_FOR_PASSWORDS_PREF,
false
);
}
listeners.init();
lazy.SessionStore.init();
lazy.BuiltInThemes.maybeInstallActiveBuiltInTheme();
if (AppConstants.MOZ_NORMANDY) {
lazy.Normandy.init();
}
lazy.SaveToPocket.init();
lazy.ResetPBMPanel.init();
AboutHomeStartupCache.init();
lazy.AccountsGlue.init();
Services.obs.notifyObservers(null, "browser-ui-startup-complete");
},
_checkForOldBuildUpdates() {
// check for update if our build is old
if (
AppConstants.MOZ_UPDATER &&
Services.prefs.getBoolPref("app.update.checkInstallTime")
) {
let buildID = Services.appinfo.appBuildID;
let today = new Date().getTime();
/* eslint-disable no-multi-spaces */
let buildDate = new Date(
buildID.slice(0, 4), // year
buildID.slice(4, 6) - 1, // months are zero-based.
buildID.slice(6, 8), // day
buildID.slice(8, 10), // hour
buildID.slice(10, 12), // min
buildID.slice(12, 14)
) // ms
.getTime();
/* eslint-enable no-multi-spaces */
const millisecondsIn24Hours = 86400000;
let acceptableAge =
Services.prefs.getIntPref("app.update.checkInstallTime.days") *
millisecondsIn24Hours;
if (buildDate + acceptableAge < today) {
// This is asynchronous, but just kick it off rather than waiting.
Cc["@mozilla.org/updates/update-service;1"]
.getService(Ci.nsIApplicationUpdateService)
.checkForBackgroundUpdates();
}
}
},
async _onSafeModeRestart(window) {
// prompt the user to confirm
let productName = lazy.gBrandBundle.GetStringFromName("brandShortName");
let strings = lazy.gBrowserBundle;
let promptTitle = strings.formatStringFromName(
"troubleshootModeRestartPromptTitle",
[productName]
);
let promptMessage = strings.GetStringFromName(
"troubleshootModeRestartPromptMessage"
);
let restartText = strings.GetStringFromName(
"troubleshootModeRestartButton"
);
let buttonFlags =
Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_IS_STRING +
Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL +
Services.prompt.BUTTON_POS_0_DEFAULT;
let rv = await Services.prompt.asyncConfirmEx(
window.browsingContext,
Ci.nsIPrompt.MODAL_TYPE_INTERNAL_WINDOW,
promptTitle,
promptMessage,
buttonFlags,
restartText,
null,
null,
null,
{}
);
if (rv.get("buttonNumClicked") != 0) {
return;
}
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
Ci.nsISupportsPRBool
);
Services.obs.notifyObservers(
cancelQuit,
"quit-application-requested",
"restart"
);
if (!cancelQuit.data) {
Services.startup.restartInSafeMode(Ci.nsIAppStartup.eAttemptQuit);
}
},
/**
* Show a notification bar offering a reset.
*
* @param reason
* String of either "unused" or "uninstall", specifying the reason
* why a profile reset is offered.
*/
_resetProfileNotification(reason) {
let win = lazy.BrowserWindowTracker.getTopWindow();
if (!win) {
return;
}
const { ResetProfile } = ChromeUtils.importESModule(
"resource://gre/modules/ResetProfile.sys.mjs"
);
if (!ResetProfile.resetSupported()) {
return;
}
let productName = lazy.gBrandBundle.GetStringFromName("brandShortName");
let resetBundle = Services.strings.createBundle(
"chrome://global/locale/resetProfile.properties"
);
let message;
if (reason == "unused") {
message = resetBundle.formatStringFromName("resetUnusedProfile.message", [
productName,
]);
} else if (reason == "uninstall") {
message = resetBundle.formatStringFromName("resetUninstalled.message", [
productName,
]);
} else {
throw new Error(
`Unknown reason (${reason}) given to _resetProfileNotification.`
);
}
let buttons = [
{
label: resetBundle.formatStringFromName(
"refreshProfile.resetButton.label",
[productName]
),
accessKey: resetBundle.GetStringFromName(
"refreshProfile.resetButton.accesskey"
),
callback() {
ResetProfile.openConfirmationDialog(win);
},
},
];
win.gNotificationBox.appendNotification(
"reset-profile-notification",
{
label: message,
image: "chrome://global/skin/icons/question-64.png",
priority: win.gNotificationBox.PRIORITY_INFO_LOW,
},
buttons
);
},
_notifyUnsignedAddonsDisabled() {
let win = lazy.BrowserWindowTracker.getTopWindow();
if (!win) {
return;
}
let message = win.gNavigatorBundle.getString(
"unsignedAddonsDisabled.message"
);
let buttons = [
{
label: win.gNavigatorBundle.getString(
"unsignedAddonsDisabled.learnMore.label"
),
accessKey: win.gNavigatorBundle.getString(
"unsignedAddonsDisabled.learnMore.accesskey"
),
callback() {
win.BrowserAddonUI.openAddonsMgr(
"addons://list/extension?unsigned=true"
);
},
},
];
win.gNotificationBox.appendNotification(
"unsigned-addons-disabled",
{
label: message,
priority: win.gNotificationBox.PRIORITY_WARNING_MEDIUM,
},
buttons
);
},
_verifySandboxUserNamespaces: function BG_verifySandboxUserNamespaces(aWin) {
if (!AppConstants.MOZ_SANDBOX) {
return;
}
lazy.SandboxUtils.maybeWarnAboutMissingUserNamespaces(
aWin.gNotificationBox
);
},
_earlyBlankFirstPaint(cmdLine) {
let startTime = Cu.now();
let shouldCreateWindow = isPrivateWindow => {
if (cmdLine.findFlag("wait-for-jsdebugger", false) != -1) {
return true;
}
if (
AppConstants.platform == "macosx" ||
Services.startup.wasSilentlyStarted ||
!Services.prefs.getBoolPref("browser.startup.blankWindow", false)
) {
return false;
}
// Until bug 1450626 and bug 1488384 are fixed, skip the blank window when
// using a non-default theme.
if (
!Services.startup.showedPreXULSkeletonUI &&
Services.prefs.getCharPref(
"extensions.activeThemeID",
"default-theme@mozilla.org"
) != "default-theme@mozilla.org"
) {
return false;
}
// Bug 1448423: Skip the blank window if the user is resisting fingerprinting
if (
Services.prefs.getBoolPref(
"privacy.resistFingerprinting.skipEarlyBlankFirstPaint",
true
) &&
ChromeUtils.shouldResistFingerprinting(
"RoundWindowSize",
null,
isPrivateWindow ||
Services.prefs.getBoolPref(
"browser.privatebrowsing.autostart",
false
)
)
) {
return false;
}
let width = getValue("width");
let height = getValue("height");
// The clean profile case isn't handled yet. Return early for now.
if (!width || !height) {
return false;
}
return true;
};
let makeWindowPrivate =
cmdLine.findFlag("private-window", false) != -1 &&
isPrivateBrowsingAllowedInRegistry();
if (!shouldCreateWindow(makeWindowPrivate)) {
return;
}
let browserWindowFeatures =
"chrome,all,dialog=no,extrachrome,menubar,resizable,scrollbars,status," +
"location,toolbar,personalbar";
// This needs to be set when opening the window to ensure that the AppUserModelID
// is set correctly on Windows. Without it, initial launches with `-private-window`
// will show up under the regular Firefox taskbar icon first, and then switch
// to the Private Browsing icon shortly thereafter.
if (makeWindowPrivate) {
browserWindowFeatures += ",private";
}
let win = Services.ww.openWindow(
null,
"about:blank",
null,
browserWindowFeatures,
null
);
// Hide the titlebar if the actual browser window will draw in it.
let hiddenTitlebar = Services.appinfo.drawInTitlebar;
if (hiddenTitlebar) {
win.windowUtils.setCustomTitlebar(true);
}
let docElt = win.document.documentElement;
docElt.setAttribute("screenX", getValue("screenX"));
docElt.setAttribute("screenY", getValue("screenY"));
// The sizemode="maximized" attribute needs to be set before first paint.
let sizemode = getValue("sizemode");
let width = getValue("width") || 500;
let height = getValue("height") || 500;
if (sizemode == "maximized") {
docElt.setAttribute("sizemode", sizemode);
// Set the size to use when the user leaves the maximized mode.
// The persisted size is the outer size, but the height/width
// attributes set the inner size.
let appWin = win.docShell.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIAppWindow);
height -= appWin.outerToInnerHeightDifferenceInCSSPixels;
width -= appWin.outerToInnerWidthDifferenceInCSSPixels;
docElt.setAttribute("height", height);
docElt.setAttribute("width", width);
} else {
// Setting the size of the window in the features string instead of here
// causes the window to grow by the size of the titlebar.
win.resizeTo(width, height);
}
// Set this before showing the window so that graphics code can use it to
// decide to skip some expensive code paths (eg. starting the GPU process).
docElt.setAttribute("windowtype", "navigator:blank");
// The window becomes visible after OnStopRequest, so make this happen now.
win.stop();
ChromeUtils.addProfilerMarker("earlyBlankFirstPaint", startTime);
win.openTime = Cu.now();
let { TelemetryTimestamps } = ChromeUtils.importESModule(
"resource://gre/modules/TelemetryTimestamps.sys.mjs"
);
TelemetryTimestamps.add("blankWindowShown");
function getValue(attr) {
return Services.xulStore.getValue(
AppConstants.BROWSER_CHROME_URL,
"main-window",
attr
);
}
},
_firstWindowTelemetry(aWindow) {
let scaling = aWindow.devicePixelRatio * 100;
try {
Services.telemetry.getHistogramById("DISPLAY_SCALING").add(scaling);
} catch (ex) {}
},
_collectStartupConditionsTelemetry() {
let nowSeconds = Math.round(Date.now() / 1000);
// Don't include cases where we don't have the pref. This rules out the first install
// as well as the first run of a build since this was introduced. These could by some
// definitions be referred to as "cold" startups, but probably not since we likely
// just wrote many of the files we use to disk. This way we should approximate a lower
// bound to the number of cold startups rather than an upper bound.
let lastCheckSeconds = Services.prefs.getIntPref(
"browser.startup.lastColdStartupCheck",
nowSeconds
);
Services.prefs.setIntPref(
"browser.startup.lastColdStartupCheck",
nowSeconds
);
try {
let secondsSinceLastOSRestart =
Services.startup.secondsSinceLastOSRestart;
let isColdStartup =
nowSeconds - secondsSinceLastOSRestart > lastCheckSeconds;
Glean.startup.isCold.set(isColdStartup);
Glean.startup.secondsSinceLastOsRestart.set(secondsSinceLastOSRestart);
} catch (ex) {
console.error(ex);
}
},
// the first browser window has finished initializing
_onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) {
lazy.AboutNewTab.init();
lazy.TabCrashHandler.init();
lazy.ProcessHangMonitor.init();
lazy.UrlbarPrefs.updateFirefoxSuggestScenario();
// A channel for "remote troubleshooting" code...
let channel = new lazy.WebChannel(
"remote-troubleshooting",
"remote-troubleshooting"
);
channel.listen((id, data, target) => {
if (data.command == "request") {
let { Troubleshoot } = ChromeUtils.importESModule(
"resource://gre/modules/Troubleshoot.sys.mjs"
);
Troubleshoot.snapshot().then(snapshotData => {
// for privacy we remove crash IDs and all preferences (but bug 1091944
// exists to expose prefs once we are confident of privacy implications)
delete snapshotData.crashes;
delete snapshotData.modifiedPreferences;
delete snapshotData.printingPreferences;
channel.send(snapshotData, target);
});
}
});
this._maybeOfferProfileReset();
this._checkForOldBuildUpdates();
// Check if Sync is configured
if (Services.prefs.prefHasUserValue("services.sync.username")) {
lazy.WeaveService.init();
}
lazy.PageThumbs.init();
lazy.NewTabUtils.init();
lazy.PageActions.init();
lazy.DoHController.init();
if (AppConstants.MOZ_SELECTABLE_PROFILES) {
lazy.SelectableProfileService.init().catch(console.error);
}
this._firstWindowTelemetry(aWindow);
this._firstWindowLoaded();
this._collectStartupConditionsTelemetry();
// Set the default favicon size for UI views that use the page-icon protocol.
lazy.PlacesUtils.favicons.setDefaultIconURIPreferredSize(
16 * aWindow.devicePixelRatio
);
this._setPrefExpectationsAndUpdate();
this._matchCBCategory();
// This observes the entire privacy.trackingprotection.* pref tree.
Services.prefs.addObserver(
"privacy.trackingprotection",
this._matchCBCategory
);
Services.prefs.addObserver(
"network.cookie.cookieBehavior",
this._matchCBCategory
);
Services.prefs.addObserver(
"network.cookie.cookieBehavior.pbmode",
this._matchCBCategory
);
Services.prefs.addObserver(
"network.http.referer.disallowCrossSiteRelaxingDefault",
this._matchCBCategory
);
Services.prefs.addObserver(
"network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation",
this._matchCBCategory
);
Services.prefs.addObserver(
"privacy.partition.network_state.ocsp_cache",
this._matchCBCategory
);
Services.prefs.addObserver(
"privacy.query_stripping.enabled",
this._matchCBCategory
);
Services.prefs.addObserver(
"privacy.query_stripping.enabled.pbmode",
this._matchCBCategory
);
Services.prefs.addObserver(
"privacy.fingerprintingProtection",
this._matchCBCategory
);
Services.prefs.addObserver(
"privacy.fingerprintingProtection.pbmode",
this._matchCBCategory
);
Services.prefs.addObserver(
ContentBlockingCategoriesPrefs.PREF_CB_CATEGORY,
this._updateCBCategory
);
Services.prefs.addObserver(
"privacy.trackingprotection",
this._setPrefExpectations
);
Services.prefs.addObserver(
"browser.contentblocking.features.strict",
this._setPrefExpectationsAndUpdate
);
lazy.CaptchaDetectionPingUtils.init();
this._verifySandboxUserNamespaces(aWindow);
},
_maybeOfferProfileReset() {
// Offer to reset a user's profile if it hasn't been used for 60 days.
const OFFER_PROFILE_RESET_INTERVAL_MS = 60 * 24 * 60 * 60 * 1000;
let lastUse = Services.appinfo.replacedLockTime;
let disableResetPrompt = Services.prefs.getBoolPref(
"browser.disableResetPrompt",
false
);
// Also check prefs.js last modified timestamp as a backstop.
// This helps for cases where the lock file checks don't work,
// e.g. NFS or because the previous time Firefox ran, it ran
// for a very long time. See bug 1054947 and related bugs.
lastUse = Math.max(
lastUse,
Services.prefs.userPrefsFileLastModifiedAtStartup
);
if (
!disableResetPrompt &&
lastUse &&
Date.now() - lastUse >= OFFER_PROFILE_RESET_INTERVAL_MS
) {
this._resetProfileNotification("unused");
} else if (AppConstants.platform == "win" && !disableResetPrompt) {
// Check if we were just re-installed and offer Firefox Reset
let updateChannel;
try {
updateChannel = ChromeUtils.importESModule(
"resource://gre/modules/UpdateUtils.sys.mjs"
).UpdateUtils.UpdateChannel;
} catch (ex) {}
if (updateChannel) {
let uninstalledValue = lazy.WindowsRegistry.readRegKey(
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"Software\\Mozilla\\Firefox",
--> --------------------
--> maximum size reached
--> --------------------
[ Verzeichnis aufwärts0.32unsichere Verbindung
Übersetzung europäischer Sprachen durch Browser
]
|
2026-03-28
|