diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/presentation/PresentationDeviceInfoManager.jsm | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/presentation/PresentationDeviceInfoManager.jsm')
-rw-r--r-- | dom/presentation/PresentationDeviceInfoManager.jsm | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/dom/presentation/PresentationDeviceInfoManager.jsm b/dom/presentation/PresentationDeviceInfoManager.jsm new file mode 100644 index 000000000..205982b9c --- /dev/null +++ b/dom/presentation/PresentationDeviceInfoManager.jsm @@ -0,0 +1,104 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- / +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ +/* 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"; + +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; + +this.EXPORTED_SYMBOLS = ["PresentationDeviceInfoService"]; + +function log(aMsg) { + //dump("PresentationDeviceInfoManager.jsm: " + aMsg + "\n"); +} + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); + +XPCOMUtils.defineLazyServiceGetter(this, "presentationDeviceManager", + "@mozilla.org/presentation-device/manager;1", + "nsIPresentationDeviceManager"); + +XPCOMUtils.defineLazyServiceGetter(this, "ppmm", + "@mozilla.org/parentprocessmessagemanager;1", + "nsIMessageBroadcaster"); + +this.PresentationDeviceInfoService = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener, + Ci.nsIObserver]), + + init: function() { + log("init"); + ppmm.addMessageListener("PresentationDeviceInfoManager:GetAll", this); + ppmm.addMessageListener("PresentationDeviceInfoManager:ForceDiscovery", this); + Services.obs.addObserver(this, "presentation-device-change", false); + }, + + getAll: function(aData, aMm) { + log("getAll"); + let deviceArray = presentationDeviceManager.getAvailableDevices().QueryInterface(Ci.nsIArray); + if (!deviceArray) { + aData.error = "DataError"; + aMm.sendAsyncMessage("PresentationDeviceInfoManager:GetAll:Result:Error", aData); + return; + } + + aData.devices = []; + for (let i = 0; i < deviceArray.length; i++) { + let device = deviceArray.queryElementAt(i, Ci.nsIPresentationDevice); + aData.devices.push({ + id: device.id, + name: device.name, + type: device.type, + }); + } + aMm.sendAsyncMessage("PresentationDeviceInfoManager:GetAll:Result:Ok", aData); + }, + + forceDiscovery: function() { + log("forceDiscovery"); + presentationDeviceManager.forceDiscovery(); + }, + + observe: function(aSubject, aTopic, aData) { + log("observe: " + aTopic); + + let device = aSubject.QueryInterface(Ci.nsIPresentationDevice); + let data = { + type: aData, + deviceInfo: { + id: device.id, + name: device.name, + type: device.type, + }, + }; + ppmm.broadcastAsyncMessage("PresentationDeviceInfoManager:OnDeviceChange", data); + }, + + receiveMessage: function(aMessage) { + if (!aMessage.target.assertPermission("presentation-device-manage")) { + debug("receive message " + aMessage.name + + " from a content process with no 'presentation-device-manage' privileges."); + return null; + } + + let msg = aMessage.data || {}; + let mm = aMessage.target; + + log("receiveMessage: " + aMessage.name); + switch (aMessage.name) { + case "PresentationDeviceInfoManager:GetAll": { + this.getAll(msg, mm); + break; + } + case "PresentationDeviceInfoManager:ForceDiscovery": { + this.forceDiscovery(); + break; + } + } + }, +}; + +this.PresentationDeviceInfoService.init(); |