Bug 1077282: Cleanup uses of GreD vs GreBinD, introcuded by v2 signature changes on OSX. Based on initial patch by rstrong. r=bsmedberg
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -269,20 +269,17 @@ static int do_main(int argc, char* argv[
if (NS_FAILED(rv)) {
Output("Couldn't find the application directory.\n");
return 255;
}
nsCOMPtr<nsIFile> greDir;
exeFile->GetParent(getter_AddRefs(greDir));
#ifdef XP_MACOSX
- nsCOMPtr<nsIFile> parent;
- greDir->GetParent(getter_AddRefs(parent));
- greDir = parent.forget();
- greDir->AppendNative(NS_LITERAL_CSTRING(kOSXResourcesFolder));
+ greDir->SetNativeLeafName(NS_LITERAL_CSTRING(kOSXResourcesFolder));
#endif
nsCOMPtr<nsIFile> appSubdir;
greDir->Clone(getter_AddRefs(appSubdir));
appSubdir->Append(NS_LITERAL_STRING(kDesktopFolder));
SetStrongPtr(appData.directory, static_cast<nsIFile*>(appSubdir.get()));
// xreDirectory already has a refcount from NS_NewLocalFile
appData.xreDirectory = xreDirectory;
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -127,38 +127,34 @@ GeckoChildProcessHost::~GeckoChildProces
#endif
}
//static
void
GeckoChildProcessHost::GetPathToBinary(FilePath& exePath)
{
if (ShouldHaveDirectoryService()) {
- MOZ_ASSERT(gGREPath);
+ MOZ_ASSERT(gGREBinPath);
#ifdef OS_WIN
- exePath = FilePath(char16ptr_t(gGREPath));
+ exePath = FilePath(char16ptr_t(gGREBinPath));
#elif MOZ_WIDGET_COCOA
nsCOMPtr<nsIFile> childProcPath;
- NS_NewLocalFile(nsDependentString(gGREPath), false,
+ NS_NewLocalFile(nsDependentString(gGREBinPath), false,
getter_AddRefs(childProcPath));
// We need to use an App Bundle on OS X so that we can hide
// the dock icon. See Bug 557225.
- nsCOMPtr<nsIFile> tempPath;
- childProcPath->GetParent(getter_AddRefs(tempPath));
- childProcPath = tempPath.forget();
- childProcPath->AppendNative(NS_LITERAL_CSTRING("MacOS"));
childProcPath->AppendNative(NS_LITERAL_CSTRING("plugin-container.app"));
childProcPath->AppendNative(NS_LITERAL_CSTRING("Contents"));
childProcPath->AppendNative(NS_LITERAL_CSTRING("MacOS"));
nsCString tempCPath;
childProcPath->GetNativePath(tempCPath);
exePath = FilePath(tempCPath.get());
#else
nsCString path;
- NS_CopyUnicodeToNative(nsDependentString(gGREPath), path);
+ NS_CopyUnicodeToNative(nsDependentString(gGREBinPath), path);
exePath = FilePath(path.get());
#endif
}
if (exePath.empty()) {
#ifdef OS_WIN
exePath = FilePath::FromWStringHack(CommandLine::ForCurrentProcess()->program());
#else
@@ -543,29 +539,19 @@ GeckoChildProcessHost::PerformAsyncLaunc
if (privs == base::PRIVILEGES_DEFAULT) {
privs = DefaultChildPrivileges();
}
// XPCOM may not be initialized in some subprocesses. We don't want
// to initialize XPCOM just for the directory service, especially
// since LD_LIBRARY_PATH is already set correctly in subprocesses
// (meaning that we don't need to set that up in the environment).
if (ShouldHaveDirectoryService()) {
- MOZ_ASSERT(gGREPath);
+ MOZ_ASSERT(gGREBinPath);
nsCString path;
-#ifdef MOZ_WIDGET_COCOA
- nsCOMPtr<nsIFile> grePath;
- nsCOMPtr<nsIFile> tempPath;
- NS_NewLocalFile(nsDependentString(gGREPath), false,
- getter_AddRefs(grePath));
- grePath->GetParent(getter_AddRefs(tempPath));
- tempPath->AppendNative(NS_LITERAL_CSTRING("MacOS"));
- tempPath->GetNativePath(path);
-#else
- NS_CopyUnicodeToNative(nsDependentString(gGREPath), path);
-#endif
+ NS_CopyUnicodeToNative(nsDependentString(gGREBinPath), path);
# if defined(OS_LINUX) || defined(OS_BSD)
# if defined(MOZ_WIDGET_ANDROID)
path += "/lib";
# endif // MOZ_WIDGET_ANDROID
const char *ld_library_path = PR_GetEnv("LD_LIBRARY_PATH");
nsCString new_ld_lib_path;
if (ld_library_path && *ld_library_path) {
new_ld_lib_path.Assign(path.get());
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1272,21 +1272,20 @@ XRE_XPCShellMain(int argc, char **argv,
argc -= 2;
argv += 2;
} else {
#ifdef XP_MACOSX
// On OSX, the GreD needs to point to Contents/Resources in the .app
// bundle. Libraries will be loaded at a relative path to GreD, i.e.
// ../MacOS.
- XRE_GetFileFromPath(argv[0], getter_AddRefs(greDir));
- nsCOMPtr<nsIFile> parentDir;
- greDir->GetParent(getter_AddRefs(parentDir));
- parentDir->GetParent(getter_AddRefs(greDir));
- greDir->AppendNative(NS_LITERAL_CSTRING("Resources"));
+ nsCOMPtr<nsIFile> tmpDir;
+ XRE_GetFileFromPath(argv[0], getter_AddRefs(tmpDir));
+ tmpDir->GetParent(getter_AddRefs(greDir));
+ greDir->SetNativeLeafName(NS_LITERAL_CSTRING("Resources"));
bool dirExists = false;
greDir->Exists(&dirExists);
if (!dirExists) {
printf("Setting GreD failed.\n");
return 1;
}
dirprovider.SetGREDirs(greDir);
#else
--- a/security/manager/ssl/tests/unit/head_psm.js
+++ b/security/manager/ssl/tests/unit/head_psm.js
@@ -131,17 +131,17 @@ function _getLibraryFunctionWithNoArgume
// XXX really want to be able to pass specific dlopen flags here.
let nsslib;
try {
nsslib = ctypes.open(path);
} catch(e) {
// In case opening the library without a full path fails,
// try again with a full path.
- let file = Services.dirsvc.get("GreD", Ci.nsILocalFile);
+ let file = Services.dirsvc.get("GreBinD", Ci.nsILocalFile);
file.append(path);
nsslib = ctypes.open(file.path);
}
let SECStatus = ctypes.int;
let func = nsslib.declare(functionName, ctypes.default_abi, SECStatus);
return func;
}
@@ -355,21 +355,19 @@ function _setupTLSServerTest(serverBinNa
addCertFromFile(certdb, "tlsserver/test-ca.der", "CTu,u,u");
const CALLBACK_PORT = 8444;
let directoryService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
let envSvc = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
- let greDir = directoryService.get("GreD", Ci.nsIFile);
- let macOSDir = greDir.parent;
- macOSDir.append("MacOS");
- envSvc.set("DYLD_LIBRARY_PATH", macOSDir.path);
- envSvc.set("LD_LIBRARY_PATH", greDir.path);
+ let greBinDir = directoryService.get("GreBinD", Ci.nsIFile);
+ envSvc.set("DYLD_LIBRARY_PATH", greBinDir.path);
+ envSvc.set("LD_LIBRARY_PATH", greBinDir.path);
envSvc.set("MOZ_TLS_SERVER_DEBUG_LEVEL", "3");
envSvc.set("MOZ_TLS_SERVER_CALLBACK_PORT", CALLBACK_PORT);
let httpServer = new HttpServer();
httpServer.registerPathHandler("/",
function handleServerCallback(aRequest, aResponse) {
aResponse.setStatusLine(aRequest.httpVersion, 200, "OK");
aResponse.setHeader("Content-Type", "text/plain");
--- a/startupcache/test/TestStartupCache.cpp
+++ b/startupcache/test/TestStartupCache.cpp
@@ -409,24 +409,16 @@ int main(int argc, char** argv)
int rv = 0;
nsresult scrv;
// Register TestStartupCacheTelemetry
nsCOMPtr<nsIFile> manifest;
scrv = NS_GetSpecialDirectory(NS_GRE_DIR,
getter_AddRefs(manifest));
-#ifdef XP_MACOSX
- if (NS_SUCCEEDED(scrv)) {
- nsCOMPtr<nsIFile> parent;
- manifest->GetParent(getter_AddRefs(parent));
- parent->AppendNative(NS_LITERAL_CSTRING("MacOS"));
- manifest = parent.forget();
- }
-#endif
if (NS_FAILED(scrv)) {
fail("NS_XPCOM_CURRENT_PROCESS_DIR");
return 1;
}
manifest->AppendNative(NS_LITERAL_CSTRING("TestStartupCacheTelemetry.manifest"));
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, manifest);
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -269,17 +269,17 @@ nsXPTIInterfaceInfoManagerGetSingleton(n
}
return iim->QueryInterface(aIID, aInstancePtr);
}
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = nullptr;
bool gXPCOMShuttingDown = false;
bool gXPCOMThreadsShutDown = false;
-char16_t* gGREPath = nullptr;
+char16_t* gGREBinPath = nullptr;
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kINIParserFactoryCID, NS_INIPARSERFACTORY_CID);
static NS_DEFINE_CID(kSimpleUnicharStreamFactoryCID,
NS_SIMPLE_UNICHAR_STREAM_FACTORY_CID);
NS_DEFINE_NAMED_CID(NS_CHROMEREGISTRY_CID);
NS_DEFINE_NAMED_CID(NS_CHROMEPROTOCOLHANDLER_CID);
@@ -579,36 +579,25 @@ NS_InitXPCOM2(nsIServiceManager** aResul
if (aAppFileLocationProvider) {
rv = nsDirectoryService::gService->RegisterProvider(aAppFileLocationProvider);
if (NS_FAILED(rv)) {
return rv;
}
}
nsCOMPtr<nsIFile> xpcomLib;
- nsDirectoryService::gService->Get(NS_GRE_DIR,
+ nsDirectoryService::gService->Get(NS_GRE_BIN_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(xpcomLib));
MOZ_ASSERT(xpcomLib);
- // set gGREPath
+ // set gGREBinPath
nsAutoString path;
xpcomLib->GetPath(path);
- gGREPath = ToNewUnicode(path);
-
-#ifdef XP_MACOSX
- nsCOMPtr<nsIFile> parent;
- xpcomLib->GetParent(getter_AddRefs(parent));
- parent->AppendNative(NS_LITERAL_CSTRING("MacOS"));
- bool pathExists = false;
- parent->Exists(&pathExists);
- if (pathExists) {
- xpcomLib = parent.forget();
- }
-#endif
+ gGREBinPath = ToNewUnicode(path);
xpcomLib->AppendNative(nsDependentCString(XPCOM_DLL));
nsDirectoryService::gService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib);
if (!mozilla::Omnijar::IsInitialized()) {
mozilla::Omnijar::Init();
}
@@ -910,18 +899,18 @@ ShutdownXPCOM(nsIServiceManager* aServMg
// Shutdown global servicemanager
if (nsComponentManagerImpl::gComponentManager) {
nsComponentManagerImpl::gComponentManager->FreeServices();
}
// Release the directory service
NS_IF_RELEASE(nsDirectoryService::gService);
- NS_Free(gGREPath);
- gGREPath = nullptr;
+ NS_Free(gGREBinPath);
+ gGREBinPath = nullptr;
if (moduleLoaders) {
bool more;
nsCOMPtr<nsISupports> el;
while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) && more) {
moduleLoaders->GetNext(getter_AddRefs(el));
// Don't worry about weak-reference observers here: there is
--- a/xpcom/build/nsXPCOMPrivate.h
+++ b/xpcom/build/nsXPCOMPrivate.h
@@ -295,17 +295,19 @@ void LogTerm();
#define MAXPATHLEN CCHMAXPATH
#else
#define MAXPATHLEN 1024
#endif
#endif
extern bool gXPCOMShuttingDown;
extern bool gXPCOMThreadsShutDown;
-extern char16_t* gGREPath; // Needed by the IPC layer from off the main thread
+
+// Needed by the IPC layer from off the main thread
+extern char16_t* gGREBinPath;
namespace mozilla {
namespace services {
/**
* Clears service cache, sets gXPCOMShuttingDown
*/
void Shutdown();
--- a/xpcom/tests/TestHarness.h
+++ b/xpcom/tests/TestHarness.h
@@ -194,16 +194,41 @@ class ScopedXPCOM : public nsIDirectoryS
NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false,
getter_AddRefs(greD));
}
mGRED = greD;
return greD.forget();
}
+ already_AddRefed<nsIFile> GetGREBinDirectory()
+ {
+ if (mGREBinD) {
+ nsCOMPtr<nsIFile> copy = mGREBinD;
+ return copy.forget();
+ }
+
+ nsCOMPtr<nsIFile> greD = GetGREDirectory();
+ if (!greD) {
+ return greD.forget();
+ }
+ greD->Clone(getter_AddRefs(mGREBinD));
+
+#ifdef XP_MACOSX
+ nsAutoCString leafName;
+ mGREBinD->GetNativeLeafName(leafName);
+ if (leafName.Equals("Resources")) {
+ mGREBinD->SetNativeLeafName(NS_LITERAL_CSTRING("MacOS"));
+ }
+#endif
+
+ nsCOMPtr<nsIFile> copy = mGREBinD;
+ return copy.forget();
+ }
+
////////////////////////////////////////////////////////////////////////////
//// nsIDirectoryServiceProvider
NS_IMETHODIMP GetFile(const char *aProperty, bool *_persistent,
nsIFile **_result)
{
// If we were supplied a directory service provider, ask it first.
if (mDirSvcProvider &&
@@ -221,25 +246,30 @@ class ScopedXPCOM : public nsIDirectoryS
nsCOMPtr<nsIFile> clone;
nsresult rv = profD->Clone(getter_AddRefs(clone));
NS_ENSURE_SUCCESS(rv, rv);
*_persistent = true;
clone.forget(_result);
return NS_OK;
- }
-
- if (0 == strcmp(aProperty, NS_GRE_DIR)) {
+ } else if (0 == strcmp(aProperty, NS_GRE_DIR)) {
nsCOMPtr<nsIFile> greD = GetGREDirectory();
NS_ENSURE_TRUE(greD, NS_ERROR_FAILURE);
*_persistent = true;
greD.forget(_result);
return NS_OK;
+ } else if (0 == strcmp(aProperty, NS_GRE_BIN_DIR)) {
+ nsCOMPtr<nsIFile> greBinD = GetGREBinDirectory();
+ NS_ENSURE_TRUE(greBinD, NS_ERROR_FAILURE);
+
+ *_persistent = true;
+ greBinD.forget(_result);
+ return NS_OK;
}
return NS_ERROR_FAILURE;
}
////////////////////////////////////////////////////////////////////////////
//// nsIDirectoryServiceProvider2
@@ -256,16 +286,17 @@ class ScopedXPCOM : public nsIDirectoryS
}
private:
const char* mTestName;
nsIServiceManager* mServMgr;
nsCOMPtr<nsIDirectoryServiceProvider> mDirSvcProvider;
nsCOMPtr<nsIFile> mProfD;
nsCOMPtr<nsIFile> mGRED;
+ nsCOMPtr<nsIFile> mGREBinD;
};
NS_IMPL_QUERY_INTERFACE(
ScopedXPCOM,
nsIDirectoryServiceProvider,
nsIDirectoryServiceProvider2
)
--- a/xpcom/tests/unit/head_xpcom.js
+++ b/xpcom/tests/unit/head_xpcom.js
@@ -10,17 +10,15 @@ function get_test_program(prog)
}
function set_process_running_environment()
{
var envSvc = Components.classes["@mozilla.org/process/environment;1"].
getService(Components.interfaces.nsIEnvironment);
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties);
- var greDir = dirSvc.get("GreD", Components.interfaces.nsIFile);
- var macOSDir = greDir.parent;
- macOSDir.append("MacOS");
- envSvc.set("DYLD_LIBRARY_PATH", macOSDir.path);
+ var greBinDir = dirSvc.get("GreBinD", Components.interfaces.nsIFile);
+ envSvc.set("DYLD_LIBRARY_PATH", greBinDir.path);
// For Linux
- envSvc.set("LD_LIBRARY_PATH", greDir.path);
+ envSvc.set("LD_LIBRARY_PATH", greBinDir.path);
//XXX: handle windows
}