1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * This module is for small observers that we want to register once per content
8 * process, usually in order to forward content-based observer service notifications
9 * to the chrome process through message passing. Using a JSM avoids having them
10 * in content.js and thereby registering N observers for N open tabs, which is bad
16 this.EXPORTED_SYMBOLS = [];
18 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
20 Cu.import("resource://gre/modules/Services.jsm");
22 let gEMEUIObserver = function(subject, topic, data) {
23 let win = subject.top;
24 let mm = getMessageManagerForWindow(win);
26 mm.sendAsyncMessage("EMEVideo:ContentMediaKeysRequest", data);
30 function getMessageManagerForWindow(aContentWindow) {
31 let ir = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
32 .getInterface(Ci.nsIDocShell)
34 .QueryInterface(Ci.nsIInterfaceRequestor);
36 // If e10s is disabled, this throws NS_NOINTERFACE for closed tabs.
37 return ir.getInterface(Ci.nsIContentFrameMessageManager);
38 } catch(e if e.result == Cr.NS_NOINTERFACE) {
43 Services.obs.addObserver(gEMEUIObserver, "mediakeys-request", false);