Bug 1246835 - Reduce #ifdefs pain in GMPChild.cpp. r=gerald

This commit is contained in:
Chris Pearce 2016-02-09 14:44:16 +13:00
Родитель a34fe426f2
Коммит d5820bea46
1 изменённых файлов: 37 добавлений и 46 удалений

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

@ -65,9 +65,7 @@ GMPChild::~GMPChild()
static bool static bool
GetFileBase(const nsAString& aPluginPath, GetFileBase(const nsAString& aPluginPath,
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
nsCOMPtr<nsIFile>& aLibDirectory, nsCOMPtr<nsIFile>& aLibDirectory,
#endif
nsCOMPtr<nsIFile>& aFileBase, nsCOMPtr<nsIFile>& aFileBase,
nsAutoString& aBaseName) nsAutoString& aBaseName)
{ {
@ -77,11 +75,9 @@ GetFileBase(const nsAString& aPluginPath,
return false; return false;
} }
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
if (NS_FAILED(aFileBase->Clone(getter_AddRefs(aLibDirectory)))) { if (NS_FAILED(aFileBase->Clone(getter_AddRefs(aLibDirectory)))) {
return false; return false;
} }
#endif
nsCOMPtr<nsIFile> parent; nsCOMPtr<nsIFile> parent;
rv = aFileBase->GetParent(getter_AddRefs(parent)); rv = aFileBase->GetParent(getter_AddRefs(parent));
@ -101,19 +97,22 @@ GetFileBase(const nsAString& aPluginPath,
return true; return true;
} }
static bool
GetFileBase(const nsAString& aPluginPath,
nsCOMPtr<nsIFile>& aFileBase,
nsAutoString& aBaseName)
{
nsCOMPtr<nsIFile> unusedLibDir;
return GetFileBase(aPluginPath, unusedLibDir, aFileBase, aBaseName);
}
static bool static bool
GetPluginFile(const nsAString& aPluginPath, GetPluginFile(const nsAString& aPluginPath,
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
nsCOMPtr<nsIFile>& aLibDirectory, nsCOMPtr<nsIFile>& aLibDirectory,
#endif
nsCOMPtr<nsIFile>& aLibFile) nsCOMPtr<nsIFile>& aLibFile)
{ {
nsAutoString baseName; nsAutoString baseName;
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
GetFileBase(aPluginPath, aLibDirectory, aLibFile, baseName); GetFileBase(aPluginPath, aLibDirectory, aLibFile, baseName);
#else
GetFileBase(aPluginPath, aLibFile, baseName);
#endif
#if defined(XP_MACOSX) #if defined(XP_MACOSX)
nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".dylib"); nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".dylib");
@ -128,22 +127,39 @@ GetPluginFile(const nsAString& aPluginPath,
return true; return true;
} }
static bool
GetPluginFile(const nsAString& aPluginPath,
nsCOMPtr<nsIFile>& aLibFile)
{
nsCOMPtr<nsIFile> unusedlibDir;
return GetPluginFile(aPluginPath, unusedlibDir, aLibFile);
}
static bool static bool
GetInfoFile(const nsAString& aPluginPath, GetInfoFile(const nsAString& aPluginPath,
nsCOMPtr<nsIFile>& aInfoFile) nsCOMPtr<nsIFile>& aInfoFile)
{ {
nsAutoString baseName; nsAutoString baseName;
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
nsCOMPtr<nsIFile> unusedLibDir;
GetFileBase(aPluginPath, unusedLibDir, aInfoFile, baseName);
#else
GetFileBase(aPluginPath, aInfoFile, baseName); GetFileBase(aPluginPath, aInfoFile, baseName);
#endif
nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".info"); nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".info");
aInfoFile->AppendRelativePath(infoFileName); aInfoFile->AppendRelativePath(infoFileName);
return true; return true;
} }
static nsCString
GetNativeTarget(nsIFile* aFile)
{
bool isLink;
nsCString path;
aFile->IsSymlink(&isLink);
if (isLink) {
aFile->GetNativeTarget(path);
} else {
aFile->GetNativePath(path);
}
return path;
}
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX) #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
static bool static bool
GetPluginPaths(const nsAString& aPluginPath, GetPluginPaths(const nsAString& aPluginPath,
@ -157,19 +173,8 @@ GetPluginPaths(const nsAString& aPluginPath,
// Mac sandbox rules expect paths to actual files and directories -- not // Mac sandbox rules expect paths to actual files and directories -- not
// soft links. // soft links.
bool isLink; aPluginDirectoryPath = GetNativeTarget(libDirectory);
libDirectory->IsSymlink(&isLink); aPluginFilePath = GetNativeTarget(libFile);
if (isLink) {
libDirectory->GetNativeTarget(aPluginDirectoryPath);
} else {
libDirectory->GetNativePath(aPluginDirectoryPath);
}
libFile->IsSymlink(&isLink);
if (isLink) {
libFile->GetNativeTarget(aPluginFilePath);
} else {
libFile->GetNativePath(aPluginFilePath);
}
return true; return true;
} }
@ -205,19 +210,10 @@ GetAppPaths(nsCString &aAppPath, nsCString &aAppBinaryPath)
return false; return false;
} }
bool isLink; // Mac sandbox rules expect paths to actual files and directories -- not
app->IsSymlink(&isLink); // soft links.
if (isLink) { aAppPath = GetNativeTarget(app);
app->GetNativeTarget(aAppPath); appBinaryPath = GetNativeTarget(appBinary);
} else {
app->GetNativePath(aAppPath);
}
appBinary->IsSymlink(&isLink);
if (isLink) {
appBinary->GetNativeTarget(aAppBinaryPath);
} else {
appBinary->GetNativePath(aAppBinaryPath);
}
return true; return true;
} }
@ -588,12 +584,7 @@ GetPluginVoucherFile(const nsAString& aPluginPath,
nsCOMPtr<nsIFile>& aOutVoucherFile) nsCOMPtr<nsIFile>& aOutVoucherFile)
{ {
nsAutoString baseName; nsAutoString baseName;
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
nsCOMPtr<nsIFile> libDir;
GetFileBase(aPluginPath, aOutVoucherFile, libDir, baseName);
#else
GetFileBase(aPluginPath, aOutVoucherFile, baseName); GetFileBase(aPluginPath, aOutVoucherFile, baseName);
#endif
nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".voucher"); nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".voucher");
aOutVoucherFile->AppendRelativePath(infoFileName); aOutVoucherFile->AppendRelativePath(infoFileName);
} }