gecko-dev/dom/push/PushServiceChildPreload.jsm
Nikhil Marathe 84fedf8359 Bug 1190661 - Send push only to child processes when in e10s mode. r=smaug
Earlier, the in-process child process message manager and any content process
child process message managers received the push event. This is because
broadcastAsyncMessage is used, but on e10s we want ServiceWorkers to run in the
child process, so the push should only be dispatched to it. This patch
introduces a list of child process listeners in the PushService (running on the
parent). PushServiceChildPreload sends a message to the PushService iff it is
running in a child process. If there are non-zero child listeners, the
PushService will send a message to all of them, otherwise it will fall back to
broadcastAsyncMessage.

We currently do not add support for precise targeting of child processes. This
is because until Bug 1182117 is fixed, all child process ServiceWorkerManagers
maintain all the service worker registrations internally. Yes this is a bug,
but that is the way things are right now. This makes it impossible to
distinguish which child should handle the notification for a given origin.
Considering we don't ship multi-process e10s, I would like to land this right
now.

When Bug 1182117 is fixed, we can remove this code since the
ServiceWorkerManager will manage registrations in the parent, and it will know
which child process is running which ServiceWorker.

--HG--
extra : commitid : Dgfkg4LqLPK
extra : rebase_source : e64a4f1c757b05fe2939a338c1ad8d14f4015a90
2015-07-30 20:00:21 -07:00

38 lines
1.3 KiB
JavaScript

/* 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");
let processType = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULRuntime).processType;
let isParent = processType === Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
Services.cpmm.addMessageListener("push", function (aMessage) {
swm.sendPushEvent(aMessage.data.originAttributes,
aMessage.data.scope, aMessage.data.payload);
});
Services.cpmm.addMessageListener("pushsubscriptionchange", function (aMessage) {
swm.sendPushSubscriptionChangeEvent(aMessage.data.originAttributes,
aMessage.data.scope);
});
if (!isParent) {
Services.cpmm.sendAsyncMessage("Push:RegisterEventNotificationListener", null, null, null);
}