2015-02-04 20:13:38 +03:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
|
|
|
|
|
|
|
|
/**
|
2017-04-04 21:25:05 +03:00
|
|
|
* This process script is for small observers that we want to register
|
|
|
|
* once per content process, usually in order to forward content-based
|
|
|
|
* observer service notifications to the chrome process through
|
|
|
|
* message passing. Using a process script avoids having them in
|
|
|
|
* content.js and thereby registering N observers for N open tabs,
|
|
|
|
* which is bad for perf.
|
2015-02-04 20:13:38 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2017-04-07 18:48:58 +03:00
|
|
|
|
2018-07-30 20:53:15 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"WebRTCChild",
|
|
|
|
"resource:///actors/WebRTCChild.jsm"
|
|
|
|
);
|
2015-02-04 20:13:38 +03:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var gEMEUIObserver = function(subject, topic, data) {
|
2015-02-20 12:38:18 +03:00
|
|
|
let win = subject.top;
|
2015-02-04 20:13:38 +03:00
|
|
|
let mm = getMessageManagerForWindow(win);
|
|
|
|
if (mm) {
|
2015-02-20 12:38:18 +03:00
|
|
|
mm.sendAsyncMessage("EMEVideo:ContentMediaKeysRequest", data);
|
2015-02-04 20:13:38 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-24 11:04:25 +03:00
|
|
|
var gDecoderDoctorObserver = function(subject, topic, data) {
|
|
|
|
let win = subject.top;
|
|
|
|
let mm = getMessageManagerForWindow(win);
|
|
|
|
if (mm) {
|
|
|
|
mm.sendAsyncMessage("DecoderDoctor:Notification", data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-04 20:13:38 +03:00
|
|
|
function getMessageManagerForWindow(aContentWindow) {
|
2018-08-03 06:49:09 +03:00
|
|
|
return aContentWindow.docShell.messageManager;
|
2015-02-04 20:13:38 +03:00
|
|
|
}
|
|
|
|
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(gEMEUIObserver, "mediakeys-request");
|
|
|
|
Services.obs.addObserver(gDecoderDoctorObserver, "decoder-doctor-notification");
|
2017-04-07 18:48:58 +03:00
|
|
|
|
2018-07-30 20:53:15 +03:00
|
|
|
// WebRTCChild observer registration.
|
2017-04-07 18:48:58 +03:00
|
|
|
const kWebRTCObserverTopics = [
|
|
|
|
"getUserMedia:request",
|
|
|
|
"recording-device-stopped",
|
|
|
|
"PeerConnection:request",
|
|
|
|
"recording-device-events",
|
|
|
|
"recording-window-ended",
|
|
|
|
];
|
|
|
|
|
|
|
|
function webRTCObserve(aSubject, aTopic, aData) {
|
2018-07-30 20:53:15 +03:00
|
|
|
WebRTCChild.observe(aSubject, aTopic, aData);
|
2017-04-07 18:48:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let topic of kWebRTCObserverTopics) {
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(webRTCObserve, topic);
|
2017-04-07 18:48:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(processShutdown, "content-child-shutdown");
|
2019-07-05 10:55:19 +03:00
|
|
|
}
|
2017-04-07 18:48:58 +03:00
|
|
|
|
|
|
|
function processShutdown() {
|
|
|
|
for (let topic of kWebRTCObserverTopics) {
|
|
|
|
Services.obs.removeObserver(webRTCObserve, topic);
|
|
|
|
}
|
|
|
|
Services.obs.removeObserver(processShutdown, "content-child-shutdown");
|
|
|
|
}
|