Bug 915002: Convert optional notification arguments to webidl dictionary, add directional/lang arguments; r=bz r=fabrice
authorKyle Machulis <kyle@nonpolynomial.com>
Wed, 09 Oct 2013 17:06:29 -0700
changeset 164115 aa94c4753dccfe0709040b5710f4fe650658605a
parent 164114 350248e072132e4dc9d4c8f765e6073359d8dd12
child 164116 da309d2360df5b34b688501338b8eaac2be7d513
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, fabrice
bugs915002
milestone27.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 915002: Convert optional notification arguments to webidl dictionary, add directional/lang arguments; r=bz r=fabrice
b2g/chrome/content/shell.js
b2g/components/AlertsService.js
dom/interfaces/notification/nsIDOMDesktopNotification.idl
dom/src/notification/DesktopNotification.cpp
dom/src/notification/Notification.cpp
dom/tests/mochitest/notification/notification_common.js
dom/webidl/AppNotificationServiceOptions.webidl
dom/webidl/DummyBinding.webidl
dom/webidl/moz.build
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -882,28 +882,30 @@ var AlertsHelper = {
   receiveMessage: function alert_receiveMessage(aMessage) {
     if (!aMessage.target.assertAppHasPermission("desktop-notification")) {
       Cu.reportError("Desktop-notification message " + aMessage.name +
                      " from a content process with no desktop-notification privileges.");
       return;
     }
 
     let data = aMessage.data;
+    let details = data.details;
     let listener = {
       mm: aMessage.target,
       title: data.title,
       text: data.text,
-      manifestURL: data.manifestURL,
+      manifestURL: details.manifestURL,
       imageURL: data.imageURL
-    }
+    };
     this.registerAppListener(data.uid, listener);
 
     this.showNotification(data.imageURL, data.title, data.text,
-                          data.textClickable, null,
-                          data.uid, null, null, data.manifestURL);
+                          details.textClickable, null,
+                          data.uid, details.dir,
+                          details.lang, details.manifestURL);
   },
 }
 
 var WebappsHelper = {
   _installers: {},
   _count: 0,
 
   init: function webapps_init() {
--- a/b2g/components/AlertsService.js
+++ b/b2g/components/AlertsService.js
@@ -60,37 +60,35 @@ AlertsService.prototype = {
     let browser = Services.wm.getMostRecentWindow("navigator:browser");
     browser.AlertsHelper.closeAlert(aName);
   },
 
   // nsIAppNotificationService
   showAppNotification: function showAppNotification(aImageURL,
                                                     aTitle,
                                                     aText,
-                                                    aTextClickable,
-                                                    aManifestURL,
                                                     aAlertListener,
-                                                    aId) {
-    let uid = (aId == "") ? "app-notif-" + uuidGenerator.generateUUID() : aId;
+                                                    aDetails) {
+    let uid = (aDetails.id == "") ?
+          "app-notif-" + uuidGenerator.generateUUID() : aDetails.id;
 
     this._listeners[uid] = {
       observer: aAlertListener,
       title: aTitle,
       text: aText,
-      manifestURL: aManifestURL,
+      manifestURL: aDetails.manifestURL,
       imageURL: aImageURL
     };
 
     cpmm.sendAsyncMessage("app-notification-send", {
       imageURL: aImageURL,
       title: aTitle,
       text: aText,
-      textClickable: aTextClickable,
-      manifestURL: aManifestURL,
-      uid: uid
+      uid: uid,
+      details: aDetails
     });
   },
 
   // AlertsService.js custom implementation
   _listeners: [],
 
   receiveMessage: function receiveMessage(aMessage) {
     let data = aMessage.data;
--- a/dom/interfaces/notification/nsIDOMDesktopNotification.idl
+++ b/dom/interfaces/notification/nsIDOMDesktopNotification.idl
@@ -2,19 +2,19 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "domstubs.idl"
 
 interface nsIObserver;
 
 // Notification service that also provides the manifest URL
-[scriptable, uuid(61c4adf4-187d-4d18-937c-4df17bc01073)]
+[scriptable, uuid(50cb17d2-dc8a-4aa6-bcd3-94d76af14e20)]
 interface nsIAppNotificationService : nsISupports
 {
     void showAppNotification(in AString  imageUrl,
                              in AString  title,
                              in AString  text,
-                             [optional] in boolean textClickable,
-                             [optional] in AString manifestURL,
-                             [optional] in nsIObserver alertListener,
-                             [optional] in AString id);
+                             in nsIObserver alertListener,
+                             // details should be a WebIDL
+                             // AppNotificationServiceOptions Dictionary object
+                             in jsval    details);
 };
--- a/dom/src/notification/DesktopNotification.cpp
+++ b/dom/src/notification/DesktopNotification.cpp
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "mozilla/dom/DesktopNotification.h"
 #include "mozilla/dom/DesktopNotificationBinding.h"
+#include "mozilla/dom/AppNotificationServiceOptionsBinding.h"
 #include "nsContentPermissionHelper.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/dom/PBrowserChild.h"
 #include "nsIDOMDesktopNotification.h"
 #include "TabChild.h"
 #include "mozilla/Preferences.h"
 #include "nsGlobalWindow.h"
 #include "nsIAppsService.h"
@@ -86,21 +87,28 @@ DesktopNotification::PostDesktopNotifica
   if (appNotifier) {
     nsCOMPtr<nsPIDOMWindow> window = GetOwner();
     uint32_t appId = (window.get())->GetDoc()->NodePrincipal()->GetAppId();
 
     if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
       nsCOMPtr<nsIAppsService> appsService = do_GetService("@mozilla.org/AppsService;1");
       nsString manifestUrl = EmptyString();
       appsService->GetManifestURLByLocalId(appId, manifestUrl);
+      mozilla::AutoSafeJSContext cx;
+      JS::RootedValue val(cx);
+      AppNotificationServiceOptionsInitializer ops;
+      ops.mTextClickable = true;
+      ops.mManifestURL = manifestUrl;
+
+      if (!ops.ToObject(cx, JS::NullPtr(), &val)) {
+        return NS_ERROR_FAILURE;
+      }
+
       return appNotifier->ShowAppNotification(mIconURL, mTitle, mDescription,
-                                              true,
-                                              manifestUrl,
-                                              mObserver,
-                                              EmptyString());
+                                              mObserver, val);
     }
   }
 #endif
 
   nsCOMPtr<nsIAlertsService> alerts = do_GetService("@mozilla.org/alerts-service;1");
   if (!alerts) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
