2016-11-15 06:07:09 +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/. */
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, manager: Cm} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
const PRESENTATION_DEVICE_PROMPT_PATH =
|
|
|
|
"chrome://presentation/content/PresentationDevicePrompt.jsm";
|
|
|
|
|
|
|
|
function log(aMsg) {
|
|
|
|
// dump("@ Presentation: " + aMsg + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function install(aData, aReason) {
|
|
|
|
}
|
|
|
|
|
|
|
|
function uninstall(aData, aReason) {
|
|
|
|
}
|
|
|
|
|
|
|
|
function startup(aData, aReason) {
|
|
|
|
log("startup");
|
|
|
|
Presentation.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
function shutdown(aData, aReason) {
|
|
|
|
log("shutdown");
|
|
|
|
Presentation.uninit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register/unregister a constructor as a factory.
|
|
|
|
function Factory() {}
|
|
|
|
Factory.prototype = {
|
2016-12-30 02:34:54 +03:00
|
|
|
register(targetConstructor) {
|
2016-11-15 06:07:09 +03:00
|
|
|
let proto = targetConstructor.prototype;
|
|
|
|
this._classID = proto.classID;
|
|
|
|
|
|
|
|
let factory = XPCOMUtils._getFactory(targetConstructor);
|
|
|
|
this._factory = factory;
|
|
|
|
|
|
|
|
let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
|
|
|
registrar.registerFactory(proto.classID, proto.classDescription,
|
|
|
|
proto.contractID, factory);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
unregister() {
|
2016-11-15 06:07:09 +03:00
|
|
|
let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
|
|
|
registrar.unregisterFactory(this._classID, this._factory);
|
|
|
|
this._factory = null;
|
|
|
|
this._classID = null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var Presentation = {
|
|
|
|
// PUBLIC APIs
|
2016-12-30 02:34:54 +03:00
|
|
|
init() {
|
2016-11-15 06:07:09 +03:00
|
|
|
log("init");
|
|
|
|
// Register PresentationDevicePrompt into a XPCOM component.
|
2017-02-02 12:08:42 +03:00
|
|
|
let {PresentationDevicePrompt} = Cu.import(PRESENTATION_DEVICE_PROMPT_PATH, {});
|
|
|
|
this.PresentationDevicePrompt = PresentationDevicePrompt;
|
2016-11-15 06:07:09 +03:00
|
|
|
this._register();
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
uninit() {
|
2016-11-15 06:07:09 +03:00
|
|
|
log("uninit");
|
|
|
|
// Unregister PresentationDevicePrompt XPCOM component.
|
|
|
|
this._unregister();
|
2017-02-02 12:08:42 +03:00
|
|
|
delete this.PresentationDevicePrompt;
|
2016-11-15 06:07:09 +03:00
|
|
|
Cu.unload(PRESENTATION_DEVICE_PROMPT_PATH);
|
|
|
|
},
|
|
|
|
|
|
|
|
// PRIVATE APIs
|
2016-12-30 02:34:54 +03:00
|
|
|
_register() {
|
2016-11-15 06:07:09 +03:00
|
|
|
log("_register");
|
|
|
|
this._devicePromptFactory = new Factory();
|
2017-02-02 12:08:42 +03:00
|
|
|
this._devicePromptFactory.register(this.PresentationDevicePrompt);
|
2016-11-15 06:07:09 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_unregister() {
|
2016-11-15 06:07:09 +03:00
|
|
|
log("_unregister");
|
|
|
|
this._devicePromptFactory.unregister();
|
|
|
|
delete this._devicePromptFactory;
|
|
|
|
},
|
|
|
|
};
|