Bug 375710 - Firefox 2.0.0.3 wants to downgrade to 2.0.0.2, patch by Masatoshi Kimura (:emk), reworked by me a bit, r=rstrong

This commit is contained in:
benjamin%smedbergs.us 2007-04-20 15:22:18 +00:00
Родитель 63d005f37c
Коммит bc0235e03f
9 изменённых файлов: 142 добавлений и 100 удалений

Просмотреть файл

@ -216,6 +216,7 @@ bin/components/libbrowserdirprovider.so
bin/components/libbrowsercomps.so
bin/components/txEXSLTRegExFunctions.js
bin/components/nsLivemarkService.js
bin/components/nsDefaultCLH.js
; Safe Browsing
bin/components/nsSafebrowsingApplication.js

Просмотреть файл

@ -224,6 +224,7 @@ bin\components\browserdirprovider.dll
bin\components\brwsrcmp.dll
bin\components\txEXSLTRegExFunctions.js
bin\components\nsLivemarkService.js
bin\components\nsDefaultCLH.js
; Safe Browsing
bin\components\nsSafebrowsingApplication.js

Просмотреть файл

@ -47,6 +47,9 @@ const nsIModule = Components.interfaces.nsIModule;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsISupportsString = Components.interfaces.nsISupportsString;
const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
const nsIProperties = Components.interfaces.nsIProperties;
const nsIFile = Components.interfaces.nsIFile;
const nsISimpleEnumerator = Components.interfaces.nsISimpleEnumerator;
/**
* This file provides a generic default command-line handler.
@ -59,6 +62,12 @@ const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
* It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
*/
function getDirectoryService()
{
return Components.classes["@mozilla.org/file/directory_service;1"]
.getService(nsIProperties);
}
var nsDefaultCLH = {
/* nsISupports */
@ -74,8 +83,40 @@ var nsDefaultCLH = {
/* nsICommandLineHandler */
handle : function clh_handle(cmdLine) {
var printDir;
while (printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false)) {
var out = "print-xpcom-dir(\"" + printDir + "\"): ";
try {
out += getDirectoryService().get(printDir, nsIFile).path;
}
catch (e) {
out += "<Not Provided>";
}
dump(out + "\n");
Components.utils.reportError(out);
}
var printDirList;
while (printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist",
false)) {
out = "print-xpcom-dirlist(\"" + printDirList + "\"): ";
try {
var list = getDirectoryService().get(printDirList,
nsISimpleEnumerator);
while (list.hasMoreElements())
out += list.getNext().QueryInterface(nsIFile).path + ";";
}
catch (e) {
out += "<Not Provided>";
}
dump(out + "\n");
Components.utils.reportError(out);
}
if (cmdLine.preventDefault)
return;
return;
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(nsIPrefBranch);
@ -90,8 +131,8 @@ var nsDefaultCLH = {
var win = windowMediator.getMostRecentWindow(singletonWindowType);
if (win) {
win.focus();
cmdLine.preventDefault = true;
return;
cmdLine.preventDefault = true;
return;
}
}
catch (e) { }

Просмотреть файл

@ -46,8 +46,7 @@ const URI_BRAND_PROPERTIES = "chrome://branding/locale/brand.properties";
const KEY_APPDIR = "XCurProcD";
const KEY_TMPDIR = "TmpD";
const KEY_LOCALDATA = "DefProfLRt";
const KEY_PROGRAMFILES = "ProgF";
const KEY_UPDROOT = "UpdRootD";
const KEY_UAPPDATA = "UAppData";
// see prio.h
@ -187,17 +186,12 @@ InstallLogWriter.prototype = {
// See the local appdata first if app dir is under Program Files.
var file = null;
var updRoot = getFile(KEY_APPDIR);
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var programFilesDir = fileLocator.get(KEY_PROGRAMFILES,
Components.interfaces.nsILocalFile);
if (programFilesDir.contains(updRoot, true)) {
var relativePath = updRoot.QueryInterface(Components.interfaces.nsILocalFile).
getRelativeDescriptor(programFilesDir);
var userLocalDir = fileLocator.get(KEY_LOCALDATA,
Components.interfaces.nsILocalFile).parent;
updRoot.setRelativeDescriptor(userLocalDir, relativePath);
var updRoot;
try {
updRoot = getFile(KEY_UPDROOT);
} catch (e) {
}
if (updRoot) {
file = appendUpdateLogPath(updRoot);
// When updating from Fx 2.0.0.1 to 2.0.0.3 (or later) on Vista,

Просмотреть файл

@ -66,8 +66,7 @@ const URI_UPDATE_NS = "http://www.mozilla.org/2005/app-update";
const KEY_APPDIR = "XCurProcD";
#ifdef XP_WIN
const KEY_LOCALDATA = "DefProfLRt";
const KEY_PROGRAMFILES = "ProgF";
const KEY_UPDROOT = "UpdRootD";
const KEY_UAPPDATA = "UAppData";
#endif
@ -237,16 +236,12 @@ function getUpdateDir(pathArray) {
function getDirInternal(key, pathArray, shouldCreate, update) {
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var dir = fileLocator.get(key, Components.interfaces.nsILocalFile);
var dir = fileLocator.get(key, Components.interfaces.nsIFile);
#ifdef XP_WIN
if (update) {
var programFilesDir = fileLocator.get(KEY_PROGRAMFILES,
Components.interfaces.nsILocalFile);
if (programFilesDir.contains(dir, true)) {
var relativePath = dir.getRelativeDescriptor(programFilesDir);
var userLocalDir = fileLocator.get(KEY_LOCALDATA,
Components.interfaces.nsILocalFile).parent;
dir.setRelativeDescriptor(userLocalDir, relativePath);
try {
dir = fileLocator.get(KEY_UPDROOT, Components.interfaces.nsIFile);
} catch (e) {
}
}
#endif
@ -352,17 +347,13 @@ function getUpdatesDir(key) {
getService(Components.interfaces.nsIProperties);
var appDir;
if (key)
appDir = fileLocator.get(key, Components.interfaces.nsILocalFile);
appDir = fileLocator.get(key, Components.interfaces.nsIFile);
else {
appDir = fileLocator.get(KEY_APPDIR, Components.interfaces.nsILocalFile);
appDir = fileLocator.get(KEY_APPDIR, Components.interfaces.nsIFile);
#ifdef XP_WIN
var programFilesDir = fileLocator.get(KEY_PROGRAMFILES,
Components.interfaces.nsILocalFile);
if (programFilesDir.contains(appDir, true)) {
var relativePath = appDir.getRelativeDescriptor(programFilesDir);
var userLocalDir = fileLocator.get(KEY_LOCALDATA,
Components.interfaces.nsILocalFile).parent;
appDir.setRelativeDescriptor(userLocalDir, relativePath);
try {
appDir = fileLocator.get(KEY_UPDROOT, Components.interfaces.nsIFile);
} catch (e) {
}
#endif
}

Просмотреть файл

@ -1418,27 +1418,6 @@ XRE_GetBinaryPath(const char* argv0, nsILocalFile* *aResult)
return NS_OK;
}
// copied from nsXREDirProvider.cpp
#ifdef XP_WIN
static nsresult
GetShellFolderPath(int folder, char result[MAXPATHLEN])
{
LPITEMIDLIST pItemIDList = NULL;
nsresult rv;
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, folder, &pItemIDList)) &&
SUCCEEDED(SHGetPathFromIDList(pItemIDList, result))) {
rv = NS_OK;
} else {
rv = NS_ERROR_NOT_AVAILABLE;
}
CoTaskMemFree(pItemIDList);
return rv;
}
#endif
#define NS_ERROR_LAUNCHED_CHILD_PROCESS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_PROFILE, 200)
#ifdef XP_WIN
@ -2583,45 +2562,17 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
#if defined(MOZ_UPDATER)
// Check for and process any available updates
nsCOMPtr<nsIFile> updRoot = dirProvider.GetAppDir();
nsCOMPtr<nsILocalFile> updRootl(do_QueryInterface(updRoot));
#ifdef XP_WIN
// Use <UserLocalDataDir>\updates\<relative path to app dir from
// Program Files> if app dir is under Program Files to avoid the
// folder virtualization mess on Windows Vista
char path[MAXPATHLEN];
rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, path);
NS_ENSURE_SUCCESS(rv, 1);
nsCOMPtr<nsILocalFile> programFilesDir;
rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_FALSE,
getter_AddRefs(programFilesDir));
NS_ENSURE_SUCCESS(rv, 1);
PRBool descendant;
rv = programFilesDir->Contains(updRootl, PR_TRUE, &descendant);
NS_ENSURE_SUCCESS(rv, 1);
if (descendant) {
nsCAutoString relativePath;
rv = updRootl->GetRelativeDescriptor(programFilesDir, relativePath);
NS_ENSURE_SUCCESS(rv, 1);
nsCOMPtr<nsILocalFile> userLocalDir;
rv = dirProvider.GetUserLocalDataDirectory(getter_AddRefs(userLocalDir));
NS_ENSURE_SUCCESS(rv, 1);
rv = NS_NewNativeLocalFile(EmptyCString(), PR_FALSE,
getter_AddRefs(updRootl));
NS_ENSURE_SUCCESS(rv, 1);
rv = updRootl->SetRelativeDescriptor(userLocalDir, relativePath);
NS_ENSURE_SUCCESS(rv, 1);
}
#endif
nsCOMPtr<nsIFile> updRoot;
PRBool persistent;
rv = dirProvider.GetFile(XRE_UPDATE_ROOT_DIR, &persistent,
getter_AddRefs(updRoot));
// XRE_UPDATE_ROOT_DIR may fail. Fallback to appDir if failed
if (NS_FAILED(rv))
updRoot = dirProvider.GetAppDir();
ProcessUpdates(dirProvider.GetGREDir(),
dirProvider.GetAppDir(),
updRootl,
updRoot,
gRestartArgc,
gRestartArgv);
#endif

Просмотреть файл

@ -60,6 +60,16 @@
// and we load localstore from somewhere else.
#define NS_LOCALSTORE_UNSAFE_FILE "LStoreS"
/**
* A directory service key which provides the update directory.
* At present this is supported only on Windows.
* Windows: Documents and Settings\<User>\Local Settings\Application Data\
* <Vendor>\<Application>\<relative path to app dir from Program Files>
* If appDir is not under the Program Files, directory service will fail.
* Callers should fallback to appDir.
*/
#define XRE_UPDATE_ROOT_DIR "UpdRootD"
class nsACString;
struct nsStaticModuleInfo;

Просмотреть файл

@ -127,13 +127,6 @@ nsXREDirProvider::SetProfile(nsIFile* aDir, nsIFile* aLocalDir)
{
NS_ASSERTION(aDir && aLocalDir, "We don't support no-profile apps yet!");
#ifdef DEBUG_bsmedberg
nsCAutoString path, path2;
aDir->GetNativePath(path);
aLocalDir->GetNativePath(path2);
printf("nsXREDirProvider::SetProfile('%s', '%s')\n", path.get(), path2.get());
#endif
nsresult rv;
rv = EnsureDirectoryExists(aDir);
@ -242,6 +235,11 @@ nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
!strcmp(aProperty, XRE_USER_APP_DATA_DIR)) {
rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
}
#ifdef XP_WIN
else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR)) {
rv = GetUpdateRootDir(getter_AddRefs(file));
}
#endif
else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
if (NS_SUCCEEDED(rv))
@ -785,6 +783,54 @@ GetShellFolderPath(int folder, char result[MAXPATHLEN])
return rv;
}
nsresult
nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
{
nsCOMPtr<nsIFile> appDir = GetAppDir();
nsCAutoString appPath;
nsresult rv = appDir->GetNativePath(appPath);
NS_ENSURE_SUCCESS(rv, rv);
// AppDir may be a short path. Convert to long path to make sure
// the consistency of the update folder location
nsCString longPath;
char *buf;
longPath.GetMutableData(&buf, MAXPATHLEN);
DWORD len = GetLongPathName(appPath.get(), buf, MAXPATHLEN);
// Failing GetLongPathName() is not fatal.
if (len <= 0 || len >= MAXPATHLEN)
longPath.Assign(appPath);
else
longPath.SetLength(len);
// Use <UserLocalDataDir>\updates\<relative path to app dir from
// Program Files> if app dir is under Program Files to avoid the
// folder virtualization mess on Windows Vista
char programFiles[MAXPATHLEN];
rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, programFiles);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 programFilesLen = strlen(programFiles);
programFiles[programFilesLen++] = '\\';
programFiles[programFilesLen] = '\0';
if (longPath.Length() < programFilesLen)
return NS_ERROR_FAILURE;
if (_strnicmp(programFiles, longPath.get(), programFilesLen) != 0)
return NS_ERROR_FAILURE;
nsCOMPtr<nsILocalFile> updRoot;
rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot));
NS_ENSURE_SUCCESS(rv, rv);
rv = updRoot->AppendRelativeNativePath(Substring(longPath, programFilesLen));
NS_ENSURE_SUCCESS(rv, rv);
NS_ADDREF(*aResult = updRoot);
return NS_OK;
}
#endif
nsresult

Просмотреть файл

@ -89,12 +89,19 @@ public:
return mGREDir;
}
/**
* Get the directory under which update directory is created.
* This method may be called before XPCOM is started. aResult
* is a clone, it may be modified.
*/
nsresult GetUpdateRootDir(nsIFile* *aResult);
/**
* Get the profile startup directory as determined by this class or by
* mAppProvider. This method may be called before XPCOM is started. aResult
* is a clone, it may be modified.
*/
nsresult GetProfileStartupDir(nsIFile* *aResult);
nsresult GetProfileStartupDir(nsIFile* *aResult);
/**
* Get the profile directory as determined by this class or by an