1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5cr.define('extensions', function() { 6 /** 7 * Encapsulated handling of ChromeOS kiosk apps options page. 8 * @constructor 9 */ 10 function KioskAppsOverlay() { 11 } 12 13 cr.addSingletonGetter(KioskAppsOverlay); 14 15 KioskAppsOverlay.prototype = { 16 /** 17 * Clear error timer id. 18 * @type {?number} 19 */ 20 clearErrorTimer_: null, 21 22 /** 23 * Initialize the page. 24 */ 25 initialize: function() { 26 chrome.send('initializeKioskAppSettings'); 27 extensions.KioskAppList.decorate($('kiosk-app-list')); 28 29 var overlay = $('kiosk-apps-page'); 30 cr.ui.overlay.setupOverlay(overlay); 31 cr.ui.overlay.globalInitialization(); 32 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); 33 34 $('kiosk-options-overlay-confirm').onclick = 35 this.handleDismiss_.bind(this); 36 $('kiosk-app-id-edit').addEventListener('keypress', 37 this.handleAppIdInputKeyPressed_.bind(this)); 38 $('kiosk-app-add').onclick = this.handleAddButtonClick_.bind(this); 39 }, 40 41 /* 42 * Invoked when the page is shown. 43 */ 44 didShowPage: function() { 45 chrome.send('getKioskAppSettings'); 46 $('kiosk-app-id-edit').focus(); 47 }, 48 49 /** 50 * Shows error for given app name/id and schedules it to cleared. 51 * @param {!string} appName App name/id to show in error banner. 52 */ 53 showError: function(appName) { 54 var errorBanner = $('kiosk-apps-error-banner'); 55 var appNameElement = errorBanner.querySelector('.kiosk-app-name'); 56 appNameElement.textContent = appName; 57 errorBanner.classList.add('visible'); 58 59 if (this.clearErrorTimer_) 60 window.clearTimeout(this.clearErrorTimer_); 61 62 // Sets a timer to clear out error banner after 5 seconds. 63 this.clearErrorTimer_ = window.setTimeout(function() { 64 errorBanner.classList.remove('visible'); 65 this.clearErrorTimer_ = null; 66 }.bind(this), 5000); 67 }, 68 69 /** 70 * Handles keypressed event in the app id input element. 71 * @private 72 */ 73 handleAppIdInputKeyPressed_: function(e) { 74 if (e.keyIdentifier == 'Enter' && e.target.value) 75 this.handleAddButtonClick_(); 76 }, 77 78 /** 79 * Handles click event on the add button. 80 * @private 81 */ 82 handleAddButtonClick_: function() { 83 var appId = $('kiosk-app-id-edit').value; 84 if (!appId) 85 return; 86 87 chrome.send('addKioskApp', [appId]); 88 $('kiosk-app-id-edit').value = ''; 89 }, 90 91 /** 92 * Handles the overlay being dismissed. 93 * @private 94 */ 95 handleDismiss_: function() { 96 this.handleAddButtonClick_(); 97 extensions.ExtensionSettings.showOverlay(null); 98 } 99 }; 100 101 /** 102 * Sets apps to be displayed in kiosk-app-list. 103 * @param {!Object.<{apps: !Array.<Object>, disableBailout: boolean}>} 104 * settings An object containing an array of app info objects and 105 * disable bailout shortcut flag. 106 */ 107 KioskAppsOverlay.setSettings = function(settings) { 108 $('kiosk-app-list').setApps(settings.apps); 109 $('kiosk-disable-bailout-shortcut').checked = settings.disableBailout; 110 $('kiosk-disable-bailout-shortcut').disabled = !settings.hasAutoLaunchApp; 111 }; 112 113 /** 114 * Update an app in kiosk-app-list. 115 * @param {!Object} app App info to be updated. 116 */ 117 KioskAppsOverlay.updateApp = function(app) { 118 $('kiosk-app-list').updateApp(app); 119 }; 120 121 /** 122 * Shows error for given app name/id. 123 * @param {!string} appName App name/id to show in error banner. 124 */ 125 KioskAppsOverlay.showError = function(appName) { 126 KioskAppsOverlay.getInstance().showError(appName); 127 }; 128 129 /** 130 * Enables consumer kiosk. 131 * @param {!boolean} enable True if consumer kiosk feature is enabled. 132 */ 133 KioskAppsOverlay.enableKiosk = function(params) { 134 $('add-kiosk-app').hidden = !params.kioskEnabled; 135 $('kiosk-disable-bailout-shortcut').parentNode.hidden = 136 !params.autoLaunchEnabled; 137 $('kiosk-app-list').setAutoLaunchEnabled(params.autoLaunchEnabled); 138 }; 139 140 // Export 141 return { 142 KioskAppsOverlay: KioskAppsOverlay 143 }; 144}); 145 146<include src="kiosk_app_list.js"></include> 147<include src="kiosk_app_disable_bailout_confirm.js"></include> 148