mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1705271 - Get rid of PushServiceAndroidGCM.sys.mjs. r=saschanaz
`PushServiceAndroidGCM` is Fennec only module and GeckoView uses `GeckoViewPush.jsm` for push service. So we should get rid of `PushServiceAndroidGCM`. Differential Revision: https://phabricator.services.mozilla.com/D160351
This commit is contained in:
parent
a017df7de0
commit
fa5c50b8cd
@ -20,7 +20,6 @@ XPCOMUtils.defineLazyServiceGetter(
|
||||
);
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
PushCrypto: "resource://gre/modules/PushCrypto.sys.mjs",
|
||||
PushServiceAndroidGCM: "resource://gre/modules/PushServiceAndroidGCM.sys.mjs",
|
||||
pushBroadcastService: "resource://gre/modules/PushBroadcastService.sys.mjs",
|
||||
});
|
||||
|
||||
@ -34,7 +33,7 @@ const CONNECTION_PROTOCOLS = (function() {
|
||||
));
|
||||
return [PushServiceWebSocket, PushServiceHttp2];
|
||||
}
|
||||
return [lazy.PushServiceAndroidGCM];
|
||||
return [];
|
||||
})();
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "console", () => {
|
||||
|
@ -1,305 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
import { PushRecord } from "resource://gre/modules/PushRecord.sys.mjs";
|
||||
import { Preferences } from "resource://gre/modules/Preferences.sys.mjs";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
PushCrypto: "resource://gre/modules/PushCrypto.sys.mjs",
|
||||
PushDB: "resource://gre/modules/PushDB.sys.mjs",
|
||||
});
|
||||
ChromeUtils.defineModuleGetter(
|
||||
lazy,
|
||||
"EventDispatcher",
|
||||
"resource://gre/modules/Messaging.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "Log", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/AndroidLog.jsm"
|
||||
).AndroidLog.bind("Push");
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "console", () => {
|
||||
let { ConsoleAPI } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/Console.sys.mjs"
|
||||
);
|
||||
return new ConsoleAPI({
|
||||
dump: lazy.Log.i,
|
||||
maxLogLevelPref: "dom.push.loglevel",
|
||||
prefix: "PushServiceAndroidGCM",
|
||||
});
|
||||
});
|
||||
|
||||
const kPUSHANDROIDGCMDB_DB_NAME = "pushAndroidGCM";
|
||||
const kPUSHANDROIDGCMDB_DB_VERSION = 5; // Change this if the IndexedDB format changes
|
||||
const kPUSHANDROIDGCMDB_STORE_NAME = "pushAndroidGCM";
|
||||
|
||||
const FXA_PUSH_SCOPE = "chrome://fxa-push";
|
||||
|
||||
const prefs = new Preferences("dom.push.");
|
||||
|
||||
/**
|
||||
* The implementation of WebPush push backed by Android's GCM
|
||||
* delivery.
|
||||
*/
|
||||
export var PushServiceAndroidGCM = {
|
||||
_mainPushService: null,
|
||||
_serverURI: null,
|
||||
|
||||
newPushDB() {
|
||||
return new lazy.PushDB(
|
||||
kPUSHANDROIDGCMDB_DB_NAME,
|
||||
kPUSHANDROIDGCMDB_DB_VERSION,
|
||||
kPUSHANDROIDGCMDB_STORE_NAME,
|
||||
"channelID",
|
||||
PushRecordAndroidGCM
|
||||
);
|
||||
},
|
||||
|
||||
observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "nsPref:changed":
|
||||
if (data == "dom.push.debug") {
|
||||
// Reconfigure.
|
||||
let debug = !!prefs.get("debug");
|
||||
lazy.console.info(
|
||||
"Debug parameter changed; updating configuration with new debug",
|
||||
debug
|
||||
);
|
||||
this._configure(this._serverURI, debug);
|
||||
}
|
||||
break;
|
||||
case "PushServiceAndroidGCM:ReceivedPushMessage":
|
||||
this._onPushMessageReceived(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
_onPushMessageReceived(data) {
|
||||
// TODO: Use Messaging.jsm for this.
|
||||
if (this._mainPushService == null) {
|
||||
// Shouldn't ever happen, but let's be careful.
|
||||
lazy.console.error("No main PushService! Dropping message.");
|
||||
return;
|
||||
}
|
||||
if (!data) {
|
||||
lazy.console.error("No data from Java! Dropping message.");
|
||||
return;
|
||||
}
|
||||
data = JSON.parse(data);
|
||||
lazy.console.debug("ReceivedPushMessage with data", data);
|
||||
|
||||
let { headers, message } = this._messageAndHeaders(data);
|
||||
|
||||
lazy.console.debug(
|
||||
"Delivering message to main PushService:",
|
||||
message,
|
||||
headers
|
||||
);
|
||||
this._mainPushService.receivedPushMessage(
|
||||
data.channelID,
|
||||
"",
|
||||
headers,
|
||||
message,
|
||||
record => {
|
||||
// Always update the stored record.
|
||||
return record;
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
_messageAndHeaders(data) {
|
||||
// Default is no data (and no encryption).
|
||||
let message = null;
|
||||
let headers = null;
|
||||
|
||||
if (data.message) {
|
||||
if (data.enc && (data.enckey || data.cryptokey)) {
|
||||
headers = {
|
||||
encryption_key: data.enckey,
|
||||
crypto_key: data.cryptokey,
|
||||
encryption: data.enc,
|
||||
encoding: data.con,
|
||||
};
|
||||
} else if (data.con == "aes128gcm") {
|
||||
headers = {
|
||||
encoding: data.con,
|
||||
};
|
||||
}
|
||||
// Ciphertext is (urlsafe) Base 64 encoded.
|
||||
message = ChromeUtils.base64URLDecode(data.message, {
|
||||
// The Push server may append padding.
|
||||
padding: "ignore",
|
||||
});
|
||||
}
|
||||
|
||||
return { headers, message };
|
||||
},
|
||||
|
||||
_configure(serverURL, debug) {
|
||||
return lazy.EventDispatcher.instance.sendRequestForResult({
|
||||
type: "PushServiceAndroidGCM:Configure",
|
||||
endpoint: serverURL.spec,
|
||||
debug,
|
||||
});
|
||||
},
|
||||
|
||||
init(options, mainPushService, serverURL) {
|
||||
lazy.console.debug("init()");
|
||||
this._mainPushService = mainPushService;
|
||||
this._serverURI = serverURL;
|
||||
|
||||
prefs.observe("debug", this);
|
||||
Services.obs.addObserver(this, "PushServiceAndroidGCM:ReceivedPushMessage");
|
||||
|
||||
return this._configure(serverURL, !!prefs.get("debug")).then(() => {
|
||||
lazy.EventDispatcher.instance.sendRequestForResult({
|
||||
type: "PushServiceAndroidGCM:Initialized",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
uninit() {
|
||||
lazy.console.debug("uninit()");
|
||||
lazy.EventDispatcher.instance.sendRequestForResult({
|
||||
type: "PushServiceAndroidGCM:Uninitialized",
|
||||
});
|
||||
|
||||
this._mainPushService = null;
|
||||
Services.obs.removeObserver(
|
||||
this,
|
||||
"PushServiceAndroidGCM:ReceivedPushMessage"
|
||||
);
|
||||
prefs.ignore("debug", this);
|
||||
},
|
||||
|
||||
onAlarmFired() {
|
||||
// No action required.
|
||||
},
|
||||
|
||||
connect(records, broadcastListeners) {
|
||||
lazy.console.debug("connect:", records);
|
||||
// It's possible for the registration or subscriptions backing the
|
||||
// PushService to not be registered with the underlying AndroidPushService.
|
||||
// Expire those that are unrecognized.
|
||||
return lazy.EventDispatcher.instance
|
||||
.sendRequestForResult({
|
||||
type: "PushServiceAndroidGCM:DumpSubscriptions",
|
||||
})
|
||||
.then(subscriptions => {
|
||||
subscriptions = JSON.parse(subscriptions);
|
||||
lazy.console.debug("connect:", subscriptions);
|
||||
// subscriptions maps chid => subscription data.
|
||||
return Promise.all(
|
||||
records.map(record => {
|
||||
if (subscriptions.hasOwnProperty(record.keyID)) {
|
||||
lazy.console.debug("connect:", "hasOwnProperty", record.keyID);
|
||||
return Promise.resolve();
|
||||
}
|
||||
lazy.console.debug("connect:", "!hasOwnProperty", record.keyID);
|
||||
// Subscription is known to PushService.jsm but not to AndroidPushService. Drop it.
|
||||
return this._mainPushService
|
||||
.dropRegistrationAndNotifyApp(record.keyID)
|
||||
.catch(error => {
|
||||
lazy.console.error(
|
||||
"connect: Error dropping registration",
|
||||
record.keyID,
|
||||
error
|
||||
);
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
async sendSubscribeBroadcast(serviceId, version) {
|
||||
// Not implemented yet
|
||||
},
|
||||
|
||||
isConnected() {
|
||||
return this._mainPushService != null;
|
||||
},
|
||||
|
||||
disconnect() {
|
||||
lazy.console.debug("disconnect");
|
||||
},
|
||||
|
||||
register(record) {
|
||||
lazy.console.debug("register:", record);
|
||||
let ctime = Date.now();
|
||||
let appServerKey = record.appServerKey
|
||||
? ChromeUtils.base64URLEncode(record.appServerKey, {
|
||||
// The Push server requires padding.
|
||||
pad: true,
|
||||
})
|
||||
: null;
|
||||
let message = {
|
||||
type: "PushServiceAndroidGCM:SubscribeChannel",
|
||||
appServerKey,
|
||||
};
|
||||
if (record.scope == FXA_PUSH_SCOPE) {
|
||||
message.service = "fxa";
|
||||
}
|
||||
// Caller handles errors.
|
||||
return lazy.EventDispatcher.instance
|
||||
.sendRequestForResult(message)
|
||||
.then(data => {
|
||||
data = JSON.parse(data);
|
||||
lazy.console.debug("Got data:", data);
|
||||
return lazy.PushCrypto.generateKeys().then(
|
||||
exportedKeys =>
|
||||
new PushRecordAndroidGCM({
|
||||
// Straight from autopush.
|
||||
channelID: data.channelID,
|
||||
pushEndpoint: data.endpoint,
|
||||
// Common to all PushRecord implementations.
|
||||
scope: record.scope,
|
||||
originAttributes: record.originAttributes,
|
||||
ctime,
|
||||
systemRecord: record.systemRecord,
|
||||
// Cryptography!
|
||||
p256dhPublicKey: exportedKeys[0],
|
||||
p256dhPrivateKey: exportedKeys[1],
|
||||
authenticationSecret: lazy.PushCrypto.generateAuthenticationSecret(),
|
||||
appServerKey: record.appServerKey,
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
unregister(record) {
|
||||
lazy.console.debug("unregister: ", record);
|
||||
return lazy.EventDispatcher.instance.sendRequestForResult({
|
||||
type: "PushServiceAndroidGCM:UnsubscribeChannel",
|
||||
channelID: record.keyID,
|
||||
});
|
||||
},
|
||||
|
||||
reportDeliveryError(messageID, reason) {
|
||||
lazy.console.warn(
|
||||
"reportDeliveryError: Ignoring message delivery error",
|
||||
messageID,
|
||||
reason
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
function PushRecordAndroidGCM(record) {
|
||||
PushRecord.call(this, record);
|
||||
this.channelID = record.channelID;
|
||||
}
|
||||
|
||||
PushRecordAndroidGCM.prototype = Object.create(PushRecord.prototype, {
|
||||
keyID: {
|
||||
get() {
|
||||
return this.channelID;
|
||||
},
|
||||
},
|
||||
});
|
@ -21,16 +21,11 @@ EXTRA_JS_MODULES += [
|
||||
]
|
||||
|
||||
if CONFIG["MOZ_BUILD_APP"] != "mobile/android":
|
||||
# Everything but Fennec.
|
||||
# Everything but GeckoView.
|
||||
EXTRA_JS_MODULES += [
|
||||
"PushServiceHttp2.sys.mjs",
|
||||
"PushServiceWebSocket.sys.mjs",
|
||||
]
|
||||
else:
|
||||
# Fennec only.
|
||||
EXTRA_JS_MODULES += [
|
||||
"PushServiceAndroidGCM.sys.mjs",
|
||||
]
|
||||
|
||||
XPCOM_MANIFESTS += [
|
||||
"components.conf",
|
||||
|
Loading…
Reference in New Issue
Block a user