Bug 1038811 - Push Notifications - Move old push to simplepush. r=nsm. sr=jst

This commit is contained in:
Doug Turner 2015-04-10 20:19:28 -07:00
parent af8acea893
commit a9c539e35c
10 changed files with 2141 additions and 2 deletions

View File

@ -51,6 +51,7 @@ MOZ_APP_ID={3c2e2abc-06d4-11e1-ac3b-374f68613e61}
MOZ_TIME_MANAGER=1
MOZ_SIMPLEPUSH=1
MOZ_PAY=1
MOZ_TOOLKIT_SEARCH=
MOZ_PLACES=

View File

@ -3942,6 +3942,7 @@ MOZ_ANDROID_MLS_STUMBLER=
MOZ_ANDROID_SHARE_OVERLAY=
ACCESSIBILITY=1
MOZ_TIME_MANAGER=
MOZ_SIMPLEPUSH=
MOZ_PAY=
MOZ_AUDIO_CHANNEL_MANAGER=
NSS_NO_LIBPKIX=
@ -7525,6 +7526,15 @@ if test -n "$MOZ_B2G_CAMERA"; then
fi
AC_SUBST(MOZ_B2G_CAMERA)
dnl ========================================================
dnl = Enable Support for SimplePush (Gonk usually)
dnl This will disable the Push API.
dnl ========================================================
if test -n "$MOZ_SIMPLEPUSH"; then
AC_DEFINE(MOZ_SIMPLEPUSH)
fi
AC_SUBST(MOZ_SIMPLEPUSH)
dnl ========================================================
dnl = Enable Support for Payment API
dnl ========================================================

View File

@ -77,7 +77,6 @@ DIRS += [
'notification',
'offline',
'power',
'push',
'quota',
'security',
'settings',
@ -137,6 +136,11 @@ if CONFIG['MOZ_GAMEPAD']:
if CONFIG['MOZ_NFC']:
DIRS += ['nfc']
if CONFIG['MOZ_SIMPLEPUSH']:
DIRS += ['simplepush']
else:
DIRS += ['push']
if CONFIG['MOZ_SECUREELEMENT']:
DIRS += ['secureelement']

147
dom/simplepush/Push.js Normal file
View File

@ -0,0 +1,147 @@
/* 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";
// Don't modify this, instead set services.push.debug.
let gDebuggingEnabled = false;
function debug(s) {
if (gDebuggingEnabled)
dump("-*- Push.js: " + s + "\n");
}
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
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/AppsUtils.jsm");
const PUSH_CID = Components.ID("{cde1d019-fad8-4044-b141-65fb4fb7a245}");
/**
* The Push component runs in the child process and exposes the SimplePush API
* to the web application. The PushService running in the parent process is the
* one actually performing all operations.
*/
function Push() {
debug("Push Constructor");
}
Push.prototype = {
__proto__: DOMRequestIpcHelper.prototype,
contractID: "@mozilla.org/push/PushManager;1",
classID : PUSH_CID,
QueryInterface : XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
Ci.nsISupportsWeakReference,
Ci.nsIObserver]),
init: function(aWindow) {
// Set debug first so that all debugging actually works.
// NOTE: We don't add an observer here like in PushService. Flipping the
// pref will require a reload of the app/page, which seems acceptable.
gDebuggingEnabled = Services.prefs.getBoolPref("services.push.debug");
debug("init()");
let principal = aWindow.document.nodePrincipal;
let appsService = Cc["@mozilla.org/AppsService;1"]
.getService(Ci.nsIAppsService);
this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
this._pageURL = principal.URI;
this.initDOMRequestHelper(aWindow, [
"PushService:Register:OK",
"PushService:Register:KO",
"PushService:Unregister:OK",
"PushService:Unregister:KO",
"PushService:Registrations:OK",
"PushService:Registrations:KO"
]);
this._cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
.getService(Ci.nsISyncMessageSender);
},
receiveMessage: function(aMessage) {
debug("receiveMessage()");
let request = this.getRequest(aMessage.data.requestID);
let json = aMessage.data;
if (!request) {
debug("No request " + json.requestID);
return;
}
switch (aMessage.name) {
case "PushService:Register:OK":
Services.DOMRequest.fireSuccess(request, json.pushEndpoint);
break;
case "PushService:Register:KO":
Services.DOMRequest.fireError(request, json.error);
break;
case "PushService:Unregister:OK":
Services.DOMRequest.fireSuccess(request, json.pushEndpoint);
break;
case "PushService:Unregister:KO":
Services.DOMRequest.fireError(request, json.error);
break;
case "PushService:Registrations:OK":
Services.DOMRequest.fireSuccess(request, json.registrations);
break;
case "PushService:Registrations:KO":
Services.DOMRequest.fireError(request, json.error);
break;
default:
debug("NOT IMPLEMENTED! receiveMessage for " + aMessage.name);
}
},
register: function() {
debug("register()");
let req = this.createRequest();
if (!Services.prefs.getBoolPref("services.push.connection.enabled")) {
// If push socket is disabled by the user, immediately error rather than
// timing out.
Services.DOMRequest.fireErrorAsync(req, "NetworkError");
return req;
}
this._cpmm.sendAsyncMessage("Push:Register", {
pageURL: this._pageURL.spec,
manifestURL: this._manifestURL,
requestID: this.getRequestId(req)
});
return req;
},
unregister: function(aPushEndpoint) {
debug("unregister(" + aPushEndpoint + ")");
let req = this.createRequest();
this._cpmm.sendAsyncMessage("Push:Unregister", {
pageURL: this._pageURL.spec,
manifestURL: this._manifestURL,
requestID: this.getRequestId(req),
pushEndpoint: aPushEndpoint
});
return req;
},
registrations: function() {
debug("registrations()");
let req = this.createRequest();
this._cpmm.sendAsyncMessage("Push:Registrations", {
manifestURL: this._manifestURL,
requestID: this.getRequestId(req)
});
return req;
}
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Push]);

