Skip to content

Commit 1eb7ddb

Browse files
committed
Bug 1749345 - Skip FirstStartup initting if a previous profile exists. r=nalexander,rhelmer,aminomancer
The thinking here being that if a previous profile exists, then the --first-startup argument is probably be passed because the user is reinstalling on a system that still has (or once had) the browser already installed on it. In that case, we're going to use that pre-existing profile, and we don't need to do the FirstStartup things, since they're primarily for systems where a new profile is being created after install. Differential Revision: https://phabricator.services.mozilla.com/D199763
1 parent 7fc1308 commit 1eb7ddb

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

browser/components/BrowserContentHandler.sys.mjs

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,27 @@ const OVERRIDE_NEW_MSTONE = 2;
158158
const OVERRIDE_NEW_BUILD_ID = 3;
159159
/**
160160
* Determines whether a home page override is needed.
161-
* Returns:
162-
* OVERRIDE_NEW_PROFILE if this is the first run with a new profile.
163-
* OVERRIDE_NEW_MSTONE if this is the first run with a build with a different
164-
* Gecko milestone (i.e. right after an upgrade).
165-
* OVERRIDE_NEW_BUILD_ID if this is the first run with a new build ID of the
166-
* same Gecko milestone (i.e. after a nightly upgrade).
167-
* OVERRIDE_NONE otherwise.
161+
* @param {boolean} [updateMilestones=true]
162+
* True if we should update the milestone prefs after comparing those prefs
163+
* with the current platform version and build ID.
164+
*
165+
* If updateMilestones is false, then this function has no side-effects.
166+
*
167+
* @returns {number}
168+
* One of the following constants:
169+
* OVERRIDE_NEW_PROFILE
170+
* if this is the first run with a new profile.
171+
* OVERRIDE_NEW_MSTONE
172+
* if this is the first run with a build with a different Gecko milestone
173+
* (i.e. right after an upgrade).
174+
* OVERRIDE_NEW_BUILD_ID
175+
* if this is the first run with a new build ID of the same Gecko
176+
* milestone (i.e. after a nightly upgrade).
177+
* OVERRIDE_NONE
178+
* otherwise.
168179
*/
169-
function needHomepageOverride(prefb) {
170-
var savedmstone = prefb.getCharPref(
180+
function needHomepageOverride(updateMilestones = true) {
181+
var savedmstone = Services.prefs.getCharPref(
171182
"browser.startup.homepage_override.mstone",
172183
""
173184
);
@@ -178,7 +189,7 @@ function needHomepageOverride(prefb) {
178189

179190
var mstone = Services.appinfo.platformVersion;
180191

181-
var savedBuildID = prefb.getCharPref(
192+
var savedBuildID = Services.prefs.getCharPref(
182193
"browser.startup.homepage_override.buildID",
183194
""
184195
);
@@ -191,19 +202,32 @@ function needHomepageOverride(prefb) {
191202
// about:rights we've removed the EULA stuff and default pref, but we need
192203
// a way to make existing profiles retain the default that we removed.
193204
if (savedmstone) {
194-
prefb.setBoolPref("browser.rights.3.shown", true);
205+
Services.prefs.setBoolPref("browser.rights.3.shown", true);
195206

196207
// Remember that we saw a major version change.
197208
gMajorUpgrade = true;
198209
}
199210

200-
prefb.setCharPref("browser.startup.homepage_override.mstone", mstone);
201-
prefb.setCharPref("browser.startup.homepage_override.buildID", buildID);
211+
if (updateMilestones) {
212+
Services.prefs.setCharPref(
213+
"browser.startup.homepage_override.mstone",
214+
mstone
215+
);
216+
Services.prefs.setCharPref(
217+
"browser.startup.homepage_override.buildID",
218+
buildID
219+
);
220+
}
202221
return savedmstone ? OVERRIDE_NEW_MSTONE : OVERRIDE_NEW_PROFILE;
203222
}
204223

205224
if (buildID != savedBuildID) {
206-
prefb.setCharPref("browser.startup.homepage_override.buildID", buildID);
225+
if (updateMilestones) {
226+
Services.prefs.setCharPref(
227+
"browser.startup.homepage_override.buildID",
228+
buildID
229+
);
230+
}
207231
return OVERRIDE_NEW_BUILD_ID;
208232
}
209233

@@ -663,7 +687,14 @@ nsBrowserContentHandler.prototype = {
663687
}
664688

665689
if (cmdLine.handleFlag("first-startup", false)) {
666-
lazy.FirstStartup.init();
690+
// We don't want subsequent calls to needHompageOverride to have different
691+
// values because the milestones in prefs got updated, so we intentionally
692+
// tell needHomepageOverride to leave the milestone prefs alone when doing
693+
// this check.
694+
let override = needHomepageOverride(false /* updateMilestones */);
695+
if (override == OVERRIDE_NEW_PROFILE) {
696+
lazy.FirstStartup.init();
697+
}
667698
}
668699

669700
var fileParam = cmdLine.handleFlagWithParam("file", false);
@@ -751,7 +782,7 @@ nsBrowserContentHandler.prototype = {
751782
"browser.startup.homepage_override.buildID",
752783
"unknown"
753784
);
754-
override = needHomepageOverride(prefb);
785+
override = needHomepageOverride();
755786
if (override != OVERRIDE_NONE) {
756787
switch (override) {
757788
case OVERRIDE_NEW_PROFILE:

0 commit comments

Comments
 (0)