/* global LazyLoader, applications, ManifestHelper*/ /* global Template, focusManager, SpatialNavigator, KeyEvent */ /* global KeyNavigationAdapter */ 'use strict'; (function(exports) { /** * Handle Web API permissions such as geolocation, getUserMedia * @class PermissionManager * @requires Applications */ function PermissionManager() { } PermissionManager.prototype = { currentOrigin: undefined, permissionType: undefined, currentPermissions: undefined, currentChoices: {}, //select choices fullscreenRequest: undefined, isVideo: false, isAudio: false, /** * special dialog for camera selection while in app mode and * permission is granted */ isCamSelector: false, responseStatus: undefined, /** * A queue of pending requests. Callers of requestPermission() must be * careful not to create an infinite loop! */ pending: [], /** * The ID of the request currently visible on the screen. This has the value * "undefined" when there is no request visible on the screen. */ currentRequestId: undefined, /** * start the PermissionManager to init variables and listeners * @memberof PermissionManager.prototype */ start: function pm_start() { // Div over in which the permission UI resides. this.overlay = document.getElementById('permission-screen'); this.dialog = document.getElementById('permission-dialog'); this.title = document.getElementById('permission-title'); this.message = document.getElementById('permission-message'); this.moreInfo = document.getElementById('permission-more-info'); this.moreInfoLink = document.getElementById('permission-more-info-link'); this.hideInfoLink = document.getElementById('permission-hide-info-link'); this.moreInfoBox = document.getElementById('permission-more-info-box'); // "Yes"/"No" buttons on the permission UI. this.buttons = document.getElementById('permission-buttons'); this.yes = document.getElementById('permission-yes'); this.no = document.getElementById('permission-no'); // Remember the choice checkbox this.remember = document.getElementById('permission-remember-checkbox'); this.rememberSection = document.getElementById('permission-remember-section'); this.deviceSelector = document.getElementById('permission-device-selector'); this.devices = document.getElementById('permission-devices'); var self = this; this.rememberSection.addEventListener('click', function onLabelClick() { self.remember.checked = !self.remember.checked; }); this.rememberSection.addEventListener('keyup', function onLabelKeyup(evt) { if (evt.keyCode === KeyEvent.DOM_VK_RETURN) { self.remember.checked = !self.remember.checked; } }); window.addEventListener('mozChromeEvent', this); window.addEventListener('attentionopening', this); window.addEventListener('attentionopened', this); /* On home/holdhome pressed, discard permission request. * XXX: We should make permission dialog be embededd in appWindow * Gaia bug is https://bugzilla.mozilla.org/show_bug.cgi?id=853711 * Gecko bug is https://bugzilla.mozilla.org/show_bug.cgi?id=852013 */ this.discardPermissionRequest = this.discardPermissionRequest.bind(this); window.addEventListener('home', this.discardPermissionRequest); window.addEventListener('holdhome', this.discardPermissionRequest); /* If an application that is currently running needs to get killed for * whatever reason we want to discard it's request for permissions. */ window.addEventListener('appterminated', (function(evt) { if (evt.detail.origin == this.currentOrigin) { this.discardPermissionRequest(); } }).bind(this)); // Ensure that the focus is not stolen by the permission overlay, as // it may appears on top of a