Bug 1114554 - Patch 1 - Notification ServiceWorker API stubs. r=wchen,baku
authorNikhil Marathe <nsm.nikhil@gmail.com>
Thu, 25 Jun 2015 18:50:24 -0700
changeset 286160 22f2bd48a54ac295353ba9302d22a60369279718
parent 286159 0d2d20d51ddf6520a0e92e533c39996ea7b5cc5a
child 286161 efc270ffbd346aeda2eb5be29c569fd64e378f19
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen, baku
bugs1114554
milestone42.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 1114554 - Patch 1 - Notification ServiceWorker API stubs. r=wchen,baku
dom/base/nsGkAtomList.h
dom/bindings/Bindings.conf
dom/notification/Notification.cpp
dom/webidl/Notification.webidl
dom/webidl/ServiceWorker.webidl
dom/workers/ServiceWorkerRegistration.cpp
dom/workers/ServiceWorkerRegistration.h
dom/workers/WorkerScope.h
--- a/dom/base/nsGkAtomList.h
+++ b/dom/base/nsGkAtomList.h
@@ -818,16 +818,17 @@ GK_ATOM(onmozfullscreenerror, "onmozfull
 GK_ATOM(onmozpointerlockchange, "onmozpointerlockchange")
 GK_ATOM(onmozpointerlockerror, "onmozpointerlockerror")
 GK_ATOM(onmoztimechange, "onmoztimechange")
 GK_ATOM(onMozMousePixelScroll, "onMozMousePixelScroll")
 GK_ATOM(onMozScrolledAreaChanged, "onMozScrolledAreaChanged")
 GK_ATOM(onmoznetworkupload, "onmoznetworkupload")
 GK_ATOM(onmoznetworkdownload, "onmoznetworkdownload")
 GK_ATOM(onnewrdsgroup, "onnewrdsgroup")
+GK_ATOM(onnotificationclick, "onnotificationclick")
 GK_ATOM(onnoupdate, "onnoupdate")
 GK_ATOM(onobsolete, "onobsolete")
 GK_ATOM(ononline, "ononline")
 GK_ATOM(onoffline, "onoffline")
 GK_ATOM(onopen, "onopen")
 GK_ATOM(onotastatuschange, "onotastatuschange")
 GK_ATOM(onoverflow, "onoverflow")
 GK_ATOM(onoverflowchanged, "onoverflowchanged")
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -864,16 +864,24 @@ DOMInterfaces = {
 'NodeIterator': {
     'wrapperCache': False,
 },
 
 'NodeList': {
     'nativeType': 'nsINodeList',
 },
 
+'NotificationEvent': {
+    'headerFile': 'mozilla/dom/NotificationEvent.h',
+    'nativeType': 'mozilla::dom::workers::NotificationEvent',
+    'binaryNames': {
+        'notification': 'notification_'
+    }
+},
+
 'OfflineAudioContext': {
     'nativeType': 'mozilla::dom::AudioContext',
 },
 
 'OfflineResourceList': {
     'nativeType': 'nsDOMOfflineResourceList',
 },
 
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -1409,20 +1409,17 @@ Notification::Get(const GlobalObject& aG
   }
 
   nsRefPtr<Promise> promise = Promise::Create(global, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
   nsCOMPtr<nsINotificationStorageCallback> callback =
     new NotificationStorageCallback(aGlobal, window, promise);
-  nsString tag = aFilter.mTag.WasPassed() ?
-                 aFilter.mTag.Value() :
-                 EmptyString();
-  aRv = notificationStorage->Get(origin, tag, callback);
+  aRv = notificationStorage->Get(origin, aFilter.mTag, callback);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   return promise.forget();
 }
 
 JSObject*
--- a/dom/webidl/Notification.webidl
+++ b/dom/webidl/Notification.webidl
@@ -63,17 +63,17 @@ dictionary NotificationOptions {
   DOMString body = "";
   DOMString tag = "";
   DOMString icon = "";
   any data = null;
   NotificationBehavior mozbehavior = null;
 };
 
 dictionary GetNotificationOptions {
-  DOMString tag;
+  DOMString tag = "";
 };
 
 dictionary NotificationBehavior {
   boolean noscreen = false;
   boolean noclear = false;
   boolean showOnlyOnce = false;
   DOMString soundFile = "";
   sequence<unsigned long> vibrationPattern;
@@ -88,8 +88,12 @@ enum NotificationPermission {
 callback NotificationPermissionCallback = void (NotificationPermission permission);
 
 enum NotificationDirection {
   "auto",
   "ltr",
   "rtl"
 };
 
+partial interface ServiceWorkerRegistration {
+  Promise<void> showNotification(DOMString title, optional NotificationOptions options);
+  Promise<sequence<Notification>> getNotifications(optional GetNotificationOptions filter);
+};
--- a/dom/webidl/ServiceWorker.webidl
+++ b/dom/webidl/ServiceWorker.webidl
@@ -7,17 +7,17 @@
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-obj
  *
  */
 
 // Still unclear what should be subclassed.
 // https://github.com/slightlyoff/ServiceWorker/issues/189
 [Func="mozilla::dom::workers::ServiceWorkerVisible",
  // FIXME(nsm): Bug 1113522. This is exposed to satisfy webidl constraints, but it won't actually work.
- Exposed=(Worker,Window)]
+ Exposed=(Window,Worker)]
 interface ServiceWorker : EventTarget {
   readonly attribute USVString scriptURL;
   readonly attribute ServiceWorkerState state;
 
   attribute EventHandler onstatechange;
 
   // FIXME(catalinb): Should inherit this from Worker.
   [Throws]
--- a/dom/workers/ServiceWorkerRegistration.cpp
+++ b/dom/workers/ServiceWorkerRegistration.cpp
@@ -590,16 +590,33 @@ ServiceWorkerRegistrationMainThread::Unr
   aRv = swm->Unregister(documentPrincipal, cb, scope);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   return promise.forget();
 }
 
+// Notification API extension.
+already_AddRefed<Promise>
+ServiceWorkerRegistrationMainThread::ShowNotification(JSContext* aCx,
+                                                      const nsAString& aTitle,
+                                                      const NotificationOptions& aOptions)
+{
+  MOZ_ASSERT(false);
+  return nullptr;
+}
+
+already_AddRefed<Promise>
+ServiceWorkerRegistrationMainThread::GetNotifications(const GetNotificationOptions& aOptions)
+{
+  MOZ_ASSERT(false);
+  return nullptr;
+}
+
 already_AddRefed<PushManager>
 ServiceWorkerRegistrationMainThread::GetPushManager(ErrorResult& aRv)
 {
   AssertIsOnMainThread();
 
 #ifdef MOZ_SIMPLEPUSH
   return nullptr;
 #else
@@ -996,10 +1013,27 @@ WorkerListener::UpdateFound()
       new FireUpdateFoundRunnable(mWorkerPrivate, this);
     AutoJSAPI jsapi;
     jsapi.Init();
     if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) {
     }
   }
 }
 
-} // namespace dom
-} // namespace mozilla
+// Notification API extension.
+already_AddRefed<Promise>
+ServiceWorkerRegistrationWorkerThread::ShowNotification(JSContext* aCx,
+                                                        const nsAString& aTitle,
+                                                        const NotificationOptions& aOptions)
+{
+  MOZ_ASSERT(false);
+  return nullptr;
+}
+
+already_AddRefed<Promise>
+ServiceWorkerRegistrationWorkerThread::GetNotifications(const GetNotificationOptions& aOptions)
+{
+  MOZ_ASSERT(false);
+  return nullptr;
+}
+
+} // dom namespace
+} // mozilla namespace
--- a/dom/workers/ServiceWorkerRegistration.h
+++ b/dom/workers/ServiceWorkerRegistration.h
@@ -7,16 +7,19 @@
 #ifndef mozilla_dom_ServiceWorkerRegistration_h
 #define mozilla_dom_ServiceWorkerRegistration_h
 
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/dom/ServiceWorkerBinding.h"
 #include "mozilla/dom/ServiceWorkerCommon.h"
 #include "mozilla/dom/workers/bindings/WorkerFeature.h"
 
