Bug 821633 - Alarm API - .getAll() need to wrap the objects respecting to the content window (part 2, Alarm API). r=vivien

This commit is contained in:
Gene Lian 2012-12-14 20:04:04 +08:00
parent f48d0b7bff
commit a4487e82f1
2 changed files with 29 additions and 8 deletions

View File

@ -238,15 +238,15 @@ this.AlarmService = {
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:
@ -299,7 +299,15 @@ this.AlarmService = {
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) {

View File

@ -17,6 +17,7 @@ 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}");
@ -115,7 +116,18 @@ AlarmsManager.prototype = {
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":
@ -158,6 +170,7 @@ AlarmsManager.prototype = {
.getService(Ci.nsIAppsService);
this._pageURL = principal.URI.spec;
this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
this._window = aWindow;
},
// Called from DOMRequestIpcHelper.