2016-05-12 04:28:46 +03:00
|
|
|
/* 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");
|
|
|
|
|
2017-08-01 18:43:56 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Services", // jshint ignore:line
|
|
|
|
"resource://gre/modules/Services.jsm");
|
2016-05-12 04:28:46 +03:00
|
|
|
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);
|
|
|
|
|
2017-08-01 18:43:56 +03:00
|
|
|
if (topic === "persistent-notification-click") {
|
2016-06-25 18:58:03 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2017-08-01 18:43:56 +03:00
|
|
|
} else if (topic === "persistent-notification-close") {
|
2016-06-25 18:58:03 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-05-12 04:28:46 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
|
|
|
|
PersistentNotificationHandler
|
|
|
|
]);
|