Bug 1337056 - Part 4: Assert that the ipcKey for a principal is avaliable when creating a PermissionKey in the child process, r=baku
authorMichael Layzell <michael@thelayzells.com>
Thu, 02 Mar 2017 16:56:01 -0500
changeset 348696 dc5c70cb15118d84c0137ea6a0f59b18e69ba73b
parent 348695 c2b8ead5376b5f5a3689e4faef9d814c27189ab6
child 348697 a21d709fd0b05f2614ad63c3e07b0540b259d068
push id31533
push userkwierso@gmail.com
push dateTue, 21 Mar 2017 23:08:53 +0000
treeherdermozilla-central@8744e9f8eb99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1337056
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1337056 - Part 4: Assert that the ipcKey for a principal is avaliable when creating a PermissionKey in the child process, r=baku MozReview-Commit-ID: G9TynCKgCVF
extensions/cookie/nsPermissionManager.cpp
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -34,16 +34,17 @@
 #include "mozilla/net/NeckoMessageUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsReadLine.h"
 #include "mozilla/Telemetry.h"
 #include "nsIConsoleService.h"
 #include "nsINavHistoryService.h"
 #include "nsToolkitCompsCID.h"
 #include "nsIObserverService.h"
+#include "nsPrintfCString.h"
 
 static nsPermissionManager *gPermissionManager = nullptr;
 
 using mozilla::dom::ContentParent;
 using mozilla::Unused; // ha!
 
 static bool
 IsChildProcess()
@@ -592,16 +593,34 @@ nsPermissionManager::PermissionKey::Crea
                                                         nsresult& aResult)
 {
   nsAutoCString origin;
   aResult = GetOriginFromPrincipal(aPrincipal, origin);
   if (NS_WARN_IF(NS_FAILED(aResult))) {
     return nullptr;
   }
 
+#ifdef DEBUG
+  // Creating a PermissionsKey to look up a permission if we haven't had those keys
+  // synced down yet is problematic, so we do a check here and emit an assertion if
+  // we see it happening.
+  if (XRE_IsContentProcess()) {
+    nsAutoCString permissionKey;
+    GetKeyForPrincipal(aPrincipal, permissionKey);
+
+    // NOTE: Theoretically an addon could ask for permissions which the process
+    // wouldn't have access to, and we wouldn't want to crash the process in
+    // this case, but our chrome code should never do this. Using NS_ASSERTION
+    // here so that we can test fetching unavaliable permissions in tests.
+    NS_ASSERTION(gPermissionManager->mAvailablePermissionKeys.Contains(permissionKey),
+                 nsPrintfCString("This content process hasn't received the "
+                                 "permissions for %s yet", permissionKey.get()).get());
+  }
+#endif
+
   return new PermissionKey(origin);
 }
 
 /**
  * Simple callback used by |AsyncClose| to trigger a treatment once
  * the database is closed.
  *
  * Note: Beware that, if you hold onto a |CloseDatabaseListener| from a