mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1239584, Part 2 - Remove message manager usage from PushService.jsm
. r=dragana
This commit is contained in:
parent
14f29bbc2a
commit
3d5613d1cf
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
XPIDL_SOURCES += [
|
XPIDL_SOURCES += [
|
||||||
'nsIPushNotifier.idl',
|
'nsIPushNotifier.idl',
|
||||||
'nsIPushObserverNotification.idl',
|
|
||||||
'nsIPushService.idl',
|
'nsIPushService.idl',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
||||||
/* 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/. */
|
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A push message received by an `nsIPushService`, used as the subject of a
|
|
||||||
* `push-notification` observer notification.
|
|
||||||
*/
|
|
||||||
[scriptable, uuid(56f57607-28b6-44b0-aa56-3d4d3c88be15)]
|
|
||||||
interface nsIPushObserverNotification : nsISupports
|
|
||||||
{
|
|
||||||
/* The URL that receives push messages from an application server. */
|
|
||||||
attribute string pushEndpoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The notification version sent by the application server. This is a
|
|
||||||
* monotonically increasing number.
|
|
||||||
*/
|
|
||||||
attribute long long version;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The notification payload. Delivery is not guaranteed; if the browser is
|
|
||||||
* offline when the application server sends the push message, the payload
|
|
||||||
* may be discarded.
|
|
||||||
*/
|
|
||||||
attribute string data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* How many times has a push event occured against this pushEndpoint
|
|
||||||
*/
|
|
||||||
attribute long long pushCount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The last time a push occured against this this pushEndpoint
|
|
||||||
*/
|
|
||||||
attribute long long lastPush;
|
|
||||||
};
|
|
@ -81,9 +81,8 @@ interface nsIPushService : nsISupports
|
|||||||
* The |endpoint| property of the subscription record is a URL string
|
* The |endpoint| property of the subscription record is a URL string
|
||||||
* that can be used to send push messages to subscribers.
|
* that can be used to send push messages to subscribers.
|
||||||
*
|
*
|
||||||
* Each incoming message fires a `push-notification` observer
|
* Each incoming message fires a `push-message` observer notification, with
|
||||||
* notification, with an `nsIPushObserverNotification` as the subject and
|
* an `nsIPushMessage` as the subject and the |scope| as the data.
|
||||||
* the |scope| as the data.
|
|
||||||
*
|
*
|
||||||
* If the server drops a subscription, a `push-subscription-change` observer
|
* If the server drops a subscription, a `push-subscription-change` observer
|
||||||
* will be fired, with the subject set to `null` and the data set to |scope|.
|
* will be fired, with the subject set to `null` and the data set to |scope|.
|
||||||
|
@ -6,6 +6,3 @@ contract @mozilla.org/push/PushManager;1 {cde1d019-fad8-4044-b141-65fb4fb7a245}
|
|||||||
component {daaa8d73-677e-4233-8acd-2c404bd01658} PushComponents.js
|
component {daaa8d73-677e-4233-8acd-2c404bd01658} PushComponents.js
|
||||||
contract @mozilla.org/push/Service;1 {daaa8d73-677e-4233-8acd-2c404bd01658}
|
contract @mozilla.org/push/Service;1 {daaa8d73-677e-4233-8acd-2c404bd01658}
|
||||||
category app-startup PushServiceParent @mozilla.org/push/Service;1
|
category app-startup PushServiceParent @mozilla.org/push/Service;1
|
||||||
|
|
||||||
component {e68997fd-8b92-49ee-af12-800830b023e8} PushComponents.js
|
|
||||||
contract @mozilla.org/push/ObserverNotification;1 {e68997fd-8b92-49ee-af12-800830b023e8}
|
|
||||||
|
@ -106,10 +106,8 @@ Object.assign(PushServiceParent.prototype, {
|
|||||||
"Push:Registration",
|
"Push:Registration",
|
||||||
"Push:Unregister",
|
"Push:Unregister",
|
||||||
"Push:Clear",
|
"Push:Clear",
|
||||||
"Push:RegisterEventNotificationListener",
|
|
||||||
"Push:NotificationForOriginShown",
|
"Push:NotificationForOriginShown",
|
||||||
"Push:NotificationForOriginClosed",
|
"Push:NotificationForOriginClosed",
|
||||||
"child-process-shutdown",
|
|
||||||
],
|
],
|
||||||
|
|
||||||
// nsIPushService methods
|
// nsIPushService methods
|
||||||
@ -169,14 +167,6 @@ Object.assign(PushServiceParent.prototype, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let {name, principal, target, data} = message;
|
let {name, principal, target, data} = message;
|
||||||
if (name === "Push:RegisterEventNotificationListener") {
|
|
||||||
this._service.registerListener(target);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (name === "child-process-shutdown") {
|
|
||||||
this._service.unregisterListener(target);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (name === "Push:NotificationForOriginShown") {
|
if (name === "Push:NotificationForOriginShown") {
|
||||||
this.notificationForOriginShown(data);
|
this.notificationForOriginShown(data);
|
||||||
return;
|
return;
|
||||||
@ -468,21 +458,7 @@ PushSubscription.prototype = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* `PushObserverNotification` instances are passed to all
|
|
||||||
* `push-notification` observers.
|
|
||||||
*/
|
|
||||||
function PushObserverNotification() {}
|
|
||||||
|
|
||||||
PushObserverNotification.prototype = {
|
|
||||||
classID: Components.ID("{e68997fd-8b92-49ee-af12-800830b023e8}"),
|
|
||||||
contractID: "@mozilla.org/push/ObserverNotification;1",
|
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPushObserverNotification]),
|
|
||||||
};
|
|
||||||
|
|
||||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
|
||||||
PushObserverNotification,
|
|
||||||
|
|
||||||
// Export the correct implementation depending on whether we're running in
|
// Export the correct implementation depending on whether we're running in
|
||||||
// the parent or content process.
|
// the parent or content process.
|
||||||
isParent ? PushServiceParent : PushServiceContent,
|
isParent ? PushServiceParent : PushServiceContent,
|
||||||
|
@ -31,6 +31,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gContentSecurityManager",
|
|||||||
"@mozilla.org/contentsecuritymanager;1",
|
"@mozilla.org/contentsecuritymanager;1",
|
||||||
"nsIContentSecurityManager");
|
"nsIContentSecurityManager");
|
||||||
|
|
||||||
|
XPCOMUtils.defineLazyServiceGetter(this, "gPushNotifier",
|
||||||
|
"@mozilla.org/push/Notifier;1",
|
||||||
|
"nsIPushNotifier");
|
||||||
|
|
||||||
this.EXPORTED_SYMBOLS = ["PushService"];
|
this.EXPORTED_SYMBOLS = ["PushService"];
|
||||||
|
|
||||||
XPCOMUtils.defineLazyGetter(this, "console", () => {
|
XPCOMUtils.defineLazyGetter(this, "console", () => {
|
||||||
@ -99,8 +103,6 @@ this.PushService = {
|
|||||||
// reduce the quota for a record. Used for testing purposes.
|
// reduce the quota for a record. Used for testing purposes.
|
||||||
_updateQuotaTestCallback: null,
|
_updateQuotaTestCallback: null,
|
||||||
|
|
||||||
_childListeners: new Set(),
|
|
||||||
|
|
||||||
// When serverURI changes (this is used for testing), db is cleaned up and a
|
// When serverURI changes (this is used for testing), db is cleaned up and a
|
||||||
// a new db is started. This events must be sequential.
|
// a new db is started. This events must be sequential.
|
||||||
_stateChangeProcessQueue: null,
|
_stateChangeProcessQueue: null,
|
||||||
@ -592,8 +594,6 @@ this.PushService = {
|
|||||||
uninit: function() {
|
uninit: function() {
|
||||||
console.debug("uninit()");
|
console.debug("uninit()");
|
||||||
|
|
||||||
this._childListeners.clear();
|
|
||||||
|
|
||||||
if (this._state == PUSH_SERVICE_UNINIT) {
|
if (this._state == PUSH_SERVICE_UNINIT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -688,38 +688,8 @@ this.PushService = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify XPCOM observers.
|
|
||||||
Services.obs.notifyObservers(
|
|
||||||
null,
|
|
||||||
"push-subscription-change",
|
|
||||||
record.scope
|
|
||||||
);
|
|
||||||
|
|
||||||
let data = {
|
|
||||||
originAttributes: record.originAttributes,
|
|
||||||
scope: record.scope
|
|
||||||
};
|
|
||||||
|
|
||||||
Services.telemetry.getHistogramById("PUSH_API_NOTIFY_REGISTRATION_LOST").add();
|
Services.telemetry.getHistogramById("PUSH_API_NOTIFY_REGISTRATION_LOST").add();
|
||||||
this._notifyListeners('pushsubscriptionchange', data);
|
gPushNotifier.notifySubscriptionChange(record.scope, record.principal);
|
||||||
},
|
|
||||||
|
|
||||||
_notifyListeners: function(name, data) {
|
|
||||||
if (this._childListeners.size > 0) {
|
|
||||||
// Try to send messages to all listeners, but remove any that fail since
|
|
||||||
// the receiver is likely gone away.
|
|
||||||
for (let listener of this._childListeners) {
|
|
||||||
try {
|
|
||||||
listener.sendAsyncMessage(name, data);
|
|
||||||
} catch(e) {
|
|
||||||
this._childListeners.delete(listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let ppmm = Cc['@mozilla.org/parentprocessmessagemanager;1']
|
|
||||||
.getService(Ci.nsIMessageListenerManager);
|
|
||||||
ppmm.broadcastAsyncMessage(name, data);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -959,29 +929,6 @@ this.PushService = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.debug("notifyApp()", aPushRecord.scope);
|
console.debug("notifyApp()", aPushRecord.scope);
|
||||||
// Notify XPCOM observers.
|
|
||||||
let notification = Cc["@mozilla.org/push/ObserverNotification;1"]
|
|
||||||
.createInstance(Ci.nsIPushObserverNotification);
|
|
||||||
notification.pushEndpoint = aPushRecord.pushEndpoint;
|
|
||||||
notification.version = aPushRecord.version;
|
|
||||||
|
|
||||||
let payload = ArrayBuffer.isView(message) ?
|
|
||||||
new Uint8Array(message.buffer) : message;
|
|
||||||
if (payload) {
|
|
||||||
notification.data = "";
|
|
||||||
for (let i = 0; i < payload.length; i++) {
|
|
||||||
notification.data += String.fromCharCode(payload[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notification.lastPush = aPushRecord.lastPush;
|
|
||||||
notification.pushCount = aPushRecord.pushCount;
|
|
||||||
|
|
||||||
Services.obs.notifyObservers(
|
|
||||||
notification,
|
|
||||||
"push-notification",
|
|
||||||
aPushRecord.scope
|
|
||||||
);
|
|
||||||
|
|
||||||
// If permission has been revoked, trash the message.
|
// If permission has been revoked, trash the message.
|
||||||
if (!aPushRecord.hasPermission()) {
|
if (!aPushRecord.hasPermission()) {
|
||||||
@ -989,14 +936,22 @@ this.PushService = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = {
|
let payload = ArrayBuffer.isView(message) ?
|
||||||
payload: payload,
|
new Uint8Array(message.buffer) : message;
|
||||||
originAttributes: aPushRecord.originAttributes,
|
|
||||||
scope: aPushRecord.scope
|
if (aPushRecord.quotaApplies()) {
|
||||||
};
|
// Don't record telemetry for chrome push messages.
|
||||||
|
Services.telemetry.getHistogramById("PUSH_API_NOTIFY").add();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload) {
|
||||||
|
gPushNotifier.notifyPushWithData(aPushRecord.scope,
|
||||||
|
aPushRecord.principal,
|
||||||
|
payload.length, payload);
|
||||||
|
} else {
|
||||||
|
gPushNotifier.notifyPush(aPushRecord.scope, aPushRecord.principal);
|
||||||
|
}
|
||||||
|
|
||||||
Services.telemetry.getHistogramById("PUSH_API_NOTIFY").add();
|
|
||||||
this._notifyListeners('push', data);
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1086,14 +1041,7 @@ this.PushService = {
|
|||||||
throw reply.error;
|
throw reply.error;
|
||||||
},
|
},
|
||||||
|
|
||||||
registerListener(listener) {
|
notificationsCleared() {
|
||||||
console.debug("registerListener: Adding child listener");
|
|
||||||
this._childListeners.add(listener);
|
|
||||||
},
|
|
||||||
|
|
||||||
unregisterListener(listener) {
|
|
||||||
console.debug("unregisterListener: Possibly removing child listener");
|
|
||||||
this._childListeners.delete(listener);
|
|
||||||
this._visibleNotifications.clear();
|
this._visibleNotifications.clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,41 +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/. */
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
this.EXPORTED_SYMBOLS = [];
|
|
||||||
|
|
||||||
const Cc = Components.classes;
|
|
||||||
const Ci = Components.interfaces;
|
|
||||||
|
|
||||||
const Cu = Components.utils;
|
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
||||||
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(this,
|
|
||||||
"swm",
|
|
||||||
"@mozilla.org/serviceworkers/manager;1",
|
|
||||||
"nsIServiceWorkerManager");
|
|
||||||
|
|
||||||
var processType = Cc["@mozilla.org/xre/app-info;1"]
|
|
||||||
.getService(Ci.nsIXULRuntime).processType;
|
|
||||||
var isParent = processType === Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
||||||
|
|
||||||
Services.cpmm.addMessageListener("push", function (aMessage) {
|
|
||||||
let {originAttributes, scope, payload} = aMessage.data;
|
|
||||||
if (payload) {
|
|
||||||
swm.sendPushEvent(originAttributes, scope, payload.length, payload);
|
|
||||||
} else {
|
|
||||||
swm.sendPushEvent(originAttributes, scope);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Services.cpmm.addMessageListener("pushsubscriptionchange", function (aMessage) {
|
|
||||||
swm.sendPushSubscriptionChangeEvent(aMessage.data.originAttributes,
|
|
||||||
aMessage.data.scope);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isParent) {
|
|
||||||
Services.cpmm.sendAsyncMessage("Push:RegisterEventNotificationListener", null, null, null);
|
|
||||||
}
|
|
@ -14,7 +14,6 @@ EXTRA_JS_MODULES += [
|
|||||||
'PushDB.jsm',
|
'PushDB.jsm',
|
||||||
'PushRecord.jsm',
|
'PushRecord.jsm',
|
||||||
'PushService.jsm',
|
'PushService.jsm',
|
||||||
'PushServiceChildPreload.jsm',
|
|
||||||
'PushServiceHttp2.jsm',
|
'PushServiceHttp2.jsm',
|
||||||
'PushServiceWebSocket.jsm',
|
'PushServiceWebSocket.jsm',
|
||||||
]
|
]
|
||||||
|
@ -10,6 +10,3 @@ var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|||||||
// and for those that match URLs provided by the parent process will set up
|
// and for those that match URLs provided by the parent process will set up
|
||||||
// a dedicated message port and notify the parent process.
|
// a dedicated message port and notify the parent process.
|
||||||
Cu.import("resource://gre/modules/RemotePageManager.jsm");
|
Cu.import("resource://gre/modules/RemotePageManager.jsm");
|
||||||
|
|
||||||
// Hooks to listen for push messages
|
|
||||||
Cu.import("resource://gre/modules/PushServiceChildPreload.jsm");
|
|
||||||
|
Loading…
Reference in New Issue
Block a user