Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: chrome/browser/resources/task_manager/main.js

Issue 8993007: WebUI TaskManager: Delay scripts loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 /* 10 /*
(...skipping 19 matching lines...) Expand all
30 ]; 30 ];
31 31
32 var COMMAND_CONTEXTMENU_COLUMN_PREFIX = 'columnContextMenu'; 32 var COMMAND_CONTEXTMENU_COLUMN_PREFIX = 'columnContextMenu';
33 var COMMAND_CONTEXTMENU_TABLE_PREFIX = 'tableContextMenu'; 33 var COMMAND_CONTEXTMENU_TABLE_PREFIX = 'tableContextMenu';
34 34
35 var localStrings = new LocalStrings(); 35 var localStrings = new LocalStrings();
36 36
37 TaskManager.prototype = { 37 TaskManager.prototype = {
38 /** 38 /**
39 * Handle window close. 39 * Handle window close.
40 * @public
41 */ 40 */
42 onClose: function () { 41 onClose: function () {
43 if (!this.disabled_) { 42 if (!this.disabled_) {
44 this.disabled_ = true; 43 this.disabled_ = true;
45 this.disableTaskManager(); 44 this.disableTaskManager();
46 } 45 }
47 }, 46 },
48 47
49 /** 48 /**
50 * Handle selection change. 49 * Handle selection change.
51 * This is also called when data of tasks are refleshed, even if selection 50 * This is also called when data of tasks are refleshed, even if selection
52 * has not been changed. 51 * has not been changed.
53 * @public
54 */ 52 */
55 onSelectionChange: function () { 53 onSelectionChange: function () {
56 var sm = this.selectionModel_; 54 var sm = this.selectionModel_;
57 var dm = this.dataModel_; 55 var dm = this.dataModel_;
58 var selectedIndexes = sm.selectedIndexes; 56 var selectedIndexes = sm.selectedIndexes;
59 var is_end_process_enabled = true; 57 var is_end_process_enabled = true;
60 if (selectedIndexes.length == 0) 58 if (selectedIndexes.length == 0)
61 is_end_process_enabled = false; 59 is_end_process_enabled = false;
62 for (var i = 0; i < selectedIndexes.length; i++) { 60 for (var i = 0; i < selectedIndexes.length; i++) {
63 var index = selectedIndexes[i]; 61 var index = selectedIndexes[i];
64 var task = dm.item(index); 62 var task = dm.item(index);
65 if (task['type'] == 'BROWSER') 63 if (task['type'] == 'BROWSER')
66 is_end_process_enabled = false; 64 is_end_process_enabled = false;
67 } 65 }
68 if (this.is_end_process_enabled_ != is_end_process_enabled) { 66 if (this.is_end_process_enabled_ != is_end_process_enabled) {
69 if (is_end_process_enabled) 67 if (is_end_process_enabled)
70 $('kill-process').removeAttribute("disabled"); 68 $('kill-process').removeAttribute("disabled");
71 else 69 else
72 $('kill-process').setAttribute("disabled", "true"); 70 $('kill-process').setAttribute("disabled", "true");
73 71
74 this.is_end_process_enabled_ = is_end_process_enabled; 72 this.is_end_process_enabled_ = is_end_process_enabled;
75 } 73 }
76 }, 74 },
77 75
78 /** 76 /**
79 * Closes taskmanager dialog. 77 * Closes taskmanager dialog.
80 * After this function is called, onClose() will be called. 78 * After this function is called, onClose() will be called.
81 * @public
82 */ 79 */
83 close: function () { 80 close: function () {
84 window.close(); 81 window.close();
85 }, 82 },
86 83
87 /** 84 /**
88 * Sends commands to kill selected processes. 85 * Sends commands to kill selected processes.
89 * @public
90 */ 86 */
91 killSelectedProcesses: function () { 87 killSelectedProcesses: function () {
92 var selectedIndexes = this.selectionModel_.selectedIndexes; 88 var selectedIndexes = this.selectionModel_.selectedIndexes;
93 var dm = this.dataModel_; 89 var dm = this.dataModel_;
94 var uniqueIds = []; 90 var uniqueIds = [];
95 for (var i = 0; i < selectedIndexes.length; i++) { 91 for (var i = 0; i < selectedIndexes.length; i++) {
96 var index = selectedIndexes[i]; 92 var index = selectedIndexes[i];
97 var task = dm.item(index); 93 var task = dm.item(index);
98 uniqueIds.push(task['uniqueId'][0]); 94 uniqueIds.push(task['uniqueId'][0]);
99 } 95 }
100 96
101 chrome.send('killProcesses', uniqueIds); 97 chrome.send('killProcesses', uniqueIds);
102 }, 98 },
103 99
104 /** 100 /**
105 * Sends command to initiate resource inspection. 101 * Sends command to initiate resource inspection.
106 * @public
107 */ 102 */
108 inspect: function (uniqueId) { 103 inspect: function (uniqueId) {
109 chrome.send('inspect', [uniqueId]); 104 chrome.send('inspect', [uniqueId]);
110 }, 105 },
111 106
112 /** 107 /**
113 * Sends command to kill a process. 108 * Sends command to kill a process.
114 * @public
115 */ 109 */
116 openAboutMemory: function () { 110 openAboutMemory: function () {
117 chrome.send('openAboutMemory'); 111 chrome.send('openAboutMemory');
118 }, 112 },
119 113
120 /** 114 /**
121 * Sends command to disable taskmanager model. 115 * Sends command to disable taskmanager model.
122 * @public
123 */ 116 */
124 disableTaskManager: function () { 117 disableTaskManager: function () {
125 chrome.send('disableTaskManager'); 118 chrome.send('disableTaskManager');
126 }, 119 },
127 120
128 /** 121 /**
129 * Sends command to enable taskmanager model. 122 * Sends command to enable taskmanager model.
130 * @public
131 */ 123 */
132 enableTaskManager: function () { 124 enableTaskManager: function () {
133 chrome.send('enableTaskManager'); 125 chrome.send('enableTaskManager');
134 }, 126 },
135 127
136 /** 128 /**
137 * Sends command to activate a page. 129 * Sends command to activate a page.
138 * @public
139 */ 130 */
140 activatePage: function (uniqueId) { 131 activatePage: function (uniqueId) {
141 chrome.send('activatePage', [uniqueId]); 132 chrome.send('activatePage', [uniqueId]);
142 }, 133 },
143 134
144 /** 135 /**
145 * Initializes taskmanager. 136 * Initializes taskmanager.
146 * @public
147 */ 137 */
148 initialize: function (dialogDom, opt) { 138 initialize: function (dialogDom, opt) {
149 if (!dialogDom) { 139 if (!dialogDom) {
150 console.log('ERROR: dialogDom is not defined.'); 140 console.log('ERROR: dialogDom is not defined.');
151 return; 141 return;
152 } 142 }
153 143
144 measureTime.startInterval('Load.DOM');
145
154 this.opt_ = opt; 146 this.opt_ = opt;
155 147
156 this.initialized_ = true; 148 this.initialized_ = true;
157 this.enableTaskManager(); 149 this.enableTaskManager();
158 150
159 this.dialogDom_ = dialogDom; 151 this.dialogDom_ = dialogDom;
160 this.document_ = dialogDom.ownerDocument; 152 this.document_ = dialogDom.ownerDocument;
161 153
162 $('close-window').addEventListener('click', this.close.bind(this));
163 $('kill-process').addEventListener('click',
164 this.killSelectedProcesses.bind(this));
165 $('about-memory-link').addEventListener('click',
166 this.openAboutMemory.bind(this));
167
168 this.is_column_shown_ = []; 154 this.is_column_shown_ = [];
169 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 155 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
170 this.is_column_shown_[i] = DEFAULT_COLUMNS[i][3]; 156 this.is_column_shown_[i] = DEFAULT_COLUMNS[i][3];
171 } 157 }
172 158
173 this.localized_column_ = []; 159 this.localized_column_ = [];
174 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 160 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
175 var column_label_id = DEFAULT_COLUMNS[i][1]; 161 var column_label_id = DEFAULT_COLUMNS[i][1];
176 var localized_label = localStrings.getString(column_label_id); 162 var localized_label = localStrings.getString(column_label_id);
177 // Falls back to raw column_label_id if localized string is not defined. 163 // Falls back to raw column_label_id if localized string is not defined.
178 if (localized_label == "") 164 if (localized_label == "")
179 localized_label = column_label_id; 165 localized_label = column_label_id;
180 166
181 this.localized_column_[i] = localized_label; 167 this.localized_column_[i] = localized_label;
182 } 168 }
183 169
170 this.initElements_();
184 this.initColumnModel_(); 171 this.initColumnModel_();
185 this.selectionModel_ = new cr.ui.ListSelectionModel(); 172 this.selectionModel_ = new cr.ui.ListSelectionModel();
186 this.dataModel_ = new cr.ui.ArrayDataModel([]); 173 this.dataModel_ = new cr.ui.ArrayDataModel([]);
187 174
188 this.selectionModel_.addEventListener('change', 175 this.selectionModel_.addEventListener('change',
189 this.onSelectionChange.bind(this)); 176 this.onSelectionChange.bind(this));
190 177
191 // Initializes compare functions for column sort. 178 // Initializes compare functions for column sort.
192 var dm = this.dataModel_; 179 var dm = this.dataModel_;
193 // Columns to sort by value instead of itself. 180 // Columns to sort by value instead of itself.
(...skipping 11 matching lines...) Expand all
205 var aValues = a[value_id]; 192 var aValues = a[value_id];
206 var bValues = b[value_id]; 193 var bValues = b[value_id];
207 var aValue = aValues && aValues[0] || 0; 194 var aValue = aValues && aValues[0] || 0;
208 var bvalue = bValues && bValues[0] || 0; 195 var bvalue = bValues && bValues[0] || 0;
209 return dm.defaultValuesCompareFunction(aValue, bvalue); 196 return dm.defaultValuesCompareFunction(aValue, bvalue);
210 }; 197 };
211 }(); 198 }();
212 dm.setCompareFunction(column_id, compare_func); 199 dm.setCompareFunction(column_id, compare_func);
213 } 200 }
214 201
215 var ary = this.dialogDom_.querySelectorAll('[visibleif]'); 202 this.initTable_();
216 for (var i = 0; i < ary.length; i++) { 203
217 var expr = ary[i].getAttribute('visibleif'); 204 // Populate the static localized strings.
218 if (!eval(expr)) 205 i18nTemplate.process(this.document_, templateData);
219 ary[i].hidden = true; 206
207 measureTime.recordInterval('Load.DOM');
208 measureTime.recordInterval('Load.Total');
209
210 loadDelayedIncludes(this);
211 },
212
213 /**
214 * Initializes the visibilities and handlers of the elements.
215 * This method is called by initialize().
arv (Not doing code reviews) 2012/01/17 21:47:06 @private
yoshiki 2012/01/18 16:54:29 Done.
216 */
217 initElements_: function() {
218 // <if expr="pp_ifdef('chromeos')">
219 // The elements 'dialog-title' and 'close-window' exist only on ChromeOS.
220 // This <if ... /if> section is removed while flattening HTML if chrome is
221 // built as Desktop Chrome.
222 if (!this.opt_['isShowTitle'])
223 $('dialog-title').style.display = 'none';
224 if (!this.opt_['isShowCloseButton'])
225 $('close-window').style.display = 'none';
226 $('close-window').addEventListener('click', this.close.bind(this));
227 // </if>
228
229 $('kill-process').addEventListener('click',
230 this.killSelectedProcesses.bind(this));
231 $('about-memory-link').addEventListener('click',
232 this.openAboutMemory.bind(this));
233 },
234
235 /**
236 * Additional initialization of taskmanager. This function is called when
237 * the loading of delayed scripts finished.
238 */
239 delayedInitialize: function() {
240 this.initColumnMenu_();
241 this.initTableMenu_();
242
243 var dm = this.dataModel_;
244 for (var i = 0; i < dm.length; i++) {
245 for (var j = 0; j < DEFAULT_COLUMNS.length; j++) {
246 var columnId = DEFAULT_COLUMNS[j][0];
247 var row = dm.item(i)[columnId];
248 for (var k = 0; k < row.length; k++) {
249 var processId = dm.item(i)['processId'][0];
250 var labelId = 'detail-' + columnId + '-pid' + processId + '-' + k;
251 var label = $(labelId);
252
253 // Initialize a context-menu, if the label exists and its context-
254 // menu is not initialized yet.
255 if (label && !label.contextMenu)
256 this.setContextMenu_(label, this.tableContextMenu_);
257 }
258 }
220 } 259 }
221 260
222 this.initTable_(); 261 this.isFinishedInitDelayed_ = true;
223 this.initColumnMenu_();
224 this.initTableMenu_();
225 this.table_.redraw(); 262 this.table_.redraw();
226 }, 263 },
227 264
228 initColumnModel_: function () { 265 initColumnModel_: function () {
229 var table_columns = new Array(); 266 var table_columns = new Array();
230 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 267 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
231 if (!this.is_column_shown_[i]) 268 if (!this.is_column_shown_[i])
232 continue; 269 continue;
233 270
234 var column = DEFAULT_COLUMNS[i]; 271 var column = DEFAULT_COLUMNS[i];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 command.menuitem = item; 304 command.menuitem = item;
268 item.textContent = this.localized_column_[i]; 305 item.textContent = this.localized_column_[i];
269 if (this.is_column_shown_[i]) 306 if (this.is_column_shown_[i])
270 item.setAttributeNode(this.document_.createAttribute("checked")); 307 item.setAttributeNode(this.document_.createAttribute("checked"));
271 this.columnSelectContextMenu_.appendChild(item); 308 this.columnSelectContextMenu_.appendChild(item);
272 } 309 }
273 310
274 this.document_.body.appendChild(this.columnSelectContextMenu_); 311 this.document_.body.appendChild(this.columnSelectContextMenu_);
275 cr.ui.Menu.decorate(this.columnSelectContextMenu_); 312 cr.ui.Menu.decorate(this.columnSelectContextMenu_);
276 313
277 cr.ui.contextMenuHandler.addContextMenuProperty(this.table_.header); 314 this.setContextMenu_(this.table_.header, this.columnSelectContextMenu_);
278 this.table_.header.contextMenu = this.columnSelectContextMenu_; 315 this.setContextMenu_(this.table_.list, this.columnSelectContextMenu_);
279
280 cr.ui.contextMenuHandler.addContextMenuProperty(this.table_.list);
281 this.table_.list.contextMenu = this.columnSelectContextMenu_;
282 316
283 this.document_.addEventListener('command', this.onCommand_.bind(this)); 317 this.document_.addEventListener('command', this.onCommand_.bind(this));
284 this.document_.addEventListener('canExecute', 318 this.document_.addEventListener('canExecute',
285 this.onCommandCanExecute_.bind(this)); 319 this.onCommandCanExecute_.bind(this));
286
287 }, 320 },
288 321
289 initTableMenu_: function () { 322 initTableMenu_: function () {
290 this.table_menu_commands_ = []; 323 this.table_menu_commands_ = [];
291 this.tableContextMenu_ = this.document_.createElement('menu'); 324 this.tableContextMenu_ = this.document_.createElement('menu');
292 325
293 var addMenuItem = function (tm, command_id, string_id, default_label) { 326 var addMenuItem = function (tm, command_id, string_id, default_label) {
294 // Creates command element to receive event. 327 // Creates command element to receive event.
295 var command = tm.document_.createElement('command'); 328 var command = tm.document_.createElement('command');
296 command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + '-' + command_id; 329 command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + '-' + command_id;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 cell.appendChild( 386 cell.appendChild(
354 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table)); 387 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table));
355 388
356 listItem.appendChild(cell); 389 listItem.appendChild(cell);
357 } 390 }
358 listItem.data = dataItem; 391 listItem.data = dataItem;
359 392
360 return listItem; 393 return listItem;
361 }, 394 },
362 395
396 setContextMenu_: function(element, contextMenuElement) {
arv (Not doing code reviews) 2012/01/17 21:47:06 I've said this before but this is too hacky. How a
yoshiki 2012/01/18 16:54:29 Thanks. Added cr.ui.contextMenuHandler.setContextM
397 if (!element.contextMenu) {
398 cr.ui.contextMenuHandler.addContextMenuProperty(element);
399 element.contextMenu = contextMenuElement;
400 }
401 },
402
363 renderColumn_: function(entry, columnId, table) { 403 renderColumn_: function(entry, columnId, table) {
364 var container = this.document_.createElement('div'); 404 var container = this.document_.createElement('div');
365 container.className = 'detail-container-' + columnId; 405 container.className = 'detail-container-' + columnId;
366 406
367 if (entry && entry[columnId]) { 407 if (entry && entry[columnId]) {
368 container.id = 'detail-container-' + columnId + '-pid' + entry.processId; 408 container.id = 'detail-container-' + columnId + '-pid' + entry.processId;
369 409
370 for (var i = 0; i < entry[columnId].length; i++) { 410 for (var i = 0; i < entry[columnId].length; i++) {
371 var label = document.createElement('div'); 411 var label = document.createElement('div');
372 if (columnId == 'title') { 412 if (columnId == 'title') {
373 var image = this.document_.createElement('img'); 413 var image = this.document_.createElement('img');
374 image.className = 'detail-title-image'; 414 image.className = 'detail-title-image';
375 image.src = entry['icon'][i]; 415 image.src = entry['icon'][i];
376 label.appendChild(image); 416 label.appendChild(image);
377 var text = this.document_.createElement('div'); 417 var text = this.document_.createElement('div');
378 text.className = 'detail-title-text'; 418 text.className = 'detail-title-text';
379 text.textContent = entry['title'][i]; 419 text.textContent = entry['title'][i];
380 label.appendChild(text); 420 label.appendChild(text);
381 421
382 cr.ui.contextMenuHandler.addContextMenuProperty(label); 422 // Chech if the delayed scripts (included in includes.js) have been
383 label.contextMenu = this.tableContextMenu_; 423 // loaded or not. If the delayed scripts ware not loaded yet, a
424 // context menu could not be initialized. In such case, it will be
425 // initialized at delayedInitialize() just after loading of delayed
426 // scripts instead of here.
427 if (this.isFinishedInitDelayed_)
428 this.setContextMenu_(label, this.tableContextMenu_);
arv (Not doing code reviews) 2012/01/17 21:47:06 ... something like: cr.ui.contextMenuHandler.setC
yoshiki 2012/01/18 16:54:29 Done.
384 429
385 label.addEventListener('dblclick', (function(uniqueId) { 430 label.addEventListener('dblclick', (function(uniqueId) {
386 this.activatePage(uniqueId); 431 this.activatePage(uniqueId);
387 }).bind(this, entry['uniqueId'][i])); 432 }).bind(this, entry['uniqueId'][i]));
388 433
389 label.data = entry; 434 label.data = entry;
390 label.index_in_group = i; 435 label.index_in_group = i;
391 } else { 436 } else {
392 label.textContent = entry[columnId][i]; 437 label.textContent = entry[columnId][i];
393 } 438 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 515
471 onCommandCanExecute_: function(event) { 516 onCommandCanExecute_: function(event) {
472 event.canExecute = true; 517 event.canExecute = true;
473 }, 518 },
474 519
475 /** 520 /**
476 * Store resourceIndex of target resource of context menu, because resource 521 * Store resourceIndex of target resource of context menu, because resource
477 * will be replaced when it is refleshed. 522 * will be replaced when it is refleshed.
478 */ 523 */
479 onTableContextMenuOpened_: function (e) { 524 onTableContextMenuOpened_: function (e) {
525 if (!this.isFinishedInitDelayed_)
526 return;
527
480 var mc = this.table_menu_commands_; 528 var mc = this.table_menu_commands_;
481 var inspect_menuitem = 529 var inspect_menuitem =
482 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-inspect'].menuitem; 530 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-inspect'].menuitem;
483 var activate_menuitem = 531 var activate_menuitem =
484 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-activate'].menuitem; 532 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-activate'].menuitem;
485 533
486 // Disabled by default. 534 // Disabled by default.
487 inspect_menuitem.disabled = true; 535 inspect_menuitem.disabled = true;
488 activate_menuitem.disabled = true; 536 activate_menuitem.disabled = true;
489 537
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 return; 625 return;
578 taskmanager.onTaskChange(start, length, tasks); 626 taskmanager.onTaskChange(start, length, tasks);
579 } 627 }
580 628
581 function taskRemoved(start, length) { 629 function taskRemoved(start, length) {
582 // Sometimes this can get called too early. 630 // Sometimes this can get called too early.
583 if (!taskmanager) 631 if (!taskmanager)
584 return; 632 return;
585 taskmanager.onTaskRemove(start, length); 633 taskmanager.onTaskRemove(start, length);
586 } 634 }
587
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698