Bumping manifests a=b2g-bump
[gecko.git] / browser / modules / ContentObservers.jsm
blob785c15cdb606fe3f47048da18d724ebc4bbda4e3
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/. */
6 /**
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
11  * for perf.
12  */
14 "use strict";
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);
25   if (mm) {
26     mm.sendAsyncMessage("EMEVideo:ContentMediaKeysRequest", data);
27   }
30 function getMessageManagerForWindow(aContentWindow) {
31   let ir = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
32                          .getInterface(Ci.nsIDocShell)
33                          .sameTypeRootTreeItem
34                          .QueryInterface(Ci.nsIInterfaceRequestor);
35   try {
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) {
39     return null;
40   }
43 Services.obs.addObserver(gEMEUIObserver, "mediakeys-request", false);