Bug 814222 - Ensure NetworkStatsManager's messages are handled and return values are wrapped. r=fabrice

This commit is contained in:
Philipp von Weitershausen 2013-01-07 15:26:42 -08:00
parent 57e7d5db0c
commit cfcb2825b6

View File

@ -12,6 +12,16 @@ 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");
// Ensure NetworkStatsService and NetworkStatsDB are loaded in the parent process
// to receive messages from the child processes.
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
let isParentProcess = !appInfo || appInfo.getService(Ci.nsIXULRuntime)
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
if (isParentProcess) {
Cu.import("resource://gre/modules/NetworkStatsService.jsm");
}
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
@ -43,14 +53,14 @@ NetworkStatsData.prototype = {
flags: nsIClassInfo.DOM_OBJECT}),
QueryInterface : XPCOMUtils.generateQI([nsIDOMMozNetworkStatsData])
}
};
// NetworkStats
const NETWORKSTATS_CONTRACTID = "@mozilla.org/networkstats;1";
const NETWORKSTATS_CID = Components.ID("{037435a6-f563-48f3-99b3-a0106d8ba5bd}");
const nsIDOMMozNetworkStats = Components.interfaces.nsIDOMMozNetworkStats;
function NetworkStats(aStats) {
function NetworkStats(aWindow, aStats) {
if (DEBUG) {
debug("NetworkStats Constructor");
}
@ -58,11 +68,10 @@ function NetworkStats(aStats) {
this.start = aStats.start || null;
this.end = aStats.end || null;
let samples = [];
let samples = this.data = Cu.createArrayIn(aWindow);
for (let i = 0; i < aStats.data.length; i++) {
samples.push(new NetworkStatsData(aStats.data[i]));
}
this.data = samples;
}
NetworkStats.prototype = {
@ -133,19 +142,16 @@ NetworkStatsManager.prototype = {
get connectionTypes() {
this.checkPrivileges();
return cpmm.sendSyncMessage("NetworkStats:Types")[0];
return ObjectWrapper.wrap(cpmm.sendSyncMessage("NetworkStats:Types")[0], this._window);
},
get sampleRate() {
this.checkPrivileges();
return cpmm.sendSyncMessage("NetworkStats:SampleRate")[0] / 1000;
},
get maxStorageSamples() {
this.checkPrivileges();
return cpmm.sendSyncMessage("NetworkStats:MaxStorageSamples")[0];
},
@ -170,7 +176,7 @@ NetworkStatsManager.prototype = {
return;
}
let result = new NetworkStats(msg.result);
let result = new NetworkStats(this._window, msg.result);
if (DEBUG) {
debug("result: " + JSON.stringify(result));
}
@ -240,4 +246,4 @@ NetworkStatsManager.prototype = {
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsData,
NetworkStats,
NetworkStatsManager])
NetworkStatsManager]);