Bug 916893 - Patch 3 - Walk up worker chain to find correct window for WorkerNotificationObserver. r=khuey
authorNikhil Marathe <nsm.nikhil@gmail.com>
Thu, 25 Jun 2015 18:53:02 -0700
changeset 281282 f6770ad6b62bb2777f97f9cf4c5096c948f379cf
parent 281281 ddbd12ab41897c8f0699451aa7b18bc80e7adf14
child 281283 1fdfbe35371a5b61f8ffffefa169bb4573e66004
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs916893
milestone41.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 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));