Skip to content

Commit 9127e8b

Browse files
committed
Bug 1322797: Replace selectedProfile with currentProfile and fix defaultProfile. r=froydnj, r=flod
The current properties selectedProfile and defaultProfile are somewhat confusing selectedProfile actually returns the default profile for the build and defaultProfile returns the default profile for non-dev-edition builds. This confusion leads to callers doing the wrong thing in some places. What most code actually cares about is being able to set/get the default profile for this build and getting the current profile in use. So this patch replaces the previous properties with currentProfile and defaultProfile which do what makes more sense. This patch also switches from using the preprocessor to change behaviour for dev-edition builds to using a boolean flag since some code was incorrectly ignoring the setting to make dev-edition use the same profile as normal builds. In order to make currentProfile correct when resetting a profile I had to move CreateResetProfile into nsToolkitProfileService. Differential Revision: https://phabricator.services.mozilla.com/D16118 --HG-- extra : rebase_source : cefe252618cd3a1b0e0cd5a71b056dd2b557f1a3 extra : intermediate-source : 35af79575f54f75d22e213fdac7ddd704b40807a extra : source : 732d1ce192408d4f595f2fce16f45c7354ce3097
1 parent d86279f commit 9127e8b

File tree

15 files changed

+219
-223
lines changed

15 files changed

+219
-223
lines changed

