зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1772100 - Part 10: Use plain object for lazy getter in browser/components/newtab/. r=Mardak
Differential Revision: https://phabricator.services.mozilla.com/D148020
This commit is contained in:
Родитель
61a9455b97
Коммит
4863993e67
|
@ -41,7 +41,9 @@ const { E10SUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/E10SUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
});
|
||||
|
||||
|
@ -60,7 +62,7 @@ const ABOUT_WELCOME_URL =
|
|||
"resource://activity-stream/aboutwelcome/aboutwelcome.html";
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"BasePromiseWorker",
|
||||
"resource://gre/modules/PromiseWorker.jsm"
|
||||
);
|
||||
|
@ -125,7 +127,7 @@ const AboutHomeStartupCacheChild = {
|
|||
);
|
||||
}
|
||||
|
||||
if (!NimbusFeatures.abouthomecache.isEnabled()) {
|
||||
if (!lazy.NimbusFeatures.abouthomecache.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -338,7 +340,7 @@ const AboutHomeStartupCacheChild = {
|
|||
return this._cacheWorker;
|
||||
}
|
||||
|
||||
this._cacheWorker = new BasePromiseWorker(CACHE_WORKER_URL);
|
||||
this._cacheWorker = new lazy.BasePromiseWorker(CACHE_WORKER_URL);
|
||||
return this._cacheWorker;
|
||||
},
|
||||
|
||||
|
@ -443,8 +445,8 @@ class BaseAboutNewTabService {
|
|||
* This is calculated in the same way the default URL is.
|
||||
*/
|
||||
|
||||
NimbusFeatures.aboutwelcome.recordExposureEvent({ once: true });
|
||||
if (NimbusFeatures.aboutwelcome.isEnabled({ defaultValue: true })) {
|
||||
lazy.NimbusFeatures.aboutwelcome.recordExposureEvent({ once: true });
|
||||
if (lazy.NimbusFeatures.aboutwelcome.isEnabled({ defaultValue: true })) {
|
||||
return ABOUT_WELCOME_URL;
|
||||
}
|
||||
return this.defaultURL;
|
||||
|
|
|
@ -10,7 +10,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
DEFAULT_SITES: "resource://activity-stream/lib/DefaultSites.jsm",
|
||||
ExperimentAPI: "resource://nimbus/ExperimentAPI.jsm",
|
||||
shortURL: "resource://activity-stream/lib/ShortURL.jsm",
|
||||
|
@ -20,16 +22,16 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "log", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "log", () => {
|
||||
const { Logger } = ChromeUtils.import(
|
||||
"resource://messaging-system/lib/Logger.jsm"
|
||||
);
|
||||
return new Logger("AboutWelcomeChild");
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "tippyTopProvider", () =>
|
||||
XPCOMUtils.defineLazyGetter(lazy, "tippyTopProvider", () =>
|
||||
(async () => {
|
||||
const provider = new TippyTopProvider();
|
||||
const provider = new lazy.TippyTopProvider();
|
||||
await provider.init();
|
||||
return provider;
|
||||
})()
|
||||
|
@ -38,7 +40,7 @@ XPCOMUtils.defineLazyGetter(this, "tippyTopProvider", () =>
|
|||
const SEARCH_REGION_PREF = "browser.search.region";
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"searchRegion",
|
||||
SEARCH_REGION_PREF,
|
||||
""
|
||||
|
@ -52,7 +54,7 @@ function getImportableSites(child) {
|
|||
getImportableSites.cache ??
|
||||
(getImportableSites.cache = (async () => {
|
||||
// Use tippy top to get packaged rich icons
|
||||
const tippyTop = await tippyTopProvider;
|
||||
const tippyTop = await lazy.tippyTopProvider;
|
||||
// Remove duplicate entries if they would appear the same
|
||||
return `[${[
|
||||
...new Set(
|
||||
|
@ -62,7 +64,7 @@ function getImportableSites(child) {
|
|||
tippyTop.processSite(site, "*");
|
||||
return JSON.stringify({
|
||||
icon: site.tippyTopIcon,
|
||||
label: shortURL(site),
|
||||
label: lazy.shortURL(site),
|
||||
});
|
||||
})
|
||||
),
|
||||
|
@ -73,18 +75,18 @@ function getImportableSites(child) {
|
|||
|
||||
async function getDefaultSites(child) {
|
||||
// Get default TopSites by region
|
||||
let sites = DEFAULT_SITES.get(
|
||||
DEFAULT_SITES.has(searchRegion) ? searchRegion : ""
|
||||
let sites = lazy.DEFAULT_SITES.get(
|
||||
lazy.DEFAULT_SITES.has(lazy.searchRegion) ? lazy.searchRegion : ""
|
||||
);
|
||||
|
||||
// Use tippy top to get packaged rich icons
|
||||
const tippyTop = await tippyTopProvider;
|
||||
const tippyTop = await lazy.tippyTopProvider;
|
||||
let defaultSites = sites.split(",").map(link => {
|
||||
let site = { url: link };
|
||||
tippyTop.processSite(site);
|
||||
return {
|
||||
icon: site.tippyTopIcon,
|
||||
title: shortURL(site),
|
||||
title: lazy.shortURL(site),
|
||||
};
|
||||
});
|
||||
return Cu.cloneInto(defaultSites, child.contentWindow);
|
||||
|
@ -105,7 +107,7 @@ class AboutWelcomeChild extends JSWindowActorChild {
|
|||
* @param {{type: string, data?: any}} action
|
||||
*/
|
||||
sendToPage(action) {
|
||||
log.debug(`Sending to page: ${action.type}`);
|
||||
lazy.log.debug(`Sending to page: ${action.type}`);
|
||||
const win = this.document.defaultView;
|
||||
const event = new win.CustomEvent("AboutWelcomeChromeToContent", {
|
||||
detail: Cu.cloneInto(action, win),
|
||||
|
@ -221,23 +223,23 @@ class AboutWelcomeChild extends JSWindowActorChild {
|
|||
|
||||
// Return to AMO gets returned early.
|
||||
if (attributionData?.template) {
|
||||
log.debug("Loading about:welcome with RTAMO attribution data");
|
||||
lazy.log.debug("Loading about:welcome with RTAMO attribution data");
|
||||
return Cu.cloneInto(attributionData, this.contentWindow);
|
||||
} else if (attributionData?.ua) {
|
||||
log.debug("Loading about:welcome with UA attribution");
|
||||
lazy.log.debug("Loading about:welcome with UA attribution");
|
||||
}
|
||||
|
||||
let experimentMetadata =
|
||||
ExperimentAPI.getExperimentMetaData({
|
||||
lazy.ExperimentAPI.getExperimentMetaData({
|
||||
featureId: "aboutwelcome",
|
||||
}) || {};
|
||||
|
||||
log.debug(
|
||||
lazy.log.debug(
|
||||
`Loading about:welcome with ${experimentMetadata?.slug ??
|
||||
"no"} experiment`
|
||||
);
|
||||
|
||||
let featureConfig = NimbusFeatures.aboutwelcome.getAllVariables();
|
||||
let featureConfig = lazy.NimbusFeatures.aboutwelcome.getAllVariables();
|
||||
featureConfig.needDefault = await this.sendQuery("AWPage:NEED_DEFAULT");
|
||||
featureConfig.needPin = await this.sendQuery("AWPage:DOES_APP_NEED_PIN");
|
||||
if (featureConfig.languageMismatchEnabled) {
|
||||
|
@ -245,12 +247,12 @@ class AboutWelcomeChild extends JSWindowActorChild {
|
|||
"AWPage:GET_APP_AND_SYSTEM_LOCALE_INFO"
|
||||
);
|
||||
}
|
||||
let defaults = AboutWelcomeDefaults.getDefaults();
|
||||
let defaults = lazy.AboutWelcomeDefaults.getDefaults();
|
||||
// FeatureConfig (from prefs or experiments) has higher precendence
|
||||
// to defaults. But the `screens` property isn't defined we shouldn't
|
||||
// override the default with `null`
|
||||
return Cu.cloneInto(
|
||||
await AboutWelcomeDefaults.prepareContentForReact({
|
||||
await lazy.AboutWelcomeDefaults.prepareContentForReact({
|
||||
...attributionData,
|
||||
...experimentMetadata,
|
||||
...defaults,
|
||||
|
@ -347,6 +349,6 @@ class AboutWelcomeChild extends JSWindowActorChild {
|
|||
* @override
|
||||
*/
|
||||
handleEvent(event) {
|
||||
log.debug(`Received page event ${event.type}`);
|
||||
lazy.log.debug(`Received page event ${event.type}`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
AddonManager: "resource://gre/modules/AddonManager.jsm",
|
||||
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
|
||||
BuiltInThemes: "resource:///modules/BuiltInThemes.jsm",
|
||||
|
@ -29,7 +31,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
LangPackMatcher: "resource://gre/modules/LangPackMatcher.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "log", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "log", () => {
|
||||
const { Logger } = ChromeUtils.import(
|
||||
"resource://messaging-system/lib/Logger.jsm"
|
||||
);
|
||||
|
@ -37,9 +39,9 @@ XPCOMUtils.defineLazyGetter(this, "log", () => {
|
|||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Telemetry",
|
||||
() => new AboutWelcomeTelemetry()
|
||||
() => new lazy.AboutWelcomeTelemetry()
|
||||
);
|
||||
|
||||
const DID_SEE_ABOUT_WELCOME_PREF = "trailhead.firstrun.didSeeAboutWelcome";
|
||||
|
@ -80,7 +82,7 @@ async function getImportableSites() {
|
|||
// Just handle these chromium-based browsers for now
|
||||
for (const browserId of ["chrome", "chromium-edge", "chromium"]) {
|
||||
// Skip if there's no profile data.
|
||||
const migrator = await MigrationUtils.getMigrator(browserId);
|
||||
const migrator = await lazy.MigrationUtils.getMigrator(browserId);
|
||||
if (!migrator) {
|
||||
continue;
|
||||
}
|
||||
|
@ -96,7 +98,7 @@ async function getImportableSites() {
|
|||
}
|
||||
|
||||
try {
|
||||
for (const row of await MigrationUtils.getRowsFromDBWithoutLocks(
|
||||
for (const row of await lazy.MigrationUtils.getRowsFromDBWithoutLocks(
|
||||
path,
|
||||
`Importable ${browserId} top sites`,
|
||||
`SELECT url
|
||||
|
@ -152,7 +154,7 @@ class AboutWelcomeObserver {
|
|||
}
|
||||
|
||||
stop() {
|
||||
log.debug(`Terminate reason is ${this.terminateReason}`);
|
||||
lazy.log.debug(`Terminate reason is ${this.terminateReason}`);
|
||||
Services.obs.removeObserver(this, "quit-application");
|
||||
if (!this.win) {
|
||||
return;
|
||||
|
@ -166,9 +168,9 @@ class AboutWelcomeObserver {
|
|||
class RegionHomeObserver {
|
||||
observe(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case Region.REGION_TOPIC:
|
||||
Services.obs.removeObserver(this, Region.REGION_TOPIC);
|
||||
this.regionHomeDeferred.resolve(Region.home);
|
||||
case lazy.Region.REGION_TOPIC:
|
||||
Services.obs.removeObserver(this, lazy.Region.REGION_TOPIC);
|
||||
this.regionHomeDeferred.resolve(lazy.Region.home);
|
||||
this.regionHomeDeferred = null;
|
||||
break;
|
||||
}
|
||||
|
@ -179,15 +181,15 @@ class RegionHomeObserver {
|
|||
// with region or rejected inside didDestroy if user exits
|
||||
// before region is available
|
||||
if (!this.regionHomeDeferred) {
|
||||
Services.obs.addObserver(this, Region.REGION_TOPIC);
|
||||
this.regionHomeDeferred = PromiseUtils.defer();
|
||||
Services.obs.addObserver(this, lazy.Region.REGION_TOPIC);
|
||||
this.regionHomeDeferred = lazy.PromiseUtils.defer();
|
||||
}
|
||||
return this.regionHomeDeferred.promise;
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.regionHomeDeferred) {
|
||||
Services.obs.removeObserver(this, Region.REGION_TOPIC);
|
||||
Services.obs.removeObserver(this, lazy.Region.REGION_TOPIC);
|
||||
// Reject unresolved deferred promise on exit
|
||||
this.regionHomeDeferred.reject(
|
||||
new Error("Unresolved region home promise")
|
||||
|
@ -206,11 +208,11 @@ class AboutWelcomeParent extends JSWindowActorParent {
|
|||
// Static methods that calls into ShellService to check
|
||||
// if Firefox is pinned or already default
|
||||
static doesAppNeedPin() {
|
||||
return ShellService.doesAppNeedPin();
|
||||
return lazy.ShellService.doesAppNeedPin();
|
||||
}
|
||||
|
||||
static isDefaultBrowser() {
|
||||
return ShellService.isDefaultBrowser();
|
||||
return lazy.ShellService.isDefaultBrowser();
|
||||
}
|
||||
|
||||
didDestroy() {
|
||||
|
@ -219,7 +221,7 @@ class AboutWelcomeParent extends JSWindowActorParent {
|
|||
}
|
||||
this.RegionHomeObserver?.stop();
|
||||
|
||||
Telemetry.sendTelemetry({
|
||||
lazy.Telemetry.sendTelemetry({
|
||||
event: "SESSION_END",
|
||||
event_context: {
|
||||
reason: this.AboutWelcomeObserver.terminateReason,
|
||||
|
@ -237,36 +239,36 @@ class AboutWelcomeParent extends JSWindowActorParent {
|
|||
* @param {Browser} the xul:browser rendering the page
|
||||
*/
|
||||
async onContentMessage(type, data, browser) {
|
||||
log.debug(`Received content event: ${type}`);
|
||||
lazy.log.debug(`Received content event: ${type}`);
|
||||
switch (type) {
|
||||
case "AWPage:SET_WELCOME_MESSAGE_SEEN":
|
||||
this.AWMessageId = data;
|
||||
try {
|
||||
Services.prefs.setBoolPref(DID_SEE_ABOUT_WELCOME_PREF, true);
|
||||
} catch (e) {
|
||||
log.debug(`Fails to set ${DID_SEE_ABOUT_WELCOME_PREF}.`);
|
||||
lazy.log.debug(`Fails to set ${DID_SEE_ABOUT_WELCOME_PREF}.`);
|
||||
}
|
||||
break;
|
||||
case "AWPage:SPECIAL_ACTION":
|
||||
SpecialMessageActions.handleAction(data, browser);
|
||||
lazy.SpecialMessageActions.handleAction(data, browser);
|
||||
break;
|
||||
case "AWPage:FXA_METRICS_FLOW_URI":
|
||||
return FxAccounts.config.promiseMetricsFlowURI("aboutwelcome");
|
||||
return lazy.FxAccounts.config.promiseMetricsFlowURI("aboutwelcome");
|
||||
case "AWPage:IMPORTABLE_SITES":
|
||||
return getImportableSites();
|
||||
case "AWPage:TELEMETRY_EVENT":
|
||||
Telemetry.sendTelemetry(data);
|
||||
lazy.Telemetry.sendTelemetry(data);
|
||||
break;
|
||||
case "AWPage:GET_ATTRIBUTION_DATA":
|
||||
let attributionData = await AboutWelcomeDefaults.getAttributionContent();
|
||||
let attributionData = await lazy.AboutWelcomeDefaults.getAttributionContent();
|
||||
return attributionData;
|
||||
case "AWPage:SELECT_THEME":
|
||||
await BuiltInThemes.ensureBuiltInThemes();
|
||||
return AddonManager.getAddonByID(
|
||||
await lazy.BuiltInThemes.ensureBuiltInThemes();
|
||||
return lazy.AddonManager.getAddonByID(
|
||||
LIGHT_WEIGHT_THEMES[data]
|
||||
).then(addon => addon.enable());
|
||||
case "AWPage:GET_SELECTED_THEME":
|
||||
let themes = await AddonManager.getAddonsByTypes(["theme"]);
|
||||
let themes = await lazy.AddonManager.getAddonsByTypes(["theme"]);
|
||||
let activeTheme = themes.find(addon => addon.isActive);
|
||||
|
||||
// convert this to the short form name that the front end code
|
||||
|
@ -276,8 +278,8 @@ class AboutWelcomeParent extends JSWindowActorParent {
|
|||
);
|
||||
return themeShortName?.toLowerCase();
|
||||
case "AWPage:GET_REGION":
|
||||
if (Region.home !== null) {
|
||||
return Region.home;
|
||||
if (lazy.Region.home !== null) {
|
||||
return lazy.Region.home;
|
||||
}
|
||||
if (!this.RegionHomeObserver) {
|
||||
this.RegionHomeObserver = new RegionHomeObserver(this);
|
||||
|
@ -305,18 +307,18 @@ class AboutWelcomeParent extends JSWindowActorParent {
|
|||
})
|
||||
);
|
||||
case "AWPage:GET_APP_AND_SYSTEM_LOCALE_INFO":
|
||||
return LangPackMatcher.getAppAndSystemLocaleInfo();
|
||||
return lazy.LangPackMatcher.getAppAndSystemLocaleInfo();
|
||||
case "AWPage:NEGOTIATE_LANGPACK":
|
||||
return LangPackMatcher.negotiateLangPackForLanguageMismatch(data);
|
||||
return lazy.LangPackMatcher.negotiateLangPackForLanguageMismatch(data);
|
||||
case "AWPage:ENSURE_LANG_PACK_INSTALLED":
|
||||
return LangPackMatcher.ensureLangPackInstalled(data);
|
||||
return lazy.LangPackMatcher.ensureLangPackInstalled(data);
|
||||
case "AWPage:SET_REQUESTED_LOCALES":
|
||||
return LangPackMatcher.setRequestedAppLocales(data);
|
||||
return lazy.LangPackMatcher.setRequestedAppLocales(data);
|
||||
case "AWPage:SEND_TO_DEVICE_EMAILS_SUPPORTED": {
|
||||
return BrowserUtils.sendToDeviceEmailsSupported();
|
||||
return lazy.BrowserUtils.sendToDeviceEmailsSupported();
|
||||
}
|
||||
default:
|
||||
log.debug(`Unexpected event ${type} was not handled.`);
|
||||
lazy.log.debug(`Unexpected event ${type} was not handled.`);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
@ -335,7 +337,7 @@ class AboutWelcomeParent extends JSWindowActorParent {
|
|||
return this.onContentMessage(name, data, browser);
|
||||
}
|
||||
|
||||
log.warn(`Not handling ${name} because the browser doesn't exist.`);
|
||||
lazy.log.warn(`Not handling ${name} because the browser doesn't exist.`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ const { AppConstants } = ChromeUtils.import(
|
|||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
AddonRepository: "resource://gre/modules/addons/AddonRepository.jsm",
|
||||
AttributionCode: "resource:///modules/AttributionCode.jsm",
|
||||
});
|
||||
|
@ -248,7 +250,7 @@ const DEFAULT_WELCOME_CONTENT = {
|
|||
};
|
||||
|
||||
async function getAddonFromRepository(data) {
|
||||
const [addonInfo] = await AddonRepository.getAddonsByIDs([data]);
|
||||
const [addonInfo] = await lazy.AddonRepository.getAddonsByIDs([data]);
|
||||
if (addonInfo.sourceURI.scheme !== "https") {
|
||||
return null;
|
||||
}
|
||||
|
@ -294,7 +296,7 @@ async function getAddonInfo(attrbObj) {
|
|||
}
|
||||
|
||||
async function getAttributionContent() {
|
||||
let attribution = await AttributionCode.getAttrDataAsync();
|
||||
let attribution = await lazy.AttributionCode.getAttrDataAsync();
|
||||
if (attribution?.source === "addons.mozilla.org") {
|
||||
let addonInfo = await getAddonInfo(attribution);
|
||||
if (addonInfo) {
|
||||
|
|
|
@ -9,25 +9,27 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
PingCentre: "resource:///modules/PingCentre.jsm",
|
||||
ClientID: "resource://gre/modules/ClientID.jsm",
|
||||
TelemetrySession: "resource://gre/modules/TelemetrySession.jsm",
|
||||
AttributionCode: "resource:///modules/AttributionCode.jsm",
|
||||
});
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"structuredIngestionEndpointBase",
|
||||
"browser.newtabpage.activity-stream.telemetry.structuredIngestion.endpoint",
|
||||
""
|
||||
);
|
||||
XPCOMUtils.defineLazyGetter(this, "telemetryClientId", () =>
|
||||
ClientID.getClientID()
|
||||
XPCOMUtils.defineLazyGetter(lazy, "telemetryClientId", () =>
|
||||
lazy.ClientID.getClientID()
|
||||
);
|
||||
XPCOMUtils.defineLazyGetter(
|
||||
this,
|
||||
lazy,
|
||||
"browserSessionId",
|
||||
() => TelemetrySession.getMetadata("").sessionId
|
||||
() => lazy.TelemetrySession.getMetadata("").sessionId
|
||||
);
|
||||
const TELEMETRY_TOPIC = "about:welcome";
|
||||
const PING_TYPE = "onboarding";
|
||||
|
@ -49,7 +51,7 @@ class AboutWelcomeTelemetry {
|
|||
*/
|
||||
get pingCentre() {
|
||||
Object.defineProperty(this, "pingCentre", {
|
||||
value: new PingCentre({ topic: TELEMETRY_TOPIC }),
|
||||
value: new lazy.PingCentre({ topic: TELEMETRY_TOPIC }),
|
||||
});
|
||||
return this.pingCentre;
|
||||
}
|
||||
|
@ -60,7 +62,7 @@ class AboutWelcomeTelemetry {
|
|||
// because it contains leading and trailing braces. Need to trim them first.
|
||||
const docID = uuid.slice(1, -1);
|
||||
const extension = `${STRUCTURED_INGESTION_NAMESPACE_MS}/${PING_TYPE}/${PING_VERSION}/${docID}`;
|
||||
return `${structuredIngestionEndpointBase}/${extension}`;
|
||||
return `${lazy.structuredIngestionEndpointBase}/${extension}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +78,7 @@ class AboutWelcomeTelemetry {
|
|||
* read the cached results for the most if not all of the pings.
|
||||
*/
|
||||
_maybeAttachAttribution(ping) {
|
||||
const attribution = AttributionCode.getCachedAttributionData();
|
||||
const attribution = lazy.AttributionCode.getCachedAttributionData();
|
||||
if (attribution && Object.keys(attribution).length) {
|
||||
ping.attribution = attribution;
|
||||
}
|
||||
|
@ -91,8 +93,8 @@ class AboutWelcomeTelemetry {
|
|||
...event,
|
||||
addon_version: Services.appinfo.appBuildID,
|
||||
locale: Services.locale.appLocaleAsBCP47,
|
||||
client_id: await telemetryClientId,
|
||||
browser_session_id: browserSessionId,
|
||||
client_id: await lazy.telemetryClientId,
|
||||
browser_session_id: lazy.browserSessionId,
|
||||
};
|
||||
|
||||
return this._maybeAttachAttribution(ping);
|
||||
|
|
|
@ -11,8 +11,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
const { AppConstants } = ChromeUtils.import(
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
SnippetsTestMessageProvider:
|
||||
"resource://activity-stream/lib/SnippetsTestMessageProvider.jsm",
|
||||
PanelTestProvider: "resource://activity-stream/lib/PanelTestProvider.jsm",
|
||||
|
@ -37,7 +38,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
TargetingContext: "resource://messaging-system/targeting/Targeting.jsm",
|
||||
MacAttribution: "resource:///modules/MacAttribution.jsm",
|
||||
});
|
||||
XPCOMUtils.defineLazyServiceGetters(this, {
|
||||
XPCOMUtils.defineLazyServiceGetters(lazy, {
|
||||
BrowserHandler: ["@mozilla.org/browser/clh;1", "nsIBrowserHandler"],
|
||||
});
|
||||
const { actionCreators: ac } = ChromeUtils.import(
|
||||
|
@ -191,7 +192,10 @@ const MessageLoaderUtils = {
|
|||
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(provider.url, { headers, credentials: "omit" });
|
||||
response = await lazy.fetch(provider.url, {
|
||||
headers,
|
||||
credentials: "omit",
|
||||
});
|
||||
} catch (e) {
|
||||
MessageLoaderUtils.reportError(e);
|
||||
}
|
||||
|
@ -278,10 +282,10 @@ const MessageLoaderUtils = {
|
|||
);
|
||||
} else if (
|
||||
RS_PROVIDERS_WITH_L10N.includes(provider.id) &&
|
||||
RemoteL10n.isLocaleSupported(MessageLoaderUtils.locale)
|
||||
lazy.RemoteL10n.isLocaleSupported(MessageLoaderUtils.locale)
|
||||
) {
|
||||
const recordId = `${RS_FLUENT_RECORD_PREFIX}-${MessageLoaderUtils.locale}`;
|
||||
const kinto = new KintoHttpClient(
|
||||
const kinto = new lazy.KintoHttpClient(
|
||||
Services.prefs.getStringPref(RS_SERVER_PREF)
|
||||
);
|
||||
const record = await kinto
|
||||
|
@ -289,7 +293,7 @@ const MessageLoaderUtils = {
|
|||
.collection(RS_COLLECTION_L10N)
|
||||
.getRecord(recordId);
|
||||
if (record && record.data) {
|
||||
const downloader = new Downloader(
|
||||
const downloader = new lazy.Downloader(
|
||||
RS_MAIN_BUCKET,
|
||||
RS_COLLECTION_L10N,
|
||||
"browser",
|
||||
|
@ -299,7 +303,7 @@ const MessageLoaderUtils = {
|
|||
await downloader.downloadToDisk(record.data, {
|
||||
retries: RS_DOWNLOAD_MAX_RETRIES,
|
||||
});
|
||||
RemoteL10n.reloadL10n();
|
||||
lazy.RemoteL10n.reloadL10n();
|
||||
} else {
|
||||
MessageLoaderUtils._handleRemoteSettingsUndesiredEvent(
|
||||
"ASR_RS_NO_MESSAGES",
|
||||
|
@ -327,8 +331,8 @@ const MessageLoaderUtils = {
|
|||
async _experimentsAPILoader(provider) {
|
||||
let experiments = [];
|
||||
for (const featureId of provider.messageGroups) {
|
||||
let FeatureAPI = NimbusFeatures[featureId];
|
||||
let experimentData = ExperimentAPI.getExperimentMetaData({
|
||||
let FeatureAPI = lazy.NimbusFeatures[featureId];
|
||||
let experimentData = lazy.ExperimentAPI.getExperimentMetaData({
|
||||
featureId,
|
||||
});
|
||||
// Not enrolled in any experiment for this feature, we can skip
|
||||
|
@ -350,7 +354,7 @@ const MessageLoaderUtils = {
|
|||
// those branches so that they would only used to record the Reach
|
||||
// event.
|
||||
const branches =
|
||||
(await ExperimentAPI.getAllBranches(experimentData.slug)) || [];
|
||||
(await lazy.ExperimentAPI.getAllBranches(experimentData.slug)) || [];
|
||||
for (const branch of branches) {
|
||||
let branchValue = branch[featureId].value;
|
||||
if (
|
||||
|
@ -558,11 +562,11 @@ class _ASRouter {
|
|||
}
|
||||
|
||||
async onPrefChange(prefName) {
|
||||
if (TARGETING_PREFERENCES.includes(prefName)) {
|
||||
if (lazy.TARGETING_PREFERENCES.includes(prefName)) {
|
||||
let invalidMessages = [];
|
||||
// Notify all tabs of messages that have become invalid after pref change
|
||||
const context = this._getMessagesContext();
|
||||
const targetingContext = new TargetingContext(context);
|
||||
const targetingContext = new lazy.TargetingContext(context);
|
||||
|
||||
for (const msg of this.state.messages.filter(this.isUnblockedMessage)) {
|
||||
if (!msg.targeting) {
|
||||
|
@ -597,9 +601,10 @@ class _ASRouter {
|
|||
// If we have added a `preview` provider, hold onto it
|
||||
...previousProviders.filter(p => p.id === "preview"),
|
||||
// The provider should be enabled and not have a user preference set to false
|
||||
...ASRouterPreferences.providers.filter(
|
||||
...lazy.ASRouterPreferences.providers.filter(
|
||||
p =>
|
||||
p.enabled && ASRouterPreferences.getUserPreference(p.id) !== false
|
||||
p.enabled &&
|
||||
lazy.ASRouterPreferences.getUserPreference(p.id) !== false
|
||||
),
|
||||
].map(async _provider => {
|
||||
// make a copy so we don't modify the source of the pref
|
||||
|
@ -724,7 +729,7 @@ class _ASRouter {
|
|||
// defined then at least one has to be enabled.
|
||||
(Array.isArray(group.userPreferences)
|
||||
? group.userPreferences.some(pref =>
|
||||
ASRouterPreferences.getUserPreference(pref)
|
||||
lazy.ASRouterPreferences.getUserPreference(pref)
|
||||
)
|
||||
: true),
|
||||
};
|
||||
|
@ -799,10 +804,10 @@ class _ASRouter {
|
|||
}
|
||||
|
||||
// Some messages have triggers that require us to initalise trigger listeners
|
||||
const unseenListeners = new Set(ASRouterTriggerListeners.keys());
|
||||
const unseenListeners = new Set(lazy.ASRouterTriggerListeners.keys());
|
||||
for (const { trigger } of newState.messages) {
|
||||
if (trigger && ASRouterTriggerListeners.has(trigger.id)) {
|
||||
ASRouterTriggerListeners.get(trigger.id).init(
|
||||
if (trigger && lazy.ASRouterTriggerListeners.has(trigger.id)) {
|
||||
lazy.ASRouterTriggerListeners.get(trigger.id).init(
|
||||
this._triggerHandler,
|
||||
trigger.params,
|
||||
trigger.patterns
|
||||
|
@ -813,7 +818,7 @@ class _ASRouter {
|
|||
// We don't need these listeners, but they may have previously been
|
||||
// initialised, so uninitialise them
|
||||
for (const triggerID of unseenListeners) {
|
||||
ASRouterTriggerListeners.get(triggerID).uninit();
|
||||
lazy.ASRouterTriggerListeners.get(triggerID).uninit();
|
||||
}
|
||||
|
||||
// We don't want to cache preview endpoints, remove them after messages are fetched
|
||||
|
@ -890,20 +895,20 @@ class _ASRouter {
|
|||
this.sendTelemetry = sendTelemetry;
|
||||
this.dispatchCFRAction = this.toWaitForInitFunc(dispatchCFRAction);
|
||||
|
||||
ASRouterPreferences.init();
|
||||
ASRouterPreferences.addListener(this.onPrefChange);
|
||||
ToolbarBadgeHub.init(this.waitForInitialized, {
|
||||
lazy.ASRouterPreferences.init();
|
||||
lazy.ASRouterPreferences.addListener(this.onPrefChange);
|
||||
lazy.ToolbarBadgeHub.init(this.waitForInitialized, {
|
||||
handleMessageRequest: this.handleMessageRequest,
|
||||
addImpression: this.addImpression,
|
||||
blockMessageById: this.blockMessageById,
|
||||
unblockMessageById: this.unblockMessageById,
|
||||
sendTelemetry: this.sendTelemetry,
|
||||
});
|
||||
ToolbarPanelHub.init(this.waitForInitialized, {
|
||||
lazy.ToolbarPanelHub.init(this.waitForInitialized, {
|
||||
getMessages: this.handleMessageRequest,
|
||||
sendTelemetry: this.sendTelemetry,
|
||||
});
|
||||
MomentsPageHub.init(this.waitForInitialized, {
|
||||
lazy.MomentsPageHub.init(this.waitForInitialized, {
|
||||
handleMessageRequest: this.handleMessageRequest,
|
||||
addImpression: this.addImpression,
|
||||
blockMessageById: this.blockMessageById,
|
||||
|
@ -926,14 +931,14 @@ class _ASRouter {
|
|||
groupImpressions,
|
||||
messageImpressions,
|
||||
previousSessionEnd,
|
||||
...(ASRouterPreferences.specialConditions || {}),
|
||||
...(lazy.ASRouterPreferences.specialConditions || {}),
|
||||
initialized: false,
|
||||
});
|
||||
await this._updateMessageProviders();
|
||||
await this.loadMessagesFromAllProviders();
|
||||
await MessageLoaderUtils.cleanupCache(this.state.providers, storage);
|
||||
|
||||
SpecialMessageActions.blockMessageById = this.blockMessageById;
|
||||
lazy.SpecialMessageActions.blockMessageById = this.blockMessageById;
|
||||
Services.obs.addObserver(this._onLocaleChanged, TOPIC_INTL_LOCALE_CHANGED);
|
||||
Services.obs.addObserver(
|
||||
this._onExperimentForceEnrolled,
|
||||
|
@ -954,14 +959,14 @@ class _ASRouter {
|
|||
this.sendTelemetry = null;
|
||||
this.dispatchCFRAction = null;
|
||||
|
||||
ASRouterPreferences.removeListener(this.onPrefChange);
|
||||
ASRouterPreferences.uninit();
|
||||
ToolbarPanelHub.uninit();
|
||||
ToolbarBadgeHub.uninit();
|
||||
MomentsPageHub.uninit();
|
||||
lazy.ASRouterPreferences.removeListener(this.onPrefChange);
|
||||
lazy.ASRouterPreferences.uninit();
|
||||
lazy.ToolbarPanelHub.uninit();
|
||||
lazy.ToolbarBadgeHub.uninit();
|
||||
lazy.MomentsPageHub.uninit();
|
||||
|
||||
// Uninitialise all trigger listeners
|
||||
for (const listener of ASRouterTriggerListeners.values()) {
|
||||
for (const listener of lazy.ASRouterTriggerListeners.values()) {
|
||||
listener.uninit();
|
||||
}
|
||||
Services.obs.removeObserver(
|
||||
|
@ -987,7 +992,7 @@ class _ASRouter {
|
|||
...this.state,
|
||||
...newState,
|
||||
};
|
||||
if (ASRouterPreferences.devtoolsEnabled) {
|
||||
if (lazy.ASRouterPreferences.devtoolsEnabled) {
|
||||
return this.updateTargetingParameters().then(state => {
|
||||
this.updateAdminState(state);
|
||||
return state;
|
||||
|
@ -998,12 +1003,12 @@ class _ASRouter {
|
|||
|
||||
updateTargetingParameters() {
|
||||
return this.getTargetingParameters(
|
||||
ASRouterTargeting.Environment,
|
||||
lazy.ASRouterTargeting.Environment,
|
||||
this._getMessagesContext()
|
||||
).then(targetingParameters => ({
|
||||
...this.state,
|
||||
providerPrefs: ASRouterPreferences.providers,
|
||||
userPrefs: ASRouterPreferences.getAllUserPreferences(),
|
||||
providerPrefs: lazy.ASRouterPreferences.providers,
|
||||
userPrefs: lazy.ASRouterPreferences.getAllUserPreferences(),
|
||||
targetingParameters,
|
||||
errors: this.errors,
|
||||
}));
|
||||
|
@ -1015,11 +1020,11 @@ class _ASRouter {
|
|||
|
||||
_loadLocalProviders() {
|
||||
// If we're in ASR debug mode add the local test providers
|
||||
if (ASRouterPreferences.devtoolsEnabled) {
|
||||
if (lazy.ASRouterPreferences.devtoolsEnabled) {
|
||||
this._localProviders = {
|
||||
...this._localProviders,
|
||||
SnippetsTestMessageProvider,
|
||||
PanelTestProvider,
|
||||
SnippetsTestMessageProvider: lazy.SnippetsTestMessageProvider,
|
||||
PanelTestProvider: lazy.PanelTestProvider,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1067,7 +1072,7 @@ class _ASRouter {
|
|||
}
|
||||
|
||||
async evaluateExpression({ expression, context }) {
|
||||
const targetingContext = new TargetingContext(context);
|
||||
const targetingContext = new lazy.TargetingContext(context);
|
||||
let evaluationStatus;
|
||||
try {
|
||||
evaluationStatus = {
|
||||
|
@ -1163,7 +1168,7 @@ class _ASRouter {
|
|||
switch (message.template) {
|
||||
case "whatsnew_panel_message":
|
||||
if (force) {
|
||||
ToolbarPanelHub.forceShowMessage(browser, message);
|
||||
lazy.ToolbarPanelHub.forceShowMessage(browser, message);
|
||||
}
|
||||
break;
|
||||
case "cfr_doorhanger":
|
||||
|
@ -1200,16 +1205,26 @@ class _ASRouter {
|
|||
}
|
||||
break;
|
||||
case "toolbar_badge":
|
||||
ToolbarBadgeHub.registerBadgeNotificationListener(message, { force });
|
||||
lazy.ToolbarBadgeHub.registerBadgeNotificationListener(message, {
|
||||
force,
|
||||
});
|
||||
break;
|
||||
case "update_action":
|
||||
MomentsPageHub.executeAction(message);
|
||||
lazy.MomentsPageHub.executeAction(message);
|
||||
break;
|
||||
case "infobar":
|
||||
InfoBar.showInfoBarMessage(browser, message, this.dispatchCFRAction);
|
||||
lazy.InfoBar.showInfoBarMessage(
|
||||
browser,
|
||||
message,
|
||||
this.dispatchCFRAction
|
||||
);
|
||||
break;
|
||||
case "spotlight":
|
||||
Spotlight.showSpotlightDialog(browser, message, this.dispatchCFRAction);
|
||||
lazy.Spotlight.showSpotlightDialog(
|
||||
browser,
|
||||
message,
|
||||
this.dispatchCFRAction
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1388,7 +1403,7 @@ class _ASRouter {
|
|||
|
||||
// Find a message that matches the targeting context as well as the trigger context (if one is provided)
|
||||
// If no trigger is provided, we should find a message WITHOUT a trigger property defined.
|
||||
return ASRouterTargeting.findMatchingMessage({
|
||||
return lazy.ASRouterTargeting.findMatchingMessage({
|
||||
messages,
|
||||
trigger: triggerId && {
|
||||
id: triggerId,
|
||||
|
@ -1542,7 +1557,7 @@ class _ASRouter {
|
|||
// To be passed to ASRouterTriggerListeners
|
||||
_triggerHandler(browser, trigger) {
|
||||
// Disable ASRouterTriggerListeners in kiosk mode.
|
||||
if (BrowserHandler.kiosk) {
|
||||
if (lazy.BrowserHandler.kiosk) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this.sendTriggerMessage({ ...trigger, browser });
|
||||
|
@ -1592,7 +1607,7 @@ class _ASRouter {
|
|||
encodeURIComponent(attributionData)
|
||||
);
|
||||
} else if (AppConstants.platform === "macosx") {
|
||||
let appPath = MacAttribution.applicationPath;
|
||||
let appPath = lazy.MacAttribution.applicationPath;
|
||||
let attributionSvc = Cc["@mozilla.org/mac-attribution;1"].getService(
|
||||
Ci.nsIMacAttributionService
|
||||
);
|
||||
|
@ -1738,7 +1753,7 @@ class _ASRouter {
|
|||
};
|
||||
let feature = featureMap[nonReachMessages[0].template];
|
||||
if (feature) {
|
||||
NimbusFeatures[feature].recordExposureEvent({ once: true });
|
||||
lazy.NimbusFeatures[feature].recordExposureEvent({ once: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1752,7 +1767,7 @@ class _ASRouter {
|
|||
|
||||
async forceWNPanel(browser) {
|
||||
let win = browser.ownerGlobal;
|
||||
await ToolbarPanelHub.enableToolbarButton();
|
||||
await lazy.ToolbarPanelHub.enableToolbarButton();
|
||||
|
||||
win.PanelUI.showSubView(
|
||||
"PanelUI-whatsNew",
|
||||
|
@ -1770,7 +1785,7 @@ class _ASRouter {
|
|||
// Set the attribute to allow the panel to close
|
||||
panel.setAttribute("noautohide", false);
|
||||
// Removing the button is enough to close the panel.
|
||||
await ToolbarPanelHub._hideToolbarButton(win);
|
||||
await lazy.ToolbarPanelHub._hideToolbarButton(win);
|
||||
}
|
||||
|
||||
async _onExperimentForceEnrolled(subject, topic, data) {
|
||||
|
|
|
@ -14,7 +14,9 @@ const { AppConstants } = ChromeUtils.import(
|
|||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
ASRouterPreferences: "resource://activity-stream/lib/ASRouterPreferences.jsm",
|
||||
AddonManager: "resource://gre/modules/AddonManager.jsm",
|
||||
ClientEnvironment: "resource://normandy/lib/ClientEnvironment.jsm",
|
||||
|
@ -31,80 +33,80 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "fxAccounts", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccounts.jsm"
|
||||
).getFxAccountsSingleton();
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"cfrFeaturesUserPref",
|
||||
"browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features",
|
||||
true
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"cfrAddonsUserPref",
|
||||
"browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons",
|
||||
true
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"isWhatsNewPanelEnabled",
|
||||
"browser.messaging-system.whatsNewPanel.enabled",
|
||||
false
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"hasAccessedFxAPanel",
|
||||
"identity.fxaccounts.toolbar.accessed",
|
||||
false
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"clientsDevicesDesktop",
|
||||
"services.sync.clients.devices.desktop",
|
||||
0
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"clientsDevicesMobile",
|
||||
"services.sync.clients.devices.mobile",
|
||||
0
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"syncNumClients",
|
||||
"services.sync.numClients",
|
||||
0
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"devtoolsSelfXSSCount",
|
||||
"devtools.selfxss.count",
|
||||
0
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"isFxAEnabled",
|
||||
FXA_ENABLED_PREF,
|
||||
true
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"isXPIInstallEnabled",
|
||||
"xpinstall.enabled",
|
||||
true
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"snippetsUserPref",
|
||||
"browser.newtabpage.activity-stream.feeds.snippets",
|
||||
false
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetters(this, {
|
||||
XPCOMUtils.defineLazyServiceGetters(lazy, {
|
||||
BrowserHandler: ["@mozilla.org/browser/clh;1", "nsIBrowserHandler"],
|
||||
TrackingDBService: [
|
||||
"@mozilla.org/tracking-db-service;1",
|
||||
|
@ -114,7 +116,7 @@ XPCOMUtils.defineLazyServiceGetters(this, {
|
|||
|
||||
const FXA_USERNAME_PREF = "services.sync.username";
|
||||
|
||||
const { activityStreamProvider: asProvider } = NewTabUtils;
|
||||
const { activityStreamProvider: asProvider } = lazy.NewTabUtils;
|
||||
|
||||
const FXA_ATTACHED_CLIENTS_UPDATE_INTERVAL = 4 * 60 * 60 * 1000; // Four hours
|
||||
const FRECENT_SITES_UPDATE_INTERVAL = 6 * 60 * 60 * 1000; // Six hours
|
||||
|
@ -168,7 +170,7 @@ function CacheListAttachedOAuthClients() {
|
|||
const now = Date.now();
|
||||
if (now - this._lastUpdated >= FXA_ATTACHED_CLIENTS_UPDATE_INTERVAL) {
|
||||
this._value = new Promise(resolve => {
|
||||
fxAccounts
|
||||
lazy.fxAccounts
|
||||
.listAttachedOAuthClients()
|
||||
.then(clients => {
|
||||
resolve(clients);
|
||||
|
@ -263,7 +265,7 @@ const QueryCache = {
|
|||
"doesAppNeedPin",
|
||||
null,
|
||||
FRECENT_SITES_UPDATE_INTERVAL,
|
||||
ShellService
|
||||
lazy.ShellService
|
||||
),
|
||||
},
|
||||
};
|
||||
|
@ -401,43 +403,43 @@ const TargetingGetters = {
|
|||
);
|
||||
},
|
||||
get browserSettings() {
|
||||
const { settings } = TelemetryEnvironment.currentEnvironment;
|
||||
const { settings } = lazy.TelemetryEnvironment.currentEnvironment;
|
||||
return {
|
||||
update: settings.update,
|
||||
};
|
||||
},
|
||||
get attributionData() {
|
||||
// Attribution is determined at startup - so we can use the cached attribution at this point
|
||||
return AttributionCode.getCachedAttributionData();
|
||||
return lazy.AttributionCode.getCachedAttributionData();
|
||||
},
|
||||
get currentDate() {
|
||||
return new Date();
|
||||
},
|
||||
get profileAgeCreated() {
|
||||
return ProfileAge().then(times => times.created);
|
||||
return lazy.ProfileAge().then(times => times.created);
|
||||
},
|
||||
get profileAgeReset() {
|
||||
return ProfileAge().then(times => times.reset);
|
||||
return lazy.ProfileAge().then(times => times.reset);
|
||||
},
|
||||
get usesFirefoxSync() {
|
||||
return Services.prefs.prefHasUserValue(FXA_USERNAME_PREF);
|
||||
},
|
||||
get isFxAEnabled() {
|
||||
return isFxAEnabled;
|
||||
return lazy.isFxAEnabled;
|
||||
},
|
||||
get sync() {
|
||||
return {
|
||||
desktopDevices: clientsDevicesDesktop,
|
||||
mobileDevices: clientsDevicesMobile,
|
||||
totalDevices: syncNumClients,
|
||||
desktopDevices: lazy.clientsDevicesDesktop,
|
||||
mobileDevices: lazy.clientsDevicesMobile,
|
||||
totalDevices: lazy.syncNumClients,
|
||||
};
|
||||
},
|
||||
get xpinstallEnabled() {
|
||||
// This is needed for all add-on recommendations, to know if we allow xpi installs in the first place
|
||||
return isXPIInstallEnabled;
|
||||
return lazy.isXPIInstallEnabled;
|
||||
},
|
||||
get addonsInfo() {
|
||||
return AddonManager.getActiveAddons(["extension", "service"]).then(
|
||||
return lazy.AddonManager.getActiveAddons(["extension", "service"]).then(
|
||||
({ addons, fullData }) => {
|
||||
const info = {};
|
||||
for (const addon of addons) {
|
||||
|
@ -475,12 +477,12 @@ const TargetingGetters = {
|
|||
},
|
||||
get isDefaultBrowser() {
|
||||
try {
|
||||
return ShellService.isDefaultBrowser();
|
||||
return lazy.ShellService.isDefaultBrowser();
|
||||
} catch (e) {}
|
||||
return null;
|
||||
},
|
||||
get devToolsOpenedCount() {
|
||||
return devtoolsSelfXSSCount;
|
||||
return lazy.devtoolsSelfXSSCount;
|
||||
},
|
||||
get topFrecentSites() {
|
||||
return QueryCache.queries.TopFrecentSites.get().then(sites =>
|
||||
|
@ -496,7 +498,7 @@ const TargetingGetters = {
|
|||
return QueryCache.queries.RecentBookmarks.get();
|
||||
},
|
||||
get pinnedSites() {
|
||||
return NewTabUtils.pinnedLinks.links.map(site =>
|
||||
return lazy.NewTabUtils.pinnedLinks.links.map(site =>
|
||||
site
|
||||
? {
|
||||
url: site.url,
|
||||
|
@ -507,7 +509,7 @@ const TargetingGetters = {
|
|||
);
|
||||
},
|
||||
get providerCohorts() {
|
||||
return ASRouterPreferences.providers.reduce((prev, current) => {
|
||||
return lazy.ASRouterPreferences.providers.reduce((prev, current) => {
|
||||
prev[current.id] = current.cohort || "";
|
||||
return prev;
|
||||
}, {});
|
||||
|
@ -519,7 +521,7 @@ const TargetingGetters = {
|
|||
return parseInt(AppConstants.MOZ_APP_VERSION.match(/\d+/), 10);
|
||||
},
|
||||
get region() {
|
||||
return Region.home || "";
|
||||
return lazy.Region.home || "";
|
||||
},
|
||||
get needsUpdate() {
|
||||
return QueryCache.queries.CheckBrowserNeedsUpdate.get();
|
||||
|
@ -537,20 +539,20 @@ const TargetingGetters = {
|
|||
return false;
|
||||
},
|
||||
get hasAccessedFxAPanel() {
|
||||
return hasAccessedFxAPanel;
|
||||
return lazy.hasAccessedFxAPanel;
|
||||
},
|
||||
get isWhatsNewPanelEnabled() {
|
||||
return isWhatsNewPanelEnabled;
|
||||
return lazy.isWhatsNewPanelEnabled;
|
||||
},
|
||||
get userPrefs() {
|
||||
return {
|
||||
cfrFeatures: cfrFeaturesUserPref,
|
||||
cfrAddons: cfrAddonsUserPref,
|
||||
snippets: snippetsUserPref,
|
||||
cfrFeatures: lazy.cfrFeaturesUserPref,
|
||||
cfrAddons: lazy.cfrAddonsUserPref,
|
||||
snippets: lazy.snippetsUserPref,
|
||||
};
|
||||
},
|
||||
get totalBlockedCount() {
|
||||
return TrackingDBService.sumAllEvents();
|
||||
return lazy.TrackingDBService.sumAllEvents();
|
||||
},
|
||||
get blockedCountByType() {
|
||||
const idToTextMap = new Map([
|
||||
|
@ -563,7 +565,7 @@ const TargetingGetters = {
|
|||
|
||||
const dateTo = new Date();
|
||||
const dateFrom = new Date(dateTo.getTime() - 42 * 24 * 60 * 60 * 1000);
|
||||
return TrackingDBService.getEventsByDateRange(dateFrom, dateTo).then(
|
||||
return lazy.TrackingDBService.getEventsByDateRange(dateFrom, dateTo).then(
|
||||
eventsByDate => {
|
||||
let totalEvents = {};
|
||||
for (let blockedType of idToTextMap.values()) {
|
||||
|
@ -596,35 +598,36 @@ const TargetingGetters = {
|
|||
);
|
||||
},
|
||||
get userId() {
|
||||
return ClientEnvironment.userId;
|
||||
return lazy.ClientEnvironment.userId;
|
||||
},
|
||||
get profileRestartCount() {
|
||||
// Counter starts at 1 when a profile is created, substract 1 so the value
|
||||
// returned matches expectations
|
||||
return (
|
||||
TelemetrySession.getMetadata("targeting").profileSubsessionCounter - 1
|
||||
lazy.TelemetrySession.getMetadata("targeting").profileSubsessionCounter -
|
||||
1
|
||||
);
|
||||
},
|
||||
get homePageSettings() {
|
||||
const url = HomePage.get();
|
||||
const url = lazy.HomePage.get();
|
||||
const { isWebExt, isCustomUrl, urls } = parseAboutPageURL(url);
|
||||
|
||||
return {
|
||||
isWebExt,
|
||||
isCustomUrl,
|
||||
urls,
|
||||
isDefault: HomePage.isDefault,
|
||||
isLocked: HomePage.locked,
|
||||
isDefault: lazy.HomePage.isDefault,
|
||||
isLocked: lazy.HomePage.locked,
|
||||
};
|
||||
},
|
||||
get newtabSettings() {
|
||||
const url = AboutNewTab.newTabURL;
|
||||
const url = lazy.AboutNewTab.newTabURL;
|
||||
const { isWebExt, isCustomUrl, urls } = parseAboutPageURL(url);
|
||||
|
||||
return {
|
||||
isWebExt,
|
||||
isCustomUrl,
|
||||
isDefault: AboutNewTab.activityStreamEnabled,
|
||||
isDefault: lazy.AboutNewTab.activityStreamEnabled,
|
||||
url: urls[0].url,
|
||||
host: urls[0].host,
|
||||
};
|
||||
|
@ -636,7 +639,7 @@ const TargetingGetters = {
|
|||
);
|
||||
},
|
||||
get activeNotifications() {
|
||||
let window = BrowserWindowTracker.getTopWindow();
|
||||
let window = lazy.BrowserWindowTracker.getTopWindow();
|
||||
|
||||
// Technically this doesn't mean we have active notifications,
|
||||
// but because we use !activeNotifications to check for conflicts, this should return true
|
||||
|
@ -656,7 +659,7 @@ const TargetingGetters = {
|
|||
},
|
||||
|
||||
get isMajorUpgrade() {
|
||||
return BrowserHandler.majorUpgrade;
|
||||
return lazy.BrowserHandler.majorUpgrade;
|
||||
},
|
||||
|
||||
get hasActiveEnterprisePolicies() {
|
||||
|
@ -817,8 +820,8 @@ const ASRouterTargeting = {
|
|||
}) {
|
||||
const sortedMessages = getSortedMessages(messages, { ordered });
|
||||
const matching = returnAll ? [] : null;
|
||||
const targetingContext = new TargetingContext(
|
||||
TargetingContext.combineContexts(
|
||||
const targetingContext = new lazy.TargetingContext(
|
||||
lazy.TargetingContext.combineContexts(
|
||||
context,
|
||||
this.Environment,
|
||||
trigger.context || {}
|
||||
|
|
|
@ -8,7 +8,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
AboutReaderParent: "resource:///actors/AboutReaderParent.jsm",
|
||||
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
|
||||
EveryWindow: "resource:///modules/EveryWindow.jsm",
|
||||
|
@ -21,7 +23,7 @@ function isPrivateWindow(win) {
|
|||
return (
|
||||
!(win instanceof Ci.nsIDOMWindow) ||
|
||||
win.closed ||
|
||||
PrivateBrowsingUtils.isWindowPrivate(win)
|
||||
lazy.PrivateBrowsingUtils.isWindowPrivate(win)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -100,7 +102,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
init(triggerHandler, hosts, patterns) {
|
||||
if (!this._initialized) {
|
||||
this.receiveMessage = this.receiveMessage.bind(this);
|
||||
AboutReaderParent.addMessageListener(this.readerModeEvent, this);
|
||||
lazy.AboutReaderParent.addMessageListener(this.readerModeEvent, this);
|
||||
this._triggerHandler = triggerHandler;
|
||||
this._initialized = true;
|
||||
}
|
||||
|
@ -129,7 +131,10 @@ const ASRouterTriggerListeners = new Map([
|
|||
|
||||
uninit() {
|
||||
if (this._initialized) {
|
||||
AboutReaderParent.removeMessageListener(this.readerModeEvent, this);
|
||||
lazy.AboutReaderParent.removeMessageListener(
|
||||
this.readerModeEvent,
|
||||
this
|
||||
);
|
||||
this._initialized = false;
|
||||
this._triggerHandler = null;
|
||||
this._hosts = new Set();
|
||||
|
@ -189,7 +194,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
init(triggerHandler, hosts = [], patterns) {
|
||||
if (!this._initialized) {
|
||||
this.onTabSwitch = this.onTabSwitch.bind(this);
|
||||
EveryWindow.registerCallback(
|
||||
lazy.EveryWindow.registerCallback(
|
||||
this.id,
|
||||
win => {
|
||||
if (!isPrivateWindow(win)) {
|
||||
|
@ -299,7 +304,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
|
||||
uninit() {
|
||||
if (this._initialized) {
|
||||
EveryWindow.unregisterCallback(this.id);
|
||||
lazy.EveryWindow.unregisterCallback(this.id);
|
||||
|
||||
this._initialized = false;
|
||||
this._triggerHandler = null;
|
||||
|
@ -333,7 +338,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
init(triggerHandler, hosts = [], patterns) {
|
||||
if (!this._initialized) {
|
||||
this.onLocationChange = this.onLocationChange.bind(this);
|
||||
EveryWindow.registerCallback(
|
||||
lazy.EveryWindow.registerCallback(
|
||||
this.id,
|
||||
win => {
|
||||
if (!isPrivateWindow(win)) {
|
||||
|
@ -368,7 +373,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
|
||||
uninit() {
|
||||
if (this._initialized) {
|
||||
EveryWindow.unregisterCallback(this.id);
|
||||
lazy.EveryWindow.unregisterCallback(this.id);
|
||||
|
||||
this._initialized = false;
|
||||
this._triggerHandler = null;
|
||||
|
@ -488,7 +493,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
"SiteProtection:ContentBlockingMilestone"
|
||||
);
|
||||
this.onLocationChange = this._onLocationChange.bind(this);
|
||||
EveryWindow.registerCallback(
|
||||
lazy.EveryWindow.registerCallback(
|
||||
this.id,
|
||||
win => {
|
||||
if (!isPrivateWindow(win)) {
|
||||
|
@ -517,7 +522,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
this,
|
||||
"SiteProtection:ContentBlockingMilestone"
|
||||
);
|
||||
EveryWindow.unregisterCallback(this.id);
|
||||
lazy.EveryWindow.unregisterCallback(this.id);
|
||||
this.onLocationChange = null;
|
||||
this._initialized = false;
|
||||
}
|
||||
|
@ -595,7 +600,7 @@ const ASRouterTriggerListeners = new Map([
|
|||
_triggerHandler: null,
|
||||
|
||||
_shouldShowCaptivePortalVPNPromo() {
|
||||
return BrowserUtils.shouldShowVPNPromo();
|
||||
return lazy.BrowserUtils.shouldShowVPNPromo();
|
||||
},
|
||||
|
||||
init(triggerHandler) {
|
||||
|
|
|
@ -14,7 +14,9 @@ const { actionTypes: at, actionCreators: ac } = ChromeUtils.import(
|
|||
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
const PREFERENCES_LOADED_EVENT = "home-pane-loaded";
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
});
|
||||
|
||||
|
@ -130,7 +132,7 @@ class AboutPreferences {
|
|||
sections = this.handleDiscoverySettings(sections);
|
||||
}
|
||||
|
||||
const featureConfig = NimbusFeatures.newtab.getAllVariables() || {};
|
||||
const featureConfig = lazy.NimbusFeatures.newtab.getAllVariables() || {};
|
||||
|
||||
this.renderPreferences(window, [
|
||||
...PREFS_BEFORE_SECTIONS(featureConfig),
|
||||
|
|
|
@ -9,14 +9,16 @@ const { AppConstants } = ChromeUtils.import(
|
|||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"DEFAULT_SITES",
|
||||
"resource://activity-stream/lib/DefaultSites.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Region",
|
||||
"resource://gre/modules/Region.jsm"
|
||||
);
|
||||
|
@ -27,77 +29,77 @@ const { actionCreators: ac, actionTypes: at } = ChromeUtils.import(
|
|||
"resource://activity-stream/common/Actions.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AboutPreferences",
|
||||
"resource://activity-stream/lib/AboutPreferences.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"DefaultPrefs",
|
||||
"resource://activity-stream/lib/ActivityStreamPrefs.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NewTabInit",
|
||||
"resource://activity-stream/lib/NewTabInit.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"SectionsFeed",
|
||||
"resource://activity-stream/lib/SectionsManager.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"RecommendationProvider",
|
||||
"resource://activity-stream/lib/RecommendationProvider.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PlacesFeed",
|
||||
"resource://activity-stream/lib/PlacesFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PrefsFeed",
|
||||
"resource://activity-stream/lib/PrefsFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Store",
|
||||
"resource://activity-stream/lib/Store.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"SystemTickFeed",
|
||||
"resource://activity-stream/lib/SystemTickFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"TelemetryFeed",
|
||||
"resource://activity-stream/lib/TelemetryFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"FaviconFeed",
|
||||
"resource://activity-stream/lib/FaviconFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"TopSitesFeed",
|
||||
"resource://activity-stream/lib/TopSitesFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"TopStoriesFeed",
|
||||
"resource://activity-stream/lib/TopStoriesFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"HighlightsFeed",
|
||||
"resource://activity-stream/lib/HighlightsFeed.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"DiscoveryStreamFeed",
|
||||
"resource://activity-stream/lib/DiscoveryStreamFeed.jsm"
|
||||
);
|
||||
|
@ -130,7 +132,7 @@ const PREFS_CONFIG = new Map([
|
|||
title:
|
||||
"Comma-separated list of default top sites to fill in behind visited sites",
|
||||
getValue: ({ geo }) =>
|
||||
DEFAULT_SITES.get(DEFAULT_SITES.has(geo) ? geo : ""),
|
||||
lazy.DEFAULT_SITES.get(lazy.DEFAULT_SITES.has(geo) ? geo : ""),
|
||||
},
|
||||
],
|
||||
[
|
||||
|
@ -460,44 +462,44 @@ const PREFS_CONFIG = new Map([
|
|||
const FEEDS_DATA = [
|
||||
{
|
||||
name: "aboutpreferences",
|
||||
factory: () => new AboutPreferences(),
|
||||
factory: () => new lazy.AboutPreferences(),
|
||||
title: "about:preferences rendering",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "newtabinit",
|
||||
factory: () => new NewTabInit(),
|
||||
factory: () => new lazy.NewTabInit(),
|
||||
title: "Sends a copy of the state to each new tab that is opened",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "places",
|
||||
factory: () => new PlacesFeed(),
|
||||
factory: () => new lazy.PlacesFeed(),
|
||||
title: "Listens for and relays various Places-related events",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "prefs",
|
||||
factory: () => new PrefsFeed(PREFS_CONFIG),
|
||||
factory: () => new lazy.PrefsFeed(PREFS_CONFIG),
|
||||
title: "Preferences",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "sections",
|
||||
factory: () => new SectionsFeed(),
|
||||
factory: () => new lazy.SectionsFeed(),
|
||||
title: "Manages sections",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "section.highlights",
|
||||
factory: () => new HighlightsFeed(),
|
||||
factory: () => new lazy.HighlightsFeed(),
|
||||
title: "Fetches content recommendations from places db",
|
||||
value: false,
|
||||
},
|
||||
{
|
||||
name: "system.topstories",
|
||||
factory: () =>
|
||||
new TopStoriesFeed(PREFS_CONFIG.get("discoverystream.config")),
|
||||
new lazy.TopStoriesFeed(PREFS_CONFIG.get("discoverystream.config")),
|
||||
title:
|
||||
"System pref that fetches content recommendations from a configurable content provider",
|
||||
// Dynamically determine if Pocket should be shown for a geo / locale
|
||||
|
@ -549,37 +551,37 @@ const FEEDS_DATA = [
|
|||
},
|
||||
{
|
||||
name: "systemtick",
|
||||
factory: () => new SystemTickFeed(),
|
||||
factory: () => new lazy.SystemTickFeed(),
|
||||
title: "Produces system tick events to periodically check for data expiry",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "telemetry",
|
||||
factory: () => new TelemetryFeed(),
|
||||
factory: () => new lazy.TelemetryFeed(),
|
||||
title: "Relays telemetry-related actions to PingCentre",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "favicon",
|
||||
factory: () => new FaviconFeed(),
|
||||
factory: () => new lazy.FaviconFeed(),
|
||||
title: "Fetches tippy top manifests from remote service",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "system.topsites",
|
||||
factory: () => new TopSitesFeed(),
|
||||
factory: () => new lazy.TopSitesFeed(),
|
||||
title: "Queries places and gets metadata for Top Sites section",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "recommendationprovider",
|
||||
factory: () => new RecommendationProvider(),
|
||||
factory: () => new lazy.RecommendationProvider(),
|
||||
title: "Handles setup and interaction for the personality provider",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "discoverystreamfeed",
|
||||
factory: () => new DiscoveryStreamFeed(),
|
||||
factory: () => new lazy.DiscoveryStreamFeed(),
|
||||
title: "Handles new pocket ui for the new tab page",
|
||||
value: true,
|
||||
},
|
||||
|
@ -598,9 +600,9 @@ class ActivityStream {
|
|||
*/
|
||||
constructor() {
|
||||
this.initialized = false;
|
||||
this.store = new Store();
|
||||
this.store = new lazy.Store();
|
||||
this.feeds = FEEDS_CONFIG;
|
||||
this._defaultPrefs = new DefaultPrefs(PREFS_CONFIG);
|
||||
this._defaultPrefs = new lazy.DefaultPrefs(PREFS_CONFIG);
|
||||
}
|
||||
|
||||
init() {
|
||||
|
@ -691,7 +693,7 @@ class ActivityStream {
|
|||
|
||||
uninit() {
|
||||
if (this.geo === "") {
|
||||
Services.obs.removeObserver(this, Region.REGION_TOPIC);
|
||||
Services.obs.removeObserver(this, lazy.Region.REGION_TOPIC);
|
||||
}
|
||||
|
||||
Services.obs.removeObserver(this, "intl:app-locales-changed");
|
||||
|
@ -702,11 +704,11 @@ class ActivityStream {
|
|||
|
||||
_updateDynamicPrefs() {
|
||||
// Save the geo pref if we have it
|
||||
if (Region.home) {
|
||||
this.geo = Region.home;
|
||||
if (lazy.Region.home) {
|
||||
this.geo = lazy.Region.home;
|
||||
} else if (this.geo !== "") {
|
||||
// Watch for geo changes and use a dummy value for now
|
||||
Services.obs.addObserver(this, Region.REGION_TOPIC);
|
||||
Services.obs.addObserver(this, lazy.Region.REGION_TOPIC);
|
||||
this.geo = "";
|
||||
}
|
||||
|
||||
|
@ -751,7 +753,7 @@ class ActivityStream {
|
|||
observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "intl:app-locales-changed":
|
||||
case Region.REGION_TOPIC:
|
||||
case lazy.Region.REGION_TOPIC:
|
||||
this._updateDynamicPrefs();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -4,16 +4,18 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
// TODO delete this?
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AboutNewTab",
|
||||
"resource:///modules/AboutNewTab.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AboutHomeStartupCache",
|
||||
"resource:///modules/BrowserGlue.jsm"
|
||||
);
|
||||
|
@ -116,7 +118,7 @@ class ActivityStreamMessageChannel {
|
|||
broadcast(action) {
|
||||
// We're trying to update all tabs, so signal the AboutHomeStartupCache
|
||||
// that its likely time to refresh the cache.
|
||||
AboutHomeStartupCache.onPreloadedNewTabMessage();
|
||||
lazy.AboutHomeStartupCache.onPreloadedNewTabMessage();
|
||||
|
||||
this.channel.sendAsyncMessage(this.outgoingMessageName, action);
|
||||
}
|
||||
|
@ -173,7 +175,7 @@ class ActivityStreamMessageChannel {
|
|||
// We're trying to update the preloaded about:newtab, so signal
|
||||
// the AboutHomeStartupCache that its likely time to refresh
|
||||
// the cache.
|
||||
AboutHomeStartupCache.onPreloadedNewTabMessage();
|
||||
lazy.AboutHomeStartupCache.onPreloadedNewTabMessage();
|
||||
|
||||
const preloadedBrowsers = this.getPreloadedBrowser();
|
||||
if (preloadedBrowsers && action.data) {
|
||||
|
@ -223,7 +225,7 @@ class ActivityStreamMessageChannel {
|
|||
// Receive AboutNewTab's Remote Pages instance, if it exists, on override
|
||||
const channel =
|
||||
this.pageURL === ABOUT_NEW_TAB_URL &&
|
||||
AboutNewTab.overridePageListener(true);
|
||||
lazy.AboutNewTab.overridePageListener(true);
|
||||
this.channel =
|
||||
channel || new RemotePages([ABOUT_HOME_URL, ABOUT_NEW_TAB_URL]);
|
||||
this.channel.addMessageListener("RemotePage:Init", this.onNewTabInit);
|
||||
|
@ -260,7 +262,7 @@ class ActivityStreamMessageChannel {
|
|||
this.onMessage
|
||||
);
|
||||
if (this.pageURL === ABOUT_NEW_TAB_URL) {
|
||||
AboutNewTab.reset(this.channel);
|
||||
lazy.AboutNewTab.reset(this.channel);
|
||||
} else {
|
||||
this.channel.destroy();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
const lazy = {};
|
||||
/* 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/. */
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"IndexedDB",
|
||||
"resource://gre/modules/IndexedDB.jsm"
|
||||
);
|
||||
|
@ -68,7 +69,7 @@ class ActivityStreamStorage {
|
|||
}
|
||||
|
||||
_openDatabase() {
|
||||
return IndexedDB.open(this.dbName, { version: this.dbVersion }, db => {
|
||||
return lazy.IndexedDB.open(this.dbName, { version: this.dbVersion }, db => {
|
||||
// If provided with array of objectStore names we need to create all the
|
||||
// individual stores
|
||||
this.storeNames.forEach(store => {
|
||||
|
@ -94,7 +95,7 @@ class ActivityStreamStorage {
|
|||
if (this.telemetry) {
|
||||
this.telemetry.handleUndesiredEvent({ event: "INDEXEDDB_OPEN_FAILED" });
|
||||
}
|
||||
await IndexedDB.deleteDatabase(this.dbName);
|
||||
await lazy.IndexedDB.deleteDatabase(this.dbName);
|
||||
return this._openDatabase();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,21 +8,23 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
RemoteL10n: "resource://activity-stream/lib/RemoteL10n.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"TrackingDBService",
|
||||
"@mozilla.org/tracking-db-service;1",
|
||||
"nsITrackingDBService"
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"milestones",
|
||||
"browser.contentblocking.cfr-milestone.milestones",
|
||||
"[]",
|
||||
|
@ -115,7 +117,7 @@ class PageAction {
|
|||
}
|
||||
|
||||
reloadL10n() {
|
||||
RemoteL10n.reloadL10n();
|
||||
lazy.RemoteL10n.reloadL10n();
|
||||
}
|
||||
|
||||
async showAddressBarNotifier(recommendation, shouldExpand = false) {
|
||||
|
@ -328,7 +330,7 @@ class PageAction {
|
|||
return string;
|
||||
}
|
||||
|
||||
const [localeStrings] = await RemoteL10n.l10n.formatMessages([
|
||||
const [localeStrings] = await lazy.RemoteL10n.l10n.formatMessages([
|
||||
{
|
||||
id: string.string_id,
|
||||
args: string.args,
|
||||
|
@ -428,15 +430,15 @@ class PageAction {
|
|||
|
||||
let { content, id } = message;
|
||||
let { primary, secondary } = content.buttons;
|
||||
let earliestDate = await TrackingDBService.getEarliestRecordedDate();
|
||||
let earliestDate = await lazy.TrackingDBService.getEarliestRecordedDate();
|
||||
let timestamp = new Date().getTime(earliestDate);
|
||||
let panelTitle = "";
|
||||
let headerLabel = this.window.document.getElementById(
|
||||
"cfr-notification-header-label"
|
||||
);
|
||||
let reachedMilestone = 0;
|
||||
let totalSaved = await TrackingDBService.sumAllEvents();
|
||||
for (let milestone of milestones) {
|
||||
let totalSaved = await lazy.TrackingDBService.sumAllEvents();
|
||||
for (let milestone of lazy.milestones) {
|
||||
if (totalSaved >= milestone) {
|
||||
reachedMilestone = milestone;
|
||||
}
|
||||
|
@ -445,7 +447,7 @@ class PageAction {
|
|||
headerLabel.firstChild.remove();
|
||||
}
|
||||
headerLabel.appendChild(
|
||||
RemoteL10n.createElement(this.window.document, "span", {
|
||||
lazy.RemoteL10n.createElement(this.window.document, "span", {
|
||||
content: message.content.heading_text,
|
||||
attributes: {
|
||||
blockedCount: reachedMilestone,
|
||||
|
@ -588,7 +590,7 @@ class PageAction {
|
|||
author.firstChild.remove();
|
||||
}
|
||||
author.appendChild(
|
||||
RemoteL10n.createElement(this.window.document, "span", {
|
||||
lazy.RemoteL10n.createElement(this.window.document, "span", {
|
||||
content: content.text,
|
||||
})
|
||||
);
|
||||
|
@ -631,7 +633,7 @@ class PageAction {
|
|||
}
|
||||
// Main body content of the dropdown
|
||||
footerText.appendChild(
|
||||
RemoteL10n.createElement(this.window.document, "span", {
|
||||
lazy.RemoteL10n.createElement(this.window.document, "span", {
|
||||
content: content.text,
|
||||
})
|
||||
);
|
||||
|
@ -879,7 +881,7 @@ const CFRPageActions = {
|
|||
async _fetchLatestAddonVersion(id) {
|
||||
let url = null;
|
||||
try {
|
||||
const response = await fetch(`${ADDONS_API_URL}/${id}/`, {
|
||||
const response = await lazy.fetch(`${ADDONS_API_URL}/${id}/`, {
|
||||
credentials: "omit",
|
||||
});
|
||||
if (response.status !== 204 && response.ok) {
|
||||
|
@ -938,7 +940,7 @@ const CFRPageActions = {
|
|||
*/
|
||||
async addRecommendation(browser, host, recommendation, dispatchCFRAction) {
|
||||
const win = browser.ownerGlobal;
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
if (lazy.PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
const lazy = {};
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"RemoteSettings",
|
||||
"resource://services-settings/remote-settings.js"
|
||||
);
|
||||
|
@ -20,17 +21,17 @@ const { setTimeout, clearTimeout } = ChromeUtils.import(
|
|||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
const { actionTypes: at, actionCreators: ac } = ChromeUtils.import(
|
||||
"resource://activity-stream/common/Actions.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Region",
|
||||
"resource://gre/modules/Region.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PersistentCache",
|
||||
"resource://activity-stream/lib/PersistentCache.jsm"
|
||||
);
|
||||
|
@ -75,7 +76,7 @@ class DiscoveryStreamFeed {
|
|||
this.loaded = false;
|
||||
|
||||
// Persistent cache for remote endpoint data.
|
||||
this.cache = new PersistentCache(CACHE_KEY, true);
|
||||
this.cache = new lazy.PersistentCache(CACHE_KEY, true);
|
||||
this.locale = Services.locale.appLocaleAsBCP47;
|
||||
this._impressionId = this.getOrCreateImpressionId();
|
||||
// Internal in-memory cache for parsing json prefs.
|
||||
|
@ -143,7 +144,7 @@ class DiscoveryStreamFeed {
|
|||
}
|
||||
|
||||
get region() {
|
||||
return Region.home;
|
||||
return lazy.Region.home;
|
||||
}
|
||||
|
||||
get showSpocs() {
|
||||
|
@ -260,7 +261,7 @@ class DiscoveryStreamFeed {
|
|||
const controller = new AbortController();
|
||||
const { signal } = controller;
|
||||
|
||||
const fetchPromise = fetch(endpoint, {
|
||||
const fetchPromise = lazy.fetch(endpoint, {
|
||||
...options,
|
||||
credentials: "omit",
|
||||
signal,
|
||||
|
@ -1088,7 +1089,7 @@ class DiscoveryStreamFeed {
|
|||
let flights = this.readDataPref(PREF_FLIGHT_BLOCKS);
|
||||
const filteredItems = data.filter(item => {
|
||||
const blocked =
|
||||
NewTabUtils.blockedLinks.isBlocked({ url: item.url }) ||
|
||||
lazy.NewTabUtils.blockedLinks.isBlocked({ url: item.url }) ||
|
||||
flights[item.flight_id];
|
||||
return !blocked;
|
||||
});
|
||||
|
@ -1692,7 +1693,7 @@ class DiscoveryStreamFeed {
|
|||
Services.obs.notifyObservers(null, "idle-daily");
|
||||
break;
|
||||
case at.DISCOVERY_STREAM_DEV_SYNC_RS:
|
||||
RemoteSettings.pollChanges();
|
||||
lazy.RemoteSettings.pollChanges();
|
||||
break;
|
||||
case at.DISCOVERY_STREAM_DEV_EXPIRE_CACHE:
|
||||
// Personalization scores update at a slower interval than content, so in order to debug,
|
||||
|
|
|
@ -9,7 +9,9 @@ const { actionTypes: at } = ChromeUtils.import(
|
|||
"resource://activity-stream/common/Actions.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
DownloadsCommon: "resource:///modules/DownloadsCommon.jsm",
|
||||
DownloadsViewUI: "resource:///modules/DownloadsViewUI.jsm",
|
||||
FileUtils: "resource://gre/modules/FileUtils.jsm",
|
||||
|
@ -38,10 +40,10 @@ class DownloadsManager {
|
|||
hostname: new URL(download.source.url).hostname,
|
||||
url: download.source.url,
|
||||
path: download.target.path,
|
||||
title: DownloadsViewUI.getDisplayName(download),
|
||||
title: lazy.DownloadsViewUI.getDisplayName(download),
|
||||
description:
|
||||
DownloadsViewUI.getSizeWithUnits(download) ||
|
||||
DownloadsCommon.strings.sizeUnknown,
|
||||
lazy.DownloadsViewUI.getSizeWithUnits(download) ||
|
||||
lazy.DownloadsCommon.strings.sizeUnknown,
|
||||
referrer,
|
||||
date_added: download.endTime,
|
||||
};
|
||||
|
@ -49,7 +51,7 @@ class DownloadsManager {
|
|||
|
||||
init(store) {
|
||||
this._store = store;
|
||||
this._downloadData = DownloadsCommon.getData(
|
||||
this._downloadData = lazy.DownloadsCommon.getData(
|
||||
null /* null for non-private downloads */,
|
||||
true,
|
||||
false,
|
||||
|
@ -104,7 +106,7 @@ class DownloadsManager {
|
|||
// Ignore blocked links, but allow long (data:) uris to avoid high CPU
|
||||
if (
|
||||
download.source.url.length < 10000 &&
|
||||
NewTabUtils.blockedLinks.isBlocked(download.source)
|
||||
lazy.NewTabUtils.blockedLinks.isBlocked(download.source)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
@ -154,18 +156,18 @@ class DownloadsManager {
|
|||
switch (action.type) {
|
||||
case at.COPY_DOWNLOAD_LINK:
|
||||
doDownloadAction(download => {
|
||||
DownloadsCommon.copyDownloadLink(download);
|
||||
lazy.DownloadsCommon.copyDownloadLink(download);
|
||||
});
|
||||
break;
|
||||
case at.REMOVE_DOWNLOAD_FILE:
|
||||
doDownloadAction(download => {
|
||||
DownloadsCommon.deleteDownload(download).catch(Cu.reportError);
|
||||
lazy.DownloadsCommon.deleteDownload(download).catch(Cu.reportError);
|
||||
});
|
||||
break;
|
||||
case at.SHOW_DOWNLOAD_FILE:
|
||||
doDownloadAction(download => {
|
||||
DownloadsCommon.showDownloadedFile(
|
||||
new FileUtils.File(download.target.path)
|
||||
lazy.DownloadsCommon.showDownloadedFile(
|
||||
new lazy.FileUtils.File(download.target.path)
|
||||
);
|
||||
});
|
||||
break;
|
||||
|
@ -174,7 +176,7 @@ class DownloadsManager {
|
|||
const openWhere =
|
||||
action.data.event && win.whereToOpenLink(action.data.event);
|
||||
doDownloadAction(download => {
|
||||
DownloadsCommon.openDownload(download, {
|
||||
lazy.DownloadsCommon.openDownload(download, {
|
||||
// Replace "current" or unknown value with "tab" as the default behavior
|
||||
// for opening downloads when handled internally
|
||||
openWhere: ["window", "tab", "tabshifted"].includes(openWhere)
|
||||
|
|
|
@ -13,14 +13,16 @@ const { RemoteSettings } = ChromeUtils.import(
|
|||
"resource://services-settings/remote-settings.js"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
|
@ -35,12 +37,12 @@ const MIN_FAVICON_SIZE = 96;
|
|||
*/
|
||||
function getFaviconInfo(uri) {
|
||||
return new Promise(resolve =>
|
||||
PlacesUtils.favicons.getFaviconDataForPage(
|
||||
lazy.PlacesUtils.favicons.getFaviconDataForPage(
|
||||
uri,
|
||||
// Package up the icon data in an object if we have it; otherwise null
|
||||
(iconUri, faviconLength, favicon, mimeType, faviconSize) =>
|
||||
resolve(iconUri ? { iconUri, faviconSize } : null),
|
||||
NewTabUtils.activityStreamProvider.THUMB_FAVICON_SIZE
|
||||
lazy.NewTabUtils.activityStreamProvider.THUMB_FAVICON_SIZE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -75,8 +77,8 @@ async function fetchVisitPaths(url) {
|
|||
JOIN path
|
||||
ON visit_id = from_visit
|
||||
WHERE visit_type IN
|
||||
(${PlacesUtils.history.TRANSITIONS.REDIRECT_PERMANENT},
|
||||
${PlacesUtils.history.TRANSITIONS.REDIRECT_TEMPORARY})
|
||||
(${lazy.PlacesUtils.history.TRANSITIONS.REDIRECT_PERMANENT},
|
||||
${lazy.PlacesUtils.history.TRANSITIONS.REDIRECT_TEMPORARY})
|
||||
)
|
||||
SELECT visit_id, (
|
||||
SELECT (
|
||||
|
@ -88,7 +90,7 @@ async function fetchVisitPaths(url) {
|
|||
FROM path
|
||||
`;
|
||||
|
||||
const visits = await NewTabUtils.activityStreamProvider.executePlacesQuery(
|
||||
const visits = await lazy.NewTabUtils.activityStreamProvider.executePlacesQuery(
|
||||
query,
|
||||
{
|
||||
columns: ["visit_id", "url"],
|
||||
|
@ -113,11 +115,11 @@ async function fetchIconFromRedirects(url) {
|
|||
const redirectedUri = Services.io.newURI(lastVisit.url);
|
||||
const iconInfo = await getFaviconInfo(redirectedUri);
|
||||
if (iconInfo && iconInfo.faviconSize >= MIN_FAVICON_SIZE) {
|
||||
PlacesUtils.favicons.setAndFetchFaviconForPage(
|
||||
lazy.PlacesUtils.favicons.setAndFetchFaviconForPage(
|
||||
Services.io.newURI(url),
|
||||
iconInfo.iconUri,
|
||||
false,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
lazy.PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
null,
|
||||
Services.scriptSecurityManager.getSystemPrincipal()
|
||||
);
|
||||
|
@ -157,11 +159,11 @@ class FaviconFeed {
|
|||
.mutate()
|
||||
.setRef("tippytop")
|
||||
.finalize();
|
||||
PlacesUtils.favicons.setAndFetchFaviconForPage(
|
||||
lazy.PlacesUtils.favicons.setAndFetchFaviconForPage(
|
||||
Services.io.newURI(url),
|
||||
iconUri,
|
||||
false,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
lazy.PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
null,
|
||||
Services.scriptSecurityManager.getSystemPrincipal()
|
||||
);
|
||||
|
|
|
@ -9,8 +9,10 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"gFilterAdultEnabled",
|
||||
"browser.newtabpage.activity-stream.filterAdult",
|
||||
true
|
||||
|
@ -55,7 +57,7 @@ const FilterAdult = {
|
|||
* A filtered array without adult links.
|
||||
*/
|
||||
filter(links) {
|
||||
if (!gFilterAdultEnabled) {
|
||||
if (!lazy.gFilterAdultEnabled) {
|
||||
return links;
|
||||
}
|
||||
|
||||
|
@ -78,7 +80,7 @@ const FilterAdult = {
|
|||
* True if it is an adult url.
|
||||
*/
|
||||
isAdultUrl(url) {
|
||||
if (!gFilterAdultEnabled) {
|
||||
if (!lazy.gFilterAdultEnabled) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -23,33 +23,35 @@ const { Dedupe } = ChromeUtils.import(
|
|||
"resource://activity-stream/common/Dedupe.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"FilterAdult",
|
||||
"resource://activity-stream/lib/FilterAdult.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"LinksCache",
|
||||
"resource://activity-stream/lib/LinksCache.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Screenshots",
|
||||
"resource://activity-stream/lib/Screenshots.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PageThumbs",
|
||||
"resource://gre/modules/PageThumbs.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"DownloadsManager",
|
||||
"resource://activity-stream/lib/DownloadsManager.jsm"
|
||||
);
|
||||
|
@ -67,13 +69,13 @@ const RECENT_DOWNLOAD_THRESHOLD = 36 * 60 * 60 * 1000;
|
|||
class HighlightsFeed {
|
||||
constructor() {
|
||||
this.dedupe = new Dedupe(this._dedupeKey);
|
||||
this.linksCache = new LinksCache(
|
||||
NewTabUtils.activityStreamLinks,
|
||||
this.linksCache = new lazy.LinksCache(
|
||||
lazy.NewTabUtils.activityStreamLinks,
|
||||
"getHighlights",
|
||||
["image"]
|
||||
);
|
||||
PageThumbs.addExpirationFilter(this);
|
||||
this.downloadsManager = new DownloadsManager();
|
||||
lazy.PageThumbs.addExpirationFilter(this);
|
||||
this.downloadsManager = new lazy.DownloadsManager();
|
||||
}
|
||||
|
||||
_dedupeKey(site) {
|
||||
|
@ -101,7 +103,7 @@ class HighlightsFeed {
|
|||
|
||||
uninit() {
|
||||
SectionsManager.disableSection(SECTION_ID);
|
||||
PageThumbs.removeExpirationFilter(this);
|
||||
lazy.PageThumbs.removeExpirationFilter(this);
|
||||
Services.obs.removeObserver(this, SYNC_BOOKMARKS_FINISHED_EVENT);
|
||||
Services.obs.removeObserver(this, BOOKMARKS_RESTORE_SUCCESS_EVENT);
|
||||
Services.obs.removeObserver(this, BOOKMARKS_RESTORE_FAILED_EVENT);
|
||||
|
@ -217,7 +219,7 @@ class HighlightsFeed {
|
|||
const orderedPages = this._orderHighlights(manyPages);
|
||||
|
||||
// Remove adult highlights if we need to
|
||||
const checkedAdult = FilterAdult.filter(orderedPages);
|
||||
const checkedAdult = lazy.FilterAdult.filter(orderedPages);
|
||||
|
||||
// Remove any Highlights that are in Top Sites already
|
||||
const [, deduped] = this.dedupe.group(
|
||||
|
@ -295,7 +297,7 @@ class HighlightsFeed {
|
|||
fetchImage(page, isStartup = false) {
|
||||
// Request a screenshot if we don't already have one pending
|
||||
const { preview_image_url: imageUrl, url } = page;
|
||||
return Screenshots.maybeCacheScreenshot(
|
||||
return lazy.Screenshots.maybeCacheScreenshot(
|
||||
page,
|
||||
imageUrl || url,
|
||||
"image",
|
||||
|
|
|
@ -8,7 +8,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
RemoteL10n: "resource://activity-stream/lib/RemoteL10n.jsm",
|
||||
});
|
||||
|
@ -58,7 +60,9 @@ class InfoBarNotification {
|
|||
formatMessageConfig(doc, content) {
|
||||
let docFragment = doc.createDocumentFragment();
|
||||
// notificationbox will only `appendChild` for documentFragments
|
||||
docFragment.appendChild(RemoteL10n.createElement(doc, "span", { content }));
|
||||
docFragment.appendChild(
|
||||
lazy.RemoteL10n.createElement(doc, "span", { content })
|
||||
);
|
||||
|
||||
return docFragment;
|
||||
}
|
||||
|
@ -155,7 +159,7 @@ const InfoBar = {
|
|||
|
||||
const win = browser.ownerGlobal;
|
||||
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
if (lazy.PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
setInterval: "resource://gre/modules/Timer.jsm",
|
||||
clearInterval: "resource://gre/modules/Timer.jsm",
|
||||
});
|
||||
|
@ -54,7 +56,7 @@ class _MomentsPageHub {
|
|||
template: "update_action",
|
||||
});
|
||||
|
||||
const _intervalId = setInterval(
|
||||
const _intervalId = lazy.setInterval(
|
||||
() => this.checkHomepageOverridePref(),
|
||||
SYSTEM_TICK_INTERVAL
|
||||
);
|
||||
|
@ -162,7 +164,7 @@ class _MomentsPageHub {
|
|||
}
|
||||
|
||||
uninit() {
|
||||
clearInterval(this.state._intervalId);
|
||||
lazy.clearInterval(this.state._intervalId);
|
||||
this.state = {};
|
||||
this._initialized = false;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
ShellService: "resource:///modules/ShellService.jsm",
|
||||
});
|
||||
|
||||
|
@ -372,7 +374,7 @@ const OnboardingMessageProvider = {
|
|||
return translatedMessages;
|
||||
},
|
||||
async _doesAppNeedPin() {
|
||||
const needPin = await ShellService.doesAppNeedPin();
|
||||
const needPin = await lazy.ShellService.doesAppNeedPin();
|
||||
return needPin;
|
||||
},
|
||||
async _doesAppNeedDefault() {
|
||||
|
@ -380,7 +382,7 @@ const OnboardingMessageProvider = {
|
|||
"browser.shell.checkDefaultBrowser",
|
||||
false
|
||||
);
|
||||
let isDefault = await ShellService.isDefaultBrowser();
|
||||
let isDefault = await lazy.ShellService.isDefaultBrowser();
|
||||
return checkDefault && !isDefault;
|
||||
},
|
||||
async getUpgradeMessage() {
|
||||
|
|
|
@ -3,14 +3,16 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"RemoteSettings",
|
||||
"resource://services-settings/remote-settings.js"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
|
@ -20,7 +22,7 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
|
||||
const { BasePromiseWorker } = ChromeUtils.import(
|
||||
"resource://gre/modules/PromiseWorker.jsm"
|
||||
|
@ -65,7 +67,7 @@ class PersonalityProvider {
|
|||
}
|
||||
const server = Services.prefs.getCharPref("services.settings.server");
|
||||
const serverInfo = await (
|
||||
await fetch(`${server}/`, {
|
||||
await lazy.fetch(`${server}/`, {
|
||||
credentials: "omit",
|
||||
})
|
||||
).json();
|
||||
|
@ -92,11 +94,11 @@ class PersonalityProvider {
|
|||
}
|
||||
|
||||
setupSyncAttachment(collection) {
|
||||
RemoteSettings(collection).on("sync", this.onSync);
|
||||
lazy.RemoteSettings(collection).on("sync", this.onSync);
|
||||
}
|
||||
|
||||
teardownSyncAttachment(collection) {
|
||||
RemoteSettings(collection).off("sync", this.onSync);
|
||||
lazy.RemoteSettings(collection).off("sync", this.onSync);
|
||||
}
|
||||
|
||||
onSync(event) {
|
||||
|
@ -117,7 +119,7 @@ class PersonalityProvider {
|
|||
*/
|
||||
async getRecipe() {
|
||||
if (!this.recipes || !this.recipes.length) {
|
||||
const result = await RemoteSettings(RECIPE_NAME).get();
|
||||
const result = await lazy.RemoteSettings(RECIPE_NAME).get();
|
||||
this.recipes = await Promise.all(
|
||||
result.map(async record => ({
|
||||
...(await this.getAttachment(record)),
|
||||
|
@ -141,7 +143,7 @@ class PersonalityProvider {
|
|||
});
|
||||
sql += " LIMIT 30000";
|
||||
|
||||
const { activityStreamProvider } = NewTabUtils;
|
||||
const { activityStreamProvider } = lazy.NewTabUtils;
|
||||
const history = await activityStreamProvider.executePlacesQuery(sql, {
|
||||
columns,
|
||||
params: {},
|
||||
|
@ -192,7 +194,7 @@ class PersonalityProvider {
|
|||
}
|
||||
|
||||
async fetchModels() {
|
||||
const models = await RemoteSettings(MODELS_NAME).get();
|
||||
const models = await lazy.RemoteSettings(MODELS_NAME).get();
|
||||
return this.personalityProviderWorker.post("fetchModels", [models]);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,37 +15,39 @@ const { shortURL } = ChromeUtils.import(
|
|||
"resource://activity-stream/lib/ShortURL.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PartnerLinkAttribution",
|
||||
"resource:///modules/PartnerLinkAttribution.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"pktApi",
|
||||
"chrome://pocket/content/pktApi.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"ExperimentAPI",
|
||||
"resource://nimbus/ExperimentAPI.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
});
|
||||
|
||||
|
@ -123,11 +125,11 @@ class PlacesObserver extends Observer {
|
|||
// default bookmarks, added when the profile is created.
|
||||
if (
|
||||
isTagging ||
|
||||
itemType !== PlacesUtils.bookmarks.TYPE_BOOKMARK ||
|
||||
source === PlacesUtils.bookmarks.SOURCES.IMPORT ||
|
||||
source === PlacesUtils.bookmarks.SOURCES.RESTORE ||
|
||||
source === PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP ||
|
||||
source === PlacesUtils.bookmarks.SOURCES.SYNC ||
|
||||
itemType !== lazy.PlacesUtils.bookmarks.TYPE_BOOKMARK ||
|
||||
source === lazy.PlacesUtils.bookmarks.SOURCES.IMPORT ||
|
||||
source === lazy.PlacesUtils.bookmarks.SOURCES.RESTORE ||
|
||||
source === lazy.PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP ||
|
||||
source === lazy.PlacesUtils.bookmarks.SOURCES.SYNC ||
|
||||
(!url.startsWith("http://") && !url.startsWith("https://"))
|
||||
) {
|
||||
return;
|
||||
|
@ -147,11 +149,12 @@ class PlacesObserver extends Observer {
|
|||
case "bookmark-removed":
|
||||
if (
|
||||
isTagging ||
|
||||
(itemType === PlacesUtils.bookmarks.TYPE_BOOKMARK &&
|
||||
source !== PlacesUtils.bookmarks.SOURCES.IMPORT &&
|
||||
source !== PlacesUtils.bookmarks.SOURCES.RESTORE &&
|
||||
source !== PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP &&
|
||||
source !== PlacesUtils.bookmarks.SOURCES.SYNC)
|
||||
(itemType === lazy.PlacesUtils.bookmarks.TYPE_BOOKMARK &&
|
||||
source !== lazy.PlacesUtils.bookmarks.SOURCES.IMPORT &&
|
||||
source !== lazy.PlacesUtils.bookmarks.SOURCES.RESTORE &&
|
||||
source !==
|
||||
lazy.PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP &&
|
||||
source !== lazy.PlacesUtils.bookmarks.SOURCES.SYNC)
|
||||
) {
|
||||
removedBookmarks.push(url);
|
||||
}
|
||||
|
@ -192,7 +195,7 @@ class PlacesFeed {
|
|||
Cc["@mozilla.org/browser/nav-bookmarks-service;1"]
|
||||
.getService(Ci.nsINavBookmarksService)
|
||||
.addObserver(this.bookmarksObserver, true);
|
||||
PlacesUtils.observers.addListener(
|
||||
lazy.PlacesUtils.observers.addListener(
|
||||
["bookmark-added", "bookmark-removed", "history-cleared", "page-removed"],
|
||||
this.placesObserver.handlePlacesEvent
|
||||
);
|
||||
|
@ -234,8 +237,8 @@ class PlacesFeed {
|
|||
this.placesChangedTimer.cancel();
|
||||
this.placesChangedTimer = null;
|
||||
}
|
||||
PlacesUtils.bookmarks.removeObserver(this.bookmarksObserver);
|
||||
PlacesUtils.observers.removeListener(
|
||||
lazy.PlacesUtils.bookmarks.removeObserver(this.bookmarksObserver);
|
||||
lazy.PlacesUtils.observers.removeListener(
|
||||
["bookmark-added", "bookmark-removed", "history-cleared", "page-removed"],
|
||||
this.placesObserver.handlePlacesEvent
|
||||
);
|
||||
|
@ -307,7 +310,7 @@ class PlacesFeed {
|
|||
|
||||
// Mark the page as typed for frecency bonus before opening the link
|
||||
if (typedBonus) {
|
||||
PlacesUtils.history.markPageAsTyped(Services.io.newURI(urlToOpen));
|
||||
lazy.PlacesUtils.history.markPageAsTyped(Services.io.newURI(urlToOpen));
|
||||
}
|
||||
|
||||
const win = action._target.browser.ownerGlobal;
|
||||
|
@ -320,20 +323,20 @@ class PlacesFeed {
|
|||
// If there's an original URL e.g. using the unprocessed %YYYYMMDDHH% tag,
|
||||
// add a visit for that so it may become a frecent top site.
|
||||
if (action.data.original_url) {
|
||||
PlacesUtils.history.insert({
|
||||
lazy.PlacesUtils.history.insert({
|
||||
url: action.data.original_url,
|
||||
visits: [{ transition: PlacesUtils.history.TRANSITION_TYPED }],
|
||||
visits: [{ transition: lazy.PlacesUtils.history.TRANSITION_TYPED }],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async saveToPocket(site, browser) {
|
||||
const sendToPocket = NimbusFeatures.pocketNewtab.getVariable(
|
||||
const sendToPocket = lazy.NimbusFeatures.pocketNewtab.getVariable(
|
||||
"sendToPocket"
|
||||
);
|
||||
// An experiment to send the user directly to Pocket's signup page.
|
||||
if (sendToPocket && !pktApi.isUserLoggedIn()) {
|
||||
const pocketNewtabExperiment = ExperimentAPI.getExperiment({
|
||||
if (sendToPocket && !lazy.pktApi.isUserLoggedIn()) {
|
||||
const pocketNewtabExperiment = lazy.ExperimentAPI.getExperiment({
|
||||
featureId: "pocketNewtab",
|
||||
});
|
||||
const pocketSiteHost = Services.prefs.getStringPref(
|
||||
|
@ -358,7 +361,7 @@ class PlacesFeed {
|
|||
|
||||
const { url, title } = site;
|
||||
try {
|
||||
let data = await NewTabUtils.activityStreamLinks.addPocketEntry(
|
||||
let data = await lazy.NewTabUtils.activityStreamLinks.addPocketEntry(
|
||||
url,
|
||||
title,
|
||||
browser
|
||||
|
@ -388,7 +391,7 @@ class PlacesFeed {
|
|||
*/
|
||||
async deleteFromPocket(itemID) {
|
||||
try {
|
||||
await NewTabUtils.activityStreamLinks.deletePocketEntry(itemID);
|
||||
await lazy.NewTabUtils.activityStreamLinks.deletePocketEntry(itemID);
|
||||
this.store.dispatch({ type: at.POCKET_LINK_DELETED_OR_ARCHIVED });
|
||||
} catch (err) {
|
||||
Cu.reportError(err);
|
||||
|
@ -402,7 +405,7 @@ class PlacesFeed {
|
|||
*/
|
||||
async archiveFromPocket(itemID) {
|
||||
try {
|
||||
await NewTabUtils.activityStreamLinks.archivePocketEntry(itemID);
|
||||
await lazy.NewTabUtils.activityStreamLinks.archivePocketEntry(itemID);
|
||||
this.store.dispatch({ type: at.POCKET_LINK_DELETED_OR_ARCHIVED });
|
||||
} catch (err) {
|
||||
Cu.reportError(err);
|
||||
|
@ -423,7 +426,7 @@ class PlacesFeed {
|
|||
},
|
||||
data
|
||||
);
|
||||
PartnerLinkAttribution.makeRequest(args);
|
||||
lazy.PartnerLinkAttribution.makeRequest(args);
|
||||
}
|
||||
|
||||
async fillSearchTopSiteTerm({ _target, data }) {
|
||||
|
@ -442,7 +445,7 @@ class PlacesFeed {
|
|||
|
||||
handoffSearchToAwesomebar({ _target, data, meta }) {
|
||||
const searchEngine = this._getDefaultSearchEngine(
|
||||
PrivateBrowsingUtils.isBrowserPrivate(_target.browser)
|
||||
lazy.PrivateBrowsingUtils.isBrowserPrivate(_target.browser)
|
||||
);
|
||||
const urlBar = _target.browser.ownerGlobal.gURLBar;
|
||||
let isFirstChange = true;
|
||||
|
@ -544,7 +547,7 @@ class PlacesFeed {
|
|||
let sponsoredTopSites = [];
|
||||
action.data.forEach(site => {
|
||||
const { url, pocket_id, isSponsoredTopSite } = site;
|
||||
NewTabUtils.activityStreamLinks.blockURL({ url, pocket_id });
|
||||
lazy.NewTabUtils.activityStreamLinks.blockURL({ url, pocket_id });
|
||||
if (isSponsoredTopSite) {
|
||||
sponsoredTopSites.push({ url });
|
||||
}
|
||||
|
@ -556,19 +559,19 @@ class PlacesFeed {
|
|||
break;
|
||||
}
|
||||
case at.BOOKMARK_URL:
|
||||
NewTabUtils.activityStreamLinks.addBookmark(
|
||||
lazy.NewTabUtils.activityStreamLinks.addBookmark(
|
||||
action.data,
|
||||
action._target.browser.ownerGlobal
|
||||
);
|
||||
break;
|
||||
case at.DELETE_BOOKMARK_BY_ID:
|
||||
NewTabUtils.activityStreamLinks.deleteBookmark(action.data);
|
||||
lazy.NewTabUtils.activityStreamLinks.deleteBookmark(action.data);
|
||||
break;
|
||||
case at.DELETE_HISTORY_URL: {
|
||||
const { url, forceBlock, pocket_id } = action.data;
|
||||
NewTabUtils.activityStreamLinks.deleteHistoryEntry(url);
|
||||
lazy.NewTabUtils.activityStreamLinks.deleteHistoryEntry(url);
|
||||
if (forceBlock) {
|
||||
NewTabUtils.activityStreamLinks.blockURL({ url, pocket_id });
|
||||
lazy.NewTabUtils.activityStreamLinks.blockURL({ url, pocket_id });
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ const { AppConstants } = ChromeUtils.import(
|
|||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
Region: "resource://gre/modules/Region.jsm",
|
||||
|
@ -68,7 +70,7 @@ class PrefsFeed {
|
|||
* Handler for when experiment data updates.
|
||||
*/
|
||||
onExperimentUpdated(event, reason) {
|
||||
const value = NimbusFeatures.newtab.getAllVariables() || {};
|
||||
const value = lazy.NimbusFeatures.newtab.getAllVariables() || {};
|
||||
this.store.dispatch(
|
||||
ac.BroadcastToContent({
|
||||
type: at.PREF_CHANGED,
|
||||
|
@ -84,7 +86,7 @@ class PrefsFeed {
|
|||
* Handler for Pocket specific experiment data updates.
|
||||
*/
|
||||
onPocketExperimentUpdated(event, reason) {
|
||||
const value = NimbusFeatures.pocketNewtab.getAllVariables() || {};
|
||||
const value = lazy.NimbusFeatures.pocketNewtab.getAllVariables() || {};
|
||||
this.store.dispatch(
|
||||
ac.BroadcastToContent({
|
||||
type: at.PREF_CHANGED,
|
||||
|
@ -98,8 +100,8 @@ class PrefsFeed {
|
|||
|
||||
init() {
|
||||
this._prefs.observeBranch(this);
|
||||
NimbusFeatures.newtab.onUpdate(this.onExperimentUpdated);
|
||||
NimbusFeatures.pocketNewtab.onUpdate(this.onPocketExperimentUpdated);
|
||||
lazy.NimbusFeatures.newtab.onUpdate(this.onExperimentUpdated);
|
||||
lazy.NimbusFeatures.pocketNewtab.onUpdate(this.onPocketExperimentUpdated);
|
||||
|
||||
this._storage = this.store.dbStorage.getDbTable("sectionPrefs");
|
||||
|
||||
|
@ -111,16 +113,16 @@ class PrefsFeed {
|
|||
|
||||
// These are not prefs, but are needed to determine stuff in content that can only be
|
||||
// computed in main process
|
||||
values.isPrivateBrowsingEnabled = PrivateBrowsingUtils.enabled;
|
||||
values.isPrivateBrowsingEnabled = lazy.PrivateBrowsingUtils.enabled;
|
||||
values.platform = AppConstants.platform;
|
||||
|
||||
// Save the geo pref if we have it
|
||||
if (Region.home) {
|
||||
values.region = Region.home;
|
||||
if (lazy.Region.home) {
|
||||
values.region = lazy.Region.home;
|
||||
this.geo = values.region;
|
||||
} else if (this.geo !== "") {
|
||||
// Watch for geo changes and use a dummy value for now
|
||||
Services.obs.addObserver(this, Region.REGION_TOPIC);
|
||||
Services.obs.addObserver(this, lazy.Region.REGION_TOPIC);
|
||||
this.geo = "";
|
||||
}
|
||||
|
||||
|
@ -174,8 +176,9 @@ class PrefsFeed {
|
|||
});
|
||||
|
||||
// Add experiment values and default values
|
||||
values.featureConfig = NimbusFeatures.newtab.getAllVariables() || {};
|
||||
values.pocketConfig = NimbusFeatures.pocketNewtab.getAllVariables() || {};
|
||||
values.featureConfig = lazy.NimbusFeatures.newtab.getAllVariables() || {};
|
||||
values.pocketConfig =
|
||||
lazy.NimbusFeatures.pocketNewtab.getAllVariables() || {};
|
||||
this._setBoolPref(values, "logowordmark.alwaysVisible", false);
|
||||
this._setBoolPref(values, "feeds.section.topstories", false);
|
||||
this._setBoolPref(values, "discoverystream.enabled", false);
|
||||
|
@ -215,10 +218,10 @@ class PrefsFeed {
|
|||
|
||||
removeListeners() {
|
||||
this._prefs.ignoreBranch(this);
|
||||
NimbusFeatures.newtab.off(this.onExperimentUpdated);
|
||||
NimbusFeatures.pocketNewtab.off(this.onPocketExperimentUpdated);
|
||||
lazy.NimbusFeatures.newtab.off(this.onExperimentUpdated);
|
||||
lazy.NimbusFeatures.pocketNewtab.off(this.onPocketExperimentUpdated);
|
||||
if (this.geo === "") {
|
||||
Services.obs.removeObserver(this, Region.REGION_TOPIC);
|
||||
Services.obs.removeObserver(this, lazy.Region.REGION_TOPIC);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,11 +236,11 @@ class PrefsFeed {
|
|||
|
||||
observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case Region.REGION_TOPIC:
|
||||
case lazy.Region.REGION_TOPIC:
|
||||
this.store.dispatch(
|
||||
ac.BroadcastToContent({
|
||||
type: at.PREF_CHANGED,
|
||||
data: { name: "region", value: Region.home },
|
||||
data: { name: "region", value: lazy.Region.home },
|
||||
})
|
||||
);
|
||||
break;
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
PersonalityProvider:
|
||||
"resource://activity-stream/lib/PersonalityProvider/PersonalityProvider.jsm",
|
||||
});
|
||||
|
@ -49,7 +50,7 @@ class RecommendationProvider {
|
|||
return;
|
||||
}
|
||||
// At this point we've determined we can successfully create a v2 personalization provider.
|
||||
this.provider = new PersonalityProvider(this.modelKeys);
|
||||
this.provider = new lazy.PersonalityProvider(this.modelKeys);
|
||||
this.provider.setScores(scores);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,14 +9,16 @@ const { PromiseUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Downloader",
|
||||
"resource://services-settings/Attachments.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"KintoHttpClient",
|
||||
"resource://services-common/kinto-http-client.js"
|
||||
);
|
||||
|
@ -293,7 +295,7 @@ class _RemoteImages {
|
|||
* with an Error.
|
||||
*/
|
||||
async #download(db, recordId) {
|
||||
const client = new KintoHttpClient(
|
||||
const client = new lazy.KintoHttpClient(
|
||||
Services.prefs.getStringPref(RS_SERVER_PREF)
|
||||
);
|
||||
|
||||
|
@ -302,7 +304,7 @@ class _RemoteImages {
|
|||
.collection(RS_COLLECTION)
|
||||
.getRecord(recordId);
|
||||
|
||||
const downloader = new Downloader(RS_MAIN_BUCKET, RS_COLLECTION);
|
||||
const downloader = new lazy.Downloader(RS_MAIN_BUCKET, RS_COLLECTION);
|
||||
|
||||
const arrayBuffer = await downloader.downloadAsBytes(record.data, {
|
||||
retries: RS_DOWNLOAD_MAX_RETRIES,
|
||||
|
|
|
@ -9,20 +9,22 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"BackgroundPageThumbs",
|
||||
"resource://gre/modules/BackgroundPageThumbs.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PageThumbs",
|
||||
"resource://gre/modules/PageThumbs.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
||||
);
|
||||
|
@ -31,7 +33,7 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|||
const GREY_10 = "#F9F9FA";
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"gPrivilegedAboutProcessEnabled",
|
||||
"browser.tabs.remote.separatePrivilegedContentProcess",
|
||||
false
|
||||
|
@ -47,21 +49,21 @@ const Screenshots = {
|
|||
*/
|
||||
async getScreenshotForURL(url) {
|
||||
try {
|
||||
await BackgroundPageThumbs.captureIfMissing(url, {
|
||||
await lazy.BackgroundPageThumbs.captureIfMissing(url, {
|
||||
backgroundColor: GREY_10,
|
||||
});
|
||||
|
||||
// The privileged about content process is able to use the moz-page-thumb
|
||||
// protocol, so if it's enabled, send that down.
|
||||
if (gPrivilegedAboutProcessEnabled) {
|
||||
return PageThumbs.getThumbnailURL(url);
|
||||
if (lazy.gPrivilegedAboutProcessEnabled) {
|
||||
return lazy.PageThumbs.getThumbnailURL(url);
|
||||
}
|
||||
|
||||
// Otherwise, for normal content processes, we fallback to using
|
||||
// Blob URIs for the screenshots.
|
||||
const imgPath = PageThumbs.getThumbnailPath(url);
|
||||
const imgPath = lazy.PageThumbs.getThumbnailPath(url);
|
||||
|
||||
const filePathResponse = await fetch(`file://${imgPath}`);
|
||||
const filePathResponse = await lazy.fetch(`file://${imgPath}`);
|
||||
const fileContents = await filePathResponse.blob();
|
||||
|
||||
// Check if the file is empty, which indicates there isn't actually a
|
||||
|
@ -81,7 +83,7 @@ const Screenshots = {
|
|||
// the usual filtering process to avoid repeated background requests, which
|
||||
// can cause unwanted high CPU, network and memory usage - Bug 1384094
|
||||
try {
|
||||
await PageThumbs._store(url, url, null, true);
|
||||
await lazy.PageThumbs._store(url, url, null, true);
|
||||
} catch (err) {
|
||||
// Probably failed to create the empty file, but not much more we can do.
|
||||
}
|
||||
|
@ -95,7 +97,7 @@ const Screenshots = {
|
|||
*/
|
||||
_shouldGetScreenshots() {
|
||||
for (let win of Services.wm.getEnumerator("navigator:browser")) {
|
||||
if (!PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
if (!lazy.PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
// As soon as we encounter 1 non-private window, screenshots are fair game.
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ const { getDefaultOptions } = ChromeUtils.import(
|
|||
"resource://activity-stream/lib/ActivityStreamStorage.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
});
|
||||
|
@ -188,7 +190,7 @@ const SectionsManager = {
|
|||
sections: new Map(),
|
||||
async init(prefs = {}, storage) {
|
||||
this._storage = storage;
|
||||
const featureConfig = NimbusFeatures.newtab.getAllVariables() || {};
|
||||
const featureConfig = lazy.NimbusFeatures.newtab.getAllVariables() || {};
|
||||
|
||||
for (const feedPrefName of Object.keys(BUILT_IN_SECTIONS(featureConfig))) {
|
||||
const optionsPrefName = `${feedPrefName}.options`;
|
||||
|
@ -237,7 +239,7 @@ const SectionsManager = {
|
|||
async addBuiltInSection(feedPrefName, optionsPrefValue = "{}") {
|
||||
let options;
|
||||
let storedPrefs;
|
||||
const featureConfig = NimbusFeatures.newtab.getAllVariables() || {};
|
||||
const featureConfig = lazy.NimbusFeatures.newtab.getAllVariables() || {};
|
||||
try {
|
||||
options = JSON.parse(optionsPrefValue);
|
||||
} catch (e) {
|
||||
|
@ -323,14 +325,14 @@ const SectionsManager = {
|
|||
card.title &&
|
||||
card.image
|
||||
) {
|
||||
PlacesUtils.history.update({
|
||||
lazy.PlacesUtils.history.update({
|
||||
url: card.url,
|
||||
title: card.title,
|
||||
description: card.description,
|
||||
previewImageURL: card.image,
|
||||
});
|
||||
// Highlights query skips bookmarks with no visits.
|
||||
PlacesUtils.history.insert({
|
||||
lazy.PlacesUtils.history.insert({
|
||||
url,
|
||||
title: card.title,
|
||||
visits: [{}],
|
||||
|
|
|
@ -7,8 +7,10 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"IDNService",
|
||||
"@mozilla.org/network/idn-service;1",
|
||||
"nsIIDNService"
|
||||
|
@ -21,7 +23,7 @@ XPCOMUtils.defineLazyServiceGetter(
|
|||
*/
|
||||
function handleIDNHost(hostname) {
|
||||
try {
|
||||
return IDNService.convertToDisplayIDN(hostname, {});
|
||||
return lazy.IDNService.convertToDisplayIDN(hostname, {});
|
||||
} catch (e) {
|
||||
// If something goes wrong (e.g. host is an IP address) just fail back
|
||||
// to the full domain.
|
||||
|
|
|
@ -7,7 +7,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
AboutWelcomeTelemetry:
|
||||
"resource://activity-stream/aboutwelcome/lib/AboutWelcomeTelemetry.jsm",
|
||||
RemoteImages: "resource://activity-stream/lib/RemoteImages.jsm",
|
||||
|
@ -16,9 +18,9 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AWTelemetry",
|
||||
() => new AboutWelcomeTelemetry()
|
||||
() => new lazy.AboutWelcomeTelemetry()
|
||||
);
|
||||
|
||||
const Spotlight = {
|
||||
|
@ -38,7 +40,7 @@ const Spotlight = {
|
|||
defaultDispatch(message) {
|
||||
if (message.type === "SPOTLIGHT_TELEMETRY") {
|
||||
const { message_id, event } = message.data;
|
||||
AWTelemetry.sendTelemetry({ message_id, event });
|
||||
lazy.AWTelemetry.sendTelemetry({ message_id, event });
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -66,7 +68,7 @@ const Spotlight = {
|
|||
this.sendUserEventTelemetry("IMPRESSION", message, dispatchCFRAction);
|
||||
dispatchCFRAction({ type: "IMPRESSION", data: message });
|
||||
|
||||
const unload = await RemoteImages.patchMessage(message.content.logo);
|
||||
const unload = await lazy.RemoteImages.patchMessage(message.content.logo);
|
||||
|
||||
if (message.content?.modal === "tab") {
|
||||
let { closedPromise } = win.gBrowser.getTabDialogBox(browser).open(
|
||||
|
@ -94,7 +96,7 @@ const Spotlight = {
|
|||
|
||||
if (params.secondaryBtn) {
|
||||
this.sendUserEventTelemetry("DISMISS", message, dispatchCFRAction);
|
||||
SpecialMessageActions.handleAction(
|
||||
lazy.SpecialMessageActions.handleAction(
|
||||
message.content.body.secondary.action,
|
||||
browser
|
||||
);
|
||||
|
@ -102,7 +104,7 @@ const Spotlight = {
|
|||
|
||||
if (params.primaryBtn) {
|
||||
this.sendUserEventTelemetry("CLICK", message, dispatchCFRAction);
|
||||
SpecialMessageActions.handleAction(
|
||||
lazy.SpecialMessageActions.handleAction(
|
||||
message.content.body.primary.action,
|
||||
browser
|
||||
);
|
||||
|
|
|
@ -7,13 +7,15 @@ const { actionTypes: at } = ChromeUtils.import(
|
|||
"resource://activity-stream/common/Actions.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"setInterval",
|
||||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"clearInterval",
|
||||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
|
@ -23,7 +25,7 @@ const SYSTEM_TICK_INTERVAL = 5 * 60 * 1000;
|
|||
|
||||
class SystemTickFeed {
|
||||
init() {
|
||||
this.intervalId = setInterval(
|
||||
this.intervalId = lazy.setInterval(
|
||||
() => this.store.dispatch({ type: at.SYSTEM_TICK }),
|
||||
SYSTEM_TICK_INTERVAL
|
||||
);
|
||||
|
@ -35,7 +37,7 @@ class SystemTickFeed {
|
|||
this.init();
|
||||
break;
|
||||
case at.UNINIT:
|
||||
clearInterval(this.intervalId);
|
||||
lazy.clearInterval(this.intervalId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,48 +22,50 @@ const { classifySite } = ChromeUtils.import(
|
|||
"resource://activity-stream/lib/SiteClassifier.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AboutNewTab",
|
||||
"resource:///modules/AboutNewTab.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PingCentre",
|
||||
"resource:///modules/PingCentre.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"UTEventReporting",
|
||||
"resource://activity-stream/lib/UTEventReporting.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"UpdateUtils",
|
||||
"resource://gre/modules/UpdateUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"HomePage",
|
||||
"resource:///modules/HomePage.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"ExtensionSettingsStore",
|
||||
"resource://gre/modules/ExtensionSettingsStore.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"ClientID",
|
||||
"resource://gre/modules/ClientID.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
ExperimentAPI: "resource://nimbus/ExperimentAPI.jsm",
|
||||
TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.jsm",
|
||||
TelemetrySession: "resource://gre/modules/TelemetrySession.jsm",
|
||||
|
@ -110,16 +112,16 @@ const ONBOARDING_ALLOWED_PAGE_VALUES = [
|
|||
];
|
||||
|
||||
XPCOMUtils.defineLazyGetter(
|
||||
this,
|
||||
lazy,
|
||||
"browserSessionId",
|
||||
() => TelemetrySession.getMetadata("").sessionId
|
||||
() => lazy.TelemetrySession.getMetadata("").sessionId
|
||||
);
|
||||
|
||||
// The scalar category for TopSites of Contextual Services
|
||||
const SCALAR_CATEGORY_TOPSITES = "contextual.services.topsites";
|
||||
// `contextId` is a unique identifier used by Contextual Services
|
||||
const CONTEXT_ID_PREF = "browser.contextual-services.contextId";
|
||||
XPCOMUtils.defineLazyGetter(this, "contextId", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "contextId", () => {
|
||||
let _contextId = Services.prefs.getStringPref(CONTEXT_ID_PREF, null);
|
||||
if (!_contextId) {
|
||||
_contextId = String(Services.uuid.generateUUID());
|
||||
|
@ -154,7 +156,7 @@ class TelemetryFeed {
|
|||
|
||||
get telemetryClientId() {
|
||||
Object.defineProperty(this, "telemetryClientId", {
|
||||
value: ClientID.getClientID(),
|
||||
value: lazy.ClientID.getClientID(),
|
||||
});
|
||||
return this.telemetryClientId;
|
||||
}
|
||||
|
@ -185,7 +187,7 @@ class TelemetryFeed {
|
|||
"deletion.request.impression_id",
|
||||
this._impressionId
|
||||
);
|
||||
Services.telemetry.scalarSet("deletion.request.context_id", contextId);
|
||||
Services.telemetry.scalarSet("deletion.request.context_id", lazy.contextId);
|
||||
}
|
||||
|
||||
handleEvent(event) {
|
||||
|
@ -211,7 +213,7 @@ class TelemetryFeed {
|
|||
|
||||
countPinnedTab(target, source = "TAB_CONTEXT_MENU") {
|
||||
const win = target.ownerGlobal;
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
if (lazy.PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
return;
|
||||
}
|
||||
const event = Object.assign(this.createPing(), {
|
||||
|
@ -229,7 +231,7 @@ class TelemetryFeed {
|
|||
countTotalPinnedTabs() {
|
||||
let pinnedTabs = 0;
|
||||
for (let win of Services.wm.getEnumerator("navigator:browser")) {
|
||||
if (win.closed || PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
if (win.closed || lazy.PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
continue;
|
||||
}
|
||||
for (let tab of win.gBrowser.tabs) {
|
||||
|
@ -303,7 +305,7 @@ class TelemetryFeed {
|
|||
*/
|
||||
get pingCentre() {
|
||||
Object.defineProperty(this, "pingCentre", {
|
||||
value: new PingCentre({ topic: ACTIVITY_STREAM_ID }),
|
||||
value: new lazy.PingCentre({ topic: ACTIVITY_STREAM_ID }),
|
||||
});
|
||||
return this.pingCentre;
|
||||
}
|
||||
|
@ -312,7 +314,9 @@ class TelemetryFeed {
|
|||
* Lazily initialize UTEventReporting to send pings
|
||||
*/
|
||||
get utEvents() {
|
||||
Object.defineProperty(this, "utEvents", { value: new UTEventReporting() });
|
||||
Object.defineProperty(this, "utEvents", {
|
||||
value: new lazy.UTEventReporting(),
|
||||
});
|
||||
return this.utEvents;
|
||||
}
|
||||
|
||||
|
@ -337,7 +341,7 @@ class TelemetryFeed {
|
|||
* @return {bool}
|
||||
*/
|
||||
get isInCFRCohort() {
|
||||
const experimentData = ExperimentAPI.getExperimentMetaData({
|
||||
const experimentData = lazy.ExperimentAPI.getExperimentMetaData({
|
||||
featureId: "cfr",
|
||||
});
|
||||
if (experimentData && experimentData.slug) {
|
||||
|
@ -588,8 +592,8 @@ class TelemetryFeed {
|
|||
action: "activity_stream_session",
|
||||
perf: session.perf,
|
||||
profile_creation_date:
|
||||
TelemetryEnvironment.currentEnvironment.profile.resetDate ||
|
||||
TelemetryEnvironment.currentEnvironment.profile.creationDate,
|
||||
lazy.TelemetryEnvironment.currentEnvironment.profile.resetDate ||
|
||||
lazy.TelemetryEnvironment.currentEnvironment.profile.creationDate,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -649,7 +653,7 @@ class TelemetryFeed {
|
|||
*/
|
||||
async applyCFRPolicy(ping) {
|
||||
if (
|
||||
UpdateUtils.getUpdateChannel(true) === "release" &&
|
||||
lazy.UpdateUtils.getUpdateChannel(true) === "release" &&
|
||||
!this.isInCFRCohort
|
||||
) {
|
||||
ping.message_id = "n/a";
|
||||
|
@ -667,7 +671,7 @@ class TelemetryFeed {
|
|||
*/
|
||||
async applyWhatsNewPolicy(ping) {
|
||||
ping.client_id = await this.telemetryClientId;
|
||||
ping.browser_session_id = browserSessionId;
|
||||
ping.browser_session_id = lazy.browserSessionId;
|
||||
// Attach page info to `event_context` if there is a session associated with this ping
|
||||
delete ping.action;
|
||||
return { ping, pingType: "whats-new-panel" };
|
||||
|
@ -675,14 +679,14 @@ class TelemetryFeed {
|
|||
|
||||
async applyInfoBarPolicy(ping) {
|
||||
ping.client_id = await this.telemetryClientId;
|
||||
ping.browser_session_id = browserSessionId;
|
||||
ping.browser_session_id = lazy.browserSessionId;
|
||||
delete ping.action;
|
||||
return { ping, pingType: "infobar" };
|
||||
}
|
||||
|
||||
async applySpotlightPolicy(ping) {
|
||||
ping.client_id = await this.telemetryClientId;
|
||||
ping.browser_session_id = browserSessionId;
|
||||
ping.browser_session_id = lazy.browserSessionId;
|
||||
delete ping.action;
|
||||
return { ping, pingType: "spotlight" };
|
||||
}
|
||||
|
@ -695,7 +699,7 @@ class TelemetryFeed {
|
|||
*/
|
||||
async applyMomentsPolicy(ping) {
|
||||
if (
|
||||
UpdateUtils.getUpdateChannel(true) === "release" &&
|
||||
lazy.UpdateUtils.getUpdateChannel(true) === "release" &&
|
||||
!this.isInCFRCohort
|
||||
) {
|
||||
ping.message_id = "n/a";
|
||||
|
@ -723,7 +727,7 @@ class TelemetryFeed {
|
|||
*/
|
||||
async applyOnboardingPolicy(ping, session) {
|
||||
ping.client_id = await this.telemetryClientId;
|
||||
ping.browser_session_id = browserSessionId;
|
||||
ping.browser_session_id = lazy.browserSessionId;
|
||||
// Attach page info to `event_context` if there is a session associated with this ping
|
||||
if (ping.action === "onboarding_user_event" && session && session.page) {
|
||||
let event_context;
|
||||
|
@ -769,7 +773,7 @@ class TelemetryFeed {
|
|||
async sendEventPing(ping) {
|
||||
delete ping.action;
|
||||
ping.client_id = await this.telemetryClientId;
|
||||
ping.browser_session_id = browserSessionId;
|
||||
ping.browser_session_id = lazy.browserSessionId;
|
||||
if (ping.value && typeof ping.value === "object") {
|
||||
ping.value = JSON.stringify(ping.value);
|
||||
}
|
||||
|
@ -863,7 +867,7 @@ class TelemetryFeed {
|
|||
return;
|
||||
}
|
||||
|
||||
let payload = { ...data, context_id: contextId };
|
||||
let payload = { ...data, context_id: lazy.contextId };
|
||||
delete payload.type;
|
||||
this.sendStructuredIngestionEvent(
|
||||
payload,
|
||||
|
@ -913,17 +917,17 @@ class TelemetryFeed {
|
|||
// If so, classify them.
|
||||
if (
|
||||
Services.prefs.getBoolPref("browser.newtabpage.enabled") &&
|
||||
AboutNewTab.newTabURLOverridden &&
|
||||
!AboutNewTab.newTabURL.startsWith("moz-extension://")
|
||||
lazy.AboutNewTab.newTabURLOverridden &&
|
||||
!lazy.AboutNewTab.newTabURL.startsWith("moz-extension://")
|
||||
) {
|
||||
value.newtab_url_category = await this._classifySite(
|
||||
AboutNewTab.newTabURL
|
||||
lazy.AboutNewTab.newTabURL
|
||||
);
|
||||
newtabAffected = true;
|
||||
}
|
||||
// Check if the newtab page setting is controlled by an extension.
|
||||
await ExtensionSettingsStore.initialize();
|
||||
const newtabExtensionInfo = ExtensionSettingsStore.getSetting(
|
||||
await lazy.ExtensionSettingsStore.initialize();
|
||||
const newtabExtensionInfo = lazy.ExtensionSettingsStore.getSetting(
|
||||
"url_overrides",
|
||||
"newTabURL"
|
||||
);
|
||||
|
@ -932,7 +936,7 @@ class TelemetryFeed {
|
|||
newtabAffected = true;
|
||||
}
|
||||
|
||||
const homePageURL = HomePage.get();
|
||||
const homePageURL = lazy.HomePage.get();
|
||||
if (
|
||||
!["about:home", "about:blank"].includes(homePageURL) &&
|
||||
!homePageURL.startsWith("moz-extension://")
|
||||
|
@ -940,7 +944,7 @@ class TelemetryFeed {
|
|||
value.home_url_category = await this._classifySite(homePageURL);
|
||||
homeAffected = true;
|
||||
}
|
||||
const homeExtensionInfo = ExtensionSettingsStore.getSetting(
|
||||
const homeExtensionInfo = lazy.ExtensionSettingsStore.getSetting(
|
||||
"prefs",
|
||||
"homepage_override"
|
||||
);
|
||||
|
@ -1135,10 +1139,10 @@ class TelemetryFeed {
|
|||
if (
|
||||
timestamp &&
|
||||
session.page === "about:home" &&
|
||||
!HomePage.overridden &&
|
||||
!lazy.HomePage.overridden &&
|
||||
Services.prefs.getIntPref("browser.startup.page") === 1
|
||||
) {
|
||||
AboutNewTab.maybeRecordTopsitesPainted(timestamp);
|
||||
lazy.AboutNewTab.maybeRecordTopsitesPainted(timestamp);
|
||||
}
|
||||
|
||||
Object.assign(session.perf, data);
|
||||
|
|
|
@ -7,7 +7,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
|
||||
const TIPPYTOP_PATH = "chrome://activity-stream/content/data/content/tippytop/";
|
||||
const TIPPYTOP_JSON_PATH =
|
||||
|
@ -41,7 +43,7 @@ class TippyTopProvider {
|
|||
// Load the Tippy Top sites from the json manifest.
|
||||
try {
|
||||
for (const site of await (
|
||||
await fetch(TIPPYTOP_JSON_PATH, {
|
||||
await lazy.fetch(TIPPYTOP_JSON_PATH, {
|
||||
credentials: "omit",
|
||||
})
|
||||
).json()) {
|
||||
|
|
|
@ -8,7 +8,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
EveryWindow: "resource:///modules/EveryWindow.jsm",
|
||||
ToolbarPanelHub: "resource://activity-stream/lib/ToolbarPanelHub.jsm",
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
|
@ -88,15 +90,15 @@ class _ToolbarBadgeHub {
|
|||
executeAction({ id, data, message_id }) {
|
||||
switch (id) {
|
||||
case "show-whatsnew-button":
|
||||
ToolbarPanelHub.enableToolbarButton();
|
||||
ToolbarPanelHub.enableAppmenuButton();
|
||||
lazy.ToolbarPanelHub.enableToolbarButton();
|
||||
lazy.ToolbarPanelHub.enableAppmenuButton();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_clearBadgeTimeout() {
|
||||
if (this.state.showBadgeTimeoutId) {
|
||||
clearTimeout(this.state.showBadgeTimeoutId);
|
||||
lazy.clearTimeout(this.state.showBadgeTimeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +132,7 @@ class _ToolbarBadgeHub {
|
|||
}
|
||||
}
|
||||
// Will call uninit on every window
|
||||
EveryWindow.unregisterCallback(this.id);
|
||||
lazy.EveryWindow.unregisterCallback(this.id);
|
||||
if (this.state.notification) {
|
||||
this._blockMessageById(this.state.notification.id);
|
||||
}
|
||||
|
@ -221,7 +223,7 @@ class _ToolbarBadgeHub {
|
|||
return;
|
||||
}
|
||||
|
||||
EveryWindow.registerCallback(
|
||||
lazy.EveryWindow.registerCallback(
|
||||
this.id,
|
||||
win => {
|
||||
if (notificationsByWindow.has(win)) {
|
||||
|
@ -252,8 +254,8 @@ class _ToolbarBadgeHub {
|
|||
}
|
||||
|
||||
if (message.content.delay) {
|
||||
this.state.showBadgeTimeoutId = setTimeout(() => {
|
||||
requestIdleCallback(() => this.registerBadgeToAllWindows(message));
|
||||
this.state.showBadgeTimeoutId = lazy.setTimeout(() => {
|
||||
lazy.requestIdleCallback(() => this.registerBadgeToAllWindows(message));
|
||||
}, message.content.delay);
|
||||
} else {
|
||||
this.registerBadgeToAllWindows(message);
|
||||
|
@ -285,7 +287,7 @@ class _ToolbarBadgeHub {
|
|||
// Only send pings for non private browsing windows
|
||||
if (
|
||||
win &&
|
||||
!PrivateBrowsingUtils.isBrowserPrivate(
|
||||
!lazy.PrivateBrowsingUtils.isBrowserPrivate(
|
||||
win.ownerGlobal.gBrowser.selectedBrowser
|
||||
)
|
||||
) {
|
||||
|
|
|
@ -7,7 +7,8 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
EveryWindow: "resource:///modules/EveryWindow.jsm",
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
Preferences: "resource://gre/modules/Preferences.jsm",
|
||||
|
@ -16,12 +17,12 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
RemoteL10n: "resource://activity-stream/lib/RemoteL10n.jsm",
|
||||
});
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PanelMultiView",
|
||||
"resource:///modules/PanelMultiView.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"TrackingDBService",
|
||||
"@mozilla.org/tracking-db-service;1",
|
||||
"nsITrackingDBService"
|
||||
|
@ -85,8 +86,8 @@ class _ToolbarPanelHub {
|
|||
|
||||
uninit() {
|
||||
this._initialized = false;
|
||||
EveryWindow.unregisterCallback(TOOLBAR_BUTTON_ID);
|
||||
EveryWindow.unregisterCallback(APPMENU_BUTTON_ID);
|
||||
lazy.EveryWindow.unregisterCallback(TOOLBAR_BUTTON_ID);
|
||||
lazy.EveryWindow.unregisterCallback(APPMENU_BUTTON_ID);
|
||||
}
|
||||
|
||||
get messages() {
|
||||
|
@ -101,7 +102,7 @@ class _ToolbarPanelHub {
|
|||
// Checkbox onclick handler gets called before the checkbox state gets toggled,
|
||||
// so we have to call it with the opposite value.
|
||||
let newValue = !event.target.checked;
|
||||
Preferences.set(WHATSNEW_ENABLED_PREF, newValue);
|
||||
lazy.Preferences.set(WHATSNEW_ENABLED_PREF, newValue);
|
||||
|
||||
this.sendUserEventTelemetry(
|
||||
event.target.ownerGlobal,
|
||||
|
@ -131,7 +132,7 @@ class _ToolbarPanelHub {
|
|||
// Turns on the Appmenu (hamburger menu) button for all open windows and future windows.
|
||||
async enableAppmenuButton() {
|
||||
if ((await this.messages).length) {
|
||||
EveryWindow.registerCallback(
|
||||
lazy.EveryWindow.registerCallback(
|
||||
APPMENU_BUTTON_ID,
|
||||
this._showAppmenuButton,
|
||||
this._hideAppmenuButton
|
||||
|
@ -142,13 +143,13 @@ class _ToolbarPanelHub {
|
|||
// Removes the button from the Appmenu.
|
||||
// Only used in tests.
|
||||
disableAppmenuButton() {
|
||||
EveryWindow.unregisterCallback(APPMENU_BUTTON_ID);
|
||||
lazy.EveryWindow.unregisterCallback(APPMENU_BUTTON_ID);
|
||||
}
|
||||
|
||||
// Turns on the Toolbar button for all open windows and future windows.
|
||||
async enableToolbarButton() {
|
||||
if ((await this.messages).length) {
|
||||
EveryWindow.registerCallback(
|
||||
lazy.EveryWindow.registerCallback(
|
||||
TOOLBAR_BUTTON_ID,
|
||||
this._showToolbarButton,
|
||||
this._hideToolbarButton
|
||||
|
@ -164,7 +165,7 @@ class _ToolbarPanelHub {
|
|||
// When the panel is hidden we want to remove any toolbar buttons that
|
||||
// might have been added as an entry point to the panel
|
||||
const removeToolbarButton = () => {
|
||||
EveryWindow.unregisterCallback(TOOLBAR_BUTTON_ID);
|
||||
lazy.EveryWindow.unregisterCallback(TOOLBAR_BUTTON_ID);
|
||||
};
|
||||
if (!panelContainer) {
|
||||
return;
|
||||
|
@ -191,7 +192,7 @@ class _ToolbarPanelHub {
|
|||
// Render what's new messages into the panel.
|
||||
async renderMessages(win, doc, containerId, options = {}) {
|
||||
// Set the checked status of the footer checkbox
|
||||
let value = Preferences.get(WHATSNEW_ENABLED_PREF);
|
||||
let value = lazy.Preferences.get(WHATSNEW_ENABLED_PREF);
|
||||
let checkbox = win.document.getElementById("panelMenu-toggleWhatsNew");
|
||||
|
||||
checkbox.checked = value;
|
||||
|
@ -200,7 +201,7 @@ class _ToolbarPanelHub {
|
|||
const messages =
|
||||
(options.force && options.messages) ||
|
||||
(await this.messages).sort(this._sortWhatsNewMessages);
|
||||
const container = PanelMultiView.getViewNode(doc, containerId);
|
||||
const container = lazy.PanelMultiView.getViewNode(doc, containerId);
|
||||
|
||||
if (messages) {
|
||||
// Targeting attribute state might have changed making new messages
|
||||
|
@ -239,7 +240,7 @@ class _ToolbarPanelHub {
|
|||
|
||||
removeMessages(win, containerId) {
|
||||
const doc = win.document;
|
||||
const messageNodes = PanelMultiView.getViewNode(
|
||||
const messageNodes = lazy.PanelMultiView.getViewNode(
|
||||
doc,
|
||||
containerId
|
||||
).querySelectorAll(".whatsNew-message");
|
||||
|
@ -260,7 +261,7 @@ class _ToolbarPanelHub {
|
|||
Cu.reportError(e);
|
||||
url = message.content.cta_url;
|
||||
}
|
||||
SpecialMessageActions.handleAction(
|
||||
lazy.SpecialMessageActions.handleAction(
|
||||
{
|
||||
type: message.content.cta_type,
|
||||
data: {
|
||||
|
@ -293,13 +294,13 @@ class _ToolbarPanelHub {
|
|||
|
||||
_createMessageElements(win, doc, message, previousDate) {
|
||||
const { content } = message;
|
||||
const messageEl = RemoteL10n.createElement(doc, "div");
|
||||
const messageEl = lazy.RemoteL10n.createElement(doc, "div");
|
||||
messageEl.classList.add("whatsNew-message");
|
||||
|
||||
// Only render date if it is different from the one rendered before.
|
||||
if (content.published_date !== previousDate) {
|
||||
messageEl.appendChild(
|
||||
RemoteL10n.createElement(doc, "p", {
|
||||
lazy.RemoteL10n.createElement(doc, "p", {
|
||||
classList: "whatsNew-message-date",
|
||||
content: new Date(content.published_date).toLocaleDateString(
|
||||
"default",
|
||||
|
@ -313,14 +314,14 @@ class _ToolbarPanelHub {
|
|||
);
|
||||
}
|
||||
|
||||
const wrapperEl = RemoteL10n.createElement(doc, "div");
|
||||
const wrapperEl = lazy.RemoteL10n.createElement(doc, "div");
|
||||
wrapperEl.doCommand = () => this._dispatchUserAction(win, message);
|
||||
wrapperEl.classList.add("whatsNew-message-body");
|
||||
messageEl.appendChild(wrapperEl);
|
||||
|
||||
if (content.icon_url) {
|
||||
wrapperEl.classList.add("has-icon");
|
||||
const iconEl = RemoteL10n.createElement(doc, "img");
|
||||
const iconEl = lazy.RemoteL10n.createElement(doc, "img");
|
||||
iconEl.src = content.icon_url;
|
||||
iconEl.classList.add("whatsNew-message-icon");
|
||||
if (content.icon_alt && content.icon_alt.string_id) {
|
||||
|
@ -334,7 +335,7 @@ class _ToolbarPanelHub {
|
|||
wrapperEl.appendChild(this._createMessageContent(win, doc, content));
|
||||
|
||||
if (content.link_text) {
|
||||
const anchorEl = RemoteL10n.createElement(doc, "a", {
|
||||
const anchorEl = lazy.RemoteL10n.createElement(doc, "a", {
|
||||
classList: "text-link",
|
||||
content: content.link_text,
|
||||
});
|
||||
|
@ -355,7 +356,7 @@ class _ToolbarPanelHub {
|
|||
const wrapperEl = new win.DocumentFragment();
|
||||
|
||||
wrapperEl.appendChild(
|
||||
RemoteL10n.createElement(doc, "h2", {
|
||||
lazy.RemoteL10n.createElement(doc, "h2", {
|
||||
classList: "whatsNew-message-title",
|
||||
content: content.title,
|
||||
attributes: this.state.contentArguments,
|
||||
|
@ -363,7 +364,7 @@ class _ToolbarPanelHub {
|
|||
);
|
||||
|
||||
wrapperEl.appendChild(
|
||||
RemoteL10n.createElement(doc, "p", {
|
||||
lazy.RemoteL10n.createElement(doc, "p", {
|
||||
content: content.body,
|
||||
classList: "whatsNew-message-content",
|
||||
attributes: this.state.contentArguments,
|
||||
|
@ -376,28 +377,28 @@ class _ToolbarPanelHub {
|
|||
_createHeroElement(win, doc, message) {
|
||||
this.maybeLoadCustomElement(win);
|
||||
|
||||
const messageEl = RemoteL10n.createElement(doc, "div");
|
||||
const messageEl = lazy.RemoteL10n.createElement(doc, "div");
|
||||
messageEl.setAttribute("id", "protections-popup-message");
|
||||
messageEl.classList.add("whatsNew-hero-message");
|
||||
const wrapperEl = RemoteL10n.createElement(doc, "div");
|
||||
const wrapperEl = lazy.RemoteL10n.createElement(doc, "div");
|
||||
wrapperEl.classList.add("whatsNew-message-body");
|
||||
messageEl.appendChild(wrapperEl);
|
||||
|
||||
wrapperEl.appendChild(
|
||||
RemoteL10n.createElement(doc, "h2", {
|
||||
lazy.RemoteL10n.createElement(doc, "h2", {
|
||||
classList: "whatsNew-message-title",
|
||||
content: message.content.title,
|
||||
})
|
||||
);
|
||||
wrapperEl.appendChild(
|
||||
RemoteL10n.createElement(doc, "p", {
|
||||
lazy.RemoteL10n.createElement(doc, "p", {
|
||||
classList: "protections-popup-content",
|
||||
content: message.content.body,
|
||||
})
|
||||
);
|
||||
|
||||
if (message.content.link_text) {
|
||||
let linkEl = RemoteL10n.createElement(doc, "a", {
|
||||
let linkEl = lazy.RemoteL10n.createElement(doc, "a", {
|
||||
classList: "text-link",
|
||||
content: message.content.link_text,
|
||||
});
|
||||
|
@ -416,7 +417,7 @@ class _ToolbarPanelHub {
|
|||
// Between now and 6 weeks ago
|
||||
const dateTo = new Date();
|
||||
const dateFrom = new Date(dateTo.getTime() - 42 * 24 * 60 * 60 * 1000);
|
||||
const eventsByDate = await TrackingDBService.getEventsByDateRange(
|
||||
const eventsByDate = await lazy.TrackingDBService.getEventsByDateRange(
|
||||
dateFrom,
|
||||
dateTo
|
||||
);
|
||||
|
@ -441,7 +442,7 @@ class _ToolbarPanelHub {
|
|||
// `earliestDate` will be either 6 weeks ago or when tracking recording
|
||||
// started. Whichever is more recent.
|
||||
earliestDate: Math.max(
|
||||
new Date(await TrackingDBService.getEarliestRecordedDate()),
|
||||
new Date(await lazy.TrackingDBService.getEarliestRecordedDate()),
|
||||
dateFrom
|
||||
),
|
||||
...totalEvents,
|
||||
|
@ -479,13 +480,13 @@ class _ToolbarPanelHub {
|
|||
}
|
||||
|
||||
_showElement(document, id, string_id) {
|
||||
const el = PanelMultiView.getViewNode(document, id);
|
||||
const el = lazy.PanelMultiView.getViewNode(document, id);
|
||||
document.l10n.setAttributes(el, string_id);
|
||||
el.hidden = false;
|
||||
}
|
||||
|
||||
_hideElement(document, id) {
|
||||
const el = PanelMultiView.getViewNode(document, id);
|
||||
const el = lazy.PanelMultiView.getViewNode(document, id);
|
||||
if (el) {
|
||||
el.hidden = true;
|
||||
}
|
||||
|
@ -502,7 +503,7 @@ class _ToolbarPanelHub {
|
|||
// Only send pings for non private browsing windows
|
||||
if (
|
||||
win &&
|
||||
!PrivateBrowsingUtils.isBrowserPrivate(
|
||||
!lazy.PrivateBrowsingUtils.isBrowserPrivate(
|
||||
win.ownerGlobal.gBrowser.selectedBrowser
|
||||
)
|
||||
) {
|
||||
|
|
|
@ -36,52 +36,54 @@ const {
|
|||
getSearchFormURL,
|
||||
} = ChromeUtils.import("resource://activity-stream/lib/SearchShortcuts.jsm");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"FilterAdult",
|
||||
"resource://activity-stream/lib/FilterAdult.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"LinksCache",
|
||||
"resource://activity-stream/lib/LinksCache.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Screenshots",
|
||||
"resource://activity-stream/lib/Screenshots.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PageThumbs",
|
||||
"resource://gre/modules/PageThumbs.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"RemoteSettings",
|
||||
"resource://services-settings/remote-settings.js"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Region",
|
||||
"resource://gre/modules/Region.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "log", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "log", () => {
|
||||
const { Logger } = ChromeUtils.import(
|
||||
"resource://messaging-system/lib/Logger.jsm"
|
||||
);
|
||||
return new Logger("TopSitesFeed");
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
});
|
||||
|
||||
|
@ -171,7 +173,9 @@ class ContileIntegration {
|
|||
|
||||
async _fetchSites() {
|
||||
if (
|
||||
!NimbusFeatures.newtab.getVariable(NIMBUS_VARIABLE_CONTILE_ENABLED) ||
|
||||
!lazy.NimbusFeatures.newtab.getVariable(
|
||||
NIMBUS_VARIABLE_CONTILE_ENABLED
|
||||
) ||
|
||||
!this._topSitesFeed.store.getState().Prefs.values[SHOW_SPONSORED_PREF]
|
||||
) {
|
||||
if (this._sites.length) {
|
||||
|
@ -182,9 +186,9 @@ class ContileIntegration {
|
|||
}
|
||||
try {
|
||||
let url = Services.prefs.getStringPref(CONTILE_ENDPOINT_PREF);
|
||||
const response = await fetch(url, { credentials: "omit" });
|
||||
const response = await lazy.fetch(url, { credentials: "omit" });
|
||||
if (!response.ok) {
|
||||
log.warn(
|
||||
lazy.log.warn(
|
||||
`Contile endpoint returned unexpected status: ${response.status}`
|
||||
);
|
||||
}
|
||||
|
@ -201,7 +205,7 @@ class ContileIntegration {
|
|||
let { tiles } = body;
|
||||
tiles = this._filterBlockedSponsors(tiles);
|
||||
if (tiles.length > MAX_NUM_SPONSORED) {
|
||||
log.warn(
|
||||
lazy.log.warn(
|
||||
`Contile provided more links than permitted. (${tiles.length} received, limit is ${MAX_NUM_SPONSORED})`
|
||||
);
|
||||
tiles.length = MAX_NUM_SPONSORED;
|
||||
|
@ -210,7 +214,9 @@ class ContileIntegration {
|
|||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
log.warn(`Failed to fetch data from Contile server: ${error.message}`);
|
||||
lazy.log.warn(
|
||||
`Failed to fetch data from Contile server: ${error.message}`
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -226,19 +232,20 @@ class TopSitesFeed {
|
|||
getShortURLForCurrentSearch
|
||||
);
|
||||
this.dedupe = new Dedupe(this._dedupeKey);
|
||||
this.frecentCache = new LinksCache(
|
||||
NewTabUtils.activityStreamLinks,
|
||||
this.frecentCache = new lazy.LinksCache(
|
||||
lazy.NewTabUtils.activityStreamLinks,
|
||||
"getTopSites",
|
||||
CACHED_LINK_PROPS_TO_MIGRATE,
|
||||
(oldOptions, newOptions) =>
|
||||
// Refresh if no old options or requesting more items
|
||||
!(oldOptions.numItems >= newOptions.numItems)
|
||||
);
|
||||
this.pinnedCache = new LinksCache(NewTabUtils.pinnedLinks, "links", [
|
||||
...CACHED_LINK_PROPS_TO_MIGRATE,
|
||||
...PINNED_FAVICON_PROPS_TO_MIGRATE,
|
||||
]);
|
||||
PageThumbs.addExpirationFilter(this);
|
||||
this.pinnedCache = new lazy.LinksCache(
|
||||
lazy.NewTabUtils.pinnedLinks,
|
||||
"links",
|
||||
[...CACHED_LINK_PROPS_TO_MIGRATE, ...PINNED_FAVICON_PROPS_TO_MIGRATE]
|
||||
);
|
||||
lazy.PageThumbs.addExpirationFilter(this);
|
||||
this._nimbusChangeListener = this._nimbusChangeListener.bind(this);
|
||||
}
|
||||
|
||||
|
@ -268,17 +275,17 @@ class TopSitesFeed {
|
|||
Services.prefs.addObserver(REMOTE_SETTING_DEFAULTS_PREF, this);
|
||||
Services.prefs.addObserver(DEFAULT_SITES_OVERRIDE_PREF, this);
|
||||
Services.prefs.addObserver(DEFAULT_SITES_EXPERIMENTS_PREF_BRANCH, this);
|
||||
NimbusFeatures.newtab.onUpdate(this._nimbusChangeListener);
|
||||
lazy.NimbusFeatures.newtab.onUpdate(this._nimbusChangeListener);
|
||||
}
|
||||
|
||||
uninit() {
|
||||
PageThumbs.removeExpirationFilter(this);
|
||||
lazy.PageThumbs.removeExpirationFilter(this);
|
||||
Services.obs.removeObserver(this, "browser-search-engine-modified");
|
||||
Services.obs.removeObserver(this, "browser-region-updated");
|
||||
Services.prefs.removeObserver(REMOTE_SETTING_DEFAULTS_PREF, this);
|
||||
Services.prefs.removeObserver(DEFAULT_SITES_OVERRIDE_PREF, this);
|
||||
Services.prefs.removeObserver(DEFAULT_SITES_EXPERIMENTS_PREF_BRANCH, this);
|
||||
NimbusFeatures.newtab.off(this._nimbusChangeListener);
|
||||
lazy.NimbusFeatures.newtab.off(this._nimbusChangeListener);
|
||||
}
|
||||
|
||||
observe(subj, topic, data) {
|
||||
|
@ -345,7 +352,7 @@ class TopSitesFeed {
|
|||
DEFAULT_TOP_SITES.length = 0;
|
||||
|
||||
// Read defaults from contile.
|
||||
const contileEnabled = NimbusFeatures.newtab.getVariable(
|
||||
const contileEnabled = lazy.NimbusFeatures.newtab.getVariable(
|
||||
NIMBUS_VARIABLE_CONTILE_ENABLED
|
||||
);
|
||||
let hasContileTiles = false;
|
||||
|
@ -462,7 +469,7 @@ class TopSitesFeed {
|
|||
|
||||
async _getRemoteConfig(firstTime = true) {
|
||||
if (!this._remoteConfig) {
|
||||
this._remoteConfig = await RemoteSettings("top-sites");
|
||||
this._remoteConfig = await lazy.RemoteSettings("top-sites");
|
||||
this._remoteConfig.on("sync", () => {
|
||||
this._readDefaults();
|
||||
});
|
||||
|
@ -492,12 +499,12 @@ class TopSitesFeed {
|
|||
|
||||
result = result.filter(topsite => {
|
||||
// Filter by region.
|
||||
if (topsite.exclude_regions?.includes(Region.home)) {
|
||||
if (topsite.exclude_regions?.includes(lazy.Region.home)) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
topsite.include_regions?.length &&
|
||||
!topsite.include_regions.includes(Region.home)
|
||||
!topsite.include_regions.includes(lazy.Region.home)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -707,7 +714,7 @@ class TopSitesFeed {
|
|||
}
|
||||
// Drop blocked default sites.
|
||||
if (
|
||||
NewTabUtils.blockedLinks.isBlocked({
|
||||
lazy.NewTabUtils.blockedLinks.isBlocked({
|
||||
url: link.url,
|
||||
})
|
||||
) {
|
||||
|
@ -736,7 +743,7 @@ class TopSitesFeed {
|
|||
const searchProvider = getSearchProvider(shortURL(link));
|
||||
if (
|
||||
searchProvider &&
|
||||
NewTabUtils.blockedLinks.isBlocked({ url: searchProvider.url })
|
||||
lazy.NewTabUtils.blockedLinks.isBlocked({ url: searchProvider.url })
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
@ -807,8 +814,8 @@ class TopSitesFeed {
|
|||
// Add in favicons if we don't already have it
|
||||
if (!copy.favicon) {
|
||||
try {
|
||||
NewTabUtils.activityStreamProvider._faviconBytesToDataURI(
|
||||
await NewTabUtils.activityStreamProvider._addFavicons([copy])
|
||||
lazy.NewTabUtils.activityStreamProvider._faviconBytesToDataURI(
|
||||
await lazy.NewTabUtils.activityStreamProvider._addFavicons([copy])
|
||||
);
|
||||
|
||||
for (const prop of PINNED_FAVICON_PROPS_TO_MIGRATE) {
|
||||
|
@ -833,7 +840,7 @@ class TopSitesFeed {
|
|||
const dedupedUnpinned = [...dedupedFrecent, ...dedupedDefaults];
|
||||
|
||||
// Remove adult sites if we need to
|
||||
const checkedAdult = FilterAdult.filter(dedupedUnpinned);
|
||||
const checkedAdult = lazy.FilterAdult.filter(dedupedUnpinned);
|
||||
|
||||
// Insert the original pinned sites into the deduped frecent and defaults.
|
||||
let withPinned = insertPinned(checkedAdult, pinned);
|
||||
|
@ -1029,7 +1036,7 @@ class TopSitesFeed {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
await Screenshots.maybeCacheScreenshot(
|
||||
await lazy.Screenshots.maybeCacheScreenshot(
|
||||
link,
|
||||
url,
|
||||
"screenshot",
|
||||
|
@ -1052,7 +1059,7 @@ class TopSitesFeed {
|
|||
* @param target {string} Id of content process where to dispatch the result
|
||||
*/
|
||||
async getScreenshotPreview(url, target) {
|
||||
const preview = (await Screenshots.getScreenshotForURL(url)) || "";
|
||||
const preview = (await lazy.Screenshots.getScreenshotForURL(url)) || "";
|
||||
this.store.dispatch(
|
||||
ac.OnlyToOneContent(
|
||||
{
|
||||
|
@ -1107,7 +1114,7 @@ class TopSitesFeed {
|
|||
if (searchTopSite) {
|
||||
toPin.searchTopSite = searchTopSite;
|
||||
}
|
||||
NewTabUtils.pinnedLinks.pin(toPin, index);
|
||||
lazy.NewTabUtils.pinnedLinks.pin(toPin, index);
|
||||
|
||||
await this._clearLinkCustomScreenshot({ customScreenshotURL, url });
|
||||
}
|
||||
|
@ -1138,7 +1145,7 @@ class TopSitesFeed {
|
|||
// then we want to make sure to unblock that link if it has previously been
|
||||
// blocked. We know if the site has been added because the index will be -1.
|
||||
if (index === -1) {
|
||||
NewTabUtils.blockedLinks.unblock({ url: site.url });
|
||||
lazy.NewTabUtils.blockedLinks.unblock({ url: site.url });
|
||||
this.frecentCache.expire();
|
||||
}
|
||||
this.insert(action);
|
||||
|
@ -1150,7 +1157,7 @@ class TopSitesFeed {
|
|||
*/
|
||||
unpin(action) {
|
||||
const { site } = action.data;
|
||||
NewTabUtils.pinnedLinks.unpin(site);
|
||||
lazy.NewTabUtils.pinnedLinks.unpin(site);
|
||||
this._broadcastPinnedSitesUpdated();
|
||||
}
|
||||
|
||||
|
@ -1158,22 +1165,22 @@ class TopSitesFeed {
|
|||
Services.prefs.clearUserPref(
|
||||
`browser.newtabpage.activity-stream.${SEARCH_SHORTCUTS_HAVE_PINNED_PREF}`
|
||||
);
|
||||
for (let pinnedLink of NewTabUtils.pinnedLinks.links) {
|
||||
for (let pinnedLink of lazy.NewTabUtils.pinnedLinks.links) {
|
||||
if (pinnedLink && pinnedLink.searchTopSite) {
|
||||
NewTabUtils.pinnedLinks.unpin(pinnedLink);
|
||||
lazy.NewTabUtils.pinnedLinks.unpin(pinnedLink);
|
||||
}
|
||||
}
|
||||
this.pinnedCache.expire();
|
||||
}
|
||||
|
||||
_unpinSearchShortcut(vendor) {
|
||||
for (let pinnedLink of NewTabUtils.pinnedLinks.links) {
|
||||
for (let pinnedLink of lazy.NewTabUtils.pinnedLinks.links) {
|
||||
if (
|
||||
pinnedLink &&
|
||||
pinnedLink.searchTopSite &&
|
||||
shortURL(pinnedLink) === vendor
|
||||
) {
|
||||
NewTabUtils.pinnedLinks.unpin(pinnedLink);
|
||||
lazy.NewTabUtils.pinnedLinks.unpin(pinnedLink);
|
||||
this.pinnedCache.expire();
|
||||
|
||||
const prevInsertedShortcuts = this.store
|
||||
|
@ -1229,7 +1236,7 @@ class TopSitesFeed {
|
|||
return;
|
||||
}
|
||||
|
||||
let pinned = NewTabUtils.pinnedLinks.links;
|
||||
let pinned = lazy.NewTabUtils.pinnedLinks.links;
|
||||
if (!pinned[index]) {
|
||||
this._pinSiteAt(site, index);
|
||||
} else {
|
||||
|
@ -1287,7 +1294,7 @@ class TopSitesFeed {
|
|||
updatePinnedSearchShortcuts({ addedShortcuts, deletedShortcuts }) {
|
||||
// Unpin the deletedShortcuts.
|
||||
deletedShortcuts.forEach(({ url }) => {
|
||||
NewTabUtils.pinnedLinks.unpin({ url });
|
||||
lazy.NewTabUtils.pinnedLinks.unpin({ url });
|
||||
});
|
||||
|
||||
// Pin the addedShortcuts.
|
||||
|
@ -1296,16 +1303,16 @@ class TopSitesFeed {
|
|||
TOP_SITES_MAX_SITES_PER_ROW;
|
||||
addedShortcuts.forEach(shortcut => {
|
||||
// Find first hole in pinnedLinks.
|
||||
let index = NewTabUtils.pinnedLinks.links.findIndex(link => !link);
|
||||
let index = lazy.NewTabUtils.pinnedLinks.links.findIndex(link => !link);
|
||||
if (
|
||||
index < 0 &&
|
||||
NewTabUtils.pinnedLinks.links.length + 1 < numberOfSlots
|
||||
lazy.NewTabUtils.pinnedLinks.links.length + 1 < numberOfSlots
|
||||
) {
|
||||
// pinnedLinks can have less slots than the total available.
|
||||
index = NewTabUtils.pinnedLinks.links.length;
|
||||
index = lazy.NewTabUtils.pinnedLinks.links.length;
|
||||
}
|
||||
if (index >= 0) {
|
||||
NewTabUtils.pinnedLinks.pin(shortcut, index);
|
||||
lazy.NewTabUtils.pinnedLinks.pin(shortcut, index);
|
||||
} else {
|
||||
// No slots available, we need to do an insert in first slot and push over other pinned links.
|
||||
this._insertPin(shortcut, 0, numberOfSlots);
|
||||
|
@ -1354,7 +1361,9 @@ class TopSitesFeed {
|
|||
break;
|
||||
case SHOW_SPONSORED_PREF:
|
||||
if (
|
||||
NimbusFeatures.newtab.getVariable(NIMBUS_VARIABLE_CONTILE_ENABLED)
|
||||
lazy.NimbusFeatures.newtab.getVariable(
|
||||
NIMBUS_VARIABLE_CONTILE_ENABLED
|
||||
)
|
||||
) {
|
||||
this._contile.refresh();
|
||||
} else {
|
||||
|
|
|
@ -10,7 +10,8 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|||
const { NewTabUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
const lazy = {};
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
|
||||
const { actionTypes: at, actionCreators: ac } = ChromeUtils.import(
|
||||
"resource://activity-stream/common/Actions.jsm"
|
||||
|
@ -29,7 +30,7 @@ const { PersistentCache } = ChromeUtils.import(
|
|||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"pktApi",
|
||||
"chrome://pocket/content/pktApi.jsm"
|
||||
);
|
||||
|
@ -136,7 +137,10 @@ class TopStoriesFeed {
|
|||
}
|
||||
|
||||
getPocketState(target) {
|
||||
const action = { type: at.POCKET_LOGGED_IN, data: pktApi.isUserLoggedIn() };
|
||||
const action = {
|
||||
type: at.POCKET_LOGGED_IN,
|
||||
data: lazy.pktApi.isUserLoggedIn(),
|
||||
};
|
||||
this.store.dispatch(ac.OnlyToOneContent(action, target));
|
||||
}
|
||||
|
||||
|
@ -192,7 +196,7 @@ class TopStoriesFeed {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(this.stories_endpoint, {
|
||||
const response = await lazy.fetch(this.stories_endpoint, {
|
||||
credentials: "omit",
|
||||
});
|
||||
if (!response.ok) {
|
||||
|
@ -292,7 +296,7 @@ class TopStoriesFeed {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(this.topics_endpoint, {
|
||||
const response = await lazy.fetch(this.topics_endpoint, {
|
||||
credentials: "omit",
|
||||
});
|
||||
if (!response.ok) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче