Bug 821633 - Alarm API - .getAll() need to wrap the objects respecting to the content window (part 2, Alarm API). r=vivien, a=blocking-basecamp
authorGene Lian <clian@mozilla.com>
Fri, 14 Dec 2012 20:04:04 +0800
changeset 122270 ef029ee6e863e161b963256b18cd18d9f8750450
parent 122269 3e0daaa7f6523a28d9d74f76c72188ba026ab8ee
child 122271 a69345742f91be4b5f9a56bb0c33f469ba2f98a9
push id1997
push userakeybl@mozilla.com
push dateMon, 07 Jan 2013 21:25:26 +0000
treeherdermozilla-beta@4baf45cdcf21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvivien, blocking-basecamp
bugs821633
milestone19.0a2
Bug 821633 - Alarm API - .getAll() need to wrap the objects respecting to the content window (part 2, Alarm API). r=vivien, a=blocking-basecamp
dom/alarm/AlarmService.jsm
dom/alarm/AlarmsManager.js
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -233,25 +233,25 @@ this.AlarmService = {
       debug("Invalid message manager: null");
       throw Components.results.NS_ERROR_FAILURE;
     }
 
     let json = null;
     switch (aMessageName)
     {
       case "Add":
-          json = aSuccess ? 
-            { requestId: aRequestId, id: aData } : 
-            { requestId: aRequestId, errorMsg: aData };
+        json = aSuccess ? 
+          { requestId: aRequestId, id: aData } : 
+          { requestId: aRequestId, errorMsg: aData };
         break;
 
       case "GetAll":
-          json = aSuccess ? 
-            { requestId: aRequestId, alarms: aData } : 
-            { requestId: aRequestId, errorMsg: aData };
+        json = aSuccess ? 
+          { requestId: aRequestId, alarms: aData } : 
+          { requestId: aRequestId, errorMsg: aData };
         break;
 
       default:
         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
         break;
     }
 
     aMessageManager.sendAsyncMessage("AlarmsManager:" + aMessageName + ":Return:" + (aSuccess ? "OK" : "KO"), json);
@@ -294,17 +294,25 @@ this.AlarmService = {
     // handle the alarm message due to any unexpected reasons.
     this._cpuWakeLocks[aAlarm.id].timer.initWithCallback(function timerCb() {
       debug("Unlock the CPU wake lock if the alarm isn't properly handled.");
       this._unlockCpuWakeLock(aAlarm.id);
     }.bind(this), 30000, Ci.nsITimer.TYPE_ONE_SHOT);
 
     let manifestURI = Services.io.newURI(aAlarm.manifestURL, null, null);
     let pageURI = Services.io.newURI(aAlarm.pageURL, null, null);
-    messenger.sendMessage("alarm", aAlarm, pageURI, manifestURI);
+
+    // We don't need to expose everything to the web content.
+    let alarm = { "id":              aAlarm.id,
+                  "date":            aAlarm.date,
+                  "respectTimezone": aAlarm.ignoreTimezone ?
+                                       "ignoreTimezone" : "honorTimezone", 
+                  "data":            aAlarm.data };
+
+    messenger.sendMessage("alarm", alarm, pageURI, manifestURI);
   },
 
   _unlockCpuWakeLock: function _unlockCpuWakeLock(aAlarmId) {
     let cpuWakeLock = this._cpuWakeLocks[aAlarmId];
     if (cpuWakeLock) {
       cpuWakeLock.wakeLock.unlock();
       cpuWakeLock.timer.cancel();
       delete this._cpuWakeLocks[aAlarmId];
--- a/dom/alarm/AlarmsManager.js
+++ b/dom/alarm/AlarmsManager.js
@@ -12,16 +12,17 @@ function debug(aStr) {
     dump("AlarmsManager: " + aStr + "\n");
 }
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
+Cu.import("resource://gre/modules/ObjectWrapper.jsm");
 
 const ALARMSMANAGER_CONTRACTID = "@mozilla.org/alarmsManager;1";
 const ALARMSMANAGER_CID        = Components.ID("{fea1e884-9b05-11e1-9b64-87a7016c3860}");
 const nsIDOMMozAlarmsManager   = Ci.nsIDOMMozAlarmsManager;
 const nsIClassInfo             = Ci.nsIClassInfo;
 
 function AlarmsManager()
 {
@@ -110,17 +111,28 @@ AlarmsManager.prototype = {
     }
 
     switch (aMessage.name) {
       case "AlarmsManager:Add:Return:OK":
         Services.DOMRequest.fireSuccess(request, json.id);
         break;
 
       case "AlarmsManager:GetAll:Return:OK":
-        Services.DOMRequest.fireSuccess(request, json.alarms);
+        // We don't need to expose everything to the web content.
+        let alarms = [];
+        json.alarms.forEach(function trimAlarmInfo(aAlarm) {
+          let alarm = { "id":              aAlarm.id,
+                        "date":            aAlarm.date,
+                        "respectTimezone": aAlarm.ignoreTimezone ?
+                                             "ignoreTimezone" : "honorTimezone", 
+                        "data":            aAlarm.data };
+          alarms.push(alarm);
+        });
+        Services.DOMRequest.fireSuccess(request,
+                                        ObjectWrapper.wrap(alarms, this._window));
         break;
 
       case "AlarmsManager:Add:Return:KO":
         Services.DOMRequest.fireError(request, json.errorMsg);
         break;
 
       case "AlarmsManager:GetAll:Return:KO":
         Services.DOMRequest.fireError(request, json.errorMsg);
@@ -153,16 +165,17 @@ AlarmsManager.prototype = {
     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
     let appsService = Cc["@mozilla.org/AppsService;1"]
                         .getService(Ci.nsIAppsService);
     this._pageURL = principal.URI.spec;
     this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
+    this._window = aWindow;
   },
 
   // Called from DOMRequestIpcHelper.
   uninit: function uninit() {
     debug("uninit()");
   },
 }