VulpesOS/assets/webapps/system.gaiamobile.org/js/trusted_window_manager.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

60 lines
1.5 KiB
JavaScript

/* global Service */
'use strict';
(function(exports) {
function TrustedWindowManager() {
this.pool = {};
}
TrustedWindowManager.prototype = {
name: 'TrustedWindowManager',
DEBUG: false,
CLASS_NAME: 'TrustedWindowManager',
EVENT_PREFIX: 'trustedwindowmanager',
debug: function tw_debug() {
if (this.DEBUG) {
console.log('[' + this.CLASS_NAME + ']' +
'[' + Service.currentTime() + ']' +
Array.slice(arguments).concat());
}
},
start: function tw_start() {
window.addEventListener('trustedopened', this);
window.addEventListener('killtrusted', this);
},
stop: function tw_stop() {
window.removeEventListener('trustedopened', this);
window.removeEventListener('killtrusted', this);
},
handleEvent: function tw_handleEvent(evt) {
var requestId;
switch(evt.type) {
case 'trustedopened':
requestId = evt.detail.config.requestId;
this.pool[requestId] = evt.detail;
this.publish('-activated');
break;
case 'killtrusted':
requestId = evt.detail.requestId;
if (this.pool[requestId]) {
this.pool[requestId].kill();
delete this.pool[requestId];
this.publish('-deactivated');
}
break;
}
},
publish: function(evtName) {
window.dispatchEvent(new CustomEvent(this.EVENT_PREFIX + evtName, {
detail: this
}));
}
};
exports.TrustedWindowManager = TrustedWindowManager;
}(window));