--- a/dom/src/notification/Notification.cpp
+++ b/dom/src/notification/Notification.cpp
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "PCOMContentPermissionRequestChild.h"
 #include "mozilla/dom/Notification.h"
+#include "mozilla/dom/AppNotificationServiceOptionsBinding.h"
 #include "mozilla/dom/OwningNonNull.h"
 #include "mozilla/Preferences.h"
 #include "TabChild.h"
 #include "nsContentUtils.h"
 #include "nsDOMEvent.h"
 #include "nsIAlertsService.h"
 #include "nsIContentPermissionPrompt.h"
 #include "nsIDocument.h"
@@ -370,21 +371,32 @@ Notification::ShowInternal()
   if (appNotifier) {
     nsCOMPtr<nsPIDOMWindow> window = GetOwner();
     uint32_t appId = (window.get())->GetDoc()->NodePrincipal()->GetAppId();
 
     if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
       nsCOMPtr<nsIAppsService> appsService = do_GetService("@mozilla.org/AppsService;1");
       nsString manifestUrl = EmptyString();
       appsService->GetManifestURLByLocalId(appId, manifestUrl);
+      mozilla::AutoSafeJSContext cx;
+      JS::RootedValue val(cx);
+      AppNotificationServiceOptionsInitializer ops;
+      ops.mTextClickable = true;
+      ops.mManifestURL = manifestUrl;
+      ops.mId = alertName;
+      ops.mDir = DirectionToString(mDir);
+      ops.mLang = mLang;
+
+      if (!ops.ToObject(cx, JS::NullPtr(), &val)) {
+        NS_WARNING("Converting dict to object failed!");
+        return NS_ERROR_FAILURE;
+      }
+
       return appNotifier->ShowAppNotification(mIconUrl, mTitle, mBody,
-                                              true,
-                                              manifestUrl,
-                                              observer,
-                                              alertName);
+                                              observer, val);
     }
   }
 #endif
 
   // In the case of IPC, the parent process uses the cookie to map to
   // nsIObserver. Thus the cookie must be unique to differentiate observers.
   nsString uniqueCookie = NS_LITERAL_STRING("notification:");
   uniqueCookie.AppendInt(sCount++);
