Bug 1750304 - Move isChinaRepack out of AppConstants r=settings-reviewers,home-newtab-reviewers,Gijs,pdahiya,omc-reviewers,mossop,mconley

AppConstants seems like the wrong place for this method

Differential Revision: https://phabricator.services.mozilla.com/D239276
This commit is contained in:
Gregory Pappas
2025-02-25 20:46:37 +00:00
parent 21ce9dc27a
commit 2300895022
10 changed files with 26 additions and 33 deletions

View File

@@ -852,7 +852,7 @@ function prepareMobileDownload(content) {
};
}
// Update CN specific QRCode url
if (AppConstants.isChinaRepack()) {
if (lazy.BrowserUtils.isChinaRepack()) {
mobileContent.hero_image.url = `${mobileContent.hero_image.url.slice(
0,
mobileContent.hero_image.url.indexOf(".svg")

View File

@@ -621,7 +621,7 @@ describe("MultiStageAboutWelcomeProton module", () => {
],
};
it("should not set url for default qrcode svg", async () => {
sandbox.stub(global.AppConstants, "isChinaRepack").returns(false);
sandbox.stub(global.BrowserUtils, "isChinaRepack").returns(false);
const data =
await AboutWelcomeDefaults.prepareContentForReact(TEST_CONTENT);
assert.propertyVal(
@@ -631,7 +631,7 @@ describe("MultiStageAboutWelcomeProton module", () => {
);
});
it("should set url for cn qrcode svg", async () => {
sandbox.stub(global.AppConstants, "isChinaRepack").returns(true);
sandbox.stub(global.BrowserUtils, "isChinaRepack").returns(true);
const data =
await AboutWelcomeDefaults.prepareContentForReact(TEST_CONTENT);
assert.propertyVal(

View File

@@ -106,9 +106,6 @@ const TEST_GLOBAL = {
AppConstants: {
MOZILLA_OFFICIAL: true,
MOZ_APP_VERSION: "69.0a1",
isChinaRepack() {
return false;
},
isPlatformAndVersionAtMost() {
return false;
},
@@ -135,6 +132,9 @@ const TEST_GLOBAL = {
sendToDeviceEmailsSupported() {
return true;
},
isChinaRepack() {
return false;
},
},
UpdateUtils: { getUpdateChannel() {} },
BasePromiseWorker: class {

View File

@@ -3,8 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const FXA_ENABLED_PREF = "identity.fxaccounts.enabled";
const DISTRIBUTION_ID_PREF = "distribution.id";
const DISTRIBUTION_ID_CHINA_REPACK = "MozillaOnline";
const TOPIC_SELECTION_MODAL_LAST_DISPLAYED_PREF =
"browser.newtabpage.activity-stream.discoverystream.topicSelection.onboarding.lastDisplayed";
const NOTIFICATION_INTERVAL_AFTER_TOPIC_MODAL_MS = 60000; // Assuming avoid notification up to 1 minute after newtab Topic Notification Modal
@@ -44,6 +42,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
ASRouterPreferences:
"resource:///modules/asrouter/ASRouterPreferences.sys.mjs",
AttributionCode: "resource:///modules/AttributionCode.sys.mjs",
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
ClientEnvironment: "resource://normandy/lib/ClientEnvironment.sys.mjs",
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
@@ -826,12 +825,7 @@ const TargetingGetters = {
return AppConstants.platform;
},
get isChinaRepack() {
return (
Services.prefs
.getDefaultBranch(null)
.getCharPref(DISTRIBUTION_ID_PREF, "default") ===
DISTRIBUTION_ID_CHINA_REPACK
);
return lazy.BrowserUtils.isChinaRepack();
},
get userId() {
return lazy.ClientEnvironment.userId;

View File

@@ -1475,7 +1475,7 @@ export const OnboardingMessageProvider = {
};
}
// Update CN specific QRCode url
if (AppConstants.isChinaRepack()) {
if (lazy.BrowserUtils.isChinaRepack()) {
mobileContent.hero_image.url = `${mobileContent.hero_image.url.slice(
0,
mobileContent.hero_image.url.indexOf(".svg")

View File

@@ -116,9 +116,6 @@ const TEST_GLOBAL = {
AppConstants: {
MOZILLA_OFFICIAL: true,
MOZ_APP_VERSION: "69.0a1",
isChinaRepack() {
return false;
},
isPlatformAndVersionAtMost() {
return false;
},

View File

@@ -91,7 +91,7 @@ var gMoreFromMozillaPane = {
id: "fxMobile",
type: "link",
label_string_id: "more-from-moz-learn-more-link",
actionURL: AppConstants.isChinaRepack()
actionURL: BrowserUtils.isChinaRepack()
? "https://www.firefox.com.cn/browsers/mobile/"
: "https://www.mozilla.org/firefox/browsers/mobile/",
},
@@ -106,7 +106,7 @@ var gMoreFromMozillaPane = {
label: {
string_id: "more-from-moz-qr-code-box-firefox-mobile-button",
},
actionURL: AppConstants.isChinaRepack()
actionURL: BrowserUtils.isChinaRepack()
? "https://www.firefox.com.cn/mobile/get-app/"
: "https://www.mozilla.org/firefox/mobile/get-app/?v=mfm",
},
@@ -241,7 +241,7 @@ var gMoreFromMozillaPane = {
"-" +
this.getTemplateName() +
`${
AppConstants.isChinaRepack() &&
BrowserUtils.isChinaRepack() &&
this.getTemplateName().includes("simple")
? "-cn"
: ""

View File

@@ -111,9 +111,6 @@ const TEST_GLOBAL = {
AppConstants: {
MOZILLA_OFFICIAL: true,
MOZ_APP_VERSION: "69.0a1",
isChinaRepack() {
return false;
},
isPlatformAndVersionAtMost() {
return false;
},

View File

@@ -270,13 +270,4 @@ export var AppConstants = Object.freeze({
#endif
USE_LIBZ_RS: @USE_LIBZ_RS_BOOL@,
// Returns true for CN region build when distibution id set as 'MozillaOnline'
isChinaRepack() {
return (
Services.prefs
.getDefaultBranch("")
.getCharPref("distribution.id", "default") === "MozillaOnline"
);
},
});

View File

@@ -558,6 +558,20 @@ export var BrowserUtils = {
}
},
/**
* Returns whether the build is a China repack.
*
* @return {boolean} True if the distribution ID is 'MozillaOnline',
* otherwise false.
*/
isChinaRepack() {
return (
Services.prefs
.getDefaultBranch("")
.getCharPref("distribution.id", "default") === "MozillaOnline"
);
},
/**
* An enumeration of the promotion types that can be passed to shouldShowPromo
*/