Bug 820617 - Add a hook to make NetworkManager not manage offline status and use it in Marionette for B2G CI. r=jgriffin

This commit is contained in:
Philipp von Weitershausen 2012-12-29 10:11:04 -08:00
parent c61f40ec7c
commit 607943a62b
4 changed files with 34 additions and 7 deletions

View File

@ -591,6 +591,13 @@ pref("browser.prompt.allowNative", false);
// a restart is required to enable a new value.
pref("network.activity.blipIntervalMilliseconds", 250);
// By default we want the NetworkManager service to manage Gecko's offline
// status for us according to the state of Wifi/cellular data connections.
// In some environments, such as the emulator or hardware with other network
// connectivity, this is not desireable, however, in which case this pref
// can be flipped to false.
pref("network.gonk.manage-offline-status", true);
pref("jsloader.reuseGlobal", true);
// Enable font inflation for browser tab content.

View File

@ -27,7 +27,9 @@ const TOPIC_INTERFACE_REGISTERED = "network-interface-registered";
const TOPIC_INTERFACE_UNREGISTERED = "network-interface-unregistered";
const TOPIC_DEFAULT_ROUTE_CHANGED = "network-default-route-changed";
const TOPIC_MOZSETTINGS_CHANGED = "mozsettings-changed";
const TOPIC_PREF_CHANGED = "nsPref:changed";
const TOPIC_XPCOM_SHUTDOWN = "xpcom-shutdown";
const PREF_MANAGE_OFFLINE_STATUS = "network.gonk.manage-offline-status";
// TODO, get USB RNDIS interface name automatically.(see Bug 776212)
const DEFAULT_USB_INTERFACE_NAME = "rndis0";
@ -109,9 +111,7 @@ function NetworkManager() {
debug("Starting worker.");
this.worker = new ChromeWorker("resource://gre/modules/net_worker.js");
this.worker.onmessage = function onmessage(event) {
this.handleWorkerMessage(event);
}.bind(this);
this.worker.onmessage = this.handleWorkerMessage.bind(this);
this.worker.onerror = function onerror(event) {
debug("Received error from worker: " + event.filename +
":" + event.lineno + ": " + event.message + "\n");
@ -122,6 +122,14 @@ function NetworkManager() {
// Callbacks to invoke when a reply arrives from the net_worker.
this.controlCallbacks = Object.create(null);
try {
this._manageOfflineStatus =
Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
} catch(ex) {
// Ignore.
}
Services.prefs.addObserver(PREF_MANAGE_OFFLINE_STATUS, this, false);
// Default values for internal and external interfaces.
this._tetheringInterface = Object.create(null);
this._tetheringInterface[TETHERING_TYPE_USB] = {externalInterface: DEFAULT_3G_INTERFACE_NAME,
@ -224,6 +232,11 @@ NetworkManager.prototype = {
let setting = JSON.parse(data);
this.handle(setting.key, setting.value);
break;
case TOPIC_PREF_CHANGED:
this._manageOfflineStatus =
Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
debug(PREF_MANAGE_OFFLINE_STATUS + " has changed to " + this._manageOfflineStatus);
break;
case TOPIC_XPCOM_SHUTDOWN:
Services.obs.removeObserver(this, TOPIC_XPCOM_SHUTDOWN);
Services.obs.removeObserver(this, TOPIC_MOZSETTINGS_CHANGED);
@ -279,6 +292,8 @@ NetworkManager.prototype = {
debug("Network '" + network.name + "' unregistered.");
},
_manageOfflineStatus: true,
networkInterfaces: null,
_preferredNetworkType: DEFAULT_PREFERRED_NETWORK_TYPE,
@ -342,13 +357,13 @@ NetworkManager.prototype = {
},
handleWorkerMessage: function handleWorkerMessage(e) {
debug("NetworkManager received message from worker: " + JSON.stringify(e.data));
let response = e.data;
let id = response.id;
let callback = this.controlCallbacks[id];
if (callback) {
callback.call(this, response);
}
debug("NetworkManager received message from worker: " + JSON.stringify(e));
},
/**
@ -405,7 +420,10 @@ NetworkManager.prototype = {
}
this.setDefaultRouteAndDNS(oldActive);
}
Services.io.offline = !this.active;
if (this._manageOfflineStatus) {
Services.io.offline = !this.active;
}
},
setDefaultRouteAndDNS: function setDefaultRouteAndDNS(oldInterface) {

View File

@ -41,6 +41,10 @@ Cu.import("resource://gre/modules/services-common/log4moz.js");
let logger = Log4Moz.repository.getLogger("Marionette");
logger.info('marionette-actors.js loaded');
Services.prefs.setBoolPref("network.gonk.manage-offline-status", false);
Services.io.manageOfflineStatus = false;
Services.io.offline = false;
// This is used to prevent newSession from returning before the telephony
// API's are ready; see bug 792647. This assumes that marionette-actors.js
// will be loaded before the 'system-message-listener-ready' message

View File

@ -60,8 +60,6 @@ let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
* If the actor returns an ID, we start the listeners. Otherwise, nothing happens.
*/
function registerSelf() {
Services.io.manageOfflineStatus = false;
Services.io.offline = false;
let msg = {value: winUtil.outerWindowID, href: content.location.href};
let register = sendSyncMessage("Marionette:register", msg);