Bug 797798: System App can't Receive Sensor Event During Early Suspend State. r=jlebar

This commit is contained in:
Steven Lee 2012-10-24 10:30:10 +08:00
parent 84f5850fcd
commit 3c5f85b5ff
2 changed files with 32 additions and 7 deletions

View File

@ -232,6 +232,11 @@ const PermissionsTable = { "resource-lock": {
privileged: DENY_ACTION,
certified: ALLOW_ACTION
},
"background-sensors": {
app: DENY_ACTION,
privileged: DENY_ACTION,
certified: ALLOW_ACTION
},
};
// Sometimes all permissions (fully expanded) need to be iterated through

View File

@ -18,6 +18,7 @@
#include "GeneratedEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/Attributes.h"
#include "nsIPermissionManager.h"
using namespace mozilla;
using namespace hal;
@ -166,7 +167,29 @@ NS_IMETHODIMP nsDeviceSensors::RemoveWindowAsListener(nsIDOMWindow *aWindow)
return NS_OK;
}
void
static bool
WindowCannotReceiveSensorEvent (nsPIDOMWindow* 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.
if (!aWindow || !aWindow->GetOuterWindow()) {
return true;
}
if (aWindow->GetOuterWindow()->IsBackground()) {
nsCOMPtr<nsIPermissionManager> permMgr =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_TRUE(permMgr, false);
uint32_t permission = nsIPermissionManager::DENY_ACTION;
permMgr->TestPermissionFromWindow(aWindow, "background-sensors", &permission);
return permission != nsIPermissionManager::ALLOW_ACTION;
}
return false;
}
void
nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData)
{
uint32_t type = aSensorData.sensor();
@ -185,13 +208,10 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData)
for (uint32_t i = windowListeners.Count(); i > 0 ; ) {
--i;
// check to see if this window is in the background. if
// it is, don't send any device motion to it.
nsCOMPtr<nsPIDOMWindow> pwindow = do_QueryInterface(windowListeners[i]);
if (!pwindow ||
!pwindow->GetOuterWindow() ||
pwindow->GetOuterWindow()->IsBackground())
continue;
if (WindowCannotReceiveSensorEvent(pwindow)) {
continue;
}
nsCOMPtr<nsIDOMDocument> domdoc;
windowListeners[i]->GetDocument(getter_AddRefs(domdoc));