Bug 1246835 - Reduce #ifdefs pain in GMPChild.cpp. r=gerald
☠☠ backed out by 35cdc40a44c4 ☠ ☠
authorChris Pearce <cpearce@mozilla.com>
Tue, 09 Feb 2016 14:44:16 +1300
changeset 329786 c0b8f05a48d564dd81012d4c5e8239dec796c0f6
parent 329785 28b8b4aec23511750ec7158ee4753353ccbd1c8b
child 329787 a5f6e1f0e0e807a615f4f3ce1c395d60b0a1323d
push id10611
push userdmitchell@mozilla.com
push dateTue, 09 Feb 2016 15:15:43 +0000
reviewersgerald
bugs1246835
milestone47.0a1
Bug 1246835 - Reduce #ifdefs pain in GMPChild.cpp. r=gerald
dom/media/gmp/GMPChild.cpp
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -60,33 +60,29 @@ GMPChild::GMPChild()
 
 GMPChild::~GMPChild()
 {
   LOGD("GMPChild dtor");
 }
 
 static bool
 GetFileBase(const nsAString& aPluginPath,
-#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
             nsCOMPtr<nsIFile>& aLibDirectory,
-#endif
             nsCOMPtr<nsIFile>& aFileBase,
             nsAutoString& aBaseName)
 {
   nsresult rv = NS_NewLocalFile(aPluginPath,
                                 true, getter_AddRefs(aFileBase));
   if (NS_FAILED(rv)) {
     return false;
   }
 
-#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
   if (NS_FAILED(aFileBase->Clone(getter_AddRefs(aLibDirectory)))) {
     return false;
   }
-#endif
 
   nsCOMPtr<nsIFile> parent;
   rv = aFileBase->GetParent(getter_AddRefs(parent));
   if (NS_FAILED(rv)) {
     return false;
   }
 
   nsAutoString parentLeafName;
@@ -97,84 +93,93 @@ GetFileBase(const nsAString& aPluginPath
 
   aBaseName = Substring(parentLeafName,
                         4,
                         parentLeafName.Length() - 1);
   return true;
 }
 
 static bool
+GetFileBase(const nsAString& aPluginPath,
+            nsCOMPtr<nsIFile>& aFileBase,
+            nsAutoString& aBaseName)
+{
+  nsCOMPtr<nsIFile> unusedLibDir;
+  return GetFileBase(aPluginPath, unusedLibDir, aFileBase, aBaseName);
+}
+
+static bool
 GetPluginFile(const nsAString& aPluginPath,
-#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
               nsCOMPtr<nsIFile>& aLibDirectory,
-#endif
               nsCOMPtr<nsIFile>& aLibFile)
 {
   nsAutoString baseName;
-#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
   GetFileBase(aPluginPath, aLibDirectory, aLibFile, baseName);
-#else
-  GetFileBase(aPluginPath, aLibFile, baseName);
-#endif
 
 #if defined(XP_MACOSX)
   nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".dylib");
 #elif defined(OS_POSIX)
   nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".so");
 #elif defined(XP_WIN)
   nsAutoString binaryName =                            baseName + NS_LITERAL_STRING(".dll");
 #else
 #error not defined
 #endif
   aLibFile->AppendRelativePath(binaryName);
   return true;
 }
 
 static bool
+GetPluginFile(const nsAString& aPluginPath,
+              nsCOMPtr<nsIFile>& aLibFile)
+{
+  nsCOMPtr<nsIFile> unusedlibDir;
+  return GetPluginFile(aPluginPath, unusedlibDir, aLibFile);
+}
+
+static bool
 GetInfoFile(const nsAString& aPluginPath,
             nsCOMPtr<nsIFile>& aInfoFile)
 {
   nsAutoString baseName;
-#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
-  nsCOMPtr<nsIFile> unusedLibDir;
-  GetFileBase(aPluginPath, unusedLibDir, aInfoFile, baseName);
-#else
   GetFileBase(aPluginPath, aInfoFile, baseName);
-#endif
   nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".info");
   aInfoFile->AppendRelativePath(infoFileName);
   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)
 static bool
 GetPluginPaths(const nsAString& aPluginPath,
                nsCString &aPluginDirectoryPath,
                nsCString &aPluginFilePath)
 {
   nsCOMPtr<nsIFile> libDirectory, libFile;
   if (!GetPluginFile(aPluginPath, libDirectory, libFile)) {
     return false;
   }
 
   // Mac sandbox rules expect paths to actual files and directories -- not
   // soft links.
-  bool isLink;
-  libDirectory->IsSymlink(&isLink);
-  if (isLink) {
-    libDirectory->GetNativeTarget(aPluginDirectoryPath);
-  } else {
-    libDirectory->GetNativePath(aPluginDirectoryPath);
-  }
-  libFile->IsSymlink(&isLink);
-  if (isLink) {
-    libFile->GetNativeTarget(aPluginFilePath);
-  } else {
-    libFile->GetNativePath(aPluginFilePath);
-  }
+  aPluginDirectoryPath = GetNativeTarget(libDirectory);
+  aPluginFilePath = GetNativeTarget(libFile);
 
   return true;
 }
 
 static bool
 GetAppPaths(nsCString &aAppPath, nsCString &aAppBinaryPath)
 {
   nsAutoCString appPath;
@@ -200,29 +205,20 @@ GetAppPaths(nsCString &aAppPath, nsCStri
     return false;
   }
   rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(appBinaryPath),
                        true, getter_AddRefs(appBinary));
   if (NS_FAILED(rv)) {
     return false;
   }
 
-  bool isLink;
-  app->IsSymlink(&isLink);
-  if (isLink) {
-    app->GetNativeTarget(aAppPath);
-  } else {
-    app->GetNativePath(aAppPath);
-  }
-  appBinary->IsSymlink(&isLink);
-  if (isLink) {
-    appBinary->GetNativeTarget(aAppBinaryPath);
-  } else {
-    appBinary->GetNativePath(aAppBinaryPath);
-  }
+  // Mac sandbox rules expect paths to actual files and directories -- not
+  // soft links.
+  aAppPath = GetNativeTarget(app);
+  appBinaryPath = GetNativeTarget(appBinary);
 
   return true;
 }
 
 bool
 GMPChild::SetMacSandboxInfo()
 {
   if (!mGMPLoader) {
@@ -583,22 +579,17 @@ GMPChild::ShutdownComplete()
   SendAsyncShutdownComplete();
 }
 
 static void
 GetPluginVoucherFile(const nsAString& aPluginPath,
                      nsCOMPtr<nsIFile>& aOutVoucherFile)
 {
   nsAutoString baseName;
-#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
-  nsCOMPtr<nsIFile> libDir;
-  GetFileBase(aPluginPath, aOutVoucherFile, libDir, baseName);
-#else
   GetFileBase(aPluginPath, aOutVoucherFile, baseName);
-#endif
   nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".voucher");
   aOutVoucherFile->AppendRelativePath(infoFileName);
 }
 
 bool
 GMPChild::PreLoadPluginVoucher()
 {
   nsCOMPtr<nsIFile> voucherFile;