Skip to content

Commit

Permalink
Bug 1077282: Cleanup uses of GreD vs GreBinD, introcuded by v2 signat…
Browse files Browse the repository at this point in the history
…ure changes on OSX. Based on initial patch by rstrong. r=bsmedberg
  • Loading branch information
Stephen Pohl committed Oct 10, 2014
1 parent 3c1fa4d commit 3a21ce5
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 69 deletions.
5 changes: 1 addition & 4 deletions browser/app/nsBrowserApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,7 @@ static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
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));
Expand Down
26 changes: 6 additions & 20 deletions ipc/glue/GeckoChildProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,15 @@ 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"));
Expand All @@ -153,7 +149,7 @@ GeckoChildProcessHost::GetPathToBinary(FilePath& exePath)
exePath = FilePath(tempCPath.get());
#else
nsCString path;
NS_CopyUnicodeToNative(nsDependentString(gGREPath), path);
NS_CopyUnicodeToNative(nsDependentString(gGREBinPath), path);
exePath = FilePath(path.get());
#endif
}
Expand Down Expand Up @@ -548,19 +544,9 @@ GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExt
// 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";
Expand Down
9 changes: 4 additions & 5 deletions js/xpconnect/src/XPCShellImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,11 +1277,10 @@ XRE_XPCShellMain(int argc, char **argv, char **envp)
// 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) {
Expand Down
10 changes: 4 additions & 6 deletions security/manager/ssl/tests/unit/head_psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function _getLibraryFunctionWithNoArguments(functionName, libraryName) {
} 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);
}
Expand Down Expand Up @@ -360,11 +360,9 @@ function _setupTLSServerTest(serverBinName)
.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);

Expand Down
8 changes: 0 additions & 8 deletions startupcache/test/TestStartupCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,6 @@ int main(int argc, char** argv)
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;
Expand Down
23 changes: 6 additions & 17 deletions xpcom/build/XPCOMInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* aOuter,
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);
Expand Down Expand Up @@ -584,26 +584,15 @@ NS_InitXPCOM2(nsIServiceManager** aResult,
}

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);
Expand Down Expand Up @@ -915,8 +904,8 @@ ShutdownXPCOM(nsIServiceManager* aServMgr)
// Release the directory service
NS_IF_RELEASE(nsDirectoryService::gService);

NS_Free(gGREPath);
gGREPath = nullptr;
NS_Free(gGREBinPath);
gGREBinPath = nullptr;

if (moduleLoaders) {
bool more;
Expand Down
4 changes: 3 additions & 1 deletion xpcom/build/nsXPCOMPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ void LogTerm();

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 {
Expand Down
37 changes: 34 additions & 3 deletions xpcom/tests/TestHarness.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,31 @@ class ScopedXPCOM : public nsIDirectoryServiceProvider2
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

Expand Down Expand Up @@ -226,15 +251,20 @@ class ScopedXPCOM : public nsIDirectoryServiceProvider2
*_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;
Expand All @@ -261,6 +291,7 @@ class ScopedXPCOM : public nsIDirectoryServiceProvider2
nsCOMPtr<nsIDirectoryServiceProvider> mDirSvcProvider;
nsCOMPtr<nsIFile> mProfD;
nsCOMPtr<nsIFile> mGRED;
nsCOMPtr<nsIFile> mGREBinD;
};

NS_IMPL_QUERY_INTERFACE(
Expand Down
8 changes: 3 additions & 5 deletions xpcom/tests/unit/head_xpcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ function set_process_running_environment()
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
}

0 comments on commit 3a21ce5

Please sign in to comment.