1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Kiosk apps menu implementation.
*/
cr.define('login', function() {
'use strict';
var Menu = cr.ui.Menu;
var MenuButton = cr.ui.MenuButton;
/**
* Creates apps menu button.
* @constructor
* @extends {cr.ui.MenuButton}
*/
var AppsMenuButton = cr.ui.define('button');
AppsMenuButton.prototype = {
__proto__: MenuButton.prototype,
/**
* Flag of whether to rebuild the menu.
* @type {boolean}
* @private
*/
needsRebuild_: true,
/**
* Array to hold apps info.
* @type {Array}
*/
data_: null,
get data() {
return this.data_;
},
set data(data) {
this.data_ = data;
this.needsRebuild_ = true;
},
/** @override */
decorate: function() {
MenuButton.prototype.decorate.call(this);
this.menu = new Menu;
cr.ui.decorate(this.menu, Menu);
document.body.appendChild(this.menu);
this.anchorType = cr.ui.AnchorType.ABOVE;
chrome.send('initializeKioskApps');
},
/** @override */
showMenu: function(shouldSetFocus) {
if (this.needsRebuild_) {
this.menu.textContent = '';
this.data_.forEach(this.addItem_, this);
this.needsRebuild_ = false;
}
MenuButton.prototype.showMenu.apply(this, arguments);
},
/**
* Invoked when apps menu becomes visible.
*/
didShow: function() {
window.setTimeout(function() {
if (!$('apps-header-bar-item').hidden)
chrome.send('checkKioskAppLaunchError');
}, 500);
},
findAndRunAppForTesting: function(id) {
this.showMenu(true);
for (var i = 0; i < this.menu.menuItems.length; i++) {
var menuNode = this.menu.menuItems[i];
if (menuNode.appId == id) {
var activationEvent = cr.doc.createEvent('Event');
activationEvent.initEvent('activate', true, true);
menuNode.dispatchEvent(activationEvent);
break;
}
}
},
/**
* Adds an app to the menu.
* @param {Object} app An app info object.
* @private
*/
addItem_: function(app) {
var menuItem = this.menu.addMenuItem(app);
menuItem.classList.add('apps-menu-item');
menuItem.appId = app.id;
menuItem.addEventListener('activate', function() {
chrome.send('launchKioskApp', [app.id]);
});
}
};
/**
* Sets apps to be displayed in the apps menu.
* @param {!Array.<!Object>} apps An array of app info objects.
*/
AppsMenuButton.setApps = function(apps) {
$('show-apps-button').data = apps;
$('login-header-bar').hasApps = apps.length > 0;
chrome.send('kioskAppsLoaded');
};
/**
* Shows the given error message.
* @param {!string} message Error message to show.
*/
AppsMenuButton.showError = function(message) {
/** @const */ var BUBBLE_OFFSET = 25;
/** @const */ var BUBBLE_PADDING = 12;
$('bubble').showTextForElement($('show-apps-button'),
message,
cr.ui.Bubble.Attachment.TOP,
BUBBLE_OFFSET,
BUBBLE_PADDING);
};
/**
* Runs app with a given id from the list of loaded apps.
* @param {!string} id of an app to run.
*/
AppsMenuButton.runAppForTesting = function(id) {
$('show-apps-button').findAndRunAppForTesting(id);
};
return {
AppsMenuButton: AppsMenuButton
};
});
|