Skip to content

Commit 032f5a8

Browse files
committed
Bug 822712 - SimplePush - Implementation. r=dougt, jst, jlebar
1 parent e79cec0 commit 032f5a8

19 files changed

+1366
-0
lines changed

b2g/app/b2g.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ pref("dom.mozContacts.enabled", true);
388388
// WebAlarms
389389
pref("dom.mozAlarms.enabled", true);
390390

391+
// SimplePush
392+
// serverURL to be assigned by services team
393+
pref("services.push.serverURL", "");
394+
pref("services.push.userAgentID", "");
395+
// exponential back-off start is 5 seconds like in HTTP/1.1
396+
pref("services.push.retryBaseInterval", 5000);
397+
// exponential back-off end is 20 minutes
398+
pref("services.push.maxRetryInterval", 1200000);
399+
// How long before a DOMRequest errors as timeout
400+
pref("services.push.requestTimeout", 10000);
401+
391402
// NetworkStats
392403
#ifdef MOZ_B2G_RIL
393404
pref("dom.mozNetworkStats.enabled", true);

b2g/installer/package-manifest.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
@BINPATH@/components/dom_indexeddb.xpt
195195
@BINPATH@/components/dom_offline.xpt
196196
@BINPATH@/components/dom_payment.xpt
197+
@BINPATH@/components/dom_push.xpt
197198
@BINPATH@/components/dom_json.xpt
198199
#ifdef MOZ_B2G_RIL
199200
@BINPATH@/components/dom_mms.xpt
@@ -505,6 +506,10 @@
505506
@BINPATH@/components/Webapps.manifest
506507
@BINPATH@/components/AppsService.js
507508
@BINPATH@/components/AppsService.manifest
509+
@BINPATH@/components/Push.js
510+
@BINPATH@/components/Push.manifest
511+
@BINPATH@/components/PushService.js
512+
@BINPATH@/components/PushService.manifest
508513

509514
@BINPATH@/components/nsDOMIdentity.js
510515
@BINPATH@/components/nsIDService.js

browser/installer/package-manifest.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
@BINPATH@/components/dom_indexeddb.xpt
198198
@BINPATH@/components/dom_offline.xpt
199199
@BINPATH@/components/dom_json.xpt
200+
@BINPATH@/components/dom_push.xpt
200201
#ifdef MOZ_B2G_RIL
201202
@BINPATH@/components/dom_mms.xpt
202203
#endif
@@ -504,6 +505,10 @@
504505
@BINPATH@/components/Webapps.manifest
505506
@BINPATH@/components/AppsService.js
506507
@BINPATH@/components/AppsService.manifest
508+
@BINPATH@/components/Push.js
509+
@BINPATH@/components/Push.manifest
510+
@BINPATH@/components/PushService.js
511+
@BINPATH@/components/PushService.manifest
507512
@BINPATH@/components/nsDOMIdentity.js
508513
@BINPATH@/components/nsIDService.js
509514
@BINPATH@/components/Identity.manifest

browser/installer/removed-files.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ xpicleanup@BIN_SUFFIX@
12221222
components/dom_json.xpt
12231223
components/dom_loadsave.xpt
12241224
components/dom_offline.xpt
1225+
components/dom_push.xpt
12251226
components/dom_range.xpt
12261227
components/dom_sidebar.xpt
12271228
components/dom_smil.xpt

