summaryrefslogtreecommitdiffstats
path: root/dom/notification/NotificationStorage.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
commit59203c63bb777a3bacec32fb8830fba33540e809 (patch)
tree58298e711c0ff0575818c30485b44a2f21bf28a0 /dom/notification/NotificationStorage.sys.mjs
parentAdding upstream version 126.0.1. (diff)
downloadfirefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz
firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/notification/NotificationStorage.sys.mjs')
-rw-r--r--dom/notification/NotificationStorage.sys.mjs60
1 files changed, 40 insertions, 20 deletions
diff --git a/dom/notification/NotificationStorage.sys.mjs b/dom/notification/NotificationStorage.sys.mjs
index e33277b598..115b9714fe 100644
--- a/dom/notification/NotificationStorage.sys.mjs
+++ b/dom/notification/NotificationStorage.sys.mjs
@@ -11,17 +11,10 @@ ChromeUtils.defineLazyGetter(lazy, "console", () => {
});
});
-const kMessageNotificationGetAllOk = "Notification:GetAll:Return:OK";
-const kMessageNotificationGetAllKo = "Notification:GetAll:Return:KO";
-const kMessageNotificationSaveKo = "Notification:Save:Return:KO";
-const kMessageNotificationDeleteKo = "Notification:Delete:Return:KO";
-
-const kMessages = [
- kMessageNotificationGetAllOk,
- kMessageNotificationGetAllKo,
- kMessageNotificationSaveKo,
- kMessageNotificationDeleteKo,
-];
+const kMessageGetAllOk = "GetAll:Return:OK";
+const kMessageGetAllKo = "GetAll:Return:KO";
+const kMessageSaveKo = "Save:Return:KO";
+const kMessageDeleteKo = "Delete:Return:KO";
export class NotificationStorage {
#requests = {};
@@ -34,14 +27,35 @@ export class NotificationStorage {
this.registerListeners();
}
+ storageQualifier() {
+ return "Notification";
+ }
+
+ prefixStorageQualifier(message) {
+ return `${this.storageQualifier()}:${message}`;
+ }
+
+ formatMessageType(message) {
+ return this.prefixStorageQualifier(message);
+ }
+
+ supportedMessages() {
+ return [
+ this.formatMessageType(kMessageGetAllOk),
+ this.formatMessageType(kMessageGetAllKo),
+ this.formatMessageType(kMessageSaveKo),
+ this.formatMessageType(kMessageDeleteKo),
+ ];
+ }
+
registerListeners() {
- for (let message of kMessages) {
+ for (let message of this.supportedMessages()) {
Services.cpmm.addMessageListener(message, this);
}
}
unregisterListeners() {
- for (let message of kMessages) {
+ for (let message of this.supportedMessages()) {
Services.cpmm.removeMessageListener(message, this);
}
}
@@ -85,7 +99,7 @@ export class NotificationStorage {
serviceWorkerRegistrationScope,
};
- Services.cpmm.sendAsyncMessage("Notification:Save", {
+ Services.cpmm.sendAsyncMessage(this.formatMessageType("Save"), {
origin,
notification,
});
@@ -98,7 +112,7 @@ export class NotificationStorage {
delete(origin, id) {
lazy.console.debug(`DELETE: ${id}`);
- Services.cpmm.sendAsyncMessage("Notification:Delete", {
+ Services.cpmm.sendAsyncMessage(this.formatMessageType("Delete"), {
origin,
id,
});
@@ -108,12 +122,12 @@ export class NotificationStorage {
var request = this.#requests[message.data.requestID];
switch (message.name) {
- case kMessageNotificationGetAllOk:
+ case this.formatMessageType(kMessageGetAllOk):
delete this.#requests[message.data.requestID];
this.#returnNotifications(message.data.notifications, request.callback);
break;
- case kMessageNotificationGetAllKo:
+ case this.formatMessageType(kMessageGetAllKo):
delete this.#requests[message.data.requestID];
try {
request.callback.done();
@@ -121,8 +135,8 @@ export class NotificationStorage {
lazy.console.debug(`Error calling callback done: ${e}`);
}
break;
- case kMessageNotificationSaveKo:
- case kMessageNotificationDeleteKo:
+ case this.formatMessageType(kMessageSaveKo):
+ case this.formatMessageType(kMessageDeleteKo):
lazy.console.debug(
`Error received when treating: '${message.name}': ${message.data.errorMsg}`
);
@@ -149,7 +163,7 @@ export class NotificationStorage {
};
var requestID = this.#getUniqueRequestID();
this.#requests[requestID] = request;
- Services.cpmm.sendAsyncMessage("Notification:GetAll", {
+ Services.cpmm.sendAsyncMessage(this.formatMessageType("GetAll"), {
origin,
tag,
requestID,
@@ -190,3 +204,9 @@ export class NotificationStorage {
QueryInterface = ChromeUtils.generateQI(["nsINotificationStorage"]);
}
+
+export class MemoryNotificationStorage extends NotificationStorage {
+ storageQualifier() {
+ return "MemoryNotification";
+ }
+}