Bug 1452826 - Simplify sensor event check; r=johannh
authorKyle Machulis <kyle@nonpolynomial.com>
Wed, 11 Apr 2018 14:15:54 -0700
changeset 414522 8908bab5b9d2ccf63f2e1a5b243c943bae5cf9d4
parent 414521 60659125bdd3014c5dcead0878f1ec659dab17ba
child 414523 209bf033ef6dd029c3253384780b5c2081d1397f
push id33870
push usercsabou@mozilla.com
push dateThu, 19 Apr 2018 22:28:45 +0000
treeherdermozilla-central@5c983ad5a421 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1452826
milestone61.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 1452826 - Simplify sensor event check; r=johannh Remove check for background-sensor permission, since there is no place in the code that grants that permission anymore. MozReview-Commit-ID: 6im17gfzmGi
dom/system/nsDeviceSensors.cpp
--- a/dom/system/nsDeviceSensors.cpp
+++ b/dom/system/nsDeviceSensors.cpp
@@ -238,52 +238,42 @@ NS_IMETHODIMP nsDeviceSensors::RemoveWin
     RemoveWindowListener((SensorType)i, aWindow);
   }
   return NS_OK;
 }
 
 static bool
 WindowCannotReceiveSensorEvent (nsPIDOMWindowInner* aWindow)
 {
-  // Check to see if this window is in the background.  If
-  // it is and it does not have the "background-sensors" permission,
-  // don't send any device motion events to it.
+  // Check to see if this window is in the background.
   if (!aWindow || !aWindow->IsCurrentInnerWindow()) {
     return true;
   }
 
   bool disabled = aWindow->GetOuterWindow()->IsBackground() ||
-                  !aWindow->IsTopLevelWindowActive();
-  if (!disabled) {
-    nsCOMPtr<nsPIDOMWindowOuter> top = aWindow->GetScriptableTop();
-    nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
-    nsCOMPtr<nsIScriptObjectPrincipal> topSop = do_QueryInterface(top);
-    if (!sop || !topSop) {
-      return true;
-    }
-
-    nsIPrincipal* principal = sop->GetPrincipal();
-    nsIPrincipal* topPrincipal = topSop->GetPrincipal();
-    if (!principal || !topPrincipal) {
-      return true;
-    }
-
-    disabled = !principal->Subsumes(topPrincipal);
+    !aWindow->IsTopLevelWindowActive();
+  if (disabled) {
+    return true;
   }
 
-  if (disabled) {
-    nsCOMPtr<nsIPermissionManager> permMgr =
-      services::GetPermissionManager();
-    NS_ENSURE_TRUE(permMgr, true);
-    uint32_t permission = nsIPermissionManager::DENY_ACTION;
-    permMgr->TestPermissionFromWindow(aWindow, "background-sensors", &permission);
-    return permission != nsIPermissionManager::ALLOW_ACTION;
+  // Check to see if this window is a cross-origin iframe
+  nsCOMPtr<nsPIDOMWindowOuter> top = aWindow->GetScriptableTop();
+  nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
+  nsCOMPtr<nsIScriptObjectPrincipal> topSop = do_QueryInterface(top);
+  if (!sop || !topSop) {
+    return true;
   }
 
-  return false;
+  nsIPrincipal* principal = sop->GetPrincipal();
+  nsIPrincipal* topPrincipal = topSop->GetPrincipal();
+  if (!principal || !topPrincipal) {
+    return true;
+  }
+
+  return !principal->Subsumes(topPrincipal);
 }
 
 // Holds the device orientation in Euler angle degrees (azimuth, pitch, roll).
 struct Orientation
 {
   enum OrientationReference
   {
     kRelative = 0,