summaryrefslogtreecommitdiffstats
path: root/dom/presentation/PresentationDeviceInfoManager.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/presentation/PresentationDeviceInfoManager.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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.js')
-rw-r--r--dom/presentation/PresentationDeviceInfoManager.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/dom/presentation/PresentationDeviceInfoManager.js b/dom/presentation/PresentationDeviceInfoManager.js
new file mode 100644
index 000000000..29e7d370c
--- /dev/null
+++ b/dom/presentation/PresentationDeviceInfoManager.js
@@ -0,0 +1,119 @@
+/* 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;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
+
+function log(aMsg) {
+ //dump("-*- PresentationDeviceInfoManager.js : " + aMsg + "\n");
+}
+
+const PRESENTATIONDEVICEINFOMANAGER_CID = Components.ID("{1bd66bef-f643-4be3-b690-0c656353eafd}");
+const PRESENTATIONDEVICEINFOMANAGER_CONTRACTID = "@mozilla.org/presentation-device/deviceInfo;1";
+
+XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
+ "@mozilla.org/childprocessmessagemanager;1",
+ "nsIMessageSender");
+
+function PresentationDeviceInfoManager() {}
+
+PresentationDeviceInfoManager.prototype = {
+ __proto__: DOMRequestIpcHelper.prototype,
+
+ classID: PRESENTATIONDEVICEINFOMANAGER_CID,
+ contractID: PRESENTATIONDEVICEINFOMANAGER_CONTRACTID,
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
+ Ci.nsIObserver,
+ Ci.nsIDOMGlobalPropertyInitializer]),
+
+ receiveMessage: function(aMsg) {
+ if (!aMsg || !aMsg.data) {
+ return;
+ }
+
+ let data = aMsg.data;
+
+ log("receive aMsg: " + aMsg.name);
+ switch (aMsg.name) {
+ case "PresentationDeviceInfoManager:OnDeviceChange": {
+ let detail = {
+ detail: {
+ type: data.type,
+ deviceInfo: data.deviceInfo,
+ }
+ };
+ let event = new this._window.CustomEvent("devicechange", Cu.cloneInto(detail, this._window));
+ this.__DOM_IMPL__.dispatchEvent(event);
+ break;
+ }
+ case "PresentationDeviceInfoManager:GetAll:Result:Ok": {
+ let resolver = this.takePromiseResolver(data.requestId);
+
+ if (!resolver) {
+ return;
+ }
+
+ resolver.resolve(Cu.cloneInto(data.devices, this._window));
+ break;
+ }
+ case "PresentationDeviceInfoManager:GetAll:Result:Error": {
+ let resolver = this.takePromiseResolver(data.requestId);
+
+ if (!resolver) {
+ return;
+ }
+
+ resolver.reject(data.error);
+ break;
+ }
+ }
+ },
+
+ init: function(aWin) {
+ log("init");
+ this.initDOMRequestHelper(aWin, [
+ {name: "PresentationDeviceInfoManager:OnDeviceChange", weakRef: true},
+ {name: "PresentationDeviceInfoManager:GetAll:Result:Ok", weakRef: true},
+ {name: "PresentationDeviceInfoManager:GetAll:Result:Error", weakRef: true},
+ ]);
+ },
+
+ uninit: function() {
+ log("uninit");
+ let self = this;
+
+ this.forEachPromiseResolver(function(aKey) {
+ self.takePromiseResolver(aKey).reject("PresentationDeviceInfoManager got destroyed");
+ });
+ },
+
+ get ondevicechange() {
+ return this.__DOM_IMPL__.getEventHandler("ondevicechange");
+ },
+
+ set ondevicechange(aHandler) {
+ this.__DOM_IMPL__.setEventHandler("ondevicechange", aHandler);
+ },
+
+ getAll: function() {
+ log("getAll");
+ let self = this;
+ return this.createPromiseWithId(function(aResolverId) {
+ cpmm.sendAsyncMessage("PresentationDeviceInfoManager:GetAll", {
+ requestId: aResolverId,
+ });
+ });
+ },
+
+ forceDiscovery: function() {
+ cpmm.sendAsyncMessage("PresentationDeviceInfoManager:ForceDiscovery");
+ },
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PresentationDeviceInfoManager]);