summaryrefslogtreecommitdiffstats
path: root/mobile/android/components/PersistentNotificationHandler.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /mobile/android/components/PersistentNotificationHandler.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/components/PersistentNotificationHandler.js')
-rw-r--r--mobile/android/components/PersistentNotificationHandler.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/mobile/android/components/PersistentNotificationHandler.js b/mobile/android/components/PersistentNotificationHandler.js
new file mode 100644
index 000000000..2a3529f5f
--- /dev/null
+++ b/mobile/android/components/PersistentNotificationHandler.js
@@ -0,0 +1,78 @@
+/* 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 { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Messaging.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, 'Services', // jshint ignore:line
+ 'resource://gre/modules/Services.jsm');
+XPCOMUtils.defineLazyServiceGetter(this, "notificationStorage",
+ "@mozilla.org/notificationStorage;1",
+ "nsINotificationStorage");
+XPCOMUtils.defineLazyServiceGetter(this, "serviceWorkerManager",
+ "@mozilla.org/serviceworkers/manager;1",
+ "nsIServiceWorkerManager");
+
+function PersistentNotificationHandler() {
+}
+
+PersistentNotificationHandler.prototype = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
+ classID: Components.ID("{75390fe7-f8a3-423a-b3b1-258d7eabed40}"),
+
+ observe(subject, topic, data) {
+ if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT) {
+ Cu.import("resource://gre/modules/NotificationDB.jsm");
+ }
+ const persistentInfo = JSON.parse(data);
+
+ if (topic === 'persistent-notification-click') {
+ notificationStorage.getByID(persistentInfo.origin, persistentInfo.id, {
+ handle(id, title, dir, lang, body, tag, icon, data, behavior, serviceWorkerRegistrationScope) {
+ serviceWorkerManager.sendNotificationClickEvent(
+ persistentInfo.originSuffix,
+ serviceWorkerRegistrationScope,
+ id,
+ title,
+ dir,
+ lang,
+ body,
+ tag,
+ icon,
+ data,
+ behavior
+ );
+ notificationStorage.delete(persistentInfo.origin, persistentInfo.id);
+ }
+ });
+ } else if (topic === 'persistent-notification-close') {
+ notificationStorage.getByID(persistentInfo.origin, persistentInfo.id, {
+ handle(id, title, dir, lang, body, tag, icon, data, behavior, serviceWorkerRegistrationScope) {
+ serviceWorkerManager.sendNotificationCloseEvent(
+ persistentInfo.originSuffix,
+ serviceWorkerRegistrationScope,
+ id,
+ title,
+ dir,
+ lang,
+ body,
+ tag,
+ icon,
+ data,
+ behavior
+ );
+ notificationStorage.delete(persistentInfo.origin, persistentInfo.id);
+ }
+ });
+ }
+ }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
+ PersistentNotificationHandler
+]);