Bug 749551 - Alarm API (System Message Integration). r=vivien
authorGene Lian <clian@mozilla.com>
Thu, 05 Jul 2012 15:53:08 +0800
changeset 101240 c28e5bf6cc40f1d0216a01ef73597631de38c875
parent 101239 6474c913b05fc1717ea5c640338bc364c8e26360
child 101241 f7ecc9ec354d795e3edbc8727e7d87124cc3c6f5
push id1729
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 20:02:43 +0000
treeherdermozilla-aurora@f4e75e148951 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvivien
bugs749551
milestone16.0a1
Bug 749551 - Alarm API (System Message Integration). r=vivien
dom/alarm/AlarmDB.jsm
dom/alarm/AlarmService.jsm
dom/alarm/AlarmsManager.js
--- a/dom/alarm/AlarmDB.jsm
+++ b/dom/alarm/AlarmDB.jsm
@@ -41,16 +41,17 @@ AlarmDB.prototype = {
     debug("upgradeSchema()");
 
     let objectStore = aDb.createObjectStore(ALARMSTORE_NAME, { keyPath: "id", autoIncrement: true });
 
     objectStore.createIndex("date",           "date",           { unique: false });
     objectStore.createIndex("ignoreTimezone", "ignoreTimezone", { unique: false });
     objectStore.createIndex("timezoneOffset", "timezoneOffset", { unique: false });
     objectStore.createIndex("data",           "data",           { unique: false });
+    objectStore.createIndex("manifestURL",    "manifestURL",    { unique: false });
 
     debug("Created object stores and indexes");
   },
 
   /**
    * @param aAlarm
    *        The record to be added.
    * @param aSuccessCb
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -19,16 +19,20 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/AlarmDB.jsm");
 
 let EXPORTED_SYMBOLS = ["AlarmService"];
 
 XPCOMUtils.defineLazyGetter(this, "ppmm", function() {
   return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
 });
 
+XPCOMUtils.defineLazyGetter(this, "messenger", function() {
+  return Cc["@mozilla.org/system-message-internal;1"].getService(Ci.nsISystemMessagesInternal);
+});
+
 let myGlobal = this;
 
 let AlarmService = {
   init: function init() {
     debug("init()");
 
     this._currentTimezoneOffset = (new Date()).getTimezoneOffset();
 
@@ -92,17 +96,18 @@ let AlarmService = {
         break;
 
       case "AlarmsManager:Add":
         // prepare a record for the new alarm to be added
         let newAlarm = {
           date: json.date, 
           ignoreTimezone: json.ignoreTimezone, 
           timezoneOffset: this._currentTimezoneOffset, 
-          data: json.data
+          data: json.data,
+          manifestURL: json.manifestURL
         };
 
         this._db.add(
           newAlarm,
           function addSuccessCb(aNewId) {
             debug("Callback after adding alarm in database.");
 
             newAlarm['id'] = aNewId;
@@ -200,32 +205,34 @@ let AlarmService = {
     }
   },
 
   _onAlarmFired: function _onAlarmFired() {
     debug("_onAlarmFired()");
 
     if (this._currentAlarm) {
       debug("Fire system intent: " + JSON.stringify(this._currentAlarm));
-      // TODO Fire a system message, see bug 755245
+      if (this._currentAlarm.manifestURL)
+        messenger.sendMessage("alarm", this._currentAlarm, this._currentAlarm.manifestURL);
       this._currentAlarm = null;
     }
 
     // reset the next alarm from the queue
     let nowTime = Date.now();
     let alarmQueue = this._alarmQueue;
     while (alarmQueue.length > 0) {
       let nextAlarm = alarmQueue.shift();
       let nextAlarmTime = this._getAlarmTime(nextAlarm);
 
       // if the next alarm has been expired, directly 
       // fire system intent for it instead of setting it
       if (nextAlarmTime <= nowTime) {
         debug("Fire system intent: " + JSON.stringify(nextAlarm));
-        // TODO Fire a system message, see bug 755245
+        if (nextAlarm.manifestURL)
+          messenger.sendMessage("alarm", nextAlarm, nextAlarm.manifestURL);
       } else {
         this._currentAlarm = nextAlarm;
         break;
       }
     }
     this._debugCurrentAlarm();
   },
 
--- a/dom/alarm/AlarmsManager.js
+++ b/dom/alarm/AlarmsManager.js
@@ -58,17 +58,17 @@ AlarmsManager.prototype = {
       default:
         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
         break;
     }
 
     let request = this.createRequest();
     this._cpmm.sendAsyncMessage(
       "AlarmsManager:Add", 
-      { requestID: this.getRequestId(request), date: aDate, ignoreTimezone: isIgnoreTimezone, data: aData }
+      { requestID: this.getRequestId(request), date: aDate, ignoreTimezone: isIgnoreTimezone, data: aData, manifestURL: this._manifestURL }
     );
     return request;
   },
 
   remove: function remove(aId) {
     debug("remove()");
 
     return this._cpmm.sendSyncMessage(
@@ -143,16 +143,24 @@ AlarmsManager.prototype = {
     if (!this.hasPrivileges)
       return null;
 
     this._cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
 
     // Add the valid messages to be listened.
     this.initHelper(aWindow, ["AlarmsManager:Add:Return:OK", "AlarmsManager:Add:Return:KO", 
                               "AlarmsManager:GetAll:Return:OK", "AlarmsManager:GetAll:Return:KO"]);
+
+    // Get the manifest URL if this is an installed app
+    this._manifestURL = null;
+    let utils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                       .getInterface(Components.interfaces.nsIDOMWindowUtils);
+    let app = utils.getApp();
+    if (app)
+      this._manifestURL = app.manifestURL;
   },
 
   // Called from DOMRequestIpcHelper.
   uninit: function uninit() {
     debug("uninit()");
   },
 }