browser/components/migration/FirefoxProfileMigrator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ FirefoxProfileMigrator.prototype.getResources = function(aProfile) {
7272
let sourceProfileDir = aProfile ? this._getAllProfiles().get(aProfile.id) :
7373
Cc["@mozilla.org/toolkit/profile-service;1"]
7474
.getService(Ci.nsIToolkitProfileService)
75-
.selectedProfile.rootDir;
75+
.currentProfile.rootDir;
7676
if (!sourceProfileDir || !sourceProfileDir.exists() ||
7777
!sourceProfileDir.isReadable())
7878
return null;

devtools/shared/system.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,14 @@ function getDeviceName() {
180180
function getProfileLocation() {
181181
// In child processes, we cannot access the profile location.
182182
try {
183+
// For some reason this line must come first or in xpcshell tests
184+
// nsXREDirProvider never gets initialised and so the profile service
185+
// crashes on initialisation.
183186
const profd = Services.dirsvc.get("ProfD", Ci.nsIFile);
184187
const profservice = Cc["@mozilla.org/toolkit/profile-service;1"]
185188
.getService(Ci.nsIToolkitProfileService);
186-
for (const profile of profservice.profiles) {
187-
if (profile.rootDir.path == profd.path) {
188-
return profile.name;
189-
}
189+
if (profservice.currentProfile) {
190+
return profservice.currentProfile.name;
190191
}
191192

192193
return profd.leafName;

toolkit/content/aboutProfiles.js

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,6 @@ XPCOMUtils.defineLazyServiceGetter(
1414
"nsIToolkitProfileService"
1515
);
1616

17-
// nsIToolkitProfileService.selectProfile can be used only during the selection
18-
// of the profile in the ProfileManager. If we are showing about:profiles in a
19-
// tab, the selectedProfile returns the default profile.
20-
// In this function we use the ProfD to find the current profile.
21-
function findCurrentProfile() {
22-
let cpd;
23-
try {
24-
cpd = Services.dirsvc.get("ProfD", Ci.nsIFile);
25-
} catch (e) {}
26-
27-
if (cpd) {
28-
for (let profile of ProfileService.profiles) {
29-
if (profile.rootDir.path == cpd.path) {
30-
return profile;
31-
}
32-
}
33-
}
34-
35-
// selectedProfile can throw if nothing is selected or if the selected profile
36-
// has been deleted.
37-
try {
38-
return ProfileService.selectedProfile;
39-
} catch (e) {
40-
return null;
41-
}
42-
}
43-
4417
function refreshUI() {
4518
let parent = document.getElementById("profiles");
4619
while (parent.firstChild) {
@@ -52,7 +25,7 @@ function refreshUI() {
5225
defaultProfile = ProfileService.defaultProfile;
5326
} catch (e) {}
5427

55-
let currentProfile = findCurrentProfile();
28+
let currentProfile = ProfileService.currentProfile;
5629

5730
for (let profile of ProfileService.profiles) {
5831
let isCurrentProfile = profile == currentProfile;
@@ -197,10 +170,10 @@ function display(profileData) {
197170
div.appendChild(sep);
198171
}
199172

173+
// This is called from the createProfileWizard.xul dialog.
200174
function CreateProfile(profile) {
201-
ProfileService.selectedProfile = profile;
202-
ProfileService.flush();
203-
refreshUI();
175+
// The wizard created a profile, just make it the default.
176+
defaultProfile(profile);
204177
}
205178

206179
function createProfileWizard() {
@@ -269,30 +242,26 @@ async function removeProfile(profile) {
269242
}
270243
}
271244

272-
// If we are deleting the selected or the default profile we must choose a
273-
// different one.
274-
let isSelected = false;
275-
try {
276-
isSelected = ProfileService.selectedProfile == profile;
277-
} catch (e) {}
278-
245+
// If we are deleting the default profile we must choose a different one.
279246
let isDefault = false;
280247
try {
281248
isDefault = ProfileService.defaultProfile == profile;
282249
} catch (e) {}
283250

284-
if (isSelected || isDefault) {
251+
if (isDefault) {
285252
for (let p of ProfileService.profiles) {
286253
if (profile == p) {
287254
continue;
288255
}
289256

290-
if (isSelected) {
291-
ProfileService.selectedProfile = p;
292-
}
293-
294257
if (isDefault) {
295-
ProfileService.defaultProfile = p;
258+
try {
259+
ProfileService.defaultProfile = p;
260+
} catch (e) {
261+
// This can happen on dev-edition if a non-default profile is in use.
262+
// In such a case the next time that dev-edition is started it will
263+
// find no default profile and just create a new one.
264+
}
296265
}
297266

298267
break;
@@ -315,10 +284,19 @@ async function removeProfile(profile) {
315284
refreshUI();
316285
}
317286

318-
function defaultProfile(profile) {
319-
ProfileService.defaultProfile = profile;
320-
ProfileService.selectedProfile = profile;
321-
ProfileService.flush();
287+
async function defaultProfile(profile) {
288+
try {
289+
ProfileService.defaultProfile = profile;
290+
ProfileService.flush();
291+
} catch (e) {
292+
// This can happen on dev-edition.
293+
let [title, msg] = await document.l10n.formatValues([
294+
{ id: "profiles-cannot-set-as-default-title" },
295+
{ id: "profiles-cannot-set-as-default-message" },
296+
]);
297+
298+
Services.prompt.alert(window, title, msg);
299+
}
322300
refreshUI();
323301
}
324302

toolkit/content/aboutProfiles.xhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<link rel="icon" type="image/png" id="favicon" href="chrome://branding/content/icon32.png" />
1313
<link rel="stylesheet" href="chrome://mozapps/skin/aboutProfiles.css" type="text/css" />
1414
<script type="application/javascript" src="chrome://global/content/aboutProfiles.js" />
15+
<link rel="localization" href="branding/brand.ftl" />
1516
<link rel="localization" href="toolkit/about/aboutProfiles.ftl" />
1617
</head>
1718
<body id="body" class="wide-container">

toolkit/locales/en-US/toolkit/about/aboutProfiles.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ profiles-remove = Remove
3131
profiles-set-as-default = Set as default profile
3232
profiles-launch-profile = Launch profile in new browser
3333
34+
profiles-cannot-set-as-default-title = Unable to set default
35+
profiles-cannot-set-as-default-message = The default profile cannot be changed for { -brand-short-name }.
36+
3437
profiles-yes = yes
3538
profiles-no = no
3639

toolkit/profile/content/profileSelection.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function startup() {
3939
listitem.setAttribute("tooltiptext", tooltiptext);
4040
listitem.profile = profile;
4141
try {
42-
if (profile === gProfileService.selectedProfile) {
42+
if (profile === gProfileService.defaultProfile) {
4343
setTimeout(function(a) {
4444
profilesElement.ensureElementIsVisible(a);
4545
profilesElement.selectItem(a);
@@ -93,16 +93,18 @@ function acceptDialog() {
9393
}
9494
gDialogParams.objects.insertElementAt(profileLock.nsIProfileLock, 0);
9595

96-
gProfileService.selectedProfile = selectedProfile.profile;
97-
gProfileService.defaultProfile = selectedProfile.profile;
96+
try {
97+
gProfileService.defaultProfile = selectedProfile.profile;
98+
} catch (e) {
99+
// This can happen on dev-edition. We'll still restart with the selected
100+
// profile based on the lock's directories.
101+
}
98102
updateStartupPrefs();
99103

100104
gDialogParams.SetInt(0, 1);
101105
/* Bug 257777 */
102106
gDialogParams.SetInt(1, document.getElementById("offlineState").checked ? 1 : 0);
103107

104-
gDialogParams.SetString(0, selectedProfile.profile.name);
105-
106108
return true;
107109
}
108110

toolkit/profile/nsIToolkitProfileService.idl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,18 @@ interface nsIToolkitProfileService : nsISupports
1818
readonly attribute nsISimpleEnumerator /*nsIToolkitProfile*/ profiles;
1919

2020
/**
21-
* The currently selected profile (the one used or about to be used by the
22-
* browser).
21+
* The profile currently in use if it is a named profile. This will return
22+
* null if the current profile path doesn't match a profile in the database.
2323
*/
24-
attribute nsIToolkitProfile selectedProfile;
24+
readonly attribute nsIToolkitProfile currentProfile;
2525

2626
/**
27-
* The default profile (the one used or about to be used by the
28-
* browser if no other profile is specified at runtime). This is the profile
29-
* marked with Default=1 in profiles.ini and is usually the same as
30-
* selectedProfile, except on Developer Edition.
31-
*
32-
* Developer Edition uses a profile named "dev-edition-default" as the
33-
* default profile (which it creates if it doesn't exist), unless a special
34-
* empty file named "ignore-dev-edition-profile" is present next to
35-
* profiles.ini. In that case Developer Edition behaves the same as any
36-
* other build of Firefox.
27+
* The default profile for this build.
28+
* On startup this is the profile selected unless overridden by command line
29+
* arguments or environment variables. Setting this will change the profile
30+
* used by default the next time the application is started.
31+
* Attempting to change the default may throw an exception on builds that do
32+
* not support changing the default profile, such as developer edition.
3733
*/
3834
attribute nsIToolkitProfile defaultProfile;
3935

0 commit comments

Comments
 (0)