Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / resources / extensions / chromeos / kiosk_app_list.js
blob3652f95bd6d7c2f17ba915270112e04d73ba7abc
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.
5 cr.define('extensions', function() {
6 /** @const */ var List = cr.ui.List;
7 /** @const */ var ListItem = cr.ui.ListItem;
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
10 /**
11 * Creates a list for showing kiosk apps.
12 * @constructor
13 * @extends {cr.ui.List}
15 var KioskAppList = cr.ui.define('list');
17 KioskAppList.prototype = {
18 __proto__: List.prototype,
20 /**
21 * True if auto launch feature can be configured.
22 * @type {?boolean}
24 autoLaunchEnabled_: false,
26 /** @override */
27 createItem: function(app) {
28 var item = new KioskAppListItem();
29 item.data = app;
30 item.autoLaunchEnabled = this.autoLaunchEnabled_;
31 return item;
34 /**
35 * Sets auto launch enabled flag.
36 * @param {boolean} enabled True if auto launch should be enabled.
38 setAutoLaunchEnabled: function(enabled) {
39 this.autoLaunchEnabled_ = enabled;
42 /**
43 * Loads the given list of apps.
44 * @param {!Array.<!Object>} apps An array of app info objects.
46 setApps: function(apps) {
47 this.dataModel = new ArrayDataModel(apps);
50 /**
51 * Updates the given app.
52 * @param {!Object} app An app info object.
54 updateApp: function(app) {
55 for (var i = 0; i < this.items.length; ++i) {
56 if (this.items[i].data.id == app.id) {
57 this.items[i].data = app;
58 break;
64 /**
65 * Creates a list item for a kiosk app.
66 * @constructor
67 * @extends {cr.ui.ListItem}
69 var KioskAppListItem = cr.ui.define(function() {
70 var el = $('kiosk-app-list-item-template').cloneNode(true);
71 el.removeAttribute('id');
72 el.hidden = false;
73 return el;
74 });
76 KioskAppListItem.prototype = {
77 __proto__: ListItem.prototype,
79 /**
80 * Data object to hold app info.
81 * @type {Object}
82 * @private
84 data_: null,
86 get data() {
87 assert(this.data_);
88 return this.data_;
91 set data(data) {
92 this.data_ = data;
93 this.redraw();
96 set autoLaunchEnabled(enabled) {
97 this.querySelector('.enable-auto-launch-button').hidden = !enabled;
98 this.querySelector('.disable-auto-launch-button').hidden = !enabled;
102 * Getter for the icon element.
103 * @type {Element}
105 get icon() {
106 return this.querySelector('.kiosk-app-icon');
110 * Getter for the name element.
111 * @type {Element}
113 get name() {
114 return this.querySelector('.kiosk-app-name');
118 * Getter for the status text element.
119 * @type {Element}
121 get status() {
122 return this.querySelector('.kiosk-app-status');
125 /** @override */
126 decorate: function() {
127 ListItem.prototype.decorate.call(this);
129 var sendMessageWithId = function(msg) {
130 return function() {
131 chrome.send(msg, [this.data.id]);
132 }.bind(this);
133 }.bind(this);
135 this.querySelector('.enable-auto-launch-button').onclick =
136 sendMessageWithId('enableKioskAutoLaunch');
137 this.querySelector('.disable-auto-launch-button').onclick =
138 sendMessageWithId('disableKioskAutoLaunch');
139 this.querySelector('.row-delete-button').onclick =
140 sendMessageWithId('removeKioskApp');
144 * Updates UI from app info data.
146 redraw: function() {
147 this.icon.classList.toggle('spinner', this.data.isLoading);
148 this.icon.style.backgroundImage = 'url(' + this.data.iconURL + ')';
150 this.name.textContent = this.data.name || this.data.id;
151 this.status.textContent = this.data.autoLaunch ?
152 loadTimeData.getString('autoLaunch') : '';
154 this.autoLaunch = this.data.autoLaunch;
159 * True if the app represented by this item will auto launch.
160 * @type {boolean}
162 cr.defineProperty(KioskAppListItem, 'autoLaunch', cr.PropertyKind.BOOL_ATTR);
164 // Export
165 return {
166 KioskAppList: KioskAppList