OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @constructor */ | 5 /** @constructor */ |
6 function TaskManager() { } | 6 function TaskManager() { } |
7 | 7 |
8 cr.addSingletonGetter(TaskManager); | 8 cr.addSingletonGetter(TaskManager); |
9 | 9 |
10 TaskManager.prototype = { | 10 TaskManager.prototype = { |
(...skipping 11 matching lines...) Expand all Loading... |
22 /** | 22 /** |
23 * Handles selection changes. | 23 * Handles selection changes. |
24 * This is also called when data of tasks are refreshed, even if selection | 24 * This is also called when data of tasks are refreshed, even if selection |
25 * has not been changed. | 25 * has not been changed. |
26 * @this | 26 * @this |
27 */ | 27 */ |
28 onSelectionChange: function() { | 28 onSelectionChange: function() { |
29 var sm = this.selectionModel_; | 29 var sm = this.selectionModel_; |
30 var dm = this.dataModel_; | 30 var dm = this.dataModel_; |
31 var selectedIndexes = sm.selectedIndexes; | 31 var selectedIndexes = sm.selectedIndexes; |
32 var is_end_process_enabled = true; | 32 var isEndProcessEnabled = true; |
33 if (selectedIndexes.length == 0) | 33 if (selectedIndexes.length == 0) |
34 is_end_process_enabled = false; | 34 isEndProcessEnabled = false; |
35 for (var i = 0; i < selectedIndexes.length; i++) { | 35 for (var i = 0; i < selectedIndexes.length; i++) { |
36 var index = selectedIndexes[i]; | 36 var index = selectedIndexes[i]; |
37 var task = dm.item(index); | 37 var task = dm.item(index); |
38 if (task['type'] == 'BROWSER') | 38 if (task['type'] == 'BROWSER') |
39 is_end_process_enabled = false; | 39 isEndProcessEnabled = false; |
40 } | 40 } |
41 if (this.is_end_process_enabled_ != is_end_process_enabled) { | 41 if (this.isEndProcessEnabled_ != isEndProcessEnabled) { |
42 if (is_end_process_enabled) | 42 if (isEndProcessEnabled) |
43 $('kill-process').removeAttribute('disabled'); | 43 $('kill-process').removeAttribute('disabled'); |
44 else | 44 else |
45 $('kill-process').setAttribute('disabled', 'true'); | 45 $('kill-process').setAttribute('disabled', 'true'); |
46 | 46 |
47 this.is_end_process_enabled_ = is_end_process_enabled; | 47 this.isEndProcessEnabled_ = isEndProcessEnabled; |
48 } | 48 } |
49 }, | 49 }, |
50 | 50 |
51 /** | 51 /** |
52 * Closes taskmanager dialog. | 52 * Closes taskmanager dialog. |
53 * After this function is called, onClose() will be called. | 53 * After this function is called, onClose() will be called. |
54 * @this | 54 * @this |
55 */ | 55 */ |
56 close: function() { | 56 close: function() { |
57 window.close(); | 57 window.close(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 this.opt_ = opt; | 89 this.opt_ = opt; |
90 | 90 |
91 this.initialized_ = true; | 91 this.initialized_ = true; |
92 | 92 |
93 this.elementsCache_ = {}; | 93 this.elementsCache_ = {}; |
94 this.dialogDom_ = dialogDom; | 94 this.dialogDom_ = dialogDom; |
95 this.document_ = dialogDom.ownerDocument; | 95 this.document_ = dialogDom.ownerDocument; |
96 | 96 |
97 this.localized_column_ = []; | 97 this.localized_column_ = []; |
98 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 98 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
99 var column_label_id = DEFAULT_COLUMNS[i][1]; | 99 var columnLabelId = DEFAULT_COLUMNS[i][1]; |
100 this.localized_column_[i] = loadTimeData.getString(column_label_id); | 100 this.localized_column_[i] = loadTimeData.getString(columnLabelId); |
101 } | 101 } |
102 | 102 |
103 this.initElements_(); | 103 this.initElements_(); |
104 this.initColumnModel_(); | 104 this.initColumnModel_(); |
105 this.selectionModel_ = new cr.ui.ListSelectionModel(); | 105 this.selectionModel_ = new cr.ui.ListSelectionModel(); |
106 this.dataModel_ = new cr.ui.ArrayDataModel([]); | 106 this.dataModel_ = new cr.ui.ArrayDataModel([]); |
107 | 107 |
108 this.selectionModel_.addEventListener('change', | 108 this.selectionModel_.addEventListener('change', |
109 this.onSelectionChange.bind(this)); | 109 this.onSelectionChange.bind(this)); |
110 | 110 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 this.isFinishedInitDelayed_ = true; | 208 this.isFinishedInitDelayed_ = true; |
209 var t = this.table_; | 209 var t = this.table_; |
210 t.redraw(); | 210 t.redraw(); |
211 addEventListener('resize', t.redraw.bind(t)); | 211 addEventListener('resize', t.redraw.bind(t)); |
212 }, | 212 }, |
213 | 213 |
214 initColumnModel_: function() { | 214 initColumnModel_: function() { |
215 var table_columns = new Array(); | 215 var tableColumns = new Array(); |
216 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 216 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
217 var column = DEFAULT_COLUMNS[i]; | 217 var column = DEFAULT_COLUMNS[i]; |
218 var columnId = column[0]; | 218 var columnId = column[0]; |
219 if (!isColumnEnabled(columnId)) | 219 if (!isColumnEnabled(columnId)) |
220 continue; | 220 continue; |
221 | 221 |
222 table_columns.push(new cr.ui.table.TableColumn(columnId, | 222 tableColumns.push(new cr.ui.table.TableColumn(columnId, |
223 this.localized_column_[i], | 223 this.localized_column_[i], |
224 column[2])); | 224 column[2])); |
225 } | 225 } |
226 | 226 |
227 for (var i = 0; i < table_columns.length; i++) { | 227 for (var i = 0; i < tableColumns.length; i++) { |
228 table_columns[i].renderFunction = this.renderColumn_.bind(this); | 228 tableColumns[i].renderFunction = this.renderColumn_.bind(this); |
229 } | 229 } |
230 | 230 |
231 this.columnModel_ = new cr.ui.table.TableColumnModel(table_columns); | 231 this.columnModel_ = new cr.ui.table.TableColumnModel(tableColumns); |
232 }, | 232 }, |
233 | 233 |
234 initColumnMenu_: function() { | 234 initColumnMenu_: function() { |
235 this.column_menu_commands_ = []; | 235 this.column_menu_commands_ = []; |
236 | 236 |
237 this.commandsElement_ = this.document_.createElement('commands'); | 237 this.commandsElement_ = this.document_.createElement('commands'); |
238 this.document_.body.appendChild(this.commandsElement_); | 238 this.document_.body.appendChild(this.commandsElement_); |
239 | 239 |
240 this.columnSelectContextMenu_ = this.document_.createElement('menu'); | 240 this.columnSelectContextMenu_ = this.document_.createElement('menu'); |
241 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 241 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
(...skipping 26 matching lines...) Expand all Loading... |
268 | 268 |
269 this.document_.addEventListener('command', this.onCommand_.bind(this)); | 269 this.document_.addEventListener('command', this.onCommand_.bind(this)); |
270 this.document_.addEventListener('canExecute', | 270 this.document_.addEventListener('canExecute', |
271 this.onCommandCanExecute_.bind(this)); | 271 this.onCommandCanExecute_.bind(this)); |
272 }, | 272 }, |
273 | 273 |
274 initTableMenu_: function() { | 274 initTableMenu_: function() { |
275 this.table_menu_commands_ = []; | 275 this.table_menu_commands_ = []; |
276 this.tableContextMenu_ = this.document_.createElement('menu'); | 276 this.tableContextMenu_ = this.document_.createElement('menu'); |
277 | 277 |
278 var addMenuItem = function(tm, command_id, string_id) { | 278 var addMenuItem = function(tm, commandId, string_id) { |
279 // Creates command element to receive event. | 279 // Creates command element to receive event. |
280 var command = tm.document_.createElement('command'); | 280 var command = tm.document_.createElement('command'); |
281 command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + '-' + command_id; | 281 command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + '-' + commandId; |
282 cr.ui.Command.decorate(command); | 282 cr.ui.Command.decorate(command); |
283 tm.table_menu_commands_[command.id] = command; | 283 tm.table_menu_commands_[command.id] = command; |
284 tm.commandsElement_.appendChild(command); | 284 tm.commandsElement_.appendChild(command); |
285 | 285 |
286 // Creates menuitem element. | 286 // Creates menuitem element. |
287 var item = tm.document_.createElement('menuitem'); | 287 var item = tm.document_.createElement('menuitem'); |
288 item.command = command; | 288 item.command = command; |
289 command.menuitem = item; | 289 command.menuitem = item; |
290 item.textContent = loadTimeData.getString(string_id); | 290 item.textContent = loadTimeData.getString(string_id); |
291 tm.tableContextMenu_.appendChild(item); | 291 tm.tableContextMenu_.appendChild(item); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 sm.endChange(); | 584 sm.endChange(); |
585 this.table_.list.endBatchUpdates(); | 585 this.table_.list.endBatchUpdates(); |
586 }, | 586 }, |
587 | 587 |
588 /** | 588 /** |
589 * Respond to a command being executed. | 589 * Respond to a command being executed. |
590 * @this | 590 * @this |
591 */ | 591 */ |
592 onCommand_: function(event) { | 592 onCommand_: function(event) { |
593 var command = event.command; | 593 var command = event.command; |
594 var command_id = command.id.split('-', 2); | 594 var commandId = command.id.split('-', 2); |
595 | 595 |
596 var main_command = command_id[0]; | 596 var mainCommand = commandId[0]; |
597 var sub_command = command_id[1]; | 597 var subCommand = commandId[1]; |
598 | 598 |
599 if (main_command == COMMAND_CONTEXTMENU_COLUMN_PREFIX) { | 599 if (mainCommand == COMMAND_CONTEXTMENU_COLUMN_PREFIX) { |
600 this.onColumnContextMenu_(sub_command, command); | 600 this.onColumnContextMenu_(subCommand, command); |
601 } else if (main_command == COMMAND_CONTEXTMENU_TABLE_PREFIX) { | 601 } else if (mainCommand == COMMAND_CONTEXTMENU_TABLE_PREFIX) { |
602 var target_unique_id = this.currentContextMenuTarget_; | 602 var targetUniqueId = this.currentContextMenuTarget_; |
603 | 603 |
604 if (!target_unique_id) | 604 if (!targetUniqueId) |
605 return; | 605 return; |
606 | 606 |
607 if (sub_command == 'inspect') | 607 if (subCommand == 'inspect') |
608 commands.inspect(target_unique_id); | 608 commands.inspect(targetUniqueId); |
609 else if (sub_command == 'activate') | 609 else if (subCommand == 'activate') |
610 commands.activatePage(target_unique_id); | 610 commands.activatePage(targetUniqueId); |
611 | 611 |
612 this.currentContextMenuTarget_ = undefined; | 612 this.currentContextMenuTarget_ = undefined; |
613 } | 613 } |
614 }, | 614 }, |
615 | 615 |
616 onCommandCanExecute_: function(event) { | 616 onCommandCanExecute_: function(event) { |
617 event.canExecute = true; | 617 event.canExecute = true; |
618 }, | 618 }, |
619 | 619 |
620 /** | 620 /** |
621 * Store resourceIndex of target resource of context menu, because resource | 621 * Store resourceIndex of target resource of context menu, because resource |
622 * will be replaced when it is refreshed. | 622 * will be replaced when it is refreshed. |
623 * @this | 623 * @this |
624 */ | 624 */ |
625 onTableContextMenuOpened_: function(e) { | 625 onTableContextMenuOpened_: function(e) { |
626 if (!this.isFinishedInitDelayed_) | 626 if (!this.isFinishedInitDelayed_) |
627 return; | 627 return; |
628 | 628 |
629 var mc = this.table_menu_commands_; | 629 var mc = this.table_menu_commands_; |
630 var inspect_menuitem = | 630 var inspectMenuitem = |
631 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-inspect'].menuitem; | 631 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-inspect'].menuitem; |
632 var activate_menuitem = | 632 var activateMenuitem = |
633 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-activate'].menuitem; | 633 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-activate'].menuitem; |
634 | 634 |
635 // Disabled by default. | 635 // Disabled by default. |
636 inspect_menuitem.disabled = true; | 636 inspectMenuitem.disabled = true; |
637 activate_menuitem.disabled = true; | 637 activateMenuitem.disabled = true; |
638 | 638 |
639 var target = e.target; | 639 var target = e.target; |
640 for (;; target = target.parentNode) { | 640 for (;; target = target.parentNode) { |
641 if (!target) return; | 641 if (!target) return; |
642 var classes = target.classList; | 642 var classes = target.classList; |
643 if (classes && | 643 if (classes && |
644 Array.prototype.indexOf.call(classes, 'detail-title') != -1) break; | 644 Array.prototype.indexOf.call(classes, 'detail-title') != -1) break; |
645 } | 645 } |
646 | 646 |
647 var index_in_group = target.index_in_group; | 647 var indexInGroup = target.index_in_group; |
648 | 648 |
649 // Sets the uniqueId for current target page under the mouse corsor. | 649 // Sets the uniqueId for current target page under the mouse corsor. |
650 this.currentContextMenuTarget_ = target.data['uniqueId'][index_in_group]; | 650 this.currentContextMenuTarget_ = target.data['uniqueId'][indexInGroup]; |
651 | 651 |
652 // Enables if the page can be inspected. | 652 // Enables if the page can be inspected. |
653 if (target.data['canInspect'][index_in_group]) | 653 if (target.data['canInspect'][indexInGroup]) |
654 inspect_menuitem.disabled = false; | 654 inspectMenuitem.disabled = false; |
655 | 655 |
656 // Enables if the page can be activated. | 656 // Enables if the page can be activated. |
657 if (target.data['canActivate'][index_in_group]) | 657 if (target.data['canActivate'][indexInGroup]) |
658 activate_menuitem.disabled = false; | 658 activateMenuitem.disabled = false; |
659 }, | 659 }, |
660 | 660 |
661 onColumnContextMenu_: function(columnId, command) { | 661 onColumnContextMenu_: function(columnId, command) { |
662 var menuitem = command.menuitem; | 662 var menuitem = command.menuitem; |
663 var checkedItemCount = 0; | 663 var checkedItemCount = 0; |
664 var checked = isColumnEnabled(columnId); | 664 var checked = isColumnEnabled(columnId); |
665 | 665 |
666 // Leaves a item visible when user tries making invisible but it is the | 666 // Leaves a item visible when user tries making invisible but it is the |
667 // last one. | 667 // last one. |
668 var enabledColumns = getEnabledColumns(); | 668 var enabledColumns = getEnabledColumns(); |
(...skipping 21 matching lines...) Expand all Loading... |
690 function init() { | 690 function init() { |
691 var params = parseQueryParams(window.location); | 691 var params = parseQueryParams(window.location); |
692 var opt = {}; | 692 var opt = {}; |
693 opt['isBackgroundMode'] = params.background; | 693 opt['isBackgroundMode'] = params.background; |
694 opt['isShowCloseButton'] = params.showclose; | 694 opt['isShowCloseButton'] = params.showclose; |
695 taskmanager.initialize(document.body, opt); | 695 taskmanager.initialize(document.body, opt); |
696 } | 696 } |
697 | 697 |
698 document.addEventListener('DOMContentLoaded', init); | 698 document.addEventListener('DOMContentLoaded', init); |
699 document.addEventListener('Close', taskmanager.onClose.bind(taskmanager)); | 699 document.addEventListener('Close', taskmanager.onClose.bind(taskmanager)); |
OLD | NEW |