1919# include < windows.h>
2020# include < shlobj.h>
2121# include " mozilla/PolicyChecks.h"
22- # include " WinUtils.h"
2322#endif
2423#ifdef XP_UNIX
2524# include < unistd.h>
5554#include " nsProxyRelease.h"
5655#include " prinrval.h"
5756#include " prthread.h"
58- #include " mozilla/XREAppData.h"
5957
6058using namespace mozilla ;
6159
62- extern const char gToolkitBuildID [];
63-
6460#define DEV_EDITION_NAME " dev-edition-default"
6561#define DEFAULT_NAME " default"
6662#define COMPAT_FILE u" compatibility.ini" _ns
@@ -1535,114 +1531,6 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
15351531 }
15361532 }
15371533
1538- if (IsWinPackageEnvironment () && mIsFirstRun && !mProfiles .isEmpty ()) {
1539- // Unlike with Snap packages, Windows packages do use dedicated profiles,
1540- // so we don't need any special behavior to create a profile for them.
1541- // However, it's likely that a user of an app package was previously using
1542- // a non-packaged installation, and so has a dedicated profile for that
1543- // installation, or possibly a "normal" default profile, and we want that
1544- // user to have some level of continuity when they make the switch. What
1545- // that means is that we need to identify the profile that is most likely to
1546- // be the one the user was last working in, and run a profile migration into
1547- // our new dedicated profile for this installation. This code handles the
1548- // first part, identifying the profile, and then hands off to the regular
1549- // profile cleanup code in XREMain to run the actual migration.
1550- nsCOMPtr<nsIToolkitProfile> oldProfile;
1551-
1552- // Packages aren't really associated with any non-packaged installation, so
1553- // we have no way to look up any specific dedicated profile. The next best
1554- // way we have to identify the most relevant profile is to find the one
1555- // that was used most recently.
1556- PRTime latestTime = 0 ;
1557-
1558- // We'll also check whether each profile would be a downgrade, unless
1559- // downgrades are being allowed.
1560- bool allowDowngrade =
1561- EnvHasValue (" MOZ_ALLOW_DOWNGRADE" ) ||
1562- CheckArg (*aArgc, aArgv, " allow-downgrade" ,
1563- static_cast <const char **>(nullptr ), CheckArgFlag::None);
1564-
1565- for (nsCOMPtr<nsIToolkitProfile> profile : mProfiles ) {
1566- // Get this profile's last used time by checking the modified time on
1567- // its lock file. This isn't an ideal way to decide when the profile was
1568- // used last, but that time doesn't seem to be reliably written anywhere
1569- // else that we can read from here.
1570- nsCOMPtr<nsIFile> rootDir;
1571- profile->GetRootDir (getter_AddRefs (rootDir));
1572- nsCOMPtr<nsIFile> lockFile;
1573- rootDir->Clone (getter_AddRefs (lockFile));
1574- lockFile->Append (u" parent.lock" _ns);
1575-
1576- PRTime lastLockTime = 0 ;
1577- lockFile->GetLastModifiedTime (&lastLockTime);
1578-
1579- if (lastLockTime <= latestTime) {
1580- continue ;
1581- }
1582-
1583- // This is (currently) the most recently used profile, but we need to
1584- // make sure it hasn't been used by a newer version of the application,
1585- // because if it has then we won't be able to load it. But also, this
1586- // whole check is a waste of time if downgrade is enabled, so check for
1587- // that condition first.
1588- if (allowDowngrade) {
1589- oldProfile = profile;
1590- latestTime = lastLockTime;
1591- continue ;
1592- }
1593-
1594- nsCOMPtr<nsIFile> compatIniFile;
1595- rootDir->Clone (getter_AddRefs (compatIniFile));
1596- if (!compatIniFile) {
1597- continue ;
1598- }
1599-
1600- compatIniFile->Append (COMPAT_FILE);
1601- nsINIParser compatIniParser;
1602- if (NS_FAILED(compatIniParser.Init (compatIniFile))) {
1603- continue ;
1604- }
1605-
1606- nsAutoCString lastVersion;
1607- if (NS_FAILED(compatIniParser.GetString (" Compatibility" , " LastVersion" ,
1608- lastVersion))) {
1609- continue ;
1610- }
1611-
1612- nsAutoCString currentVersion;
1613- if (gAppData ) {
1614- BuildCompatVersion (gAppData ->version , gAppData ->buildID ,
1615- gToolkitBuildID , currentVersion);
1616- } else {
1617- // gAppData is the preferred way to get the app version and build ID,
1618- // but xpcshell doesn't initialize it, so we need a fallback. This
1619- // assumes that the app and toolkit version/build ID are the same, which
1620- // is not good to assume in general, but should be fine for xpcshell.
1621- BuildCompatVersion (MOZILLA_VERSION, gToolkitBuildID , gToolkitBuildID ,
1622- currentVersion);
1623- }
1624- if (CompareCompatVersions (lastVersion, currentVersion) > 0 ) {
1625- continue ;
1626- }
1627-
1628- oldProfile = profile;
1629- latestTime = lastLockTime;
1630- }
1631-
1632- // We can't invoke the migrator directly from here because the component
1633- // manager isn't running yet, so signal to our caller that it should start a
1634- // migration whenever possible. We need to do that before creating a new
1635- // profile here because the refresh procedure will create one later.
1636- if (oldProfile) {
1637- mCurrent = oldProfile.forget ();
1638- mCurrent ->GetRootDir (aRootDir);
1639- mCurrent ->GetLocalDir (aLocalDir);
1640- NS_ADDREF (*aProfile = mCurrent );
1641- mStartupReason = u" firstrun-migrated-default" _ns;
1642- return NS_MIGRATE_INTO_PACKAGE;
1643- }
1644- }
1645-
16461534 // If this is a first run then create a new profile.
16471535 if (mIsFirstRun ) {
16481536 // If we're configured to always show the profile manager then don't create
@@ -1735,8 +1623,8 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
17351623
17361624 GetDefaultProfile (getter_AddRefs (mCurrent ));
17371625
1738- // None of the profiles was marked as default (generally only happens if
1739- // the user modifies profiles.ini manually). Let the user choose.
1626+ // None of the profiles was marked as default (generally only happens if the
1627+ // user modifies profiles.ini manually). Let the user choose.
17401628 if (!mCurrent ) {
17411629 return NS_ERROR_SHOW_PROFILE_MANAGER;
17421630 }
@@ -1790,22 +1678,14 @@ nsresult nsToolkitProfileService::CreateResetProfile(
17901678 * default as well.
17911679 */
17921680nsresult nsToolkitProfileService::ApplyResetProfile (
1793- nsIToolkitProfile* aOldProfile, bool aDeleteOldProfile ) {
1681+ nsIToolkitProfile* aOldProfile) {
17941682 // If the old profile would have been the default for old installs then mark
17951683 // the new profile as such.
17961684 if (mNormalDefault == aOldProfile) {
17971685 SetNormalDefault (mCurrent );
17981686 }
17991687
1800- // For a "standard" profile reset, the current dedicated profile (the one that
1801- // we've just created and reset into) should match the one that we've migrated
1802- // from; that means we want to make this one our new dedicated default.
1803- // If they don't match, it might be because we migrated from a different
1804- // installation's dedicated profile, or a non-dedicated profile; in that case
1805- // we aren't deleting the old profile, but we still need to set the new one as
1806- // this installation's default.
1807- if (mUseDedicatedProfile &&
1808- (mDedicatedProfile == aOldProfile || !aDeleteOldProfile)) {
1688+ if (mUseDedicatedProfile && mDedicatedProfile == aOldProfile) {
18091689 bool wasLocked = false ;
18101690 nsCString val;
18111691 if (NS_SUCCEEDED(
@@ -1821,31 +1701,27 @@ nsresult nsToolkitProfileService::ApplyResetProfile(
18211701 }
18221702 }
18231703
1824- if (aDeleteOldProfile) {
1825- nsCString name;
1826- nsresult rv = aOldProfile->GetName (name);
1827- NS_ENSURE_SUCCESS (rv, rv);
1704+ nsCString name;
1705+ nsresult rv = aOldProfile->GetName (name);
1706+ NS_ENSURE_SUCCESS (rv, rv);
18281707
1829- // Don't remove the old profile's files until after we've successfully
1830- // flushed the profile changes to disk.
1831- rv = aOldProfile->Remove (false );
1832- NS_ENSURE_SUCCESS (rv, rv);
1708+ // Don't remove the old profile's files until after we've successfully flushed
1709+ // the profile changes to disk.
1710+ rv = aOldProfile->Remove (false );
1711+ NS_ENSURE_SUCCESS (rv, rv);
18331712
1834- // Switching the name will make this the default for dev-edition if
1835- // appropriate.
1836- rv = mCurrent ->SetName (name);
1837- NS_ENSURE_SUCCESS (rv, rv);
1838- }
1713+ // Switching the name will make this the default for dev-edition if
1714+ // appropriate.
1715+ rv = mCurrent ->SetName (name);
1716+ NS_ENSURE_SUCCESS (rv, rv);
18391717
1840- nsresult rv = Flush ();
1718+ rv = Flush ();
18411719 NS_ENSURE_SUCCESS (rv, rv);
18421720
1843- if (aDeleteOldProfile) {
1844- // Now that the profile changes are flushed, try to remove the old profile's
1845- // files. If we fail the worst that will happen is that an orphan directory
1846- // is left. Let this run in the background while we start up.
1847- RemoveProfileFiles (aOldProfile, true );
1848- }
1721+ // Now that the profile changes are flushed, try to remove the old profile's
1722+ // files. If we fail the worst that will happen is that an orphan directory is
1723+ // left. Let this run in the background while we start up.
1724+ RemoveProfileFiles (aOldProfile, true );
18491725
18501726 return NS_OK;
18511727}
@@ -2057,25 +1933,6 @@ bool nsToolkitProfileService::IsSnapEnvironment() {
20571933 return (strcmp (snapName, " firefox" ) == 0 );
20581934}
20591935
2060- /* *
2061- * Like Snaps, Windows app packages
2062- * (https://docs.microsoft.com/en-us/windows/msix/overview) use a
2063- * different installation directory for every version of the application, but
2064- * we have an alternative method of obtaining a per-installation hash for such
2065- * packages. Because of that, we don't disable dedicated profiles for them.
2066- * We still need to know when we're in one though, because we have special
2067- * migration behavior there; see comments in SelectStartupProfile.
2068- */
2069- bool nsToolkitProfileService::IsWinPackageEnvironment () {
2070- #ifdef XP_WIN
2071- if (EnvHasValue (" MOZ_TEST_EMULATE_PACKAGE" ) ||
2072- mozilla::widget::WinUtils::HasPackageIdentity ()) {
2073- return true ;
2074- }
2075- #endif
2076- return false ;
2077- }
2078-
20791936/* *
20801937 * In some situations dedicated profile support does not work well. This
20811938 * includes a handful of linux distributions which always install different
0 commit comments