diff --git a/content/events/test/Makefile.in b/content/events/test/Makefile.in
index 488085373624..5d7c62ec7f7a 100644
--- a/content/events/test/Makefile.in
+++ b/content/events/test/Makefile.in
@@ -85,6 +85,7 @@ _TEST_FILES = \
test_bug741666.html \
test_dom_keyboard_event.html \
test_dom_mouse_event.html \
+ test_bug742376.html \
$(NULL)
#bug 585630
diff --git a/content/events/test/test_bug742376.html b/content/events/test/test_bug742376.html
new file mode 100644
index 000000000000..156a679d4b28
--- /dev/null
+++ b/content/events/test/test_bug742376.html
@@ -0,0 +1,58 @@
+
+
+
+
+ Test for Bug 742376
+
+
+
+
+
+
+Mozilla Bug 742376
+
+
+
+
+
diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp
index 4b19d71d5217..2ce84bc30ee8 100644
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -10040,35 +10040,44 @@ nsGlobalWindow::EnableDeviceSensor(PRUint32 aType)
}
}
- if (alreadyEnabled)
- return;
-
mEnabledSensors.AppendElement(aType);
+ if (alreadyEnabled) {
+ return;
+ }
+
nsCOMPtr ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
- if (ac)
+ if (ac) {
ac->AddWindowListener(aType, this);
+ }
}
void
nsGlobalWindow::DisableDeviceSensor(PRUint32 aType)
{
PRInt32 doomedElement = -1;
+ PRInt32 listenerCount = 0;
for (PRUint32 i = 0; i < mEnabledSensors.Length(); i++) {
if (mEnabledSensors[i] == aType) {
doomedElement = i;
- break;
+ listenerCount++;
}
}
- if (doomedElement == -1)
+ if (doomedElement == -1) {
return;
+ }
mEnabledSensors.RemoveElementAt(doomedElement);
+ if (listenerCount > 1) {
+ return;
+ }
+
nsCOMPtr ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
- if (ac)
+ if (ac) {
ac->RemoveWindowListener(aType, this);
+ }
}
NS_IMETHODIMP
diff --git a/dom/system/nsDeviceSensors.cpp b/dom/system/nsDeviceSensors.cpp
index 8722c0b29a72..c69cefb29bf4 100644
--- a/dom/system/nsDeviceSensors.cpp
+++ b/dom/system/nsDeviceSensors.cpp
@@ -118,6 +118,17 @@ nsDeviceSensors::~nsDeviceSensors()
}
}
+NS_IMETHODIMP nsDeviceSensors::ListenerCount(PRUint32 aType, PRInt32 *aRetVal)
+{
+ if (!mEnabled) {
+ *aRetVal = 0;
+ return NS_OK;
+ }
+
+ *aRetVal = mWindowListeners[aType]->Length();
+ return NS_OK;
+}
+
NS_IMETHODIMP nsDeviceSensors::AddWindowListener(PRUint32 aType, nsIDOMWindow *aWindow)
{
if (!mEnabled)
diff --git a/xpcom/system/nsIDeviceSensors.idl b/xpcom/system/nsIDeviceSensors.idl
index 482c168e2c04..b57f878afc30 100644
--- a/xpcom/system/nsIDeviceSensors.idl
+++ b/xpcom/system/nsIDeviceSensors.idl
@@ -24,11 +24,14 @@ interface nsIDeviceSensorData : nsISupports
readonly attribute double z;
};
-[scriptable, uuid(b672bfe0-4479-4094-a9ef-1b6847720d07)]
+[scriptable, uuid(83306c9f-1c8f-43c4-900a-245d7f219511)]
interface nsIDeviceSensors : nsISupports
{
+ long listenerCount(in unsigned long aType);
+
// Holds pointers, not AddRef objects -- it is up to the caller
// to call RemoveWindowListener before the window is deleted.
+
[noscript] void addWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
[noscript] void removeWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
[noscript] void removeWindowAsListener(in nsIDOMWindow aWindow);