View File

@ -0,0 +1,8 @@
# DOM API
component {cde1d019-fad8-4044-b141-65fb4fb7a245} Push.js
contract @mozilla.org/push/PushManager;1 {cde1d019-fad8-4044-b141-65fb4fb7a245}
# Component to initialize PushService on startup.
component {4b8caa3b-3c58-4f3c-a7f5-7bd9cb24c11d} PushServiceLauncher.js
contract @mozilla.org/push/ServiceLauncher;1 {4b8caa3b-3c58-4f3c-a7f5-7bd9cb24c11d}
category app-startup PushServiceLauncher @mozilla.org/push/ServiceLauncher;1

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
/* 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}"),
contractID: "@mozilla.org/push/ServiceLauncher;1",
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":
Services.obs.removeObserver(this, "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]);

14
dom/simplepush/moz.build Normal file
View File

@ -0,0 +1,14 @@
# vim: set filetype=python:
# 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/.
EXTRA_COMPONENTS += [
'Push.js',
'Push.manifest',
'PushServiceLauncher.js',
]
EXTRA_JS_MODULES += [
'PushService.jsm',
]

View File

@ -0,0 +1,15 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
[NavigatorProperty="push",
JSImplementation="@mozilla.org/push/PushManager;1",
CheckPermissions="push",
Pref="services.push.enabled"]
interface PushManager {
DOMRequest register();
DOMRequest unregister(DOMString pushEndpoint);
DOMRequest registrations();
};

View File

@ -353,7 +353,6 @@ WEBIDL_FILES = [
'ProfileTimelineMarker.webidl',
'Promise.webidl',
'PromiseDebugging.webidl',
'PushManager.webidl',
'RadioNodeList.webidl',
'Range.webidl',
'Rect.webidl',
@ -661,6 +660,12 @@ if CONFIG['MOZ_B2G_BT']:
'BluetoothManager.webidl',
]
if CONFIG['MOZ_SIMPLEPUSH']:
WEBIDL_FILES += SimplePushManager.webidl
else:
WEBIDL_FILES += [
]
if CONFIG['MOZ_NFC']:
WEBIDL_FILES += [
'MozIsoDepTech.webidl',