Bug 916893 - Patch 3 - Walk up worker chain to find correct window for WorkerNotificationObserver. r=khuey
☠☠ backed out by 531f100d2bd8 ☠ ☠
authorNikhil Marathe <nsm.nikhil@gmail.com>
Tue, 28 Apr 2015 13:15:51 -0700
changeset 268367 7dc2448065a98863e8df27b21d9708921edf0057
parent 268366 c3b07f0d1a6000e231395e3a2261f980271779e1
child 268368 0d860fd125343f67d71dafddd4e435cd624884f4
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs916893
milestone41.0a1
Bug 916893 - Patch 3 - Walk up worker chain to find correct window for WorkerNotificationObserver. r=khuey In case of child workers.
dom/notification/Notification.cpp
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -976,17 +976,17 @@ NotificationObserver::Observe(nsISupport
                               const char16_t* aData)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(mNotificationRef);
   Notification* notification = mNotificationRef->GetNotification();
   MOZ_ASSERT(notification);
   if (!strcmp("alertclickcallback", aTopic)) {
     nsCOMPtr<nsPIDOMWindow> window = notification->GetOwner();
-    if (!window || !window->IsCurrentInnerWindow()) {
+    if (NS_WARN_IF(!window || !window->IsCurrentInnerWindow())) {
       // Window has been closed, this observer is not valid anymore
       return NS_ERROR_FAILURE;
     }
 
     bool doDefaultAction = notification->DispatchClickEvent();
     if (doDefaultAction) {
       nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
       if (doc) {
@@ -1012,26 +1012,31 @@ WorkerNotificationObserver::Observe(nsIS
                                     const char16_t* aData)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(mNotificationRef);
   // For an explanation of why it is OK to pass this rawptr to the event
   // runnables, see the Notification class comment.
   Notification* notification = mNotificationRef->GetNotification();
   // We can't assert notification here since the feature could've unset it.
-  if (!notification) {
+  if (NS_WARN_IF(!notification)) {
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(notification->mWorkerPrivate);
 
   nsRefPtr<WorkerRunnable> r;
   if (!strcmp("alertclickcallback", aTopic)) {
-    nsCOMPtr<nsPIDOMWindow> window = notification->mWorkerPrivate->GetWindow();
-    if (!window || !window->IsCurrentInnerWindow()) {
+    WorkerPrivate* top = notification->mWorkerPrivate;
+    while (top->GetParent()) {
+      top = top->GetParent();
+    }
+
+    nsPIDOMWindow* window = top->GetWindow();
+    if (NS_WARN_IF(!window || !window->IsCurrentInnerWindow())) {
       // Window has been closed, this observer is not valid anymore
       return NS_ERROR_FAILURE;
     }
 
     // Instead of bothering with adding features and other worker lifecycle
     // management, we simply hold strongrefs to the window and document.
     nsMainThreadPtrHandle<nsPIDOMWindow> windowHandle(
       new nsMainThreadPtrHolder<nsPIDOMWindow>(window));