dom/apps/src/PermissionsTable.jsm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ this.PermissionsTable = { geolocation: {
124124
privileged: DENY_ACTION,
125125
certified: ALLOW_ACTION
126126
},
127+
push: {
128+
app: ALLOW_ACTION,
129+
privileged: ALLOW_ACTION,
130+
certified: ALLOW_ACTION
131+
},
127132
settings: {
128133
app: DENY_ACTION,
129134
privileged: DENY_ACTION,

dom/dom-config.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DOM_SRCDIRS = \
88
dom/encoding \
99
dom/file \
1010
dom/power \
11+
dom/push \
1112
dom/quota \
1213
dom/media \
1314
dom/network/src \

dom/messages/SystemMessagePermissionsChecker.jsm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ this.SystemMessagePermissionsTable = {
7474
"notification": {
7575
"desktop-notification": []
7676
},
77+
"push": {
78+
"push": []
79+
},
80+
"push-register": {
81+
"push": []
82+
},
7783
"sms-received": {
7884
"sms": []
7985
},

dom/moz.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interfaces = [
2626
'geolocation',
2727
'notification',
2828
'permission',
29+
'push',
2930
'svg',
3031
'smil',
3132
'apps',
@@ -51,6 +52,7 @@ PARALLEL_DIRS += [
5152
'media',
5253
'messages',
5354
'power',
55+
'push',
5456
'quota',
5557
'settings',
5658
'mobilemessage',

dom/push/Makefile.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
# You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
DEPTH = @DEPTH@
6+
topsrcdir = @top_srcdir@
7+
srcdir = @srcdir@
8+
VPATH = @srcdir@
9+
10+
relativesrcdir = @relativesrcdir@
11+
12+
include $(DEPTH)/config/autoconf.mk
13+
14+
include $(topsrcdir)/config/rules.mk

dom/push/moz.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# vim: set filetype=python:
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
PARALLEL_DIRS += ['src']

dom/push/src/Makefile.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
# You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
DEPTH = @DEPTH@
6+
topsrcdir = @top_srcdir@
7+
srcdir = @srcdir@
8+
VPATH = @srcdir@
9+
10+
include $(DEPTH)/config/autoconf.mk
11+
12+
EXTRA_COMPONENTS = \
13+
Push.js \
14+
Push.manifest \
15+
PushService.js \
16+
PushService.manifest \
17+
$(NULL)
18+
19+
include $(topsrcdir)/config/rules.mk
20+

dom/push/src/Push.js

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
"use strict";
6+
7+
function debug(s) {
8+
// dump("-*- Push.js: " + s + "\n");
9+
}
10+
11+
const Cc = Components.classes;
12+
const Ci = Components.interfaces;
13+
const Cu = Components.utils;
14+
15+
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
16+
Cu.import("resource://gre/modules/Services.jsm");
17+
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
18+
Cu.import("resource://gre/modules/AppsUtils.jsm");
19+
20+
const PUSH_CID = Components.ID("{c7ad4f42-faae-4e8b-9879-780a72349945}");
21+
22+
/**
23+
* The Push component runs in the child process and exposes the SimplePush API
24+
* to the web application. The PushService running in the parent process is the
25+
* one actually performing all operations.
26+
*/
27+
function Push()
28+
{
29+
debug("Push Constructor");
30+
}
31+
32+
Push.prototype = {
33+
__proto__: DOMRequestIpcHelper.prototype,
34+
35+
classID : PUSH_CID,
36+
37+
QueryInterface : XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer]),
38+
39+
init: function(aWindow) {
40+
debug("init()");
41+
42+
let principal = aWindow.document.nodePrincipal;
43+
44+
this._pageURL = principal.URI;
45+
46+
let appsService = Cc["@mozilla.org/AppsService;1"]
47+
.getService(Ci.nsIAppsService);
48+
this._app = appsService.getAppByLocalId(principal.appId);
49+
this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
50+
if (!this._manifestURL)
51+
return null;
52+
53+
let perm = Services.perms.testExactPermissionFromPrincipal(principal,
54+
"push");
55+
if (perm != Ci.nsIPermissionManager.ALLOW_ACTION)
56+
return null;
57+
58+
this.initHelper(aWindow, []);
59+
60+
this.initMessageListener([
61+
"PushService:Register:OK",
62+
"PushService:Register:KO",
63+
"PushService:Unregister:OK",
64+
"PushService:Unregister:KO",
65+
"PushService:Registrations:OK",
66+
"PushService:Registrations:KO"
67+
]);
68+
69+
this._cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
70+
.getService(Ci.nsISyncMessageSender);
71+
72+
var self = this;
73+
return {
74+
register: self.register.bind(self),
75+
unregister: self.unregister.bind(self),
76+
registrations: self.registrations.bind(self),
77+
__exposedProps__: {
78+
register: "r",
79+
unregister: "r",
80+
registrations: "r"
81+
}
82+
};
83+
},
84+
85+
receiveMessage: function(aMessage) {
86+
debug("receiveMessage()");
87+
let request = this.getRequest(aMessage.data.requestID);
88+
let json = aMessage.data;
89+
if (!request) {
90+
debug("No request " + json.requestID);
91+
return;
92+
}
93+
94+
switch (aMessage.name) {
95+
case "PushService:Register:OK":
96+
Services.DOMRequest.fireSuccess(request, json.pushEndpoint);
97+
break;
98+
case "PushService:Register:KO":
99+
Services.DOMRequest.fireError(request, json.error);
100+
break;
101+
case "PushService:Unregister:OK":
102+
Services.DOMRequest.fireSuccess(request, json.pushEndpoint);
103+
break;
104+
case "PushService:Unregister:KO":
105+
Services.DOMRequest.fireError(request, json.error);
106+
break;
107+
case "PushService:Registrations:OK":
108+
Services.DOMRequest.fireSuccess(request, json.registrations);
109+
break;
110+
case "PushService:Registrations:KO":
111+
Services.DOMRequest.fireError(request, json.error);
112+
break;
113+
default:
114+
debug("NOT IMPLEMENTED! receiveMessage for " + aMessage.name);
115+
}
116+
},
117+
118+
register: function() {
119+
debug("register()");
120+
var req = this.createRequest();
121+
this._cpmm.sendAsyncMessage("Push:Register", {
122+
pageURL: this._pageURL.spec,
123+
manifestURL: this._manifestURL,
124+
requestID: this.getRequestId(req)
125+
});
126+
return req;
127+
},
128+
129+
unregister: function(aPushEndpoint) {
130+
debug("unregister(" + aPushEndpoint + ")");
131+
var req = this.createRequest();
132+
this._cpmm.sendAsyncMessage("Push:Unregister", {
133+
pageURL: this._pageURL.spec,
134+
manifestURL: this._manifestURL,
135+
requestID: this.getRequestId(req),
136+
pushEndpoint: aPushEndpoint
137+
});
138+
return req;
139+
},
140+
141+
registrations: function() {
142+
debug("registrations()");
143+
var req = this.createRequest();
144+
this._cpmm.sendAsyncMessage("Push:Registrations", {
145+
manifestURL: this._manifestURL,
146+
requestID: this.getRequestId(req)
147+
});
148+
return req;
149+
}
150+
}
151+
152+
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Push]);

dom/push/src/Push.manifest

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
component {c7ad4f42-faae-4e8b-9879-780a72349945} Push.js
2+
contract @mozilla.org/Push;1 {c7ad4f42-faae-4e8b-9879-780a72349945}
3+
category JavaScript-navigator-property push @mozilla.org/Push;1
4+

0 commit comments

Comments
 (0)