+// Support for Notification API extension.
+#include "mozilla/dom/NotificationBinding.h"
+
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 
 class Promise;
 class PushManager;
 class WorkerListener;
@@ -106,16 +109,25 @@ public:
   Update();
 
   already_AddRefed<Promise>
   Unregister(ErrorResult& aRv);
 
   JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
+  // Partial interface from Notification API.
+  already_AddRefed<Promise>
+  ShowNotification(JSContext* aCx,
+                   const nsAString& aTitle,
+                   const NotificationOptions& aOptions);
+
+  already_AddRefed<Promise>
+  GetNotifications(const GetNotificationOptions& aOptions);
+
   already_AddRefed<workers::ServiceWorker>
   GetInstalling() override;
 
   already_AddRefed<workers::ServiceWorker>
   GetWaiting() override;
 
   already_AddRefed<workers::ServiceWorker>
   GetActive() override;
@@ -185,16 +197,25 @@ public:
   Update();
 
   already_AddRefed<Promise>
   Unregister(ErrorResult& aRv);
 
   JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
+  // Partial interface from Notification API.
+  already_AddRefed<Promise>
+  ShowNotification(JSContext* aCx,
+                   const nsAString& aTitle,
+                   const NotificationOptions& aOptions);
+
+  already_AddRefed<Promise>
+  GetNotifications(const GetNotificationOptions& aOptions);
+
   already_AddRefed<workers::ServiceWorker>
   GetInstalling() override;
 
   already_AddRefed<workers::ServiceWorker>
   GetWaiting() override;
 
   already_AddRefed<workers::ServiceWorker>
   GetActive() override;
--- a/dom/workers/WorkerScope.h
+++ b/dom/workers/WorkerScope.h
@@ -203,16 +203,17 @@ class ServiceWorkerGlobalScope final : p
   nsRefPtr<ServiceWorkerRegistrationWorkerThread> mRegistration;
 
   ~ServiceWorkerGlobalScope();
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerGlobalScope,
                                            WorkerGlobalScope)
+  IMPL_EVENT_HANDLER(notificationclick)
 
   ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);
 
   virtual bool
   WrapGlobalObject(JSContext* aCx,
                    JS::MutableHandle<JSObject*> aReflector) override;
 
   static bool