mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 12:35:58 +00:00
Bug 863599 - Load PushService on Desktop. r=dougt sr=gavin
This commit is contained in:
parent
c8852d8ef7
commit
53325a3cb8
@ -12,7 +12,6 @@ Cu.import('resource://gre/modules/DOMFMRadioParent.jsm');
|
||||
Cu.import('resource://gre/modules/AlarmService.jsm');
|
||||
Cu.import('resource://gre/modules/ActivitiesService.jsm');
|
||||
Cu.import('resource://gre/modules/PermissionPromptHelper.jsm');
|
||||
Cu.import('resource://gre/modules/PushService.jsm');
|
||||
Cu.import('resource://gre/modules/ObjectWrapper.jsm');
|
||||
Cu.import('resource://gre/modules/accessibility/AccessFu.jsm');
|
||||
Cu.import('resource://gre/modules/Payment.jsm');
|
||||
|
@ -510,6 +510,7 @@
|
||||
@BINPATH@/components/AppsService.manifest
|
||||
@BINPATH@/components/Push.js
|
||||
@BINPATH@/components/Push.manifest
|
||||
@BINPATH@/components/PushServiceLauncher.js
|
||||
|
||||
@BINPATH@/components/nsDOMIdentity.js
|
||||
@BINPATH@/components/nsIDService.js
|
||||
|
@ -185,6 +185,7 @@
|
||||
@BINPATH@/components/dom_canvas.xpt
|
||||
@BINPATH@/components/dom_contacts.xpt
|
||||
@BINPATH@/components/dom_alarm.xpt
|
||||
@BINPATH@/components/dom_push.xpt
|
||||
@BINPATH@/components/dom_core.xpt
|
||||
@BINPATH@/components/dom_css.xpt
|
||||
@BINPATH@/components/dom_devicestorage.xpt
|
||||
@ -517,6 +518,9 @@
|
||||
@BINPATH@/components/ContactManager.manifest
|
||||
@BINPATH@/components/AlarmsManager.js
|
||||
@BINPATH@/components/AlarmsManager.manifest
|
||||
@BINPATH@/components/Push.js
|
||||
@BINPATH@/components/Push.manifest
|
||||
@BINPATH@/components/PushServiceLauncher.js
|
||||
@BINPATH@/components/TCPSocket.js
|
||||
@BINPATH@/components/TCPSocketParentIntermediary.js
|
||||
@BINPATH@/components/TCPSocket.manifest
|
||||
|
@ -1,4 +1,9 @@
|
||||
# DOM API
|
||||
component {c7ad4f42-faae-4e8b-9879-780a72349945} Push.js
|
||||
contract @mozilla.org/Push;1 {c7ad4f42-faae-4e8b-9879-780a72349945}
|
||||
category JavaScript-navigator-property push @mozilla.org/Push;1
|
||||
|
||||
# Component to initialize PushService on startup.
|
||||
component {4b8caa3b-3c58-4f3c-a7f5-7bd9cb24c11d} PushServiceLauncher.js
|
||||
contract @mozilla.org/dom/push/service;1 {4b8caa3b-3c58-4f3c-a7f5-7bd9cb24c11d}
|
||||
category app-startup PushServiceLauncher @mozilla.org/dom/push/service;1
|
||||
|
@ -19,7 +19,9 @@ Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
|
||||
Cu.import("resource://gre/modules/Timer.jsm");
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||
Cu.import("resource://gre/modules/AlarmService.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AlarmService",
|
||||
"resource://gre/modules/AlarmService.jsm");
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["PushService"];
|
||||
|
||||
@ -285,14 +287,12 @@ const STATE_READY = 3;
|
||||
this.PushService = {
|
||||
observe: function observe(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "final-ui-startup":
|
||||
Services.obs.removeObserver(this, "final-ui-startup");
|
||||
this.init();
|
||||
break;
|
||||
case "profile-change-teardown":
|
||||
Services.obs.removeObserver(this, "profile-change-teardown");
|
||||
this._shutdown();
|
||||
break;
|
||||
/*
|
||||
* We need to call uninit() on shutdown to clean up things that modules aren't very good
|
||||
* at automatically cleaning up, so we don't get shutdown leaks on browser shutdown.
|
||||
*/
|
||||
case "xpcom-shutdown":
|
||||
this.uninit();
|
||||
case "network-active-changed": /* On B2G. */
|
||||
case "network:offline-status-changed": /* On desktop. */
|
||||
// In case of network-active-changed, always disconnect existing
|
||||
@ -414,29 +414,6 @@ this.PushService = {
|
||||
if (!prefs.get("enabled"))
|
||||
return null;
|
||||
|
||||
Services.obs.addObserver(this, "profile-change-teardown", false);
|
||||
Services.obs.addObserver(this, "webapps-uninstall", false);
|
||||
|
||||
// On B2G the NetworkManager interface fires a network-active-changed
|
||||
// event.
|
||||
//
|
||||
// The "active network" is based on priority - i.e. Wi-Fi has higher
|
||||
// priority than data. The PushService should just use the preferred
|
||||
// network, and not care about all interface changes.
|
||||
// network-active-changed is not fired when the network goes offline, but
|
||||
// socket connections time out. The check for Services.io.offline in
|
||||
// _beginWSSetup() prevents unnecessary retries. When the network comes
|
||||
// back online, network-active-changed is fired.
|
||||
//
|
||||
// On non-B2G platforms, the offline-status-changed event is used to know
|
||||
// when to (dis)connect. It may not fire if the underlying OS changes
|
||||
// networks; in such a case we rely on timeout.
|
||||
//
|
||||
// On B2G both events fire, one after the other, when the network goes
|
||||
// online, so we explicitly check for the presence of NetworkManager and
|
||||
// don't add an observer for offline-status-changed on B2G.
|
||||
Services.obs.addObserver(this, this._getNetworkStateChangeEventName(), false);
|
||||
|
||||
this._db = new PushDB(this);
|
||||
|
||||
let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
|
||||
@ -465,6 +442,29 @@ this.PushService = {
|
||||
}
|
||||
);
|
||||
|
||||
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
||||
Services.obs.addObserver(this, "webapps-uninstall", false);
|
||||
|
||||
// On B2G the NetworkManager interface fires a network-active-changed
|
||||
// event.
|
||||
//
|
||||
// The "active network" is based on priority - i.e. Wi-Fi has higher
|
||||
// priority than data. The PushService should just use the preferred
|
||||
// network, and not care about all interface changes.
|
||||
// network-active-changed is not fired when the network goes offline, but
|
||||
// socket connections time out. The check for Services.io.offline in
|
||||
// _beginWSSetup() prevents unnecessary retries. When the network comes
|
||||
// back online, network-active-changed is fired.
|
||||
//
|
||||
// On non-B2G platforms, the offline-status-changed event is used to know
|
||||
// when to (dis)connect. It may not fire if the underlying OS changes
|
||||
// networks; in such a case we rely on timeout.
|
||||
//
|
||||
// On B2G both events fire, one after the other, when the network goes
|
||||
// online, so we explicitly check for the presence of NetworkManager and
|
||||
// don't add an observer for offline-status-changed on B2G.
|
||||
Services.obs.addObserver(this, this._getNetworkStateChangeEventName(), false);
|
||||
|
||||
// This is only used for testing. Different tests require connecting to
|
||||
// slightly different URLs.
|
||||
prefs.observe("serverURL", this);
|
||||
@ -486,11 +486,16 @@ this.PushService = {
|
||||
this._stopAlarm();
|
||||
},
|
||||
|
||||
_shutdown: function() {
|
||||
debug("_shutdown()");
|
||||
uninit: function() {
|
||||
if (!this._started)
|
||||
return;
|
||||
|
||||
debug("uninit()");
|
||||
|
||||
prefs.ignore("serverURL", this);
|
||||
Services.obs.removeObserver(this, this._getNetworkStateChangeEventName());
|
||||
Services.obs.removeObserver(this, "webapps-uninstall", false);
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown", false);
|
||||
|
||||
if (this._db) {
|
||||
this._db.close();
|
||||
@ -511,8 +516,9 @@ this.PushService = {
|
||||
// try to reconnect. Stop the timer.
|
||||
this._stopAlarm();
|
||||
|
||||
if (this._requestTimeoutTimer)
|
||||
if (this._requestTimeoutTimer) {
|
||||
this._requestTimeoutTimer.cancel();
|
||||
}
|
||||
|
||||
debug("shutdown complete!");
|
||||
},
|
||||
@ -1453,5 +1459,3 @@ this.PushService = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PushService.init();
|
||||
|
40
dom/push/src/PushServiceLauncher.js
Normal file
40
dom/push/src/PushServiceLauncher.js
Normal file
@ -0,0 +1,40 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
const Cr = Components.results;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function PushServiceLauncher() {
|
||||
};
|
||||
|
||||
PushServiceLauncher.prototype = {
|
||||
classID: Components.ID("{4b8caa3b-3c58-4f3c-a7f5-7bd9cb24c11d}"),
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
||||
Ci.nsISupportsWeakReference]),
|
||||
|
||||
observe: function observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "app-startup":
|
||||
Services.obs.addObserver(this, "final-ui-startup", true);
|
||||
break;
|
||||
case "final-ui-startup":
|
||||
if (!Services.prefs.getBoolPref("services.push.enabled")) {
|
||||
return;
|
||||
}
|
||||
Cu.import("resource://gre/modules/PushService.jsm");
|
||||
PushService.init();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PushServiceLauncher]);
|
@ -7,4 +7,5 @@
|
||||
EXTRA_COMPONENTS += [
|
||||
'Push.js',
|
||||
'Push.manifest',
|
||||
'PushServiceLauncher.js',
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user