Bug 1416686 - Reduce the uses of IPC_FAIL_NO_REASON in GMPChild.cpp. draft
authorJames Cheng <jacheng@mozilla.com>
Mon, 13 Nov 2017 09:35:03 +0000
changeset 703566 d0d57446a09ce1359d4112d99b6371c25abd77b4
parent 703561 270c0e71fff4ff1c1e2f619140fb8092a81fa0d6
child 703570 9fe637d1243f00923a558b7de4bfc19a94943ad4
child 703639 cf895e067ea06214fbe355832824d2f8222814c6
child 704003 9c4047e967ce7b86a8e9b798d7abe2271d4133c8
push id90862
push userbmo:jacheng@mozilla.com
push dateMon, 27 Nov 2017 03:14:03 +0000
bugs1416686, 1416667
milestone59.0a1
Bug 1416686 - Reduce the uses of IPC_FAIL_NO_REASON in GMPChild.cpp. Originally, we use IPC_FAIL_NO_REASON to make IPC call return error and then it invokes MOZ_CRASH to kill the process itself. By using IPC_FAIL, we can pass a descriptive reason to GMPChild::ProcessingError and Bug 1416667 will use MOZ_CRASH_UNSAFE_PRINTF to print the reason to the crash report. In addition, we use CrashReporter::AnnotateCrashReport to record the lib path without exposing the data publicly. MozReview-Commit-ID: 15n1PItLgAp
dom/media/gmp/GMPChild.cpp
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -6,16 +6,17 @@
 #include "GMPChild.h"
 #include "GMPContentChild.h"
 #include "GMPProcessChild.h"
 #include "GMPLoader.h"
 #include "GMPVideoDecoderChild.h"
 #include "GMPVideoEncoderChild.h"
 #include "GMPVideoHost.h"
 #include "nsDebugImpl.h"
+#include "nsExceptionHandler.h"
 #include "nsIFile.h"
 #include "nsXULAppAPI.h"
 #include "gmp-video-decode.h"
 #include "gmp-video-encode.h"
 #include "GMPPlatform.h"
 #include "mozilla/ipc/CrashReporterClient.h"
 #include "mozilla/ipc/ProcessChild.h"
 #include "GMPUtils.h"
@@ -540,57 +541,84 @@ ToCString(const nsTArray<Pair<nsCString,
 
 mozilla::ipc::IPCResult
 GMPChild::AnswerStartPlugin(const nsString& aAdapter)
 {
   LOGD("%s", __FUNCTION__);
 
   nsCString libPath;
   if (!GetUTF8LibPath(libPath)) {
-    return IPC_FAIL_NO_REASON(this);
+    CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("GMPLibraryPath"),
+                                       NS_ConvertUTF16toUTF8(mPluginPath));
+
+#ifdef XP_WIN
+    return IPC_FAIL(
+      this,
+      nsPrintfCString("Failed to get lib path with error(%d).", GetLastError())
+        .get());
+#else
+    return IPC_FAIL(
+      this,
+      "Failed to get lib path.");
+#endif
   }
 
   auto platformAPI = new GMPPlatformAPI();
   InitPlatformAPI(*platformAPI, this);
 
   mGMPLoader = MakeUnique<GMPLoader>();
 #if defined(MOZ_GMP_SANDBOX)
   if (!mGMPLoader->CanSandbox()) {
     LOGD("%s Can't sandbox GMP, failing", __FUNCTION__);
     delete platformAPI;
-    return IPC_FAIL_NO_REASON(this);
+    return IPC_FAIL(this, "Can't sandbox GMP.");
   }
 #endif
   bool isChromium = aAdapter.EqualsLiteral("chromium");
 #if defined(MOZ_GMP_SANDBOX) && defined(XP_MACOSX)
   MacSandboxPluginType pluginType = MacSandboxPluginType_GMPlugin_Default;
   if (isChromium) {
     pluginType = MacSandboxPluginType_GMPlugin_EME_Widevine;
   }
   if (!SetMacSandboxInfo(pluginType)) {
     NS_WARNING("Failed to set Mac GMP sandbox info");
     delete platformAPI;
-    return IPC_FAIL_NO_REASON(this);
+    return IPC_FAIL(
+      this,
+      nsPrintfCString("Failed to set Mac GMP sandbox info with plugin type %d.",
+                      pluginType).get());
   }
 #endif
 
   GMPAdapter* adapter = nullptr;
   if (isChromium) {
     auto&& paths = MakeCDMHostVerificationPaths();
     GMP_LOG("%s CDM host paths=%s", __func__, ToCString(paths).get());
     adapter = new ChromiumCDMAdapter(Move(paths));
   }
 
   if (!mGMPLoader->Load(libPath.get(),
                         libPath.Length(),
                         platformAPI,
                         adapter)) {
     NS_WARNING("Failed to load GMP");
     delete platformAPI;
-    return IPC_FAIL_NO_REASON(this);
+    CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("GMPLibraryPath"),
+                                       NS_ConvertUTF16toUTF8(mPluginPath));
+
+#ifdef XP_WIN
+    return IPC_FAIL(
+      this,
+      nsPrintfCString("Failed to load GMP with error(%d).", GetLastError())
+        .get());
+#else
+    return IPC_FAIL(
+      this,
+      "Failed to load GMP.");
+#endif
   }
 
   return IPC_OK();
 }
 
 MessageLoop*
 GMPChild::GMPMessageLoop()
 {