Bug 1429093 - Part 1: Only allow notification click to call allowWindowInteraction. r=bkelly, a=lizzard
authorTom Tung <shes050117@gmail.com>
Wed, 10 Jan 2018 18:05:07 +0800
changeset 454580 ca41b3ad357787fbb4b593cef2bec2d51612c2b2
parent 454579 42e8f9c29d3bde92f65a93543413275649925905
child 454581 57b52fb5a9a5b3c45b9fc807f93b3e5801e809ef
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly, lizzard
bugs1429093
milestone59.0
Bug 1429093 - Part 1: Only allow notification click to call allowWindowInteraction. r=bkelly, a=lizzard
dom/workers/ServiceWorkerPrivate.cpp
--- a/dom/workers/ServiceWorkerPrivate.cpp
+++ b/dom/workers/ServiceWorkerPrivate.cpp
@@ -1248,28 +1248,32 @@ public:
     RefPtr<NotificationEvent> event =
       NotificationEvent::Constructor(target, mEventName,
                                      nei, result);
     if (NS_WARN_IF(result.Failed())) {
       return false;
     }
 
     event->SetTrusted(true);
-    aWorkerPrivate->GlobalScope()->AllowWindowInteraction();
-    RefPtr<AllowWindowInteractionHandler> allowWindowInteraction =
-      new AllowWindowInteractionHandler(aWorkerPrivate);
+
+    RefPtr<AllowWindowInteractionHandler> allowWindowInteraction;
+    if (mEventName.EqualsLiteral(NOTIFICATION_CLICK_EVENT_NAME)) {
+      allowWindowInteraction =
+        new AllowWindowInteractionHandler(aWorkerPrivate);
+    }
+
     nsresult rv = DispatchExtendableEventOnWorkerScope(aCx,
                                                        aWorkerPrivate->GlobalScope(),
                                                        event,
                                                        allowWindowInteraction);
     // Don't reject when catching an exception
-    if (NS_FAILED(rv) && rv != NS_ERROR_XPC_JS_THREW_EXCEPTION) {
+    if (NS_FAILED(rv) && rv != NS_ERROR_XPC_JS_THREW_EXCEPTION &&
+        allowWindowInteraction) {
       allowWindowInteraction->FinishedWithResult(Rejected);
     }
-    aWorkerPrivate->GlobalScope()->ConsumeWindowInteraction();
 
     return true;
   }
 };
 
 } // namespace anonymous
 
 nsresult