Bug 841608 - 'Assertion: Uh, inner window set as event target! with FireMozTimeChangeEvent'. r=smaug.
authorBen Turner <bent.mozilla@gmail.com>
Fri, 15 Feb 2013 14:03:18 -0800
changeset 131949 f125f034e2221820f17a91cc226626842839eb5d
parent 131948 f1b4f443548dce0b45648e53d5322e2bd176e98b
child 131950 424de81686026d1a638a45ed36212957ffa63419
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs841608
milestone21.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 841608 - 'Assertion: Uh, inner window set as event target! with FireMozTimeChangeEvent'. r=smaug.
dom/time/TimeChangeObserver.cpp
dom/time/TimeChangeObserver.h
--- a/dom/time/TimeChangeObserver.cpp
+++ b/dom/time/TimeChangeObserver.cpp
@@ -34,24 +34,27 @@ nsSystemTimeChangeObserver::~nsSystemTim
 }
 
 void
 nsSystemTimeChangeObserver::FireMozTimeChangeEvent()
 {
   ListenerArray::ForwardIterator iter(mWindowListeners);
   while (iter.HasMore()) {
     nsWeakPtr weakWindow = iter.GetNext();
-    nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(weakWindow);
+    nsCOMPtr<nsPIDOMWindow> innerWindow = do_QueryReferent(weakWindow);
+    nsCOMPtr<nsPIDOMWindow> outerWindow;
     nsCOMPtr<nsIDocument> document;
-    if (!window || !(document = window->GetDoc())) {
+    if (!innerWindow ||
+        !(document = innerWindow->GetExtantDoc()) ||
+        !(outerWindow = innerWindow->GetOuterWindow())) {
       mWindowListeners.RemoveElement(weakWindow);
       continue;
     }
 
-    nsContentUtils::DispatchTrustedEvent(document, window,
+    nsContentUtils::DispatchTrustedEvent(document, outerWindow,
       NS_LITERAL_STRING("moztimechange"), /* bubbles = */ true,
       /* canceable = */ false);
   }
 }
 
 void
 nsSystemTimeChangeObserver::Notify(const int64_t& aClockDeltaMS)
 {
@@ -70,28 +73,35 @@ nsSystemTimeChangeObserver::Notify(const
 void
 nsSystemTimeChangeObserver::Notify(
   const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
 {
   FireMozTimeChangeEvent();
 }
 
 nsresult
-nsSystemTimeChangeObserver::AddWindowListener(nsIDOMWindow* aWindow)
+nsSystemTimeChangeObserver::AddWindowListener(nsPIDOMWindow* aWindow)
 {
   return GetInstance()->AddWindowListenerImpl(aWindow);
 }
 
 nsresult
-nsSystemTimeChangeObserver::AddWindowListenerImpl(nsIDOMWindow* aWindow)
+nsSystemTimeChangeObserver::AddWindowListenerImpl(nsPIDOMWindow* aWindow)
 {
   if (!aWindow) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
+  if (aWindow->IsOuterWindow()) {
+    aWindow = aWindow->GetCurrentInnerWindow();
+    if (!aWindow) {
+      return NS_ERROR_FAILURE;
+    }
+  }
+
   nsWeakPtr windowWeakRef = do_GetWeakReference(aWindow);
   NS_ASSERTION(windowWeakRef, "nsIDOMWindow implementations shuld support weak ref");
 
   if (mWindowListeners.IndexOf(windowWeakRef) !=
       ListenerArray::array_type::NoIndex) {
     return NS_OK;
   }
 
@@ -100,28 +110,39 @@ nsSystemTimeChangeObserver::AddWindowLis
     RegisterSystemTimezoneChangeObserver(sObserver);
   }
 
   mWindowListeners.AppendElement(windowWeakRef);
   return NS_OK;
 }
 
 nsresult
-nsSystemTimeChangeObserver::RemoveWindowListener(nsIDOMWindow* aWindow)
+nsSystemTimeChangeObserver::RemoveWindowListener(nsPIDOMWindow* aWindow)
 {
   if (!sObserver) {
     return NS_OK;
   }
 
   return GetInstance()->RemoveWindowListenerImpl(aWindow);
 }
 
 nsresult
-nsSystemTimeChangeObserver::RemoveWindowListenerImpl(nsIDOMWindow* aWindow)
+nsSystemTimeChangeObserver::RemoveWindowListenerImpl(nsPIDOMWindow* aWindow)
 {
+  if (!aWindow) {
+    return NS_OK;
+  }
+
+  if (aWindow->IsOuterWindow()) {
+    aWindow = aWindow->GetCurrentInnerWindow();
+    if (!aWindow) {
+      return NS_ERROR_FAILURE;
+    }
+  }
+
   mWindowListeners.RemoveElement(NS_GetWeakReference(aWindow));
 
   if (mWindowListeners.IsEmpty()) {
     UnregisterSystemClockChangeObserver(sObserver);
     UnregisterSystemTimezoneChangeObserver(sObserver);
   }
 
   return NS_OK;
--- a/dom/time/TimeChangeObserver.h
+++ b/dom/time/TimeChangeObserver.h
@@ -26,19 +26,19 @@ public:
 
   // Implementing hal::SystemClockChangeObserver::Notify()
   void Notify(const int64_t& aClockDeltaMS);
 
   // Implementing hal::SystemTimezoneChangeObserver::Notify()
   void Notify(
     const mozilla::hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo);
 
-  static nsresult AddWindowListener(nsIDOMWindow* aWindow);
-  static nsresult RemoveWindowListener(nsIDOMWindow* aWindow);
+  static nsresult AddWindowListener(nsPIDOMWindow* aWindow);
+  static nsresult RemoveWindowListener(nsPIDOMWindow* aWindow);
 private:
-  nsresult AddWindowListenerImpl(nsIDOMWindow* aWindow);
-  nsresult RemoveWindowListenerImpl(nsIDOMWindow* aWindow);
+  nsresult AddWindowListenerImpl(nsPIDOMWindow* aWindow);
+  nsresult RemoveWindowListenerImpl(nsPIDOMWindow* aWindow);
   nsSystemTimeChangeObserver() { };
   ListenerArray mWindowListeners;
   void FireMozTimeChangeEvent();
 };
 
 #endif //_mozilla_time_change_observer_h_