Bug 933275 - Switching WebrtcUI.js to use the new notifications.jsm api; r=wesj
authorWes Johnston <wjohnston@mozilla.com>
Tue, 05 Nov 2013 22:07:55 -0800
changeset 153699 540035c526a712ae14f1bb76fd1bcba4591a2a3b
parent 153698 84423ee7ca76087af03703fb752f6ab9656425fe
child 153700 ca25c3516cff821ef2b28d1285460f38adca7634
push id3372
push userwjohnston@mozilla.com
push dateWed, 06 Nov 2013 06:09:16 +0000
treeherderfx-team@ca25c3516cff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs933275
milestone28.0a1
Bug 933275 - Switching WebrtcUI.js to use the new notifications.jsm api; r=wesj
mobile/android/chrome/content/WebrtcUI.js
mobile/android/modules/Notifications.jsm
--- a/mobile/android/chrome/content/WebrtcUI.js
+++ b/mobile/android/chrome/content/WebrtcUI.js
@@ -1,45 +1,42 @@
 /* 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/. */
 "use strict";
 
+XPCOMUtils.defineLazyModuleGetter(this, "Notifications", "resource://gre/modules/Notifications.jsm");
+
 var WebrtcUI = {
+  _notificationId: null,
+
   observe: function(aSubject, aTopic, aData) {
     if (aTopic === "getUserMedia:request") {
       this.handleRequest(aSubject, aTopic, aData);
     } else if (aTopic === "recording-device-events") {
       switch (aData) {
         case "shutdown":
         case "starting":
           this.notify();
           break;
       }
     }
   },
 
-  get notificationId() {
-    delete this.notificationId;
-    return this.notificationId = uuidgen.generateUUID().toString();
-  },
-
   notify: function() {
     let windows = MediaManagerService.activeMediaCaptureWindows;
     let count = windows.Count();
     let msg = {};
     if (count == 0) {
-      msg = {
-        type: "Notification:Hide",
-        id: this.notificationId
+      if (this._notificationId) {
+        Notifications.cancel(this._notificationId);
+        this._notificationId = null;
       }
     } else {
-      msg = {
-        type: "Notification:Show",
-        id: this.notificationId,
+      let notificationOptions = {
         title: Strings.brand.GetStringFromName("brandShortName"),
         when: null, // hide the date row
         light: [0xFF9500FF, 1000, 1000],
         ongoing: true
       };
 
       let cameraActive = false;
       let audioActive = false;
@@ -48,34 +45,36 @@ var WebrtcUI = {
         let hasAudio = {};
         let hasVideo = {};
         MediaManagerService.mediaCaptureWindowState(win, hasVideo, hasAudio);
         if (hasVideo.value) cameraActive = true;
         if (hasAudio.value) audioActive = true;
       }
 
       if (cameraActive && audioActive) {
-        msg.text = Strings.browser.GetStringFromName("getUserMedia.sharingCameraAndMicrophone.message2");
-        msg.smallicon = "drawable:alert_mic_camera";
+        notificationOptions.message = Strings.browser.GetStringFromName("getUserMedia.sharingCameraAndMicrophone.message2");
+        notificationOptions.icon = "drawable:alert_mic_camera";
       } else if (cameraActive) {
-        msg.text = Strings.browser.GetStringFromName("getUserMedia.sharingCamera.message2");
-        msg.smallicon = "drawable:alert_camera";
+        notificationOptions.message = Strings.browser.GetStringFromName("getUserMedia.sharingCamera.message2");
+        notificationOptions.icon = "drawable:alert_camera";
       } else if (audioActive) {
-        msg.text = Strings.browser.GetStringFromName("getUserMedia.sharingMicrophone.message2");
-        msg.smallicon = "drawable:alert_mic";
+        notificationOptions.message = Strings.browser.GetStringFromName("getUserMedia.sharingMicrophone.message2");
+        notificationOptions.icon = "drawable:alert_mic";
       } else {
         // somethings wrong. lets throw
         throw "Couldn't find any cameras or microphones being used"
       }
 
+      if (this._notificationId)
+          Notifications.update(this._notificationId, notificationOptions);
+      else
+        this._notificationId = Notifications.create(notificationOptions);
       if (count > 1)
         msg.count = count;
     }
-
-    sendMessageToJava(msg);
   },
 
   handleRequest: function handleRequest(aSubject, aTopic, aData) {
     let constraints = aSubject.getConstraints();
 
     Services.wm.getMostRecentWindow(null).navigator.mozGetUserMediaDevices(
       constraints,
       function (devices) {
--- a/mobile/android/modules/Notifications.jsm
+++ b/mobile/android/modules/Notifications.jsm
@@ -74,16 +74,21 @@ Notification.prototype = {
       this._onClick = aOptions.onClick;
     else
       this._onClick = null;
 
     if ("cookie" in aOptions && aOptions.cookie != null)
       this._cookie = aOptions.cookie;
     else
       this._cookie = null;
+
+    if ("light" in aOptions && aOptions.light != null)
+      this._light = aOptions.light;
+    else
+      this._light = null;
   },
 
   show: function() {
     let msg = {
         type: "Notification:Show",
         id: this._id,
         title: this._title,
         smallIcon: this._icon,
@@ -111,16 +116,19 @@ Notification.prototype = {
           buttonId: button.buttonId,
           title : button.title,
           icon : button.icon
         };
         msg.actions.push(obj);
       }
     }
 
+    if (this._light)
+      msg.light = this._light;
+
     Services.androidBridge.handleGeckoMessage(JSON.stringify(msg));
     return this;
   },
 
   cancel: function() {
     let msg = {
         type: "Notification:Hide",
         id: this._id