Bug 681562 - Restrict DeviceMotion to the active document. r=smaug
authorDoug Turner <dougt@dougt.org>
Wed, 31 Aug 2011 19:39:49 -0700
changeset 76364 9fa4dee3e94769eb69446707ad722228312a25c3
parent 76363 74e7ea3b71bea757c39f2b898441844bead28a53
child 76365 f872cb0915860c6c6b3cb481a3a59174ab2f709d
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerssmaug
bugs681562
milestone9.0a1
Bug 681562 - Restrict DeviceMotion to the active document. r=smaug
dom/system/nsDeviceMotion.cpp
--- a/dom/system/nsDeviceMotion.cpp
+++ b/dom/system/nsDeviceMotion.cpp
@@ -34,16 +34,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsDeviceMotion.h"
 
 #include "nsAutoPtr.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMWindow.h"
+#include "nsPIDOMWindow.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIServiceManager.h"
 #include "nsIPrivateDOMEvent.h"
 #include "nsIDOMDeviceOrientationEvent.h"
 #include "nsIDOMDeviceMotionEvent.h"
 #include "nsIServiceManager.h"
 #include "nsIPrefService.h"
@@ -227,36 +228,42 @@ nsDeviceMotion::DeviceMotionChanged(PRUi
     --i;
     nsRefPtr<nsDeviceMotionData> a = new nsDeviceMotionData(type, x, y, z);
     mListeners[i]->OnMotionChange(a);
   }
 
   for (PRUint32 i = mWindowListeners.Length(); 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(mWindowListeners[i]);
+    if (!pwindow || pwindow->GetOuterWindow()->IsBackground())
+      continue;
+
     nsCOMPtr<nsIDOMDocument> domdoc;
     mWindowListeners[i]->GetDocument(getter_AddRefs(domdoc));
 
     if (domdoc) {
       nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mWindowListeners[i]);
       if (type == nsIDeviceMotionData::TYPE_ACCELERATION)
         FireDOMMotionEvent(domdoc, target, x, y, z);
       else if (type == nsIDeviceMotionData::TYPE_ORIENTATION)
         FireDOMOrientationEvent(domdoc, target, x, y, z);
     }
   }
   return NS_OK;
 }
 
 void
 nsDeviceMotion::FireDOMOrientationEvent(nsIDOMDocument *domdoc,
-                                         nsIDOMEventTarget *target,
-                                         double alpha,
-                                         double beta,
-                                         double gamma)
+                                        nsIDOMEventTarget *target,
+                                        double alpha,
+                                        double beta,
+                                        double gamma)
 {
   nsCOMPtr<nsIDOMEvent> event;
   PRBool defaultActionEnabled = PR_TRUE;
   domdoc->CreateEvent(NS_LITERAL_STRING("DeviceOrientationEvent"), getter_AddRefs(event));
 
   nsCOMPtr<nsIDOMDeviceOrientationEvent> oe = do_QueryInterface(event);
 
   if (!oe) {