--- a/dom/tests/mochitest/notification/notification_common.js
+++ b/dom/tests/mochitest/notification/notification_common.js
@@ -4,30 +4,30 @@ const ALERTS_SERVICE_CONTRACT_ID = "@moz
 const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{e86d888c-e41b-4b78-9104-2f2742a532de}");
 const SYSTEM_ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/system-alerts-service;1";
 
 var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager.
   QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar);
 
 var mockAlertsService = {
   showAlertNotification: function(imageUrl, title, text, textClickable,
-                                  cookie, alertListener, name) {
+                                  cookie, alertListener, name, bidi, lang) {
     // probably should do this async....
     SpecialPowers.wrap(alertListener).observe(null, "alertshow", cookie);
 
     if (SpecialPowers.getBoolPref("notification.prompt.testing.click_on_notification") == true) {
        SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", cookie);
     }
 
     SpecialPowers.wrap(alertListener).observe(null, "alertfinished", cookie);
   },
 
-  showAppNotification: function(imageUrl, title, text, textClickable,
-                                manifestURL, alertListener) {
-    this.showAlertNotification(imageUrl, title, text, textClickable, "", alertListener, "");
+  showAppNotification: function(imageUrl, title, text, alertListener, details) {
+    this.showAlertNotification(imageUrl, title, text, details.textClickable, "",
+                               alertListener, details.name, details.dir, details.lang);
   },
 
   QueryInterface: function(aIID) {
     if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) ||
         SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService) ||
         SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAppNotificationService)) {
       return this;
     }
new file mode 100644
--- /dev/null
+++ b/dom/webidl/AppNotificationServiceOptions.webidl
@@ -0,0 +1,15 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+interface MozObserver;
+
+dictionary AppNotificationServiceOptions {
+  boolean textClickable = false;
+  DOMString manifestURL = "";
+  DOMString id = "";
+  DOMString dir = "";
+  DOMString lang = "";
+};
--- a/dom/webidl/DummyBinding.webidl
+++ b/dom/webidl/DummyBinding.webidl
@@ -22,13 +22,14 @@ interface DummyInterface : EventTarget {
   void frameRequestCallback(FrameRequestCallback arg);
   void MmsParameters(optional MmsParameters arg);
   void MmsAttachment(optional MmsAttachment arg);
   void AsyncScrollEventDetail(optional AsyncScrollEventDetail arg);
   void OpenWindowEventDetail(optional OpenWindowEventDetail arg);
   void DOMWindowResizeEventDetail(optional DOMWindowResizeEventDetail arg);
   void WifiOptions(optional WifiCommandOptions arg1,
                    optional WifiResultOptions arg2);
+  void AppNotificationServiceOptions(optional AppNotificationServiceOptions arg);
 };
 
 interface DummyInterfaceWorkers {
   BlobPropertyBag blobBag();
 };
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -14,16 +14,17 @@ PREPROCESSED_WEBIDL_FILES = [
     'Crypto.webidl',
     'Navigator.webidl',
 ]
 
 WEBIDL_FILES = [
     'AbstractWorker.webidl',
     'AnalyserNode.webidl',
     'AnimationEvent.webidl',
+    'AppNotificationServiceOptions.webidl',
     'ArchiveReader.webidl',
     'ArchiveRequest.webidl',
     'Attr.webidl',
     'AudioBuffer.webidl',
     'AudioBufferSourceNode.webidl',
     'AudioContext.webidl',
     'AudioDestinationNode.webidl',
     'AudioListener.webidl',